Jump to content

Overview Middleware4j

From Commander4j
Revision as of 21:47, 9 November 2026 by Dgarratt (talk | contribs) (Updated by push_wiki.py)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Middleware4j converts files from one format to another and delivers the result where it is needed. It was written as a companion to Commander4j, but it has no dependency on it and can be used on its own for any file based integration.

A typical use is linking Commander4j to an ERP system: a material master arrives from SAP as an IDOC and is turned into the XML that Commander4j imports, or a Commander4j production declaration is turned into the CSV file that Sage expects.

The idea in one picture

Everything Middleware4j does is described by a map. A map has three parts, and data always flows through them in the same order.

   file arrives                                                      result is
   in a folder                                                       delivered
        |                                                                ^
        v                                                                |
 +-----------------+        +-----------------+        +--------------------------+
 | INPUT CONNECTOR |        |       MAP       |        |   OUTPUT CONNECTOR(S)    |
 |                 |  XML   |     (XSLT)      |  XML   |                          |
 | native format   | -----> | rearranges the  | -----> | XML to the target format |
 | to XML          |        | XML             |        | one or many per map      |
 +-----------------+        +-----------------+        +--------------------------+
   CSV, fixed width,          your stylesheet            CSV, fixed width, XML,
   XML, IDOC, Excel                                      Excel, socket, MQTT
  1. The input connector watches a folder. When a file arrives it reads it and converts it into XML. A CSV file, for example, becomes a list of rows and columns written as XML.
  2. The map is an XSLT stylesheet. It receives the XML from the input connector and rearranges it into the XML that the output connector needs.
  3. The output connector takes that XML and writes it in the target format: a CSV file, a fixed width text file, an XML file, a spreadsheet, or data sent to a network device.

Two rules are worth remembering:

  • A map has exactly one input connector, so one input format.
  • A map can have several output connectors. One incoming file can produce a CSV file for one system and an XML file for another at the same time.

The stylesheet never writes CSV or text itself. It always writes XML, in the layout the chosen output connector expects, and the connector does the final conversion. Those layouts are listed on the Connectors page, and Creating a Map walks through building a map from start to finish.

What you edit

There is no configuration screen. A map is made from two kinds of text file:

File Where What it holds
config.xml xml/config The list of maps: which folder to watch, which connector types to use, where to write the results. See Maps.
A stylesheet (.xsl) xslt The transformation for one map. See Creating a Map and XSLT Extension Functions.

Middleware4j reads config.xml when it starts, so restart it after changing a map.

Supported formats

The Type column is the value used in config.xml.

Format Type Input Output
ASCII fixed column text files ASCII Yes Yes
CSV delimited text files CSV Yes Yes
XML documents XML Yes Yes
IDOC SAP flat file IDOCs IDOC Yes No
Excel spreadsheets XLS for input, EXCEL for output Yes Yes
SOCKET send to a TCP/IP device SOCKET No Yes
MQTT publish to an MQTT broker MQTT No Yes

Three more connector types move a file without converting it. Each is used as a matched pair, with the same type on the input and the output, and no stylesheet is involved.

Purpose Type
RAW copy or move a file to one or more folders RAW
EMAIL send a file as an email attachment EMAIL
PDF_PRINT print a PDF file on a named printer PDF_PRINT

The transformation engine

Stylesheets are run by Saxon-HE 12, which supports XSLT 2.0 and 3.0. Middleware4j adds its own extension functions for padding, trimming and date conversion, and stylesheets can look up values from reference data files held next to them.

The installation includes two sets of samples:

  • samples/basic holds fourteen small maps, Map01 to Map14, covering each connector type. These are the maps in the config.xml that is installed, so they are ready to try as soon as the program is started.
  • samples/advanced holds over fifty maps and their stylesheets, taken from real integrations between Commander4j and SAP, Sage, Tropos and B2MML (S95) systems. They are the best starting point for a new map of your own.

Running Middleware4j

Mode Description
Service Runs in the background with no user interface. This is the normal way to run in production. See Installation Middleware4j.
Desktop Opens a window listing the maps, their folders and a running count of files in and out. Useful while building and testing a map. See Middleware Example Screen.

Every map runs independently, each checking its own input folder at its own interval.

Keeping an eye on it

  • Every file received, and every stage of its conversion, is copied to interface/log. See Seeing what happened.
  • Problems are reported by email to the Error distribution list, and a daily count of files processed is sent to the Monitor list. See EMAIL.

See also: Maps, Connectors, Creating a Map, Middleware4j Example Configuration, Installation Middleware4j