Jump to content

Middleware4j Example Configuration

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 is mainly a background service with no user interface. You can run it on the desktop and see a status display listing the maps and the number of files each has processed, but the configuration itself is done in XML and XSL files.

This page shows the complete set of files needed for one simple conversion, and explains each part. The example takes a fixed column text file, picks out two of its columns, joins them together and writes the result to an XML document. It is Map02 from the sample configuration that is installed with the program, so you can run it yourself.

For a step by step guide to building a map of your own, see Creating a Map.

Configuration

The file config.xml is found in the xml/config folder below the installation folder. This example contains only one map, but there is no limit, and one copy of the program can run many maps at the same time.

config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
   <version>3</version>
   <description>c4jMiddleware Example</description>
   <logPath/>
   <XSLTPath/>
   <logArchiveRetentionDays>3</logArchiveRetentionDays>
   <retryOpenFileCount>3</retryOpenFileCount>
   <retryOpenFileDelay>1000</retryOpenFileDelay>
   <enableEmailNotifications>true</enableEmailNotifications>
   <statusReportTime>09:00:00</statusReportTime>
   <maps>
      <map>
         <id>Map02</id>
         <enabled>true</enabled>
         <description>ASCII File Fixed Column to XML</description>
         <enableEmailNotifications>true</enableEmailNotifications>
         <connectors>
            <input>
               <id>in1</id>
               <description>Read ASCII Flat File</description>
               <type>ASCII</type>
               <url>
                  <path>./interface/input/Map02 ASCII to XML</path>
                  <mask/>
                  <prefix/>
                  <pollingInterval>1000</pollingInterval>
               </url>
               <xsl>
                  <XSLTPath/>
                  <XSLT>Map02_ASCII_to_XML.xsl</XSLT>
               </xsl>
               <ascii>
                  <pattern>1-4,18-21</pattern>
               </ascii>
            </input>
            <output>
               <id>out1</id>
               <enabled>true</enabled>
               <description>Write XML</description>
               <type>XML</type>
               <url>
                  <path>./interface/output/Map02 ASCII to XML</path>
                  <prefix/>
                  <fileExtension/>
                  <use83GUID>false</use83GUID>
                  <retainOriginalFilename>false</retainOriginalFilename>
               </url>
            </output>
         </connectors>
      </map>
   </maps>
</config>

The tables below describe the settings used in this example. The full list is on the Maps page.

Element Value Description
logPath Blank or path Where the copies of each file and conversion stage are saved. Leave blank for the default, interface/log.
XSLTPath Blank or path Where the XSLT style sheets are kept. Leave blank for the default, xslt.
logArchiveRetentionDays nnn Number of days to keep files in the log folder before they are deleted automatically.
retryOpenFileCount nnn How many times the program tries to gain access to an input file before reporting an error.
retryOpenFileDelay nnnn How long to wait before retrying a file operation, in milliseconds.
enableEmailNotifications true or false Enable or disable email notifications. See EMAIL.
statusReportTime HH:MM:SS Time of day (UTC) at which the daily statistics email is sent.

Map

Element Value Description
id id A short unique name for the map.
enabled true or false A simple way to switch a map off without deleting it. Middleware4j must be restarted after changing it.
description string Description of what the map does.

Input Connector

Element Value Description
id id A map can have only one input but several outputs. in1 is suggested for the input id.
description string Meaningful description of the input.
type ASCII In this example the input type is ASCII, a fixed column text file.
path string Path to the input folder. It can be a network share, provided Middleware4j has permission to use it.
mask Blank or ext File extension used to select files for processing. If blank, each type uses its own default; for ASCII that is txt.
pollingInterval nnnn How often to check for input files, in milliseconds.
XSLT string File name of the style sheet to use. Only the file name; the folder is taken from XSLTPath. It can be left out when no transformation is needed.
pattern nn-nn,nn-nn Only used by the ASCII type. A list of column start and end positions. This example defines two columns.

Output Connector

Element Value Description
id id A map can have more than one output and each must have a unique id.
enabled true or false An output is only used when this is true.
description string Meaningful description of the output.
type XML In this example the output type is XML.
path string Path to the output folder. It can be a network share, provided Middleware4j has permission to use it.

XSLT Style Sheet

Map02_ASCII_to_XML.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">
    <xsl:output encoding="UTF-8" indent='yes' method="xml" />
    <xsl:template match='data'>
        <test>
            <xsl:apply-templates select="row"/>
        </test>
    </xsl:template>
    <xsl:template match='row'>
            <barcode><xsl:value-of select='col[1]'/>-<xsl:value-of select='col[2]'/></barcode>
    </xsl:template>
