SWIFT MX
Since Camel 3.20
The SWIFT MX data format is used to encode and decode SWIFT MX messages. The data format leverages the library Prowide ISO 20022 to encode and decode SWIFT MX messages.
Options
The SWIFT MX dataformat supports the following options which are listed below.
| Name | Default | Java Type | Description |
|---|---|---|---|
|
| Whether to marshal messages in JSON format. | |
| The type of MX message to produce when unmarshalling an input stream. If not set, it will be automatically detected from the namespace used. | ||
| Refers to a specific configuration to use when unmarshalling an input stream to lookup from the registry. | ||
| Refers to a specific configuration to use when marshalling a message to lookup from the registry. |
In Spring DSL, you configure the data format using this tag:
<camelContext>
<dataFormats>
<swiftMx id="swiftInJson" writeInJson="true"/>
</dataFormats>
...
</camelContext> Then you can use it later by its reference:
-
Java
-
XML
-
YAML
from("direct:startEncode")
.marshal("swiftInJson")
.to("mock:result"); <route>
<from uri="direct:startEncode" />
<marshal>
<custom ref="swiftInJson" />
</marshal>
<to uri="mock:result" />
</route> - route:
from:
uri: direct:startEncode
steps:
- marshal:
custom:
ref: swiftInJson
- to:
uri: mock:result Most of the time, you won’t need to declare the data format if you use the default options. In that case, you can declare the data format inline as shown below:
-
Java
-
XML
-
YAML
from("direct:startEncode")
.marshal().swiftMx()
.to("mock:result"); <route>
<from uri="direct:startEncode" />
<marshal>
<swiftMx />
</marshal>
<to uri="mock:result" />
</route> - route:
from:
uri: direct:startEncode
steps:
- marshal:
swiftMx: {}
- to:
uri: mock:result Marshal
In this example, we marshal the messages read from a JMS queue in SWIFT format before storing the result into a file.
-
Java
-
XML
-
YAML
from("jms://myqueue")
.marshal().swiftMx()
.to("file://data.bin"); <route>
<from uri="jms://myqueue"/>
<marshal>
<swiftMx/>
</marshal>
<to uri="file://data.bin"/>
</route> - route:
from:
uri: jms://myqueue
steps:
- marshal:
swiftMx: {}
- to:
uri: file://data.bin Unmarshal
The unmarshaller converts the input data into the concrete class of type com.prowidesoftware.swift.model.mx.AbstractMX that best matches with the content of the message.
In this example, we unmarshal the content of a file to get SWIFT MX objects before processing them with the newOrder processor.
-
Java
-
XML
-
YAML
from("file://data.bin")
.unmarshal().swiftMx()
.process("newOrder"); <route>
<from uri="file://data.bin"/>
<unmarshal>
<swiftMx/>
</unmarshal>
<to uri="bean:newOrder"/>
</route> - route:
from:
uri: file://data.bin
steps:
- unmarshal:
swiftMx: {}
- to:
uri: bean:newOrder Translating between MT and MX
The SWIFT MX and SWIFT MT data formats read and write messages, but they do not translate one format into the other. They also do not validate messages against SWIFT network rules or usage guidelines such as CBPR+ or SEPA.
To convert a message, such as an MT103 into a pacs.008, unmarshal it with SWIFT MT, map the fields to an ISO 20022 model class such as MxPacs00800108 in your own bean or processor, and marshal the result with SWIFT MX. The other direction works the same way, starting with SWIFT MX.
Translation that follows the official SWIFT mapping rules is outside the scope of Camel. Use a dedicated translation product or service for that.
Dependencies
To use SWIFT MX in your Camel routes, you need to add a dependency on camel-swift which implements this data format.
If you use Maven, you can add the following to your pom.xml:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-swift</artifactId>
<version>x.x.x</version> <!-- use the same version as your Camel core version -->
</dependency>