Time for action – running the quickstart

We will see the web services quickstart in the following steps:

  1. Change your current directory to the quickstart's directory samples/quickstarts/webservice_consumer1. Deploy the quickstart using the ant deploy command.
  2. Before running the quickstart, review the jboss-esb.xml file and see how the message is directed towards a SOAP endpoint which this quickstart also installs.
  3. Run the quickstart using the ant runtest command.
  4. Review the quickstart's output in the server.log file.

What just happened?

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.

Transformers/converters

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:

  • ByteArrayToString:

    org.jboss.soa.esb.actions.converters.ByteArrayToString This action converts a byte[] message payload into a Java String.

  • LongToDateConverter:

    org.jboss.soa.esb.actions.converters.LongToDateConverter This action converts a Java Long type in the message payload into a java.util.Date.

  • ObjectInvoke:

    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.

  • ObjectToCSVString:

    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.

  • ObjectToXStream:

    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.

  • XStreamGToObject:

    org.jboss.soa.esb.actions.converters.ObjectToXStream This action converts XML to an object using XStream.

  • PersistAction:

    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.

  • SmooksAction:

    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.

Smooks message fragment processing

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:

  • Templating: Smooks enables you to define templates with XSLT or FreeMarker (http://freemarker.sourceforge.net/) to govern the message transformation.
  • Java Binding: A very common, and very annoying task, is binding data to Java objects. Smooks provides dedicated visitor logic to perform this bining so you don't have to design the logic yourself.
  • Message Splitting: We reviewed different types of message routing OOTB actions earlier in this chapter. One characteristic that all these have in common is that they treat the messages being routed as atomic units. In contrast, Smooks supports splitting messages into fragments and then routing the fragments to different destinations. In addition, you can even route these message fragments over different transports.
  • Enrichment: Another common message processing task is to use information in a message as a "seed" to be used to add additional information to the message. Smooks enables you to "enrich" amessage fragment with data extracted from a database.
  • Persistence: As a counter point to enrichment, Smook supports persisting message fragments into databases.
  • Validation: Smooks provides visitor loic to perform validation, of data in message fragments.

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:

  • When you have to split messages: As we described earlier, one of Smooks' most powerful features is the ability to perform message splitting. If you use Smooks for content-based routing, you can split messages into fragments, route the fragments to different destinations in different formats (for example, routing XML to one service, Java to another, CSV data to another, and so on), and enrich or otherwise process the message fragments as they are routed. In addition, you can process the fragments into data in different formats.
  • When performance and scalability are required: Another advantage of using Smooks for message splitting and routing is Smooks' high throughput rate and ability to handle very large messages (over 50 MB in size) efficiently.

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:

  • The following is an example of a 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">
  • The following action results in the message being written to the server log before it undergoes XSLT transformation. A similar action is also invoked after the transformation.
    <action name="print-before"
            class="org.jboss.soa.esb.actions.SystemPrintln">
        <property name="message"
                  value="[transform_XML2XML_simple]Message before transformation"/>
    </action>
  • And here is the SmooksAction:
    <action name="simple-transform"
            class="org.jboss.soa.esb.smooks.SmooksAction">
        <propertyname="smooksConfig" value="/smooks-res.xml"/>
    </action>
  • The set of Smooks commands to be executed is defined in the 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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset