Jump to content

Overview Middleware4j: Difference between revisions

From Commander4j
Updated by push_wiki.py
Updated by push_wiki.py
 
Line 1: Line 1:
Middleware4j is a file-based message transformation and routing engine. It was originally developed as a companion component to [[Commander4j]], but has no dependencies on it and can be used as a standalone middleware solution for any system integration requirement.
'''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.


== Purpose ==
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.


Many manufacturing and logistics sites need to exchange data between systems that use incompatible file formats — for example, sending production output data from Commander4j to an ERP system that expects CSV or fixed-column ASCII files, or receiving process orders from SAP in IDOC format and converting them to Commander4j's XML format. Middleware4j handles these conversions automatically, running continuously in the background as a service.
== The idea in one picture ==


== How It Works ==
Everything Middleware4j does is described by a '''[[Maps|map]]'''. A map has three parts, and data always flows through them in the same order.


Middleware4j monitors a set of input directories for incoming files. When a file arrives, it is read by the appropriate '''connector''', converted to an internal XML representation, optionally transformed by an XSLT stylesheet, and then written to one or more output destinations by one or more output connectors.
<pre>
  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
</pre>


This pipeline is defined by a '''[[Maps|Map]]''' — a configuration block that specifies:
# 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.
* One input connector (how to read the incoming file)
# 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.
* One or more output connectors (where to send the result and in what format)
# 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.
* Optional XSLT stylesheets for transforming the data
* Optional conditions for routing to different outputs based on message content


Multiple maps run simultaneously in background threads, each independently monitoring its own input directory.
Two rules are worth remembering:


== Supported Formats ==
* 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:


{| class="wikitable"
{| class="wikitable"
|-
|-
! Format !! Input !! Output
! File !! Where !! What it holds
|-
|-
| [[ASCII]] — fixed-column flat files || ✓ || ✓
| <code>config.xml</code> || <code>xml/config</code> || The list of maps: which folder to watch, which connector types to use, where to write the results. See [[Maps]].
|-
|-
| [[CSV]] — delimited text files || ✓ || ✓
| A stylesheet (<code>.xsl</code>) || <code>xslt</code> || The transformation for one map. See [[Creating a Map]] and [[XSLT Extension Functions]].
|}
 
Middleware4j reads <code>config.xml</code> when it starts, so restart it after changing a map.
 
== Supported formats ==
 
The '''Type''' column is the value used in <code>config.xml</code>.
 
{| class="wikitable"
|-
|-
| [[XML]] — structured XML documents || ✓ || ✓
! Format !! Type !! Input !! Output
|-
|-
| IDOC — SAP IDOC format || ✓ || ✓
| [[ASCII]] fixed column text files || <code>ASCII</code> || Yes || Yes
|-
|-
| Excel — XLS/XLSX spreadsheets || ✓ || ✓
| [[CSV]] delimited text files || <code>CSV</code> || Yes || Yes
|-
|-
| [[EMAIL]] — email with attachments || ✓ || ✓
| [[XML]] documents || <code>XML</code> || Yes || Yes
|-
| [[IDOC]] SAP flat file IDOCs || <code>IDOC</code> || Yes || No
|-
| [[EXCEL|Excel]] spreadsheets || <code>XLS</code> for input, <code>EXCEL</code> for output || Yes || Yes
|-
| [[SOCKET]] send to a TCP/IP device || <code>SOCKET</code> || No || Yes
|-
| [[MQTT]] publish to an MQTT broker || <code>MQTT</code> || 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.
 
{| class="wikitable"
|-
|-
| [[RAW]] — unmodified file copy || ✓ || ✓
! Purpose !! Type
|-
|-
| [[PDF_PRINT]] — print PDF to a named print queue || ✓ || ✓
| [[RAW]] copy or move a file to one or more folders || <code>RAW</code>
|-
|-
| [[SOCKET]] — TCP/IP socket transmission || || ✓
| [[EMAIL]] send a file as an email attachment || <code>EMAIL</code>
|-
|-
| MQTT — publish to an MQTT broker || || ✓
| [[PDF PRINT|PDF_PRINT]] print a PDF file on a named printer || <code>PDF_PRINT</code>
|}
|}


== XSLT Transformation ==
== The transformation engine ==


The transformation engine is built on '''Saxon 12''' (XSLT 2.0). Stylesheets can use standard XPath 2.0 expressions as well as a set of custom Middleware4j extension functions for string manipulation, date formatting, and reading from external reference data files.
Stylesheets are run by '''Saxon-HE 12''', which supports XSLT 2.0 and 3.0. Middleware4j adds its own [[XSLT Extension Functions|extension functions]] for padding, trimming and date conversion, and stylesheets can look up values from reference data files held next to them.


Over 60 sample XSLT stylesheets are included covering real-world integration scenarios between Commander4j and common ERP and MES systems (SAP, Sage, Tropos, B2MML S95, and others).
The installation includes two sets of samples:


== Deployment Modes ==
* <code>samples/basic</code> holds fourteen small maps, Map01 to Map14, covering each connector type. These are the maps in the <code>config.xml</code> that is installed, so they are ready to try as soon as the program is started.
* <code>samples/advanced</code> 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.


Middleware4j can be run in two modes:
== Running Middleware4j ==


{| class="wikitable"
{| class="wikitable"
Line 58: Line 99:
! Mode !! Description
! Mode !! Description
|-
|-
| '''Service''' || Runs as a background daemon (or Windows service) with no user interface. This is the normal production deployment.
| '''Service''' || Runs in the background with no user interface. This is the normal way to run in production. See [[Installation Middleware4j]].
|-
|-
| '''GUI''' || Launches a desktop window showing configured maps and real-time message counts. Useful for testing and monitoring.
| '''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]].
|}
|}


See [[Installation Middleware4j]] for how to deploy as a Windows service.
Every map runs independently, each checking its own input folder at its own interval.


== Relationship to Commander4j ==
== Keeping an eye on it ==


Middleware4j processes Commander4j's outbound XML messages (such as Production Declarations, Despatch Advice, and Equipment Tracking events) and converts them into whatever format an external system requires. It also handles inbound flows — receiving data from external systems (material masters, process orders, pallet status changes) in their native format and converting them to Commander4j's XML interface format for import.
* Every file received, and every stage of its conversion, is copied to <code>interface/log</code>. See [[Creating a Map#Seeing what happened|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]], [[Middleware4j Example Configuration]], [[Installation Middleware4j]]
See also: [[Maps]], [[Connectors]], [[Creating a Map]], [[Middleware4j Example Configuration]], [[Installation Middleware4j]]


[[Category:Middleware4j]]
[[Category:Middleware4j]]

Latest revision as of 21:47, 9 November 2026

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