cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1354441 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
Date Wed, 27 Jun 2012 11:44:39 GMT
Author: sergeyb
Date: Wed Jun 27 11:44:38 2012
New Revision: 1354441

URL: http://svn.apache.org/viewvc?rev=1354441&view=rev
Log:
[CXF-4396] Checking a port when 0.0.0.0 address gets replaced

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java?rev=1354441&r1=1354440&r2=1354441&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java Wed
Jun 27 11:44:38 2012
@@ -200,7 +200,10 @@ public final class HttpUtils {
             if (!absolute) {
                 u = URI.create(base + u.toString());
             } else {
-                u = URI.create(u.toString().replace(ANY_IP_ADDRESS, serverAndPort));
+                int originalPort = u.getPort();
+                String replaceValue = originalPort == -1 ? ANY_IP_ADDRESS
+                    : ANY_IP_ADDRESS + ":" + originalPort;
+                u = URI.create(u.toString().replace(replaceValue, serverAndPort));
             }
         }
         return u;

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java?rev=1354441&r1=1354440&r2=1354441&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
Wed Jun 27 11:44:38 2012
@@ -178,6 +178,29 @@ public class HttpUtilsTest extends Asser
         assertEquals("http://localhost:8080/bar/foo", u.toString());
     }
     
+    @Test
+    public void testReplaceAnyIPAddressWithPort() {
+        Message m = new MessageImpl();
+        HttpServletRequest req = EasyMock.createMock(HttpServletRequest.class);
+        m.put(AbstractHTTPDestination.HTTP_REQUEST, req);
+        req.getScheme();
+        EasyMock.expectLastCall().andReturn("http");
+        req.getServerName();
+        EasyMock.expectLastCall().andReturn("localhost");
+        req.getLocalPort();
+        EasyMock.expectLastCall().andReturn(8080);
+        EasyMock.replay(req);
+        URI u = HttpUtils.toAbsoluteUri(URI.create("http://0.0.0.0:8080/bar/foo"), m);
+        assertEquals("http://localhost:8080/bar/foo", u.toString());
+    }
+    
+    @Test
+    public void testReplaceLocalHostWithPort() {
+        Message m = new MessageImpl();
+        URI u = HttpUtils.toAbsoluteUri(URI.create("http://localhost:8080/bar/foo"), m);
+        assertEquals("http://localhost:8080/bar/foo", u.toString());
+    }
+    
     private void doTestGetBaseAddress(String baseURI, String expected) {
         Message m = new MessageImpl();
         Exchange exchange = new ExchangeImpl();



Mime
View raw message