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 > UDP Transport
Date Wed, 26 Sep 2012 18:57:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/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/UDP+Transport">UDP
Transport</a></h2>
    <h4>Page  <b>added</b> by             <a href="https://cwiki.apache.org/confluence/display/~dkulp">Daniel
Kulp</a>
    </h4>
         <br/>
    <div class="notificationGreySide">
         
<h1><a name="UDPTransport-UDPTransport"></a>UDP Transport</h1>

<p>CXF provides a transport plugin to support transporting small (under about 60K) message
payloads over UDP.  It supports both unicast and multicast packet transfers.</p>


<h3><a name="UDPTransport-CreatingaserveronaUDPport"></a>Creating a server
on a UDP port</h3>
<p>To use the UDP transport, you just need to include the cxf-rt-transports-udp module
on the classpath and use a "udp://host:port" style URL for the address.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
        JaxWsServerFactoryBean factory = <span class="code-keyword">new</span>
JaxWsServerFactoryBean();
        factory.setBus(getStaticBus());
        factory.setAddress(<span class="code-quote">"udp:<span class="code-comment">//localhost:8888"</span>);
</span>        factory.setServiceBean(<span class="code-keyword">new</span>
GreeterImpl());
        server = factory.create();
</pre>
</div></div>

<p>That will start the server on localhost UDP port 8888.   You can also omit the hostname
(udp://:8888) to bind to all the addresses or use one of the multicast addresses (example:
udp://239.255.255.250:3702) to respond to the appropriate broadcasts.</p>

<h3><a name="UDPTransport-Clientconfiguration"></a>Client configuration</h3>
<p>Similar to the server side, you just need to use the appropriate UDP url in order
for the client to use UDP.  </p>

<p>If the hostname is specified in the URL, the Datagram will be sent directly to the
host:port.   If the hostname is not specified, the Datagram will be sent as a broadcast to
the specific port.   If the hostname is a multicast address, the Datagram will be sent Multicast
to the given port.</p>

<h4><a name="UDPTransport-Acceptingmultipleresponses"></a>Accepting multiple
responses</h4>

<p>UDP is different than the other CXF transports in that it allows multiple responses
to be received for a single request.  For example, if you send out a request via a multicast
or broadcast, several servers could respond to that request.   The basic JAX-WS generated
interfaces only allow a single response to be returned to the application.  However, if you
use the JAX-WS Asynchronous methods, you can have CXF call the AsyncHandler for each response.
  To enable this, set the request property "udp.multi.response.timeout" to a timeout value
greater than 0.   CXF will wait that long for responses to come in before returning back to
the application.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-comment">//wait 3 seconds <span class="code-keyword">for</span>
responses
</span>((BindingProvider)proxy).getRequestContext().put(<span class="code-quote">"udp.multi.response.timeout"</span>,
3000);
proxy.greetMeAsync(<span class="code-quote">"World"</span>, <span class="code-keyword">new</span>
AsyncHandler&lt;<span class="code-object">String</span>&gt;() {
    <span class="code-keyword">public</span> void handleResponse(Response&lt;<span
class="code-object">Object</span>&gt; res) {
            <span class="code-object">System</span>.out.println(res.get());
    }
});
</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/UDP+Transport">View
Online</a>
              |
       <a href="https://cwiki.apache.org/confluence/display/CXF20DOC/UDP+Transport?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
           </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message