cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: Letting users to avoid setting use.async.conduit property
Date Fri, 21 Aug 2015 12:02:43 GMT
Repository: cxf
Updated Branches:
  refs/heads/master d567e03fd -> 9f32e2bf5


Letting users to avoid setting use.async.conduit property


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

Branch: refs/heads/master
Commit: 9f32e2bf5bc3ed9b896e0e81f993e76a445cb609
Parents: d567e03
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Fri Aug 21 13:02:24 2015 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Fri Aug 21 13:02:24 2015 +0100

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/client/AbstractClient.java | 21 ++++++++++++++++++--
 .../cxf/systest/jaxrs/JAXRSAsyncClientTest.java |  4 +++-
 .../jaxrs/JAXRSClientServerBookTest.java        |  5 +++++
 3 files changed, 27 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/9f32e2bf/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 bb1b76e..b16269a 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
@@ -33,9 +33,11 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.logging.Logger;
 
@@ -106,7 +108,9 @@ public abstract class AbstractClient implements Client {
     private static final String HEADER_SPLIT_PROPERTY =
         "org.apache.cxf.http.header.split";
     private static final Logger LOG = LogUtils.getL7dLogger(AbstractClient.class);
-        
+    private static final Set<String> KNOWN_METHODS = new HashSet<String>(
+        Arrays.asList("GET", "POST", "HEAD", "OPTIONS", "PUT", "DELETE", "TRACE"));
+    
     protected ClientConfiguration cfg = new ClientConfiguration();
     private ClientState state;
     private AtomicBoolean closed = new AtomicBoolean(); 
@@ -905,7 +909,7 @@ public abstract class AbstractClient implements Client {
         m.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
         m.put(Message.INBOUND_MESSAGE, Boolean.FALSE);
         
-        m.put(Message.HTTP_REQUEST_METHOD, httpMethod);
+        setRequestMethod(m, httpMethod);
         m.put(Message.PROTOCOL_HEADERS, headers);
         if (currentURI.isAbsolute() && currentURI.getScheme().startsWith(HTTP_SCHEME))
{
             m.put(Message.ENDPOINT_ADDRESS, currentURI.toString());
@@ -947,6 +951,19 @@ public abstract class AbstractClient implements Client {
         return m;
     }
     
+    private void setRequestMethod(Message m, String httpMethod) {
+        m.put(Message.HTTP_REQUEST_METHOD, httpMethod);
+        if (!KNOWN_METHODS.contains(httpMethod) && !m.containsKey("use.async.http.conduit"))
{
+            // if the async conduit is loaded then let it handle this method without users

+            // having to explicitly request it given that, without reflectively updating
+            // HTTPUrlConnection, it will not work without the async conduit anyway
+            m.put("use.async.http.conduit", true);
+        }
+        //TODO: consider setting "use.httpurlconnection.method.reflection" here too - 
+        // if the async conduit is not loaded then the only way for the custom HTTP verb

+        // to be supported is to attempt to reflectively modify HTTPUrlConnection
+    }
+
     protected void setEmptyRequestPropertyIfNeeded(Message outMessage, Object body) {
         if (body == null) {
             outMessage.put("org.apache.cxf.empty.request", true);

http://git-wip-us.apache.org/repos/asf/cxf/blob/9f32e2bf/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java
index 40c1255..e10e487 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java
@@ -81,8 +81,10 @@ public class JAXRSAsyncClientTest extends AbstractBusClientServerTestBase
{
     public void testRetrieveBookCustomMethodAsyncSync() throws Exception {
         String address = "http://localhost:" + PORT + "/bookstore/retrieve";
         WebClient wc = WebClient.create(address);
+        // Setting this property is not needed given that 
+        // we have the async conduit loaded in the test module:
+        // WebClient.getConfig(wc).getRequestContext().put("use.async.http.conduit", true);
         wc.type("application/xml").accept("application/xml");
-        WebClient.getConfig(wc).getRequestContext().put("use.async.http.conduit", true);
         Book book = wc.invoke("RETRIEVE", new Book("Retrieve", 123L), Book.class);
         assertEquals("Retrieve", book.getName());
         wc.close();

http://git-wip-us.apache.org/repos/asf/cxf/blob/9f32e2bf/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
index 67cd611..8a1a1a5 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
@@ -114,6 +114,11 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase
{
         if (useReflection) {
             WebClient.getConfig(wc).getRequestContext().put("use.httpurlconnection.method.reflection",
true);
         }
+        // CXF RS Client code will set this property to true if the http verb is unknown
+        // and this property is not already set. The async conduit is loaded in the tests
module
+        // but we do want to test HTTPUrlConnection reflection hence we set this property
to false
+        WebClient.getConfig(wc).getRequestContext().put("use.async.http.conduit", false);
+        
         return wc.invoke("RETRIEVE", new Book("Retrieve", 123L), Book.class);
     }
     


Mime
View raw message