| <?xml version="1.0" encoding="ISO-8859-1" ?> |
| <!-- ~ Licensed to the Apache Software Foundation (ASF) under one ~ or more |
| contributor license agreements. See the NOTICE file ~ distributed with this |
| work for additional information ~ regarding copyright ownership. The ASF |
| licenses this file ~ to you under the Apache License, Version 2.0 (the ~ |
| "License"); you may not use this file except in compliance ~ with the License. |
| You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0 |
| ~ ~ Unless required by applicable law or agreed to in writing, ~ software |
| distributed under the License is distributed on an ~ * "AS IS" BASIS, WITHOUT |
| WARRANTIES OR CONDITIONS OF ANY ~ KIND, either express or implied. See the |
| License for the ~ specific language governing permissions and limitations |
| ~ under the License. --> |
| |
| <document> |
| <properties> |
| <title>Apache Synapse - Sample 262</title> |
| </properties> |
| <body> |
| <section |
| name="Sample 263: Transport switching - JMS to http/s using JBoss Messaging(JBM)"> |
| <div class="xmlConf"> |
| <definitions xmlns="http://ws.apache.org/ns/synapse" |
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| xsi:schemaLocation="http://ws.apache.org/ns/synapse http://synapse.apache.org/ns/2010/04/configuration/synapse_config.xsd"> |
| |
| <proxy name="StockQuoteProxy" transports="jms"> |
| <target> |
| <inSequence> |
| <property action="set" name="OUT_ONLY" value="true"/> |
| </inSequence> |
| <endpoint> |
| <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> |
| </endpoint> |
| <outSequence> |
| <send/> |
| </outSequence> |
| </target> |
| <publishWSDL uri="file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl"/> |
| <parameter name="transport.jms.ContentType"> |
| <rules> |
| <jmsProperty>contentType</jmsProperty> |
| <default>application/xml</default> |
| </rules> |
| </parameter> |
| </proxy> |
| </definitions> |
| </div> |
| <subsection name="Objective"> |
| <p> |
| Objective: Introduction to switching transports with proxy |
| services. |
| The JMS provider will be |
| <a class="externalLink" href="http://jboss.org/jbossmessaging/">JBoss Messaging(JBM).</a> |
| </p> |
| </subsection> |
| <subsection name="Pre-requisites"> |
| <p> |
| <ul> |
| <li> |
| Start the Axis2 server and deploy the SimpleStockQuoteService |
| (Refer |
| steps above) |
| </li> |
| <li> |
| <a class="externalLink" href="http://jboss.org/jbossmessaging/">Download</a> |
| , install and start JBM server, and configure Synapse to listen |
| on JBM (refer notes below) |
| <br /> |
| </li> |
| <li> |
| Start the Synapse configuration numbered 263 |
| <div class="command"> |
| Unix/Linux: sh synapse.sh -sample 263 |
| <br /> |
| Windows: synapse.bat -sample 23 |
| </div> |
| </li> |
| <li> |
| We need to configure the required queues in JBM. Add the |
| following entry to JBM jms configuration inside |
| file-config/stand-alone/non-clustered/jbm-jms.xml. |
| Once JBM is |
| installed and started you should get a message as |
| follows: |
| <div class="xmlConf"> |
| <queue name="StockQuoteProxy"> |
| <entry name="StockQuoteProxy"/> |
| </queue> |
| </div> |
| </li> |
| <li> |
| Once you started the JBM server with the above changes you'll be |
| able to see the following on STDOUT |
| <div class="consoleOutput"> |
| 10:18:02,673 INFO [org.jboss.messaging.core.server.impl.MessagingServerImpl] JBoss Messaging Server version 2.0.0.BETA3 (maggot, 104) started |
| </div> |
| </li> |
| <li> |
| <p>You will now need to configure the Axis2 instance used by |
| Synapse |
| (not the sample Axis2 server) to enable JMS support using |
| the |
| above provider. Refer Axis2 documentation on setting up JMS |
| in |
| detail (http://ws.apache.org/axis2/1_1/jms-transport.html). |
| You |
| will also need to copy the jbm-core-client.jar, |
| jbm-jms-client.jar, jnp-client.jar(these jars are inside client |
| folder ) and jbm-transports.jar, netty.jar(these jars are from |
| lib folder) jars from JBM into the lib directory to allow |
| Synapse |
| to connect to the JBM JMS provider. This was tested with |
| JBM |
| 2.0.0.BETA3 |
| </p> |
| </li> |
| <li> |
| <p>You need to add the following configuration for Axis2 JMS transport listener in axis2.xml found at repository/conf/axis2.xml. |
| </p> |
| <div class="consoleOutput"> |
| <transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener"> |
| <parameter name="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</parameter> |
| <parameter name="java.naming.provider.url">jnp://localhost:1099</parameter> |
| <parameter name="java.naming.factory.url.pkgs">org.jboss.naming:org.jnp.interfaces</parameter> |
| <parameter name="transport.jms.ConnectionFactoryJNDIName">ConnectionFactory</parameter> |
| </div> |
| </li> |
| <li> |
| On the Synapse debug log you will notice that the JMS listener |
| received the request message as: |
| <div class="consoleOutput"> |
| [JMSWorker-1] DEBUG ProxyServiceMessageReceiver -Proxy Service StockQuoteProxy received a new message... |
| </div> |
| </li> |
| |
| <li> |
| <p>In this sample, the client sends the request message to the |
| proxy service exposed over JMS in Synsape. Synapse forwards this |
| message to the HTTP EPR of the simple stock quote service hosted |
| on the sample Axis2 server. Note that the operation is out-only |
| and no response is sent back to the client. The |
| transport.jms.ContentType property is necessary to allow the JMS |
| transport to determine the content type of incoming messages. |
| With the given configuration it will first try to read the |
| content type from the 'contentType' message property and fall |
| back to 'application/xml' (i.e. POX) if this property is not |
| set. |
| Note that the JMS client used in this example doesn't send any |
| content type information. |
| </p> |
| </li> |
| |
| </ul> |
| </p> |
| </subsection> |
| <subsection name="Executing the Client"> |
| <p> |
| Once you start the Synapse configuration 250 and request for the WSDL of the |
| proxy service (http://localhost:8280/services/StockQuoteProxy?wsdl) you will |
| notice that its exposed only on the JMS transport. This is because the configuration specified this |
| requirement in the proxy service definition. |
| </p> |
| <div class="command"> |
| ant jmsclient -Djms_type=pox -Djms_dest=StockQuoteProxy -Djms_payload=MSFT -Djava.naming.provider.url=jnp://localhost:1099 -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory -D=java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces |
| </div> |
| |
| <p>Now if you examine the console running the sample Axis2 server, |
| you will see a message indicating that the server has accepted an |
| order as follows: </p> |
| <div class="consoleOutput"> |
| Accepted order for : 16517 stocks of MSFT at $169.14622538721846 |
| </div> |
| </subsection> |
| |
| </section> |
| <p> |
| <a href="../samples.html">Back to Catalog</a> |
| </p> |
| </body> |
| </document> |