cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache CXF Documentation > Jax-WS Java First with jms Transport
Date Tue, 21 Sep 2010 00:13:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/9/1/_/styles/combined.css?spaceKey=CXF20DOC&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CXF20DOC/Jax-WS+Java+First+with+jms+Transport">Jax-WS
Java First with jms Transport</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~bimargulies@gmail.com">Benson
Margulies</a>
    </h4>
        <br/>
                         <h4>Changes (2)</h4>
                                 
    
<div id="page-diffs">
            <table class="diff" cellpadding="0" cellspacing="0">
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">
<br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">{note<span
class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span><span class="diff-added-chars"style="background-color: #dfd;">:</span>title=New</span>
Functionality for 2.3} <br></td></tr>
            <tr><td class="diff-unchanged" >As of CXF 2.3, the configuration mechanism
described on this page is obsolete, replaced by  <br>a much simpler, standard-conforming
alternative. See <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <div class='panelMacro'><table class='noteMacro'><colgroup><col
width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/warning.gif"
width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>New
Functionality for 2.3</b><br />As of CXF 2.3, the configuration mechanism described
on this page is obsolete, replaced by <br/>
a much simpler, standard-conforming alternative. See<br/>
<a href="/confluence/display/CXF20DOC/SOAP+over+JMS+1.0+support" title="SOAP over JMS 1.0
support">SOAP over JMS 1.0 support</a>.</td></tr></table></div>


<p><a href="/confluence/download/attachments/69467/cxf_java_first.zip?version=1&amp;modificationDate=1193342665000">Download
JAX-WS java first sample showing maven build, http and jms transport.</a></p>

<p>This example works almost the same as th JAX WS Java First Example with http. The
only two things that are different is that you configure the jms:conduit (JMS Config for client)
and jms:endpoint(JMS Config for server) in the cxf.xml. This file will be loaded automatically
when cxf starts.<br/>
Of course you could do the complete config in spring but I wanted to stick with the JAX WS
Java First example. </p>

<p>Things to consider when doing the jms config:</p>
<ul>
	<li>name the jms:conduit like the client endpoint name + jms.conduit</li>
	<li>name the jms:endpoint like the server endpoint name + jms.endpoint</li>
</ul>


<p>The address in the proxy factory and server factory has to be set to jms://. The
real addess has to be set in the conduit and destination.</p>

<p>In fact once all is set up it is quite easy. Only the fact that you have to connect
jms:conduit and service by the endpoint name is not very intuitive.</p>

<p>You can download the complete example above. Additionally you need the activemq binaries.
Start activemq before testing the service. There is no configuration required.</p>

<p>cxf.xml</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;?xml version=<span class="code-quote">"1.0"</span>
encoding=<span class="code-quote">"UTF-8"</span>?&gt;</span>
&lt;beans xmlns=<span class="code-quote">"http://www.springframework.org/schema/beans"</span>
 <span class="code-keyword">xmlns:xsi</span>=<span class="code-quote">"http://www.w3.org/2001/XMLSchema-instance"</span>
 <span class="code-keyword">xmlns:cxf</span>=<span class="code-quote">"http://cxf.apache.org/core"</span>
 <span class="code-keyword">xmlns:soap</span>=<span class="code-quote">"http://cxf.apache.org/bindings/soap"</span>
 <span class="code-keyword">xmlns:jaxws</span>=<span class="code-quote">"http://cxf.apache.org/jaxws"</span>
 <span class="code-keyword">xmlns:jms</span>=<span class="code-quote">"http://cxf.apache.org/transports/jms"</span>
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/bindings/soap http://cxf.apache.org/schema/bindings/soap.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/transports/jms http://cxf.apache.org/schemas/configuration/jms.xsd"&gt;

 <span class="code-tag">&lt;import resource=<span class="code-quote">"classpath:META-INF/cxf/cxf.xml"</span>
