Author: alessio.soldano(a)jboss.com
Date: 2013-05-06 10:33:28 -0400 (Mon, 06 May 2013)
New Revision: 17531
Added:
stack/cxf/trunk/modules/addons/transports/udp/
stack/cxf/trunk/modules/addons/transports/udp/pom.xml
stack/cxf/trunk/modules/addons/transports/udp/src/
stack/cxf/trunk/modules/addons/transports/udp/src/main/
stack/cxf/trunk/modules/addons/transports/udp/src/main/java/
stack/cxf/trunk/modules/addons/transports/udp/src/main/java/org/
stack/cxf/trunk/modules/addons/transports/udp/src/main/java/org/jboss/
stack/cxf/trunk/modules/addons/transports/udp/src/main/java/org/jboss/wsf/
stack/cxf/trunk/modules/addons/transports/udp/src/main/java/org/jboss/wsf/stack/
stack/cxf/trunk/modules/addons/transports/udp/src/main/java/org/jboss/wsf/stack/cxf/
stack/cxf/trunk/modules/addons/transports/udp/src/main/java/org/jboss/wsf/stack/cxf/addons/
stack/cxf/trunk/modules/addons/transports/udp/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/
stack/cxf/trunk/modules/addons/transports/udp/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/udp/
stack/cxf/trunk/modules/addons/transports/udp/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/udp/Messages.properties
stack/cxf/trunk/modules/addons/transports/udp/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/udp/UDPConduit.java
stack/cxf/trunk/modules/addons/transports/udp/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/udp/UDPDestination.java
stack/cxf/trunk/modules/addons/transports/udp/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/udp/UDPTransportFactory.java
stack/cxf/trunk/modules/addons/transports/udp/src/main/resources/
stack/cxf/trunk/modules/addons/transports/udp/src/main/resources/META-INF/
stack/cxf/trunk/modules/addons/transports/udp/src/main/resources/META-INF/cxf/
stack/cxf/trunk/modules/addons/transports/udp/src/main/resources/META-INF/cxf/bus-extensions.txt
stack/cxf/trunk/modules/addons/transports/udp/src/test/
stack/cxf/trunk/modules/addons/transports/udp/src/test/java/
stack/cxf/trunk/modules/addons/transports/udp/src/test/java/org/
stack/cxf/trunk/modules/addons/transports/udp/src/test/java/org/jboss/
stack/cxf/trunk/modules/addons/transports/udp/src/test/java/org/jboss/wsf/
stack/cxf/trunk/modules/addons/transports/udp/src/test/java/org/jboss/wsf/stack/
stack/cxf/trunk/modules/addons/transports/udp/src/test/java/org/jboss/wsf/stack/cxf/
stack/cxf/trunk/modules/addons/transports/udp/src/test/java/org/jboss/wsf/stack/cxf/addons/
stack/cxf/trunk/modules/addons/transports/udp/src/test/java/org/jboss/wsf/stack/cxf/addons/transports/
stack/cxf/trunk/modules/addons/transports/udp/src/test/java/org/jboss/wsf/stack/cxf/addons/transports/udp/
stack/cxf/trunk/modules/addons/transports/udp/src/test/java/org/jboss/wsf/stack/cxf/addons/transports/udp/Greeter.java
stack/cxf/trunk/modules/addons/transports/udp/src/test/java/org/jboss/wsf/stack/cxf/addons/transports/udp/GreeterImpl.java
stack/cxf/trunk/modules/addons/transports/udp/src/test/java/org/jboss/wsf/stack/cxf/addons/transports/udp/UDPTransportTest.java
stack/cxf/trunk/modules/addons/transports/udp/src/test/resources/
Modified:
stack/cxf/trunk/modules/addons/pom.xml
stack/cxf/trunk/modules/addons/transports/http/httpserver/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/httpserver/HttpServerDestination.java
Log:
[JBWS-3595] Initial implementation of alternative udp transport (no Mina dependency,
direct java.io usage for any type of datagram)
Modified: stack/cxf/trunk/modules/addons/pom.xml
===================================================================
--- stack/cxf/trunk/modules/addons/pom.xml 2013-05-03 07:03:22 UTC (rev 17530)
+++ stack/cxf/trunk/modules/addons/pom.xml 2013-05-06 14:33:28 UTC (rev 17531)
@@ -17,6 +17,7 @@
<!-- Modules -->
<modules>
<module>transports/http/httpserver</module>
+ <module>transports/udp</module>
</modules>
</project>
Modified:
stack/cxf/trunk/modules/addons/transports/http/httpserver/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/httpserver/HttpServerDestination.java
===================================================================
---
stack/cxf/trunk/modules/addons/transports/http/httpserver/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/httpserver/HttpServerDestination.java 2013-05-03
07:03:22 UTC (rev 17530)
+++
stack/cxf/trunk/modules/addons/transports/http/httpserver/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/httpserver/HttpServerDestination.java 2013-05-06
14:33:28 UTC (rev 17531)
@@ -155,7 +155,7 @@
}
catch (Exception e)
{
- LOG.throwing(Handler.class.getName(),
"handle(com.sun.net.httpserver.HttpExchange ex)", e);
+ LOG.throwing(Handler.class.getName(), "handle(" +
HttpExchange.class.getName() + " ex)", e);
if (e instanceof IOException)
{
throw (IOException) e;
Added: stack/cxf/trunk/modules/addons/transports/udp/pom.xml
===================================================================
--- stack/cxf/trunk/modules/addons/transports/udp/pom.xml (rev 0)
+++ stack/cxf/trunk/modules/addons/transports/udp/pom.xml 2013-05-06 14:33:28 UTC (rev
17531)
@@ -0,0 +1,31 @@
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <name>JBoss Web Services - Stack CXF UDP transport</name>
+ <artifactId>jbossws-cxf-transports-udp</artifactId>
+ <packaging>jar</packaging>
+
+ <parent>
+ <groupId>org.jboss.ws.cxf</groupId>
+ <artifactId>jbossws-cxf-addons</artifactId>
+ <version>4.2.0-SNAPSHOT</version>
+ <relativePath>../../../pom.xml</relativePath>
+ </parent>
+
+ <!-- Dependencies -->
+ <dependencies>
+
+ <!-- CXF dependencies -->
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-frontend-jaxws</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Added:
stack/cxf/trunk/modules/addons/transports/udp/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/udp/Messages.properties
===================================================================
---
stack/cxf/trunk/modules/addons/transports/udp/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/udp/Messages.properties
(rev 0)
+++
stack/cxf/trunk/modules/addons/transports/udp/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/udp/Messages.properties 2013-05-06
14:33:28 UTC (rev 17531)
@@ -0,0 +1 @@
+
Added:
stack/cxf/trunk/modules/addons/transports/udp/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/udp/UDPConduit.java
===================================================================
---
stack/cxf/trunk/modules/addons/transports/udp/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/udp/UDPConduit.java
(rev 0)
+++
stack/cxf/trunk/modules/addons/transports/udp/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/udp/UDPConduit.java 2013-05-06
14:33:28 UTC (rev 17531)
@@ -0,0 +1,236 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.stack.cxf.addons.transports.udp;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.InterfaceAddress;
+import java.net.MulticastSocket;
+import java.net.NetworkInterface;
+import java.net.URI;
+import java.util.Enumeration;
+import java.util.logging.Logger;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.helpers.LoadingByteArrayOutputStream;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.transport.AbstractConduit;
+import org.apache.cxf.ws.addressing.EndpointReferenceType;
+
+/**
+ * A modified version of Apache CXF org.apache.cxf.transport.udp.UDPConduit
+ * that does not rely on Apache Mina and directly uses basic java.io for
+ * any type of datagram.
+ *
+ * @author alessio.soldano(a)jboss.com
+ */
+public class UDPConduit extends AbstractConduit
+{
+ private static final String MULTI_RESPONSE_TIMEOUT =
"udp.multi.response.timeout";
+
+ private static final Logger LOG = LogUtils.getL7dLogger(UDPDestination.class);
+
+ Bus bus;
+
+ public UDPConduit(EndpointReferenceType t, final Bus bus)
+ {
+ super(t);
+ this.bus = bus;
+ }
+
+ private void dataReceived(Message message, byte bytes[], boolean async)
+ {
+ final Message inMessage = new MessageImpl();
+ inMessage.setExchange(message.getExchange());
+ message.getExchange().setInMessage(inMessage);
+ inMessage.setContent(InputStream.class, new ByteArrayInputStream(bytes));
+ incomingObserver.onMessage(inMessage);
+ if (!message.getExchange().isSynchronous())
+ {
+ message.getExchange().setInMessage(null);
+ }
+ }
+
+ public void prepare(final Message message) throws IOException
+ {
+ try
+ {
+ String address = (String) message.get(Message.ENDPOINT_ADDRESS);
+ if (StringUtils.isEmpty(address))
+ {
+ address = this.getTarget().getAddress().getValue();
+ }
+ URI uri = new URI(address);
+ if (StringUtils.isEmpty(uri.getHost())) { //broadcast
+ String s = uri.getSchemeSpecificPart();
+ if (s.startsWith("//:"))
+ {
+ s = s.substring(3);
+ }
+ if (s.indexOf('/') != -1)
+ {
+ s = s.substring(0, s.indexOf('/'));
+ }
+ int port = Integer.parseInt(s);
+ send(message, null, port);
+ } else {
+ InetSocketAddress isa = new InetSocketAddress(uri.getHost(), uri.getPort());
+ send(message, isa, isa.getPort());
+ }
+ }
+ catch (Exception ex)
+ {
+ throw new IOException(ex);
+ }
+ }
+
+ private void send(Message message, InetSocketAddress isa, int port)
+ {
+ message.setContent(OutputStream.class, new SocketOutputStream(port, isa,
message));
+ }
+
+ private final class SocketOutputStream extends LoadingByteArrayOutputStream
+ {
+ private final int port;
+
+ private final Message message;
+
+ private final InetSocketAddress isa;
+
+ private SocketOutputStream(int port, InetSocketAddress isa, Message message)
+ {
+ this.port = port;
+ this.message = message;
+ this.isa = isa;
+ }
+
+ public void close() throws IOException
+ {
+ super.close();
+ DatagramSocket socket = (isa != null) ? new MulticastSocket(null) : new
DatagramSocket();
+ socket.setSendBufferSize(this.size());
+ socket.setReceiveBufferSize(64 * 1024);
+ socket.setBroadcast(true);
+
+ if (isa == null) //broadcast
+ {
+ Enumeration<NetworkInterface> interfaces =
NetworkInterface.getNetworkInterfaces();
+ while (interfaces.hasMoreElements())
+ {
+ NetworkInterface networkInterface = interfaces.nextElement();
+ if (!networkInterface.isUp() || networkInterface.isLoopback())
+ {
+ continue;
+ }
+ for (InterfaceAddress interfaceAddress :
networkInterface.getInterfaceAddresses())
+ {
+ InetAddress broadcast = interfaceAddress.getBroadcast();
+ if (broadcast == null)
+ {
+ continue;
+ }
+ DatagramPacket sendPacket = new DatagramPacket(this.getRawBytes(), 0,
this.size(), broadcast, port);
+ try
+ {
+ socket.send(sendPacket);
+ }
+ catch (Exception e)
+ {
+ //ignore
+ }
+ }
+ }
+ }
+ else
+ {
+ DatagramPacket sendPacket = new DatagramPacket(this.getRawBytes(), 0,
this.size(), isa);
+ try
+ {
+ socket.send(sendPacket);
+ }
+ catch (Exception e)
+ {
+ //ignore
+ }
+ }
+
+ if (!message.getExchange().isOneWay())
+ {
+ byte bytes[] = new byte[64 * 1024];
+ DatagramPacket p = new DatagramPacket(bytes, bytes.length);
+ Object to = message.getContextualProperty(MULTI_RESPONSE_TIMEOUT);
+ Integer i = null;
+ if (to instanceof String)
+ {
+ i = Integer.parseInt((String) to);
+ }
+ else if (to instanceof Integer)
+ {
+ i = (Integer) to;
+ }
+ if (i == null || i <= 0 || message.getExchange().isSynchronous())
+ {
+ socket.setSoTimeout(30000);
+ socket.receive(p);
+ dataReceived(message, bytes, false);
+ }
+ else
+ {
+ socket.setSoTimeout(i);
+ boolean found = false;
+ try
+ {
+ while (true)
+ {
+ socket.receive(p);
+ dataReceived(message, bytes, false);
+ found = true;
+ }
+ }
+ catch (java.net.SocketTimeoutException ex)
+ {
+ if (!found)
+ {
+ throw ex;
+ }
+ }
+ }
+ }
+ socket.close();
+ }
+ }
+
+ protected Logger getLogger()
+ {
+ return LOG;
+ }
+
+}
Added:
stack/cxf/trunk/modules/addons/transports/udp/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/udp/UDPDestination.java
===================================================================
---
stack/cxf/trunk/modules/addons/transports/udp/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/udp/UDPDestination.java
(rev 0)
+++
stack/cxf/trunk/modules/addons/transports/udp/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/udp/UDPDestination.java 2013-05-06
14:33:28 UTC (rev 17531)
@@ -0,0 +1,227 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.stack.cxf.addons.transports.udp;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetSocketAddress;
+import java.net.MulticastSocket;
+import java.net.URI;
+import java.util.logging.Logger;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.helpers.LoadingByteArrayOutputStream;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.ExchangeImpl;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.AbstractDestination;
+import org.apache.cxf.transport.Conduit;
+import org.apache.cxf.workqueue.AutomaticWorkQueue;
+import org.apache.cxf.workqueue.WorkQueueManager;
+import org.apache.cxf.ws.addressing.EndpointReferenceType;
+
+/**
+ * A modified version of Apache CXF org.apache.cxf.transport.udp.UDPDestination
+ * that does not rely on Apache Mina and directly uses basic java.io for any
+ * type of datagram.
+ *
+ * @author alessio.soldano(a)jboss.com
+ */
+public class UDPDestination extends AbstractDestination
+{
+ private static final Logger LOG = LogUtils.getL7dLogger(UDPDestination.class);
+
+ AutomaticWorkQueue queue;
+
+ volatile DatagramSocket socket;
+
+ public UDPDestination(Bus b, EndpointReferenceType ref, EndpointInfo ei)
+ {
+ super(b, ref, ei);
+ }
+
+ class SocketListener implements Runnable
+ {
+ public void run()
+ {
+ while (true)
+ {
+ if (socket == null)
+ {
+ return;
+ }
+ try
+ {
+ byte bytes[] = new byte[64 * 1024];
+ final DatagramPacket p = new DatagramPacket(bytes, bytes.length);
+ socket.receive(p);
+
+ LoadingByteArrayOutputStream out = new LoadingByteArrayOutputStream()
+ {
+ public void close() throws IOException
+ {
+ super.close();
+ final DatagramPacket p2 = new DatagramPacket(getRawBytes(), 0,
this.size(), p.getSocketAddress());
+ socket.send(p2);
+ }
+ };
+
+ UDPConnectionInfo info = new UDPConnectionInfo(out, new
ByteArrayInputStream(bytes, 0, p.getLength()));
+
+ final MessageImpl m = new MessageImpl();
+ final Exchange exchange = new ExchangeImpl();
+ exchange.setDestination(UDPDestination.this);
+ m.setDestination(UDPDestination.this);
+ exchange.setInMessage(m);
+ m.setContent(InputStream.class, info.in);
+ m.put(UDPConnectionInfo.class, info);
+ queue.execute(new Runnable()
+ {
+ public void run()
+ {
+ getMessageObserver().onMessage(m);
+ }
+ });
+ }
+ catch (IOException e)
+ {
+ if (socket != null) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+
+ /** {@inheritDoc}*/
+ @Override
+ protected Conduit getInbuiltBackChannel(Message inMessage)
+ {
+ if (inMessage.getExchange().isOneWay())
+ {
+ return null;
+ }
+ final UDPConnectionInfo info = inMessage.get(UDPConnectionInfo.class);
+ return new AbstractBackChannelConduit()
+ {
+ public void prepare(Message message) throws IOException
+ {
+ message.setContent(OutputStream.class, info.out);
+ }
+ };
+ }
+
+ /** {@inheritDoc}*/
+ @Override
+ protected Logger getLogger()
+ {
+ return LOG;
+ }
+
+ protected void activate()
+ {
+ WorkQueueManager queuem = bus.getExtension(WorkQueueManager.class);
+ queue = queuem.getNamedWorkQueue("udp-transport");
+ if (queue == null)
+ {
+ queue = queuem.getAutomaticWorkQueue();
+ }
+
+ try
+ {
+ URI uri = new URI(this.getAddress().getAddress().getValue());
+ InetSocketAddress isa = null;
+ if (StringUtils.isEmpty(uri.getHost()))
+ {
+ String s = uri.getSchemeSpecificPart();
+ if (s.startsWith("//:"))
+ {
+ s = s.substring(3);
+ }
+ if (s.indexOf('/') != -1)
+ {
+ s = s.substring(0, s.indexOf('/'));
+ }
+ int port = Integer.parseInt(s);
+ isa = new InetSocketAddress(port);
+ }
+ else
+ {
+ isa = new InetSocketAddress(uri.getHost(), uri.getPort());
+ }
+ DatagramSocket s;
+ if (isa.getAddress().isMulticastAddress())
+ {
+ s = new MulticastSocket(null);
+ ((MulticastSocket) s).setTimeToLive(1);
+ s.bind(new InetSocketAddress(isa.getPort()));
+ ((MulticastSocket) s).joinGroup(isa.getAddress());
+ }
+ else
+ {
+ s = new DatagramSocket(null);
+ s.bind(new InetSocketAddress(isa.getAddress(), isa.getPort()));
+ }
+ s.setReuseAddress(true);
+ s.setReceiveBufferSize(64 * 1024);
+ s.setSendBufferSize(64 * 1024);
+ socket = s;
+ queue.execute(new SocketListener());
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ throw new RuntimeException(ex);
+ }
+ }
+
+ protected void deactivate()
+ {
+ if (socket != null)
+ {
+ DatagramSocket s = socket;
+ socket = null;
+ s.close();
+ }
+ }
+
+ static class UDPConnectionInfo
+ {
+ final OutputStream out;
+
+ final InputStream in;
+
+ public UDPConnectionInfo(OutputStream o, InputStream i)
+ {
+ out = o;
+ in = i;
+ }
+ }
+}
Added:
stack/cxf/trunk/modules/addons/transports/udp/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/udp/UDPTransportFactory.java
===================================================================
---
stack/cxf/trunk/modules/addons/transports/udp/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/udp/UDPTransportFactory.java
(rev 0)
+++
stack/cxf/trunk/modules/addons/transports/udp/src/main/java/org/jboss/wsf/stack/cxf/addons/transports/udp/UDPTransportFactory.java 2013-05-06
14:33:28 UTC (rev 17531)
@@ -0,0 +1,118 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.jboss.wsf.stack.cxf.addons.transports.udp;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.annotation.Resource;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.common.injection.NoJSR250Annotations;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.AbstractTransportFactory;
+import org.apache.cxf.transport.Conduit;
+import org.apache.cxf.transport.ConduitInitiator;
+import org.apache.cxf.transport.Destination;
+import org.apache.cxf.transport.DestinationFactory;
+import org.apache.cxf.ws.addressing.AttributedURIType;
+import org.apache.cxf.ws.addressing.EndpointReferenceType;
+
+@NoJSR250Annotations(unlessNull = { "bus" })
+public class UDPTransportFactory extends AbstractTransportFactory
+ implements DestinationFactory, ConduitInitiator {
+
+ public static final String TRANSPORT_ID =
"http://cxf.apache.org/transports/udp";
+ public static final List<String> DEFAULT_NAMESPACES
+ = Arrays.asList(TRANSPORT_ID);
+
+ private static final Logger LOG = LogUtils.getL7dLogger(UDPTransportFactory.class);
+ private static final Set<String> URI_PREFIXES = new HashSet<String>();
+ static {
+ URI_PREFIXES.add("udp://");
+ }
+
+ private Set<String> uriPrefixes = new HashSet<String>(URI_PREFIXES);
+
+ public UDPTransportFactory() {
+ this(null);
+ }
+ public UDPTransportFactory(Bus b) {
+ super(DEFAULT_NAMESPACES, null);
+ bus = b;
+ register();
+ }
+
+ @Resource(name = "cxf")
+ public void setBus(Bus b) {
+ super.setBus(b);
+ }
+
+ public Destination getDestination(EndpointInfo ei) throws IOException {
+ return getDestination(ei, null);
+ }
+
+ protected Destination getDestination(EndpointInfo ei,
+ EndpointReferenceType reference)
+ throws IOException {
+ if (reference == null) {
+ reference = createReference(ei);
+ }
+ return new UDPDestination(bus, reference, ei);
+ }
+
+
+ public Conduit getConduit(EndpointInfo ei) throws IOException {
+ return getConduit(ei, null);
+ }
+
+ public Conduit getConduit(EndpointInfo ei, EndpointReferenceType target) throws
IOException {
+ LOG.log(Level.FINE, "Creating conduit for {0}", ei.getAddress());
+ if (target == null) {
+ target = createReference(ei);
+ }
+ return new UDPConduit(target, bus);
+ }
+
+
+ public Set<String> getUriPrefixes() {
+ return uriPrefixes;
+ }
+ public void setUriPrefixes(Set<String> s) {
+ uriPrefixes = s;
+ }
+ EndpointReferenceType createReference(EndpointInfo ei) {
+ EndpointReferenceType epr = new EndpointReferenceType();
+ AttributedURIType address = new AttributedURIType();
+ address.setValue(ei.getAddress());
+ epr.setAddress(address);
+ return epr;
+ }
+
+}
Added:
stack/cxf/trunk/modules/addons/transports/udp/src/main/resources/META-INF/cxf/bus-extensions.txt
===================================================================
---
stack/cxf/trunk/modules/addons/transports/udp/src/main/resources/META-INF/cxf/bus-extensions.txt
(rev 0)
+++
stack/cxf/trunk/modules/addons/transports/udp/src/main/resources/META-INF/cxf/bus-extensions.txt 2013-05-06
14:33:28 UTC (rev 17531)
@@ -0,0 +1 @@
+org.jboss.wsf.stack.cxf.addons.transports.udp.UDPTransportFactory::true
Added:
stack/cxf/trunk/modules/addons/transports/udp/src/test/java/org/jboss/wsf/stack/cxf/addons/transports/udp/Greeter.java
===================================================================
---
stack/cxf/trunk/modules/addons/transports/udp/src/test/java/org/jboss/wsf/stack/cxf/addons/transports/udp/Greeter.java
(rev 0)
+++
stack/cxf/trunk/modules/addons/transports/udp/src/test/java/org/jboss/wsf/stack/cxf/addons/transports/udp/Greeter.java 2013-05-06
14:33:28 UTC (rev 17531)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.stack.cxf.addons.transports.udp;
+
+import javax.jws.WebService;
+
+@WebService
+public interface Greeter
+{
+ public String greetMe(String requestType);
+
+ public void pingMe();
+
+ public String sayHi();
+}
Added:
stack/cxf/trunk/modules/addons/transports/udp/src/test/java/org/jboss/wsf/stack/cxf/addons/transports/udp/GreeterImpl.java
===================================================================
---
stack/cxf/trunk/modules/addons/transports/udp/src/test/java/org/jboss/wsf/stack/cxf/addons/transports/udp/GreeterImpl.java
(rev 0)
+++
stack/cxf/trunk/modules/addons/transports/udp/src/test/java/org/jboss/wsf/stack/cxf/addons/transports/udp/GreeterImpl.java 2013-05-06
14:33:28 UTC (rev 17531)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.stack.cxf.addons.transports.udp;
+
+import javax.jws.WebService;
+
+@WebService(serviceName = "SOAPService",
+ portName = "SoapPort",
+ endpointInterface =
"org.jboss.wsf.stack.cxf.addons.transports.udp.Greeter",
+ targetNamespace = "http://apache.org/hello_world/services")
+public class GreeterImpl implements Greeter
+{
+ public GreeterImpl() {
+ }
+
+ public String greetMe(String requestType) {
+ return "Hello " + requestType;
+ }
+
+ public void pingMe() {
+ }
+
+ public String sayHi() {
+ return "Hi!";
+ }
+}
Added:
stack/cxf/trunk/modules/addons/transports/udp/src/test/java/org/jboss/wsf/stack/cxf/addons/transports/udp/UDPTransportTest.java
===================================================================
---
stack/cxf/trunk/modules/addons/transports/udp/src/test/java/org/jboss/wsf/stack/cxf/addons/transports/udp/UDPTransportTest.java
(rev 0)
+++
stack/cxf/trunk/modules/addons/transports/udp/src/test/java/org/jboss/wsf/stack/cxf/addons/transports/udp/UDPTransportTest.java 2013-05-06
14:33:28 UTC (rev 17531)
@@ -0,0 +1,124 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.stack.cxf.addons.transports.udp;
+
+import java.net.NetworkInterface;
+import java.util.Enumeration;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
+import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class UDPTransportTest
+{
+ private static final String PORT = "9434";
+ private static Server server;
+ private static Bus bus;
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception
+ {
+ bus = BusFactory.newInstance().createBus();
+ BusFactory.setDefaultBus(bus);
+ JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
+ factory.setBus(bus);
+ factory.setAddress("udp://:" + PORT);
+ factory.setServiceBean(new GreeterImpl());
+ server = factory.create();
+ }
+
+ @AfterClass
+ public static void shutdown() throws Exception
+ {
+ server.stop();
+ server = null;
+ if (bus != null) {
+ bus.shutdown(true);
+ }
+ bus = null;
+ }
+
+ @Test
+ public void testSimpleUDP() throws Exception
+ {
+ JaxWsProxyFactoryBean fact = new JaxWsProxyFactoryBean();
+ fact.setAddress("udp://localhost:" + PORT);
+ Greeter g = fact.create(Greeter.class);
+ for (int x = 0; x < 5; x++)
+ {
+ Assert.assertEquals("Hello World", g.greetMe("World"));
+ }
+
+ ((java.io.Closeable) g).close();
+ }
+
+ @Test
+ public void testBroadcastUDP() throws Exception
+ {
+ Enumeration<NetworkInterface> interfaces =
NetworkInterface.getNetworkInterfaces();
+ int count = 0;
+ while (interfaces.hasMoreElements())
+ {
+ NetworkInterface networkInterface = interfaces.nextElement();
+ if (!networkInterface.isUp() || networkInterface.isLoopback())
+ {
+ continue;
+ }
+ count++;
+ }
+ if (count == 0)
+ {
+ //no non-loopbacks, cannot do broadcasts
+ System.out.println("Skipping broadcast test");
+ return;
+ }
+
+ JaxWsProxyFactoryBean fact = new JaxWsProxyFactoryBean();
+ fact.setAddress("udp://:" + PORT + "/foo");
+ Greeter g = fact.create(Greeter.class);
+ Assert.assertEquals("Hello World", g.greetMe("World"));
+ ((java.io.Closeable) g).close();
+ }
+
+ @Test
+ public void testLargeRequest() throws Exception
+ {
+ JaxWsProxyFactoryBean fact = new JaxWsProxyFactoryBean();
+ fact.setAddress("udp://localhost:" + PORT);
+ Greeter g = fact.create(Greeter.class);
+ StringBuilder b = new StringBuilder(100000);
+ for (int x = 0; x < 10000; x++)
+ {
+ b.append("Hello ");
+ }
+ Assert.assertEquals("Hello " + b.toString(), g.greetMe(b.toString()));
+
+ ((java.io.Closeable) g).close();
+ }
+}