<?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">
&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;
             xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
             xsi:schemaLocation=&quot;http://ws.apache.org/ns/synapse http://synapse.apache.org/ns/2010/04/configuration/synapse_config.xsd&quot;&gt;

    &lt;proxy name=&quot;StockQuoteProxy&quot; transports=&quot;jms&quot;&gt;
        &lt;target&gt;
            &lt;inSequence&gt;
                &lt;property action=&quot;set&quot; name=&quot;OUT_ONLY&quot; value=&quot;true&quot;/&gt;
            &lt;/inSequence&gt;
            &lt;endpoint&gt;
                &lt;address uri=&quot;http://localhost:9000/services/SimpleStockQuoteService&quot;/&gt;
            &lt;/endpoint&gt;
            &lt;outSequence&gt;
                &lt;send/&gt;
            &lt;/outSequence&gt;
        &lt;/target&gt;
        &lt;publishWSDL uri=&quot;file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl&quot;/&gt;
        &lt;parameter name=&quot;transport.jms.ContentType&quot;&gt;
            &lt;rules&gt;
                &lt;jmsProperty&gt;contentType&lt;/jmsProperty&gt;
                &lt;default&gt;application/xml&lt;/default&gt;
            &lt;/rules&gt;
        &lt;/parameter&gt;
    &lt;/proxy&gt;
&lt;/definitions&gt;
			</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">
&lt;queue name=&quot;StockQuoteProxy&quot;&gt;
    &lt;entry name=&quot;StockQuoteProxy&quot;/&gt;
&lt;/queue&gt;
							</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">
&lt;transportReceiver name=&quot;jms&quot; class=&quot;org.apache.axis2.transport.jms.JMSListener&quot;&gt;
   &lt;parameter name=&quot;java.naming.factory.initial&quot;&gt;org.jnp.interfaces.NamingContextFactory&lt;/parameter&gt;
   &lt;parameter name=&quot;java.naming.provider.url&quot;&gt;jnp://localhost:1099&lt;/parameter&gt;
   &lt;parameter name=&quot;java.naming.factory.url.pkgs&quot;&gt;org.jboss.naming:org.jnp.interfaces&lt;/parameter&gt;
&lt;parameter name=&quot;transport.jms.ConnectionFactoryJNDIName&quot;&gt;ConnectionFactory&lt;/parameter&gt;
							</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>