Artix Data Services
Deprecated, will be removed in Apache Camel 2.1
The Artix DS Data Format supports the Artix Data Services (ADS) product which provides a framework for reading and writing a huge number of vertical message payloads like SWIFT, SEPA, FpML, TWIST, ISO 20022, CREST and FIX. In addition ADS provides tooling and a framework for reading and writing any legacy binary or text file using any kind of encoding like fixed width, delimited, XML, CSV and so forth.
ADS also provides a transformation framework making it very easy to implement the Message Translator pattern using the ADS tooling to design the transformation.
Unmarhalling
The first step to using ADS is usually to unmarshal some message from one of the Camel Components like File, HTTP or JMS etc.
from("activemq:InputQueue").
unmarshal().artixDS(DocumentElement.class).
to("mqseries:OutputQueue");
The above unmarshals using the Artix DS Data Format for the element DocumentElement which is generated by the Artix DS tooling; DocumentElement is the root element of the message structure.
The above will use the default formatting for the data type. However with Artix DS you can switch from the default format to other formats easily. So you could add a specific format if you wish...
from("activemq:InputQueue").
unmarshal().artixDS(DocumentElement.class, ArtixDSContentType.Xml).
to("mqseries:OutputQueue");
If you use static imports this can be even more readable...
unmarshal().artixDS(DocumentElement.class, Xml).
Unmarshalling SWIFT messages
If you are working with SWIFT messages then as of camel-artixds version 1.3.6.0 or later there is a handy SwiftFormat helper class which avoids you having to know which Element class you want to use.
So you can unmarshal SWIFT messages using this code
from("activemq:InputQueue").
unmarshal(new SwiftFormat()).
to("mqseries:OutputQueue");
Marshalling
Marshalling is the reverse of unmarshalling suprise suprise
.
Here's an example which unmarshals using one format (XML) and then marshals using a different format (in this case tagged value pairs).
from("activemq:XmlInput").
unmarshal().artixDS(DocumentElement.class, ArtixDSContentType.Xml).
marshal().artixDS(ArtixDSContentType.TagValuePair).
to("mqseries:TagOutput");
Type conversions
An alternative to explicit unmarshalling in the DSL you can just use the common convertBodyTo(Class) method in the DSL to convert using the default content type to a particular ComplexDataObject from Artix DS. This mechanism uses the inbuilt Camel Type Converter mechanism ot automatically marshal and unmarshal using the default content type for a model.
For example the following...
from("activemq:InputQueue").
convertBodyTo(DocumentElement.class).
to("mqseries:OutputQueue");
Is equivalent to this
from("activemq:InputQueue").
unmarshal().artixDS(DocumentElement.class).
to("mqseries:OutputQueue");
Using Transformations
To use the Message Translator pattern with ADS its a simple matter of using the ADS tooling to create your transformation, then just using the generated transformation class in the Bean Integration in Camel.
For example image you define a transformation in the ADS IDE to translate SWIFT to FIX format. You will then have a generated SwiftToFix Java class. You can then use the transformation in your Camel DSL via Java or the Xml Configuration as follows
from("activemq:SwiftQueue").
bean(SwiftToFix.class).
to("mqseries:FixQueue");
Configuring via Spring XML
The following example shows how to use Artix DS using Spring XML; in this case it unmarshals the content of a JMS queue as XML using the Artix DS data model; then marshals it using a tag/value pair.
<camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
<route>
<from uri="activemq:MyInputQueue"/>
<unmarshal>
<artixDS contentType="Xml" elementTypeName="iso.std.iso.x20022.tech.xsd.pacs.x008.x001.x01.DocumentElement"/>
</unmarshal>
<marshal>
<artixDS contentType="TagValuePair"/>
</marshal>
<to uri="mqseries:MyOutputQueue"/>
</route>
</camelContext>
Content Types and auto discovery
You may have spotted in the above that we use the ArtixDSContentType which is an enum in Java and the Xml Configuration to describe the kind of XML format to use such as binary, XML, Text etc.
If no content type is specified we always use the default content type of the Artix DS model in question. This is equivalent to the Default content type.
If you wish to be flexible in what you accept or emit, we also support the Auto content type which will look for the Content-Type header on the input message and use that to try determine which of the content types to use; if none can be found then Default is used.
e.g. you could support content posted with a MIME type of application/xml to indicate XML or application/x-java-serialized-object for serialization or text/plain for text etc.
Using camel-artixds
To use this module you need to use the FUSE Mediation Router distribution. Or you could just add the following to your pom.xml, substituting the version number for the latest & greatest release.
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-artixds</artifactId>
<version>1.5.3.0-fuse</version>
</dependency>
And ensure you are pointing at the maven repo
<repository>
<id>open.iona.m2</id>
<name>FUSESource Open Source Community Release Repository</name>
<url>http: <snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>