Middleware4j Example Configuration: Difference between revisions
Updated by push_wiki.py |
|||
| Line 1: | Line 1: | ||
[[ | [[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 <code>config.xml</code> is found in the <code>xml/config</code> 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''' | '''config.xml''' | ||
<syntaxhighlight lang="xml"> | <syntaxhighlight lang="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> | |||
</syntaxhighlight> | </syntaxhighlight> | ||
The tables below describe the settings used in this example. The full list is on the [[Maps]] page. | |||
===Header=== | ===Header=== | ||
| Line 43: | Line 73: | ||
! Element !! Value !! Description | ! Element !! Value !! Description | ||
|- | |- | ||
| style="width: 150px"| | | style="width: 150px"|logPath || style="width: 90px"|Blank or path || Where the copies of each file and conversion stage are saved. Leave blank for the default, <code>interface/log</code>. | ||
|- | |- | ||
| XSLTPath || Blank or | | XSLTPath || Blank or path || Where the XSLT style sheets are kept. Leave blank for the default, <code>xslt</code>. | ||
|- | |- | ||
| logArchiveRetentionDays || nnn || Number of days to keep log | | logArchiveRetentionDays || nnn || Number of days to keep files in the log folder before they are deleted automatically. | ||
|- | |- | ||
| retryOpenFileCount || nnn || How many times | | 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. | | retryOpenFileDelay || nnnn || How long to wait before retrying a file operation, in milliseconds. | ||
|- | |- | ||
| enableEmailNotifications || true or false || Enable or disable email notifications. | | 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=== | ===Map=== | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
! Element !! Value !! Description | ! Element !! Value !! Description | ||
|- | |- | ||
| style="width: 150px"|id || style="width: 90px"|id || | | style="width: 150px"|id || style="width: 90px"|id || A short unique name for the map. | ||
|- | |- | ||
| enabled || | | 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. | | description || string || Description of what the map does. | ||
| Line 73: | Line 105: | ||
! Element !! Value !! Description | ! Element !! Value !! Description | ||
|- | |- | ||
| style="width: 150px"|id || style="width: 90px"|id || | | style="width: 150px"|id || style="width: 90px"|id || A map can have only one input but several outputs. <code>in1</code> is suggested for the input id. | ||
|- | |- | ||
| description || string || | | description || string || Meaningful description of the input. | ||
|- | |- | ||
| type || ASCII || In this example | | type || ASCII || In this example the input type is ASCII, a fixed column text file. | ||
|- | |- | ||
| path || string || Path to input folder. | | path || string || Path to the input folder. It can be a network share, provided Middleware4j has permission to use it. | ||
|- | |- | ||
| mask || | | mask || Blank or ext || File extension used to select files for processing. If blank, each type uses its own default; for ASCII that is <code>txt</code>. | ||
|- | |- | ||
| | | 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 <code>XSLTPath</code>. 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. | ||
|} | |} | ||
| Line 95: | Line 127: | ||
! Element !! Value !! Description | ! Element !! Value !! Description | ||
|- | |- | ||
| style="width: 150px"|id || style="width: 90px"|id || A map can have more than one output and each | | style="width: 150px"|id || style="width: 90px"|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 <code>true</code>. | ||
|- | |- | ||
| | | description || string || Meaningful description of the output. | ||
|- | |- | ||
| type || | | 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== | ==XSLT Style Sheet== | ||
''' | '''Map02_ASCII_to_XML.xsl''' | ||
<syntaxhighlight lang="xml"> | <syntaxhighlight lang="xml"> | ||
<?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" | xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||
exclude-result-prefixes="xs" | exclude-result-prefixes="xs" | ||
| Line 121: | Line 153: | ||
</xsl:template> | </xsl:template> | ||
<xsl:template match='row'> | <xsl:template match='row'> | ||
<barcode><xsl:value-of select='col[1]'/>-<xsl:value-of select='col[2]'/></barcode> | <barcode><xsl:value-of select='col[1]'/>-<xsl:value-of select='col[2]'/></barcode> | ||
</xsl:template> | </xsl:template> | ||
</xsl:stylesheet> | |||
</syntaxhighlight> | </syntaxhighlight> | ||
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. | |||
<syntaxhighlight lang="xml"> | <syntaxhighlight lang="xml"> | ||
<xsl:template match='data'> | |||
</syntaxhighlight> | </syntaxhighlight> | ||
This line | This line selects the XML made by the input connector, whose top element is called <code>data</code>. | ||
<syntaxhighlight lang="xml"> | <syntaxhighlight lang="xml"> | ||
<test> | |||
<xsl:apply-templates select="row"/> | |||
</test> | |||
</syntaxhighlight> | </syntaxhighlight> | ||
This creates the root element of the output which we are | This creates the root element of the output, which we are calling <code>test</code>, and then calls a template for each input row. | ||
<syntaxhighlight lang="xml"> | <syntaxhighlight lang="xml"> | ||
<xsl:template match='row'> | |||
<barcode><xsl:value-of select='col[1]'/>-<xsl:value-of select='col[2]'/></barcode> | |||
</xsl:template> | |||
</syntaxhighlight> | </syntaxhighlight> | ||
The input connector was told to read two columns from the file by the <code><pattern></code> setting. This statement joins the values of those two columns with a <code>-</code> between them. As only two columns were read, they are referred to as <code>col[1]</code> and <code>col[2]</code>. | |||
This statement | |||
==Example Input== | ==Example Input== | ||
<syntaxhighlight lang="Plaintext"> | <syntaxhighlight lang="Plaintext"> | ||
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 | |||
</syntaxhighlight> | </syntaxhighlight> | ||
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 <code>1-4,18-21</code> says. | |||
==Example Output== | ==Example Output== | ||
<syntaxhighlight lang="xml"> | <syntaxhighlight lang="xml"> | ||
<?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> | |||
</syntaxhighlight> | </syntaxhighlight> | ||
The | The first and third columns of the text file have been extracted and joined with a <code>-</code> between them. There are many more [[Connectors|connector types]] than ASCII and XML, and both the input and the output type can be changed. | ||
==Logs and Debug information== | ==Logs and Debug information== | ||
When a file is processed | When a file is processed, copies of each stage are saved in the <code>interface/log</code> 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 | |||
{| class="wikitable" | |||
|- | |||
! File name contains !! Content | |||
|- | |||
| <code>_INPUT_BACKUP_</code> || An unmodified copy of the original input file. | |||
|- | |||
| <code>_XSLT_INPUT_</code> || The intermediate stage, in which the text file has been converted into XML. This is the input to the style sheet. | |||
|- | |||
| <code>_XSLT_OUTPUT_</code> || 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 [[Creating a Map#Seeing what happened|Seeing what happened]]. | |||
==Intermediate Stage== | ==Intermediate Stage== | ||
'''20240409184646716_XSLT_INPUT_Map02_in1_ASCII_GEN ASCII File Fixed Column 1.txt.xml''' | |||
<syntaxhighlight lang="xml"> | <syntaxhighlight lang="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> | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==Email== | |||
Errors and a daily summary are reported by email. The mail server and the lists of recipients are set up in <code>xml/config/email.xml</code>, which is described on the [[EMAIL]] page. | |||
See also: [[Creating a Map]], [[Maps]], [[Connectors]], [[ASCII]] | |||
[[Category:Middleware4j]] | |||
Latest revision as of 21:47, 9 November 2026
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.
Header
| 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>
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