Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.10.7. Supported Transformations
10.7.1. Java Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
10.7.1.1. Java Transformer Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
You can create a Java-based transformer in SwitchYard using any of the following methods:
When using the @Transformer annotation, the SwitchYard maven plug-in automatically generates the <transform.java> definition and adds them to the
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
Here, the
- Implement the
org.switchyard.transform.Transformer
interface and add a <transform.java> definition to yourswitchyard.xml
. - Annotate one or more methods on your Java class with @Transformer annotation.
switchyard.xml
packaged in your application. Here is an example of a Java class that produces the <transform.java> definition:
from
and to
elements of the @Transformer annotation are optional. You can use them to specify the qualified type name used during transformer registration. If not specified, the full class name of the method parameter is used as the from
type and the full class name of the return type is used as the to
type.
The CDI bean name specified by @Named annotation is used to resolve transformer class. If not specified, the class name of the transformer is used instead. Here is an example:
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
Note
The bean attribute and class attribute are mutually exclusive.
10.7.2. JAXB Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
10.7.2.1. JAXB Transformer Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
SwitchYard automatically detects and adds the JAXB Transformations for your application deployment. For example, if you develop a CDI Bean Service and use JAXB generated types in the Service Interface, you do not need to configure any of the transformations. SwitchYard automatically detects their availability for your application and automatically applies them at the appropriate time during service invocation.
The JAXB transformer allows you to perform Java to XML and XML to Java transformations using JAXB (XML marshalling and unmarshalling). The JAXB Transformer is similar to the JSON Transformer configuration. It also requires a
to
and from
configuration with one Java type and one QNamed XML type.
For example in the source file
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
Here, the @XmlElementDecl annotation implies that the XML QName associated with the
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
ObjectFactory.java
, the factory methods represent the available marshallings/unmarshallings as shown below:
@XmlElementDecl(namespace = "http://com.acme/orders", name = "create") public JAXBElement<CreateOrder> createOrder(CreateOrder value) { return new JAXBElement<Order>(_CreateOrder_QNAME, CreateOrder.class, null, value); }
@XmlElementDecl(namespace = "http://com.acme/orders", name = "create")
public JAXBElement<CreateOrder> createOrder(CreateOrder value) {
return new JAXBElement<Order>(_CreateOrder_QNAME, CreateOrder.class, null, value);
}
com.acme.orders.CreateOrder
type is "{http://com.acme/orders}create". This means that you can have the following SwitchYard JAXB Transformer configurations:
<transform.jaxb from="{http://com.acme/orders}create" to="java:com.acme.orders.CreateOrder" /> <transform.jaxb from="java:com.acme.orders.CreateOrder" to="{http://com.acme/orders}create" />
<transform.jaxb from="{http://com.acme/orders}create" to="java:com.acme.orders.CreateOrder" />
<transform.jaxb from="java:com.acme.orders.CreateOrder" to="{http://com.acme/orders}create" />
10.7.3. JSON Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
10.7.3.1. JSON Transformer Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
The JSON transformer provides a basic mapping facility between POJOs and JSON (JSON marshalling and unmarshalling). Just like the JAXB Transformer, specification of the transformer requires a
to
and from
specification with one Java type and one QNamed JSON type, depending on whether you are performing a Java to JSON or JSON to Java transformation.
Here is an example configuration of JSON to Java transformation:
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
<trfm:transform.json from="{urn:switchyard-quickstart:transform-json:1.0}order" to="java:org.switchyard.quickstarts.transform.json.Order"/>
<trfm:transform.json
from="{urn:switchyard-quickstart:transform-json:1.0}order"
to="java:org.switchyard.quickstarts.transform.json.Order"/>
Here is a sample configuration of Java to JSON transformation:
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
<trfm:transform.json from="java:org.switchyard.quickstarts.transform.json.Order" to="{urn:switchyard-quickstart:transform-json:1.0}order"/>
<trfm:transform.json
from="java:org.switchyard.quickstarts.transform.json.Order"
to="{urn:switchyard-quickstart:transform-json:1.0}order"/>
10.7.4. Smooks Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
10.7.4.1. Smooks Transformer Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
SwitchYard provides three distinct transformation models for Smooks:
- XML to Java : Based on a standard Smooks Java Binding configuration.
- Java to XML: Based on a standard Smooks Java Binding configuration.
- Smooks : This is a normal Smooks transformation in which you must define which Smooks filtering result is to be exported back to the SwitchYard Message as the transformation result.
You can declare a Smooks transformation by including a <transform.smooks> definition in your
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
The Smooks and XSLT translators require an external configuration file that tells the translator how to go about its actions. In the example above, the
switchyard.xml
. Here is an example:
<transform.smooks config="/smooks/OrderAck_XML.xml" from="java:org.switchyard.quickstarts.transform.smooks.OrderAck" to="{urn:switchyard-quickstart:transform-smooks:1.0}submitOrderResponse" type="JAVA2XML"/>
<transform.smooks config="/smooks/OrderAck_XML.xml"
from="java:org.switchyard.quickstarts.transform.smooks.OrderAck"
to="{urn:switchyard-quickstart:transform-smooks:1.0}submitOrderResponse"
type="JAVA2XML"/>
config
attribute points to a Smooks resource containing the mapping definition. The type
attribute can be one of SMOOKS, XML2JAVA, or JAVA2XML.
For more information on Smooks and XSLT configuration files, see Red Hat JBoss Fuse Development Guide Volume 2: Smooks.
For more information on the elements that extend the abstract transform, see the
/docs/schema/soa/org/switchyard/transform/config/model/v1/transform_<latest_version>.xsd
.
10.7.5. XSLT Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
10.7.5.1. XSLT Transformer Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
You can perform transformations with the XSLT transformer using an XSLT. You can configure it by specifying the
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
to
and from
QNames, and the path to the XSLT. Here is an example of XSLT Transformer configuration:
<transform.xslt from="{http://acme/}A" to="{http://acme/}B" xsltFile="com/acme/xslt/A2B.xslt"/>
<transform.xslt from="{http://acme/}A" to="{http://acme/}B" xsltFile="com/acme/xslt/A2B.xslt"/>