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/636424b0
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/636424b0
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/636424b0

Branch: refs/heads/3.0.x-fixes
Commit: 636424b0bfea052bbd10c42dcfa202e50c1b3521
Parents: 56f4859
Author: Sergey Beryozkin <[email protected]>
Authored: Fri Aug 21 13:02:24 2015 +0100
Committer: Sergey Beryozkin <[email protected]>
Committed: Fri Aug 21 16:43:34 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/636424b0/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/636424b0/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 1b747a0..084322d 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
@@ -82,8 +82,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/636424b0/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 003fc9a..ba9115a 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);
     }
     

Reply via email to