/&gt;</span>
 <span class="code-tag">&lt;import resource=<span class="code-quote">"classpath:META-INF/cxf/cxf-extension-soap.xml"</span>
/&gt;</span>
 <span class="code-tag">&lt;import resource=<span class="code-quote">"classpath:META-INF/cxf/cxf-extension-local.xml"</span>
/&gt;</span>
 <span class="code-tag">&lt;import resource=<span class="code-quote">"classpath:META-INF/cxf/cxf-extension-http.xml"</span>
/&gt;</span>
 <span class="code-tag">&lt;import resource=<span class="code-quote">"classpath:META-INF/cxf/cxf-servlet.xml"</span>
/&gt;</span>
 <span class="code-tag">&lt;import resource=<span class="code-quote">"classpath:META-INF/cxf/cxf-extension-jms.xml"</span>
/&gt;</span>
 <span class="code-tag">&lt;cxf:bus&gt;</span>
 <span class="code-tag">&lt;cxf:features&gt;</span>
 <span class="code-tag">&lt;cxf:logging/&gt;</span>
 <span class="code-tag">&lt;/cxf:features&gt;</span>
 <span class="code-tag">&lt;/cxf:bus&gt;</span>

 <span class="code-tag">&lt;jms:conduit name=<span class="code-quote">"{http://service.test/}IHelloPort.jms-conduit"</span>&gt;</span>
 &lt;jms:address destinationStyle=<span class="code-quote">"queue"</span>
jndiConnectionFactoryName=<span class="code-quote">"ConnectionFactory"</span>
 jndiDestinationName=<span class="code-quote">"dynamicQueues/test.cxf.jmstransport.queue"</span>
connectionUserName=<span class="code-quote">"testUser"</span> connectionPassword=<span
class="code-quote">"testPassword"</span>&gt;
 <span class="code-tag">&lt;jms:JMSNamingProperty name=<span class="code-quote">"java.naming.factory.initial"</span>
value=<span class="code-quote">"org.apache.activemq.jndi.ActiveMQInitialContextFactory"</span>
/&gt;</span>
 <span class="code-tag">&lt;jms:JMSNamingProperty name=<span class="code-quote">"java.naming.provider.url"</span>
value=<span class="code-quote">"tcp://localhost:61616"</span> /&gt;</span>
 <span class="code-tag">&lt;/jms:address&gt;</span>
 <span class="code-tag">&lt;/jms:conduit&gt;</span>

 <span class="code-tag">&lt;jms:destination name=<span class="code-quote">"{http://service.test/}IHelloPort.jms-destination"</span>&gt;</span>
 &lt;jms:address destinationStyle=<span class="code-quote">"queue"</span>
jndiConnectionFactoryName=<span class="code-quote">"ConnectionFactory"</span>
jndiDestinationName=<span class="code-quote">"dynamicQueues/test.cxf.jmstransport.queue"</span>
 connectionUserName=<span class="code-quote">"testUser"</span> connectionPassword=<span
class="code-quote">"testPassword"</span>&gt;
 <span class="code-tag">&lt;jms:JMSNamingProperty name=<span class="code-quote">"java.naming.factory.initial"</span>
value=<span class="code-quote">"org.apache.activemq.jndi.ActiveMQInitialContextFactory"</span>
/&gt;</span>
 <span class="code-tag">&lt;jms:JMSNamingProperty name=<span class="code-quote">"java.naming.provider.url"</span>
value=<span class="code-quote">"tcp://localhost:61616"</span> /&gt;</span>
 <span class="code-tag">&lt;/jms:address&gt;</span>
 <span class="code-tag">&lt;/jms:destination&gt;</span>
<span class="code-tag">&lt;/beans&gt;</span>
</pre>
</div></div>

<p>Server:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-object">Object</span> implementor = <span class="code-keyword">new</span>
Hello();
 JaxWsServerFactoryBean svrFactory = <span class="code-keyword">new</span> JaxWsServerFactoryBean();
 svrFactory.setServiceClass(IHello.class);
 svrFactory.setAddress(<span class="code-quote">"jms:<span class="code-comment">//"</span>);
