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).

...

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

  <http:endpoint service="b:http"
                 endpoint="endpoint"
                 targetService="b:pipeline"
                 role="consumer"
                 locationURI="http://localhost:8192/bridge/"
                 defaultMep="http://www.w3.org/2004/08/wsdl/in-only" />

</beans>

EIP SU

The EIP SU contains the definition of the pipeline pattern, which can be used as a bridge between two InOnly MEPs and an InOut MEP. The XSLT transformer primary MEP is an InOut, as it will receive an incoming message, transform it, and send the answer back to the consumer. But in our case, the HTTP component and JMS component should send and receive an InOnly MEP, hence the need for the Pipeline.

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

  <eip:pipeline service="b:pipeline" endpoint="endpoint">
    <eip:transformer>
      <eip:exchange-target service="b:xslt" />
    </eip:transformer>
    <eip:target>
      <eip:exchange-target service="b:jms" />
    </eip:target>
  </eip:pipeline>

</beans>

XSLT SU

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

Code Block
langxml
<?xml version="1.0"?>
<beans xmlns:sm="http://servicemix.apache.org/config/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 service="b:xslt" endpoint="endpoint">
        <sm:component>
          <bean class="org.apache.servicemix.components.xslt.XsltComponent">
            <property name="xsltResource" value="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.

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" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:template match="node() | @*">
    <xsl:copy>
      <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

JMS SU

For the JMS provider, we will reuse the embedded ActiveMQ broker which is started with ServiceMix, and output the request in the bridge.output JMS queue.

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="vm://localhost" />
  </bean>

</beans>

Building, Deploying and Testing

To build the SUs and SA, run the following command in the bridge root directory:

Code Block

mvn install

Then, deploy the SA and needed components to a started ServiceMix container:

Code Block

cd bridge-sa
mvn jbi:projectDeploy