cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: Temp avoiding supporting absolute current URI for ws schemes
Date Tue, 10 Jun 2014 16:01:14 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 50c679edc -> 98a481d18


Temp avoiding supporting absolute current URI for ws schemes


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/98a481d1
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/98a481d1
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/98a481d1

Branch: refs/heads/master
Commit: 98a481d18a94a0d41d9ffaa0b924445b4f47be2c
Parents: 50c679e
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Tue Jun 10 17:00:43 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Tue Jun 10 17:00:43 2014 +0100

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/client/AbstractClient.java   |  1 -
 .../apache/cxf/jaxrs/client/LocalClientState.java | 18 ++++++++++--------
 .../org/apache/cxf/jaxrs/client/WebClient.java    |  3 ++-
 .../apache/cxf/jaxrs/client/WebClientTest.java    | 12 ++++++++----
 4 files changed, 20 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/98a481d1/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
index 76f8335..b4e9fad 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
@@ -340,7 +340,6 @@ public abstract class AbstractClient implements Client {
     
     protected void resetBaseAddress(URI uri) {
         state.setBaseURI(uri);
-        resetCurrentBuilder(uri);
     }
     
     protected void resetCurrentBuilder(URI uri) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/98a481d1/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/LocalClientState.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/LocalClientState.java
b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/LocalClientState.java
index a70d9b6..aeddb0c 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/LocalClientState.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/LocalClientState.java
@@ -34,7 +34,6 @@ import org.apache.cxf.jaxrs.impl.UriBuilderImpl;
  */
 public class LocalClientState implements ClientState {
     private static final String HTTP_SCHEME = "http";
-    private static final String WS_SCHEME = "ws";
     
     private MultivaluedMap<String, String> requestHeaders = new MetadataMap<String,
String>(false, true);
     private MultivaluedMap<String, String> templates;
@@ -48,11 +47,7 @@ public class LocalClientState implements ClientState {
     
     public LocalClientState(URI baseURI) {
         this.baseURI = baseURI;
-        if (isSupportedScheme(baseURI)) {
-            this.currentBuilder = new UriBuilderImpl().uri(baseURI);
-        } else {
-            this.currentBuilder = new UriBuilderImpl().uri("/");
-        }
+        resetCurrentUri();
     }
     
     public LocalClientState(URI baseURI, URI currentURI) {
@@ -69,7 +64,13 @@ public class LocalClientState implements ClientState {
         this.currentBuilder = cs.currentBuilder != null ? cs.currentBuilder.clone() : null;
     }
     
-    
+    private void resetCurrentUri() {
+        if (isSupportedScheme(baseURI)) {
+            this.currentBuilder = new UriBuilderImpl().uri(baseURI);
+        } else {
+            this.currentBuilder = new UriBuilderImpl().uri("/");
+        }
+    }
     
     public void setCurrentBuilder(UriBuilder currentBuilder) {
         this.currentBuilder = currentBuilder;
@@ -81,6 +82,7 @@ public class LocalClientState implements ClientState {
     
     public void setBaseURI(URI baseURI) {
         this.baseURI = baseURI;
+        resetCurrentUri();
     }
     
     public URI getBaseURI() {
@@ -152,6 +154,6 @@ public class LocalClientState implements ClientState {
     
     private static boolean isSupportedScheme(URI uri) {
         return !StringUtils.isEmpty(uri.getScheme()) 
-            && (uri.getScheme().startsWith(HTTP_SCHEME) || uri.getScheme().startsWith(WS_SCHEME));
+            && uri.getScheme().startsWith(HTTP_SCHEME);
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/98a481d1/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
index 325922c..16ac260 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
@@ -679,7 +679,8 @@ public class WebClient extends AbstractClient {
     public WebClient to(String newAddress, boolean forward) {
         getState().setTemplates(null);
         if (forward) {
-            if (!newAddress.startsWith(getBaseURI().toString())) {
+            if (!newAddress.startsWith("/") 
+                && !newAddress.startsWith(getBaseURI().toString())) {
                 throw new IllegalArgumentException("Base address can not be preserved");
             }
             resetCurrentBuilder(URI.create(newAddress));

http://git-wip-us.apache.org/repos/asf/cxf/blob/98a481d1/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java b/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
index dab2ab7..f0fe6df 100644
--- a/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
+++ b/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
@@ -110,18 +110,22 @@ public class WebClientTest extends Assert {
     
     @Test 
     public void testBaseCurrentWebSocketPath() {
-        assertEquals(URI.create("ws://foo"), WebClient.create("ws://foo").getBaseURI());
-        assertEquals(URI.create("ws://foo"), WebClient.create("ws://foo").getCurrentURI());
+        WebClient wc = WebClient.create("ws://foo");
+        assertEquals(URI.create("ws://foo"), wc.getBaseURI());
+        assertEquals(URI.create("/"), wc.getCurrentURI());
+        wc.path("a");
+        assertEquals(URI.create("ws://foo"), wc.getBaseURI());
+        assertEquals(URI.create("/a"), wc.getCurrentURI());
     }
     
     @Test 
     public void testNewBaseCurrentWebSocketPath() {
         WebClient wc = WebClient.create("ws://foo");
         assertEquals(URI.create("ws://foo"), wc.getBaseURI());
-        assertEquals(URI.create("ws://foo"), wc.getCurrentURI());
+        assertEquals(URI.create("/"), wc.getCurrentURI());
         wc.to("ws://bar", false);
         assertEquals(URI.create("ws://bar"), wc.getBaseURI());
-        assertEquals(URI.create("ws://bar"), wc.getCurrentURI());
+        assertEquals(URI.create("/"), wc.getCurrentURI());
     }
     
     @Test 


Mime
View raw message