cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1408702 - 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 Tue, 13 Nov 2012 12:36:36 GMT
Author: sergeyb
Date: Tue Nov 13 12:36:35 2012
New Revision: 1408702

URL: http://svn.apache.org/viewvc?rev=1408702&view=rev
Log:
[CXF-4631] Using HttpServletRequest.getServerPort to build the absolute URI, thanks to Jakub
BocheĊ„ski

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=1408702&r1=1408701&r2=1408702&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 Tue
Nov 13 12:36:35 2012
@@ -271,11 +271,13 @@ public final class HttpUtils {
         boolean absolute = u.isAbsolute();
         if (request != null && (!absolute || u.toString().contains(ANY_IP_ADDRESS_START)))
{
             String serverAndPort = request.getServerName();
+            boolean localAddressUsed = false;
             if (absolute && ANY_IP_ADDRESS.equals(serverAndPort)) {
                 serverAndPort = request.getLocalAddr();
+                localAddressUsed = true;
             }
                 
-            int port = request.getLocalPort();
+            int port = localAddressUsed ? request.getLocalPort() : request.getServerPort();
             if (port != DEFAULT_HTTP_PORT) {
                 serverAndPort += ":" + port;
             }

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=1408702&r1=1408701&r2=1408702&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
Tue Nov 13 12:36:35 2012
@@ -171,7 +171,7 @@ public class HttpUtilsTest extends Asser
         EasyMock.expectLastCall().andReturn("http");
         req.getServerName();
         EasyMock.expectLastCall().andReturn("localhost");
-        req.getLocalPort();
+        req.getServerPort();
         EasyMock.expectLastCall().andReturn(8080);
         EasyMock.replay(req);
         URI u = HttpUtils.toAbsoluteUri(URI.create("http://0.0.0.0/bar/foo"), m);
@@ -187,7 +187,7 @@ public class HttpUtilsTest extends Asser
         EasyMock.expectLastCall().andReturn("http");
         req.getServerName();
         EasyMock.expectLastCall().andReturn("localhost");
-        req.getLocalPort();
+        req.getServerPort();
         EasyMock.expectLastCall().andReturn(8080);
         EasyMock.replay(req);
         URI u = HttpUtils.toAbsoluteUri(URI.create("http://0.0.0.0:8080/bar/foo"), m);



Mime
View raw message