</xsl:stylesheet>

This is the style sheet that defines how the output is written. Middleware4j does the first part of the work: the ASCII input connector reads the text file and represents it as XML. The style sheet is then applied to that XML to produce the output.

<xsl:template match='data'>

This line selects the XML made by the input connector, whose top element is called data.

<test>
     <xsl:apply-templates select="row"/>
</test>

This creates the root element of the output, which we are calling test, and then calls a template for each input row.

<xsl:template match='row'>
     <barcode><xsl:value-of select='col[1]'/>-<xsl:value-of select='col[2]'/></barcode>
</xsl:template>

The input connector was told to read two columns from the file by the <pattern> setting. This statement joins the values of those two columns with a - between them. As only two columns were read, they are referred to as col[1] and col[2].

Example Input

1232     ABCB    5676    EFGF
1233     ABCC    5677    EFGG
1234     ABCD    5678    EFGH
1235     ABCE    5679    EFGI
1236     ABCF    5680    EFGJ
1237     ABCG    5681    EFGK
1238     ABCH    5682    EFGL
1239     ABCI    5683    EFGM
1240     ABCJ    5684    EFGN
1241     ABCK    5685    EFGO

This input file has no meaning other than to show how Middleware4j works. It has four columns of data. We want the two that hold numbers, the first and the third, which are at character positions 1 to 4 and 18 to 21. That is what the pattern 1-4,18-21 says.

Example Output

<?xml version="1.0" encoding="UTF-8"?>
<test>
  <barcode>1232-5676</barcode>
  <barcode>1233-5677</barcode>
  <barcode>1234-5678</barcode>
  <barcode>1235-5679</barcode>
  <barcode>1236-5680</barcode>
  <barcode>1237-5681</barcode>
  <barcode>1238-5682</barcode>
  <barcode>1239-5683</barcode>
  <barcode>1240-5684</barcode>
  <barcode>1241-5685</barcode>
</test>

The first and third columns of the text file have been extracted and joined with a - between them. There are many more connector types than ASCII and XML, and both the input and the output type can be changed.

Logs and Debug information

When a file is processed, copies of each stage are saved in the interface/log folder. The file names are made up of the date and time, the stage, the map id, the connector id, the connector type and the original file name.

20240409184646700_INPUT_BACKUP_Map02_in1_ASCII_GEN ASCII File Fixed Column 1.txt
20240409184646716_XSLT_INPUT_Map02_in1_ASCII_GEN ASCII File Fixed Column 1.txt.xml
20240409184646757_XSLT_OUTPUT_Map02_in1_ASCII_GEN ASCII File Fixed Column 1.txt.xml
File name contains Content
_INPUT_BACKUP_ An unmodified copy of the original input file.
_XSLT_INPUT_ The intermediate stage, in which the text file has been converted into XML. This is the input to the style sheet.
_XSLT_OUTPUT_ The result of the style sheet, which is passed to the output connector.

These files are the best tool for working out why a map is not producing what you expect. See Seeing what happened.

Intermediate Stage

20240409184646716_XSLT_INPUT_Map02_in1_ASCII_GEN ASCII File Fixed Column 1.txt.xml

<?xml version="1.0" encoding="UTF-8"?>
<data cols="2" filename="GEN ASCII File Fixed Column 1.txt" rows="10" type="ASCII">
   <row cols="2" id="1">
       <col id="1">1232</col>
       <col id="2">5676</col>
   </row>
   <row cols="2" id="2">
       <col id="1">1233</col>
       <col id="2">5677</col>
   </row>
   <row cols="2" id="3">
       <col id="1">1234</col>
       <col id="2">5678</col>
   </row>
   <row cols="2" id="4">
       <col id="1">1235</col>
       <col id="2">5679</col>
   </row>
   <row cols="2" id="5">
       <col id="1">1236</col>
       <col id="2">5680</col>
   </row>
   <row cols="2" id="6">
       <col id="1">1237</col>
       <col id="2">5681</col>
   </row>
   <row cols="2" id="7">
       <col id="1">1238</col>
       <col id="2">5682</col>
   </row>
   <row cols="2" id="8">
       <col id="1">1239</col>
       <col id="2">5683</col>
   </row>
   <row cols="2" id="9">
       <col id="1">1240</col>
       <col id="2">5684</col>
   </row>
   <row cols="2" id="10">
       <col id="1">1241</col>
       <col id="2">5685</col>
   </row>
</data>

Email

Errors and a daily summary are reported by email. The mail server and the lists of recipients are set up in xml/config/email.xml, which is described on the EMAIL page.

See also: Creating a Map, Maps, Connectors, ASCII