cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r615027 - in /incubator/cxf/trunk/rt/transports: http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestinationTest.java http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
Date Thu, 24 Jan 2008 21:50:26 GMT
Author: dkulp
Date: Thu Jan 24 13:50:25 2008
New Revision: 615027

URL: http://svn.apache.org/viewvc?rev=615027&view=rev
Log:
[CXF-1403] Patch from Sergey Beryozkin applied.  Thanks!

Modified:
    incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestinationTest.java
    incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java

Modified: incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestinationTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestinationTest.java?rev=615027&r1=615026&r2=615027&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestinationTest.java
(original)
+++ incubator/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestinationTest.java
Thu Jan 24 13:50:25 2008
@@ -159,6 +159,22 @@
     }
     
     @Test
+    public void testRandomPortAllocation() throws Exception {
+        transportFactory = new JettyHTTPTransportFactory();
+        transportFactory.setBus(new CXFBusImpl());
+        ServiceInfo serviceInfo = new ServiceInfo();
+        serviceInfo.setName(new QName("bla", "Service"));
+        EndpointInfo ei = new EndpointInfo(serviceInfo, "");
+        ei.setName(new QName("bla", "Port"));
+        
+        Destination d1 = transportFactory.getDestination(ei);
+        URL url = new URL(d1.getAddress().getAddress().getValue());
+        assertTrue("No random port has been allocated", 
+                   url.getPort() > 0);
+        
+    }
+    
+    @Test
     public void testGetMultiple() throws Exception {
         transportFactory = new JettyHTTPTransportFactory();
         transportFactory.setBus(new CXFBusImpl());

Modified: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java?rev=615027&r1=615026&r2=615027&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
(original)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
Thu Jan 24 13:50:25 2008
@@ -22,6 +22,7 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.net.HttpURLConnection;
+import java.net.ServerSocket;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Enumeration;
@@ -70,7 +71,7 @@
     public static final String HTTP_RESPONSE = "HTTP.RESPONSE";
     public static final String HTTP_CONTEXT = "HTTP.CONTEXT";
     public static final String PROTOCOL_HEADERS_CONTENT_TYPE = Message.CONTENT_TYPE.toLowerCase();
-    
+        
     private static final Logger LOG = LogUtils.getL7dLogger(AbstractHTTPDestination.class);
     
     private static final long serialVersionUID = 1L;
@@ -232,6 +233,20 @@
     
     protected static EndpointInfo getAddressValue(EndpointInfo ei, boolean dp) {       
         if (dp) {
+            
+            String eiAddress = ei.getAddress();
+            if (eiAddress == null) {
+                try {
+                    ServerSocket s = new ServerSocket(0);
+                    ei.setAddress("http://localhost:" + s.getLocalPort());
+                    s.close();
+                    return ei;
+                } catch (IOException ex) {
+                    // problem allocating a random port, go to the default one
+                    ei.setAddress("http://localhost");
+                }
+            }
+            
             String addr = StringUtils.addDefaultPortIfMissing(ei.getAddress());
             if (addr != null) {
                 ei.setAddress(addr);



Mime
View raw message