cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1099421 - 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, 04 May 2011 11:43:32 GMT
Author: sergeyb
Date: Wed May  4 11:43:31 2011
New Revision: 1099421

URL: http://svn.apache.org/viewvc?rev=1099421&view=rev
Log:
[CXF-3478] Using Message.BASE_PATH when available for determining the endpoint address

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=1099421&r1=1099420&r2=1099421&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
May  4 11:43:31 2011
@@ -20,9 +20,8 @@
 package org.apache.cxf.jaxrs.utils;
 
 import java.io.UnsupportedEncodingException;
-import java.net.MalformedURLException;
 import java.net.URI;
-import java.net.URL;
+import java.net.URISyntaxException;
 import java.net.URLEncoder;
 import java.text.SimpleDateFormat;
 import java.util.List;
@@ -212,8 +211,9 @@ public final class HttpUtils {
     public static String getBaseAddress(Message m) {
         String endpointAddress = getEndpointAddress(m);
         try {
-            return new URL(endpointAddress).getPath();
-        } catch (MalformedURLException ex) {
+            String path = new URI(endpointAddress).getRawPath();
+            return path.length() == 0 ? "/" : path;
+        } catch (URISyntaxException ex) {
             return endpointAddress == null ? "/" : endpointAddress;
         }
     }
@@ -229,7 +229,8 @@ public final class HttpUtils {
                     ? request.getAttribute("org.apache.cxf.transport.endpoint.address") :
null;
                 address = property != null ? property.toString() : ei.getAddress();
             } else {
-                address = d.getAddress().getAddress().getValue();
+                address = m.containsKey(Message.BASE_PATH) 
+                    ? (String)m.get(Message.BASE_PATH) : d.getAddress().getAddress().getValue();
             }
         } else {
             address = (String)m.get(Message.ENDPOINT_ADDRESS);

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=1099421&r1=1099420&r2=1099421&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 May  4 11:43:31 2011
@@ -23,9 +23,12 @@ import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.Response;
 
 import org.apache.cxf.jaxrs.model.ParameterType;
+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.transport.Destination;
+import org.easymock.EasyMock;
 
 import org.junit.Assert;
 import org.junit.Test;
@@ -118,5 +121,35 @@ public class HttpUtilsTest extends Asser
         assertEquals(Response.Status.BAD_REQUEST,
                      HttpUtils.getParameterFailureStatus(ParameterType.COOKIE));
     }
+
+    @Test
+    public void testGetBaseAddressHttpUri() {
+        doTestGetBaseAddress("http://localhost:8080/store?query", "/store");
+    }
+    
+    @Test
+    public void testGetBaseAddressHttpEncodedUri() {
+        doTestGetBaseAddress("http://localhost:8080/store%20?query", "/store%20");
+    }
+    
+    @Test
+    public void testGetBaseAddressJmsUri() {
+        doTestGetBaseAddress("jms://topic", "/");
+    }
     
+    @Test
+    public void testGetBaseAddressWithoutScheme() {
+        doTestGetBaseAddress("/s", "/s");
+    }
+    
+    private void doTestGetBaseAddress(String baseURI, String expected) {
+        Message m = new MessageImpl();
+        Exchange exchange = new ExchangeImpl();
+        m.setExchange(exchange);
+        Destination dest = EasyMock.createMock(Destination.class);
+        exchange.setDestination(dest);
+        m.put(Message.BASE_PATH, baseURI);
+        String address = HttpUtils.getBaseAddress(m);
+        assertEquals(expected, address);
+    }
 }



Mime
View raw message