Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

ServiceMix can be used as a protocol bridge. The following tutorial will explain how to create a JBI Service Assembly (aka a JBI application) to bridge two different protocols. In this example, we will bridge the HTTP/SOAP with the JMS protocol using an InOnly MEP. We will also put between the two protocols an XSLT transformation.
We will leverage ServiceMix archetypes and maven plugin (see Maven JBI plugin).

This tutorial has been written for ServiceMix 3.1. For ServiceMix 3.0, see this page.

Identifying the service units

...

Code Block
mvn archetype:create \
        -DarchetypeGroupId=org.apache.servicemix.tooling \
        -DarchetypeArtifactId=servicemix-http-consumer-service-unit \
        -DarchetypeVersion=3.01-incubating \
        -DgroupId=org.apache.servicemix.samples.bridge \
        -DartifactId=bridge-http-su

mvn archetype:create \
        -DarchetypeGroupId=org.apache.servicemix.tooling \
        -DarchetypeArtifactId=servicemix-jms-provider-service-unit \
        -DarchetypeVersion=3.01-incubating \
        -DgroupId=org.apache.servicemix.samples.bridge \
        -DartifactId=bridge-jms-su

mvn archetype:create \
        -DarchetypeGroupId=org.apache.servicemix.tooling \
        -DarchetypeArtifactId=servicemix-eip-service-unit \
        -DarchetypeVersion=3.01-incubating \
        -DgroupId=org.apache.servicemix.samples.bridge \
        -DartifactId=bridge-eip-su

mvn archetype:create \
        -DarchetypeGroupId=org.apache.servicemix.tooling \
        -DarchetypeArtifactId=servicemix-lwcontainer-service-unit \
        -DarchetypeVersion=3.01-incubating \
        -DgroupId=org.apache.servicemix.samples.bridge \
        -DartifactId=bridge-xslt-su

mvn archetype:create \
        -DarchetypeGroupId=org.apache.servicemix.tooling \
        -DarchetypeArtifactId=servicemix-service-assembly \
        -DarchetypeVersion=3.01-incubating \
        -DgroupId=org.apache.servicemix.samples.bridge \
        -DartifactId=bridge-sa

...

The XSLT transformation will be deployed on the servicemix-lwcontainer saxon SE using the following servicemixxbean.xml configuration file.

Code Block
langxml
<?xml version="1.0"?>
<beans xmlns:smsaxon="http://servicemix.apache.org/configsaxon/1.0"
       xmlns:b="http://servicemix.apache.org/samples/bridge">

  <classpath>
    <location>.</location>
    <location>lib/servicemix-components-3.0-incubating-SNAPSHOT.jar</location>
  </classpath>

  <sm:serviceunit id="jbi">
    <sm:activationSpecs>
      <sm:activationSpec <saxon:xslt service="b:xslt" endpoint="endpoint">
        <sm:component>
          <bean class="org.apache.servicemix.components.xslt.XsltComponent">result="string"
            <property name="xsltResource" valueresource="classpath:bridge.xslt" />
          </bean>
        </sm:component>
      </sm:activationSpec>
    </sm:activationSpecs>
  </sm:serviceunit>

</beans>

Note the <classpath/> tag which defines the SU root directory as a component of the classpath. This is used by the xslt component to find the stylesheet using the spring "classpath:" URL style classpath:bridge.xsdl uri used to point to the XSLT. The classpath is automatically defined by the componentand includes the root directory of the SU (see Classloaders).

We need to create the bridge.xslt stylesheet and put in in the src/main/resources directory of this SU, along the servicemix.xml configuration file.
Let's use an identity stylesheet:

...

Code Block
langxml
<?xml version="1.0"?>
<beans xmlns:jms="http://servicemix.apache.org/jms/1.0"
       xmlns:b="http://servicemix.apache.org/samples/bridge">

  <jms:endpoint service="b:jms"
                endpoint="endpoint"
                role="provider"
                destinationStyle="queue"
                jmsProviderDestinationName="bridge.output"
                connectionFactory="#connectionFactory" />

  <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL" value="vmtcp://localhost:61616" />
  </bean>

</beans>

Building, Deploying and Testing

...