cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject svn commit: r478504 - in /incubator/cxf/trunk: common/common/src/main/java/org/apache/cxf/common/util/ common/common/src/test/java/org/apache/cxf/common/util/ rt/transports/http/src/main/java/org/apache/cxf/transport/http/ rt/transports/http/src/test/j...
Date Thu, 23 Nov 2006 08:04:05 GMT
Author: mmao
Date: Thu Nov 23 00:04:05 2006
New Revision: 478504

URL: http://svn.apache.org/viewvc?view=rev&rev=478504
Log:
CXF-253
If the port number is missing then the server will fail during launch
So now we set the default port to 80

Modified:
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/StringUtils.java
    incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/util/StringUtilsTest.java
    incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
    incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/JettyHTTPDestinationTest.java

Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/StringUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/StringUtils.java?view=diff&rev=478504&r1=478503&r2=478504
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/StringUtils.java
(original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/StringUtils.java
Thu Nov 23 00:04:05 2006
@@ -169,11 +169,43 @@
         return results;
     } 
     
+    public static String getFirstFound(String contents, String regex) {
+        List<String> founds = getFound(contents, regex);
+        if (isEmpty(founds)) {
+            return null;
+        }
+        return founds.get(0);
+    }
+    
     public static String formatVersionNumber(String target) {
         List<String> found = StringUtils.getFound(target, "\\d+\\.\\d+\\.?\\d*");
         if (isEmpty(found)) {
             return target;
         }
         return getFirstNotEmpty(found);
+    }
+    
+    public static String addDefaultPortIfMissing(String urlString) {
+        return addDefaultPortIfMissing(urlString, "80");
+    }
+    
+    public static String addDefaultPortIfMissing(String urlString, String defaultPort) {
+        URL url = null;
+        try {
+            url = new URL(urlString);
+        } catch (MalformedURLException e) {
+            return urlString;
+        }
+        if (url.getPort() != -1) {
+            return urlString;
+        }
+        String regex = "http://([^/]+)";        
+        String found = StringUtils.getFirstFound(urlString, regex);
+        String replacer = "http://" + found + ":" + defaultPort;
+        
+        if (!StringUtils.isEmpty(found)) {
+            urlString = urlString.replaceFirst(regex, replacer);
+        }                
+        return urlString;
     }
 }

Modified: incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/util/StringUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/util/StringUtilsTest.java?view=diff&rev=478504&r1=478503&r2=478504
==============================================================================
--- incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/util/StringUtilsTest.java
(original)
+++ incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/util/StringUtilsTest.java
Thu Nov 23 00:04:05 2006
@@ -64,4 +64,14 @@
         assertEquals("2.0", StringUtils.formatVersionNumber("2.0-incubator-M1-SNAPSHOT"));
         assertEquals("2.0.12", StringUtils.formatVersionNumber("2.0.12-incubator-M1-SNAPSHOT"));
     }
+    
+    public void testAddPortIfMissing() throws Exception {
+        assertEquals("http://localhost:80", StringUtils.addDefaultPortIfMissing("http://localhost"));
+        assertEquals("http://localhost:80/", StringUtils.addDefaultPortIfMissing("http://localhost/"));
+        assertEquals("http://localhost:80/abc", StringUtils.addDefaultPortIfMissing("http://localhost/abc"));
+        assertEquals("http://localhost:80", StringUtils.addDefaultPortIfMissing("http://localhost:80"));
+        
+        assertEquals("http://localhost:9090", 
+                     StringUtils.addDefaultPortIfMissing("http://localhost", "9090"));
+    }
 }

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?view=diff&rev=478504&r1=478503&r2=478504
==============================================================================
--- 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 Nov 23 00:04:05 2006
@@ -32,6 +32,7 @@
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.Base64Exception;
 import org.apache.cxf.common.util.Base64Utility;
+import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.configuration.ConfigurationProvider;
 import org.apache.cxf.configuration.security.AuthorizationPolicy;
 import org.apache.cxf.message.Message;
@@ -167,9 +168,9 @@
     protected abstract void copyRequestHeaders(Message message,
                                                Map<String, List<String>> headers);
 
-    protected final String getAddressValue() {
-        return endpointInfo.getAddress();
-    }
+    protected final String getAddressValue() {       
+        return StringUtils.addDefaultPortIfMissing(endpointInfo.getAddress());
+    }        
 
     private void init() {
         if (!isSetServer()) {

Modified: incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/JettyHTTPDestinationTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/JettyHTTPDestinationTest.java?view=diff&rev=478504&r1=478503&r2=478504
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/JettyHTTPDestinationTest.java
(original)
+++ incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/JettyHTTPDestinationTest.java
Thu Nov 23 00:04:05 2006
@@ -34,6 +34,7 @@
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.common.util.Base64Utility;
+import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.configuration.security.AuthorizationPolicy;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.io.AbstractCachedOutputStream;
@@ -110,7 +111,7 @@
         assertNotNull("unexpected null address", ref);
         assertEquals("unexpected address",
                      EndpointReferenceUtils.getAddress(ref),
-                     EndpointReferenceUtils.getAddress(address));
+                     StringUtils.addDefaultPortIfMissing(EndpointReferenceUtils.getAddress(address)));
     }
     public void testRemoveServant() throws Exception {
         destination = setUpDestination();



Mime
View raw message