</span> svrFactory.setServiceBean(implementor);
 svrFactory.getInInterceptors().add(<span class="code-keyword">new</span> LoggingInInterceptor());
 svrFactory.getOutInterceptors().add(<span class="code-keyword">new</span> LoggingInInterceptor());
 svrFactory.create();

</pre>
</div></div>

<p>Client:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
JaxWsProxyFactoryBean factory = <span class="code-keyword">new</span> JaxWsProxyFactoryBean();
 factory.getInInterceptors().add(<span class="code-keyword">new</span> LoggingInInterceptor());
 factory.getOutInterceptors().add(<span class="code-keyword">new</span> LoggingInInterceptor());
 factory.setServiceClass(IHello.class);
 factory.setAddress(<span class="code-quote">"jms:<span class="code-comment">//"</span>);
</span> IHello hello = (IHello) factory.create(); 
</pre>
</div></div>

<p>If you don't want to use the spring configuration file to configure JMS transport,
you could use the Java code to configure them.</p>

<p>Server:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-object">Object</span> implementor = <span class="code-keyword">new</span>
Hello();
 JaxWsServerFactoryBean svrFactory = <span class="code-keyword">new</span> JaxWsServerFactoryBean();
 svrFactory.setServiceClass(IHello.class);
 svrFactory.setAddress(<span class="code-quote">"jms:<span class="code-comment">//"</span>);
</span> svrFactory.setServiceBean(implementor);
 svrFactory.getInInterceptors().add(<span class="code-keyword">new</span> LoggingInInterceptor());
 svrFactory.getOutInterceptors().add(<span class="code-keyword">new</span> LoggingInInterceptor());
 <span class="code-comment">// We need to create the server first but not start the
server
</span> svrFactory.setStart(<span class="code-keyword">false</span>);
 Server server = svrFactory.create();
 <span class="code-comment">// Get the destination from the server
</span> JMSDestination jmsDestination = (JMSDestination)server.getDestination();
 ServerConfig serverConfig = <span class="code-keyword">new</span> ServerConfig();
 serverConfig.setMessageTimeToLive(1000);
 ...
 jmsDestination.setServerConfig(serverConfig);
 ...
 <span class="code-comment">// Start the server after the configuration
</span> server.start();
</pre>
</div></div>

<p>Client:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
JaxWsProxyFactoryBean factory = <span class="code-keyword">new</span> JaxWsProxyFactoryBean();
 factory.getInInterceptors().add(<span class="code-keyword">new</span> LoggingInInterceptor());
 factory.getOutInterceptors().add(<span class="code-keyword">new</span> LoggingInInterceptor());
 factory.setServiceClass(IHello.class);
 factory.setAddress(<span class="code-quote">"jms:<span class="code-comment">//"</span>);
</span> IHello hello = (IHello) factory.create();
 <span class="code-comment">// You could also configure the jmsConduit with Java code
</span> Client client = ClientProxy.getClient(hello);
 JMSConduit jmsConduit = (JMSConduit) client.getConduit();
 ClientConfig clientConfig = <span class="code-keyword">new</span> ClientConfig();
 clientConfig.setClientReceiveTimeout(1000);
 ...
 jmsConduit.setClientConfig(clientConfiguration);
 AddressType address = <span class="code-keyword">new</span> AddressType();
 address.setConnectionUserName(<span class="code-quote">"testUser"</span>);
 address.setConnectionPassword(<span class="code-quote">"testPasswd"</span>);
 ...
 jmsConduit.setJMSAddress(address);
</pre>
</div></div>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CXF20DOC/Jax-WS+Java+First+with+jms+Transport">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=69467&revisedVersion=9&originalVersion=8">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CXF20DOC/Jax-WS+Java+First+with+jms+Transport?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message