cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [CONF] Apache CXF Documentation > UDP Transport
Date Wed, 26 Sep 2012 18:57:00 GMT
    <base href="">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CXF20DOC&amp;forWysiwyg=true"
<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="">UDP
    <h4>Page  <b>added</b> by             <a href="">Daniel
    <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>
        factory.setAddress(<span class="code-quote">"udp:<span class="code-comment">//localhost:8888"</span>);
</span>        factory.setServiceBean(<span class="code-keyword">new</span>
        server = factory.create();

<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:// 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

<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>
</span>((BindingProvider)proxy).getRequestContext().put(<span class="code-quote">"udp.multi.response.timeout"</span>,
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());

    <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href=""
class="grey">Change Notification Preferences</a>
       <a href="">View
       <a href=";showCommentArea=true#addcomment">Add

View raw message