cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1494587 - in /cxf/trunk/rt: frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ rs/client/src/main/java/org/apache/cxf/ja...
Date Wed, 19 Jun 2013 12:31:38 GMT
Author: sergeyb
Date: Wed Jun 19 12:31:37 2013
New Revision: 1494587

URL: http://svn.apache.org/r1494587
Log:
Not encoding comma in queries, trying to encode non-encoded URLs when constructing WebClients

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
    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
    cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
    cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
    cxf/trunk/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java?rev=1494587&r1=1494586&r2=1494587&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
Wed Jun 19 12:31:37 2013
@@ -878,7 +878,7 @@ public class UriBuilderImpl extends UriB
         }
     }
 
-    private UriBuilder uriAsTemplate(String uri) {
+    public UriBuilder uriAsTemplate(String uri) {
         // This can be a start of replacing URI class Parser completely
         // but it can be too complicated, the following code is needed for now 
         // to deal with URIs containing template variables. 

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=1494587&r1=1494586&r2=1494587&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 19 12:31:37 2013
@@ -78,7 +78,7 @@ public final class HttpUtils {
     
     // there are more of such characters, ex, '*' but '*' is not affected by UrlEncode
     private static final String PATH_RESERVED_CHARACTERS = "=@/:!$&\'(),;~";
-    private static final String QUERY_RESERVED_CHARACTERS = "?/";
+    private static final String QUERY_RESERVED_CHARACTERS = "?/,";
     
     private static final String CURRENT_PATH_SEGMENT = ".";
     private static final String PARENT_PATH_SEGMENT = "..";

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=1494587&r1=1494586&r2=1494587&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 19 12:31:37 2013
@@ -45,6 +45,11 @@ public class HttpUtilsTest extends Asser
     }
     
     @Test
+    public void testCommaInQuery() {
+        assertEquals("a+,b", HttpUtils.queryEncode("a ,b"));
+    }
+    
+    @Test
     public void testRelativize() throws Exception {
         // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6226081
         URI a = new URI("file:/c:/abc/def/myDocument/doc.xml");

Modified: cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=1494587&r1=1494586&r2=1494587&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java (original)
+++ cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java Wed
Jun 19 12:31:37 2013
@@ -100,8 +100,8 @@ public abstract class AbstractClient imp
     protected static final String REQUEST_CONTEXT = "RequestContext";
     protected static final String RESPONSE_CONTEXT = "ResponseContext";
     protected static final String KEEP_CONDUIT_ALIVE = "KeepConduitAlive";
+    protected static final String HTTP_SCHEME = "http";
     
-    private static final String HTTP_SCHEME = "http";
     private static final String PROXY_PROPERTY = "jaxrs.proxy";
     private static final String HEADER_SPLIT_PROPERTY =
         "org.apache.cxf.http.header.split";

Modified: cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=1494587&r1=1494586&r2=1494587&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java (original)
+++ cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java Wed Jun
19 12:31:37 2013
@@ -56,6 +56,7 @@ import org.apache.cxf.feature.Feature;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxrs.impl.ResponseImpl;
+import org.apache.cxf.jaxrs.impl.UriBuilderImpl;
 import org.apache.cxf.jaxrs.model.ParameterType;
 import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
@@ -79,7 +80,7 @@ public class WebClient extends AbstractC
     private static final String RESPONSE_TYPE = "response.type";
     
     protected WebClient(String baseAddress) {
-        this(URI.create(baseAddress));
+        this(convertStringToURI(baseAddress));
     }
     
     protected WebClient(URI baseURI) {
@@ -1178,6 +1179,20 @@ public class WebClient extends AbstractC
         return clientState;
     }
     
+    static URI convertStringToURI(String baseAddress) {
+        try {
+            return URI.create(baseAddress);
+        } catch (RuntimeException ex) {
+            // no need to check "https" scheme or indeed ':' 
+            // as the relative address will not work as the base address
+            if (baseAddress.startsWith(HTTP_SCHEME)) {
+                return new UriBuilderImpl().uriAsTemplate(baseAddress).build();
+            } else {
+                throw ex;
+            }
+        }
+    }
+    
     // Async related code, consider pushing most of it to AbstractClient
     public AsyncInvoker async() {
         return new AsyncInvokerImpl();

Modified: cxf/trunk/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java?rev=1494587&r1=1494586&r2=1494587&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java (original)
+++ cxf/trunk/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java Wed
Jun 19 12:31:37 2013
@@ -81,6 +81,12 @@ public class WebClientTest extends Asser
     }
     
     @Test
+    public void testAddressNotEncoded() {
+        URI u = WebClient.create("http://localhost/somepath ").getCurrentURI();
+        assertEquals("http://localhost/somepath%20", u.toString());
+    }
+    
+    @Test
     public void testDoubleAsteriscs() {
         URI u = WebClient.create("http://foo").path("**").getCurrentURI();
         assertEquals("http://foo/**", u.toString());



Mime
View raw message