We will see the web services quickstart in the following steps:
samples/quickstarts/webservice_consumer1
. Deploy the quickstart using the ant deploy
command.jboss-esb.xml
file and see how the message is directed towards a SOAP endpoint which this quickstart also installs.ant runtest
command.server.log
file.In this quickstart, the ESB deploys both a WAR and an ESB archive. The WAR archive contains a web service, HelloWorldWS
. When we invoked the runtest
target, we sent a JMS message to the service, which then invoked HelloWorldWS
using the request we provided from the JMS message. The SOAP response is then displayed on the console by the custom MyResponseAction
action.
These OOTB actions are used by services that expect data in different forms to communicate with each other, without you having to create glue code to convert that data from one form to another. The specific data that transformers and converters process is a message's "payload" (the message body and the message's attachments and defined properties). The default way for an action to get/set a message's payload is through the MessagePayloadProxy
class.
The specific actions in the transformers and converters actions group are:
org.jboss.soa.esb.actions.converters.ByteArrayToString
This action converts a byte[]
message payload into a Java String.
org.jboss.soa.esb.actions.converters.LongToDateConverter
This action converts a Java Long type in the message payload into a java.util.Date
.
org.jboss.soa.esb.actions.converters.ObjectInvoke
This action takes a serialized object, which consists of full message payload, and passes it to a configured processor class. The processed results then become the new message payload.
org.jboss.soa.esb.actions.converters.ObjectToCSVString
This action converts a message into a comma separated string based on a list of property names that you supply.
org.jboss.soa.esb.actions.converters.ObjectToXStream
This action is similar to the ObjectInvoke
action, except that it converts the object to XML using Xstream.
org.jboss.soa.esb.actions.converters.ObjectToXStream
This action converts XML to an object using XStream.
org.jboss.soa.esb.actions.MessagePersister
This action doesn't really transform or convert a message, it writes it to the persistent message store. The most common use of the action is that it is how JBoss ESB itself writes messages to the dead letter queue (DLQ), but it can be used in any situation when you want to store a message.
org.jboss.soa.esb.smooks.SmooksAction
This action enables you to use a powerful set of Smooks operations with JBoss ESB. We'll examine this action in detail in the next section.
Let's look at transformations and the SmooksAction
OOTB action.
But first, let's take a minute to introduce JBoss Smooks (http://www.smooks.org).
Smooks is best known as a transformation engine, that is, a utility to perform data transformations from one form to another (for example from XML to POJO's). However, that's a misconception (not to mention a disservice to Smooks) as Smooks has many more capabilities. A more accurate way to view Smooks is as a framework to enable you to perform different types of processing on message fragments, where a message fragment is a selected subset of the information in a message.
Smooks is able to handle different types of message fragments, and is able to perform different types of processing due to its modular design. Smooks' design is based on "visitor logic". A Smooks "visitor" is Java code that is designed to perform a specific type of operation on a specific type of message fragment. The message transformation types that Smooks performs include:
However, when should you use Smooks for content-based routing? The types of situations in which you should consider using Smooks for content-based routing include:
Let's take a look an example of transformations and the SmooksAction
out-of-the-box action.
The example is the aptly named transform_XML2XML_simple
quickstart. This quickstart performs a message transformation by applying an XSLT (EXtensible Stylesheet Language Transformations) to an XML message. The message is then transformed into XML in a different form. The interesting parts of the quickstart's jboss-esb.xml file are:
mep
that we described earlier in this chapter. The pattern used by this quickstart is OneWay
in that the requester invokes a service (by sending it a message) and then does not wait for a response:<actions mep="OneWay">
<action name="print-before" class="org.jboss.soa.esb.actions.SystemPrintln"> <property name="message" value="[transform_XML2XML_simple]Message before transformation"/> </action>
SmooksAction
:<action name="simple-transform" class="org.jboss.soa.esb.smooks.SmooksAction"> <propertyname="smooksConfig" value="/smooks-res.xml"/> </action>
smooks-res.xml
file. This file contains:<?xmlversion='1.0'encoding='UTF-8'?> <smooks-resource-listxmlns=http://www.milyn.org/xsd/smooks-1.0.xsd> <resource-configselector="OrderLine"> <resourcetype="xsl"> <![CDATA[<line-item> <product> <xsl:value-of select="./Product/@productId"/> </product> <price> <xsl:value-of select="./Product/@price"/> </price> <quantity> <xsl:value-of select="@quantity"/> </quantity> </line-item>]]> </resource> <paramname="is-xslt-templatelet">true</param> </resource-config> </smooks-resource-list>
If this file looks a bit confusing, don't worry. The XPath commands that will be used by the SmooksAction
and XSLT to transform the message into a different form are highlighted.