Jump to content

Middleware4j Example Configuration: Difference between revisions

From Commander4j
Updated by push_wiki.py
 
Line 1: Line 1:
[[Category:Middleware4j]]
[[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.
The middlware application is predominatly a backgroud service which does not have a user interface. You can run the application and see a status display showing the names of the maps and the number of messages processed - but the actual configuration is done via 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.


This page will show the basic set of files required to perform a simple message transformation. In this example we will take a flat ascii text file and parse it so that 2 of the columns of date are combined and put into an xml document.
For a step by step guide to building a map of your own, see [[Creating a Map]].


The config.xml file shown below is found in the <install folder>/xml folder. This example contains only 1 map (transformation) but there is no limit and you can configure a single instance of the program to perform multiple operations which run concurrenly in different background tasks (threads).
==Configuration==


Although this example converts from plain text to xml there are many other options which will be covered elsewhere in the wiki.
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.


==Configuration==
'''config.xml'''
'''config.xml'''
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<config description="c4jMiddleware Example">
<config>
    <logPath/>
  <version>3</version>
    <XSLTPath/>
  <description>c4jMiddleware Example</description>
    <logArchiveRetentionDays>3</logArchiveRetentionDays>
  <logPath/>
    <retryOpenFileCount>3</retryOpenFileCount>
  <XSLTPath/>
    <retryOpenFileDelay>1000</retryOpenFileDelay>
  <logArchiveRetentionDays>3</logArchiveRetentionDays>
    <enableEmailNotifications>true</enableEmailNotifications>
  <retryOpenFileCount>3</retryOpenFileCount>
    <statusReportTime>09:00:00</statusReportTime>
  <retryOpenFileDelay>1000</retryOpenFileDelay>
    <map id="demo01" enabled="Y" description="GEN ASCII File Fixed Column to XML">
  <enableEmailNotifications>true</enableEmailNotifications>
        <input id="in1" description="Read ASCII Flat File">
  <statusReportTime>09:00:00</statusReportTime>
            <type>ASCII</type>
  <maps>
            <path>./interface/input/demo01 (GEN ASCII File Fixed Column)</path>
      <map>
            <mask>txt</mask>
        <id>Map02</id>
            <inputPattern>1-4,18-21</inputPattern>
        <enabled>true</enabled>
            <pollingInterval>1000</pollingInterval>
        <description>ASCII File Fixed Column to XML</description>
            <XSLT>ASCII_to_XML_Example.xsl</XSLT>
        <enableEmailNotifications>true</enableEmailNotifications>
        </input>
        <connectors>
        <output id="out1" enabled="Y" description="Write XML">
            <input>
            <path>./interface/output/demo01 (GEN XML)</path>
              <id>in1</id>
            <type>XML</type>
              <description>Read ASCII Flat File</description>
             <XSLT/>
              <type>ASCII</type>
        </output>
              <url>
    </map>
                  <path>./interface/input/Map02 ASCII to XML</path>
</config>
                  <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"|logpath || style="width: 90px"|Blank or Path || Specifies where log files are saved - leave blank for default.  
| 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 Path || Specified where XSTL (Style Sheets) used for xml transformations are located.  
| 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 files before automatically deleting them.  
| logArchiveRetentionDays || nnn || Number of days to keep files in the log folder before they are deleted automatically.
|-
|-
| retryOpenFileCount || nnn || How many times should the program attempt to gain exclusive access to a file before returning an error.  
| 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. Refer to [[EMAIL Connector]]
| 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 || Simple ID which you want to use for the Map.  
| style="width: 150px"|id || style="width: 90px"|id || A short unique name for the map.
|-
|-
| enabled || Y or N || Simple way to enable or disable a map without having to delete it. Middleware needs to be restarted after changing.
| 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 || Any single map can only have 1 input but multiple outputs. Suggest 'in1' for input 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 || Meaningfull description of what the input is.  
| description || string || Meaningful description of the input.
|-
|-
| type || ASCII || In this example we define the input type to be ASCII aka Flat File.  
| type || ASCII || In this example the input type is ASCII, a fixed column text file.
|-
|-
| path || string || Path to input folder. Can be a network share providing middleware has permissions.
| path || string || Path to the input folder. It can be a network share, provided Middleware4j has permission to use it.
|-
|-
| mask || txt || File extension used to filter files for processing. If blank each type will use a default 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>.
|-
|-
| inputPattern || nn-nn,nn-nn || This setting is only appropriate for the ASCII type. It consists of column start and stop positions. This example defines 2 columns.
| pollingInterval || nnnn || How often to check for input files, in milliseconds.
|-
|-
| pollingInterval || nnnn || Frequency in milliseconds to check for input files.  
| 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.
|-
|-
| XLST || string || Filename of the Style Sheet to use. Only the filename. Path will default. In some scenarios this can be blank.
| 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 output must have a unique id.
| style="width: 150px"|id || style="width: 90px"|id || A map can have more than one output and each must have a unique id.
|-
|-
| description || string || Meaningfull description of what the output is.
| enabled || true or false || An output is only used when this is <code>true</code>.
|-
|-
| path || string || Path to output folder. Can be a network share providing middleware has permissions.
| description || string || Meaningful description of the output.
|-
|-
| type || ASCII || In this example we define the output type to be XML.
| type || XML || In this example the output type is XML.
|-
|-
| XLST || string || Filename of the Style Sheet to use. Only the filename. Path will default. In some scenarios this can be blank.
| 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==
'''ASCII_to_XML_Example.xsl'''
'''Map02_ASCII_to_XML.xsl'''
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
<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>
</xsl:stylesheet>
</syntaxhighlight>
</syntaxhighlight>


The above is the XSLT style sheet that we are going to use to define how the output data should be written. Don't worry about the inner workings at this point. The middleware java code is going to do some of the work and read the ASCII data into memory and represent it as XML. This style sheet is then applied to that temporary xml to generate the output file.
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'>
<xsl:template match='data'>
</syntaxhighlight>
</syntaxhighlight>


This line is used to select the intermediate in memory version of the data.
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>
<test>
      <xsl:apply-templates select="row"/>
    <xsl:apply-templates select="row"/>
</test>
</test>
</syntaxhighlight>
</syntaxhighlight>


This creates the root element of the output which we are going to call "test" and then calls a template for each input row.
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'>
<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>
</syntaxhighlight>
</syntaxhighlight>


If you recall from the input definition we are extracting 2 colums of data from the input file which were defined by the `<inputPattern>`
The input connector was told to read two columns from the file by the <code>&lt;pattern&gt;</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 combines the values of the columns in memory and puts a - delimiter between them. As the input map only read the 2 columns into memory they can be referenced as [1] and [2] in this step.
 
==Email==
'''email.xml'''
<syntaxhighlight lang="xml">
<?xml version="1.0" encoding="UTF-8"?>
<emailSettings>
    <!-- The section called "configuration" is always the active one - rename as appropriate-->
    <!-- Google gmail Example -->
    <configuration>
        <property name="mail.smtp.auth" value="true"/>
        <property name="mail.smtp.starttls.enable" value="true"/>
        <property name="mail.smtp.host" value="smtp.gmail.com"/>
        <property name="mail.smtp.socketFactory.port" value="465"/>
        <property name="mail.smtp.user" value="email@gmail.com"/>
        <property name="mail.smtp.password" value="password"/>
        <property name="mail.smtp.socketFactory.class" value="javax.net.ssl.SSLSocketFactory"/>
        <property name="mail.smtp.auth" value="true"/>
        <property name="mail.smtp.port" value="465"/>
        <property name="mail.smtp.from" value="email@gmail.com"/>
        <property name="mail.debug" value="true"/>
    </configuration1>
    <!-- Distribution Lists are referred to within message mapping Config.xml -->
    <distributionList id="Monitor" enabled="Y" maxFrequencyMins="5">
        <toAddressList>dummy1@gmail.com,dummy2@gmail.com</toAddressList>
    </distributionList>
    <distributionList id="Error" enabled="Y" maxFrequencyMins="5">
        <toAddressList>dummy1@gmail.com,dummy2@gmail.com</toAddressList>
    </distributionList>
    <distributionList id="Excel" enabled="Y" maxFrequencyMins="5">
        <toAddressList>dummy1@gmail.com,dummy2@gmail.com</toAddressList>
    </distributionList>
    <distributionList id="PDF" enabled="Y" maxFrequencyMins="0" description="Email PDF">
        <toAddressList>dummy1@gmail.com,dummy2@gmail.com</toAddressList>
    </distributionList>
</emailSettings>
</syntaxhighlight>


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


In the above example input file which has no purspose/meaning other than to illustrate how the middleware works, you can see 4 columns of data. In this example we are trying to extract the columns which contain numeric data, columns 1 and 3, and write the output to a xml file.
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"?>
<?xml version="1.0" encoding="UTF-8"?>
<test>
<test>
  <barcode>1232-5676</barcode>
  <barcode>1232-5676</barcode>
  <barcode>1233-5677</barcode>
  <barcode>1233-5677</barcode>
  <barcode>1234-5678</barcode>
  <barcode>1234-5678</barcode>
  <barcode>1235-5679</barcode>
  <barcode>1235-5679</barcode>
  <barcode>1236-5680</barcode>
  <barcode>1236-5680</barcode>
  <barcode>1237-5681</barcode>
  <barcode>1237-5681</barcode>
  <barcode>1238-5682</barcode>
  <barcode>1238-5682</barcode>
  <barcode>1239-5683</barcode>
  <barcode>1239-5683</barcode>
  <barcode>1240-5684</barcode>
  <barcode>1240-5684</barcode>
  <barcode>1241-5685</barcode>
  <barcode>1241-5685</barcode>
</test>
</test>
</syntaxhighlight>
</syntaxhighlight>


The above shows the output from the middleware transformation. Columns 1 and 3 of the flat file have been extracted and then combined with a "-" between them before writing to the output. Again - there is no significant purpose or meaning to this example, it just illustrates what can be done.
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.
 
Note that there are more than ASCII and XML types and you can change both input and output types.


==Logs and Debug information==
==Logs and Debug information==
When a file is processed by middleware a number of log files will be created which show the intermediate stages for the message processing. The filenames for these log messages are composed of the date and time followed by the message type and original input filename.
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.


  2024_04_09_18_46_46_700 INPUT_BACKUP_ASCII GEN ASCII File Fixed Column 1.txt
  20240409184646700_INPUT_BACKUP_Map02_in1_ASCII_GEN ASCII File Fixed Column 1.txt
  2024_04_09_18_46_46_716 INPUT_IMPORTED_ASCII_in1_GEN ASCII File Fixed Column 1.txt.xml
  20240409184646716_XSLT_INPUT_Map02_in1_ASCII_GEN ASCII File Fixed Column 1.txt.xml
  2024_04_09_18_46_46_757 INPUT_TRANSFORMED_ASCII_in1_GEN ASCII File Fixed Column 1.txt.xml
  20240409184646757_XSLT_OUTPUT_Map02_in1_ASCII_GEN ASCII File Fixed Column 1.txt.xml


The above directory listing shows 3 files related to the processing of this sample message.
{| class="wikitable"
<span style="color:#FFFFFF; background:#ff0000">2024-04-09-18-46-46-700 INPUT-BACKUP-ASCII GEN ASCII File
|-
Fixed Column 1.txt</span>
! File name contains !! Content
is a unmodified backup of the original input file.
|-
 
| <code>_INPUT_BACKUP_</code> || An unmodified copy of the original input file.
<span style="color:#FFFFFF; background:#ff0000">2024-04-09-18-46-46-716 INPUT-IMPORTED-ASCII-in1-GEN ASCII
|-
File Fixed Column 1.txt.xml</span>
| <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.
shows the intermediate stage of the file in which the flat ascii text file has been converted into a XML  
|-
file. This version is used as input to the XSLT Style Sheet.
| <code>_XSLT_OUTPUT_</code> || The result of the style sheet, which is passed to the output connector.
|}


<span style="color:#FFFFFF; background:#ff0000">2024-04-09-18-46-46-757 INPUT-TRANSFORMED-ASCII-in1-GEN
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]].
ASCII File Fixed Column 1.txt.xml</span>
is a copy of the ouput file generated.


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

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