You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2014/10/13 13:41:32 UTC

git commit: [CXF-6045] Registering BodyWriters early

Repository: cxf
Updated Branches:
  refs/heads/master 43c65b076 -> 2321c67b6


[CXF-6045] Registering BodyWriters early


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

Branch: refs/heads/master
Commit: 2321c67b65a9f8a0863153573510bbd57d94238b
Parents: 43c65b0
Author: Sergey Beryozkin <sb...@talend.com>
Authored: Mon Oct 13 12:41:14 2014 +0100
Committer: Sergey Beryozkin <sb...@talend.com>
Committed: Mon Oct 13 12:41:14 2014 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/client/ClientProxyImpl.java       |  4 ++--
 .../org/apache/cxf/jaxrs/client/WebClient.java  |  2 +-
 .../client/spec/ClientRequestContextImpl.java   |  4 ++--
 .../jaxrs/JAXRS20ClientServerBookTest.java      | 21 ++++++++++++++++++--
 4 files changed, 24 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/2321c67b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
index ebee107..09c7766 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
@@ -118,6 +118,7 @@ public class ClientProxyImpl extends AbstractClient implements
         this.isRoot = isRoot;
         this.inheritHeaders = inheritHeaders;
         initValuesMap(varValues);
+        cfg.getOutInterceptors().add(new BodyWriter());
     }
     
     private void initValuesMap(Object... varValues) {
@@ -663,9 +664,8 @@ public class ClientProxyImpl extends AbstractClient implements
             
             if (body != null) {
                 outMessage.put("BODY_INDEX", bodyIndex);
-                outMessage.getInterceptorChain().add(new BodyWriter());
             }
-    
+            
             Map<String, Object> reqContext = getRequestContext(outMessage);
             reqContext.put(OperationResourceInfo.class.getName(), ori);
             reqContext.put("BODY_INDEX", bodyIndex);

http://git-wip-us.apache.org/repos/asf/cxf/blob/2321c67b/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 f792025..a266102 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
@@ -96,6 +96,7 @@ public class WebClient extends AbstractClient {
     protected WebClient(ClientState state) {
         super(state);
         cfg.getInInterceptors().add(new ClientAsyncResponseInterceptor());
+        cfg.getOutInterceptors().add(new BodyWriter());
     }
     
     
@@ -1122,7 +1123,6 @@ public class WebClient extends AbstractClient {
         
         if (body != null) {
             m.put(Type.class, inGenericType);
-            m.getInterceptorChain().add(new BodyWriter());
         }
         setPlainOperationNameProperty(m, httpMethod + ":" + uri.toString());
         return m;

http://git-wip-us.apache.org/repos/asf/cxf/blob/2321c67b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientRequestContextImpl.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientRequestContextImpl.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientRequestContextImpl.java
index 7a3d27d..3f76cea 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientRequestContextImpl.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientRequestContextImpl.java
@@ -139,10 +139,10 @@ public class ClientRequestContextImpl extends AbstractRequestContextImpl
             } else {
                 type = entity.getClass();
             }
-        }
-        if (type != null) {
             m.put(Type.class, type);
+            m.remove("org.apache.cxf.empty.request");
         }
+        
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/cxf/blob/2321c67b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
index 497b31a..1cfccf4 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
@@ -326,6 +326,16 @@ public class JAXRS20ClientServerBookTest extends AbstractBusClientServerTestBase
         Book book = wc.invoke("DELETE", new Book("book", 555L), Book.class);
         assertEquals(561L, book.getId());
     }
+    @Test
+    public void testReplaceBookMistypedCTAndHttpVerb2() throws Exception {
+        
+        String endpointAddress = "http://localhost:" + PORT + "/bookstore/books2/mistyped"; 
+        WebClient wc = WebClient.create(endpointAddress,
+                                        Collections.singletonList(new ReplaceBodyFilter()));
+        wc.accept("text/mistypedxml").header("THEMETHOD", "PUT");
+        Book book = wc.invoke("GET", null, Book.class);
+        assertEquals(561L, book.getId());
+    }
     
     @Test
     public void testPostGetCollectionGenericEntityAndType() throws Exception {
@@ -670,9 +680,12 @@ public class JAXRS20ClientServerBookTest extends AbstractBusClientServerTestBase
             String expectedMethod = null; 
             if (rc.getAcceptableMediaTypes().contains(MediaType.valueOf("text/mistypedxml"))
                 && rc.getHeaders().getFirst("THEMETHOD") != null) {
-                expectedMethod = "DELETE";
+                expectedMethod = MediaType.TEXT_XML_TYPE.equals(rc.getMediaType()) ? "DELETE" : "GET";
                 rc.setUri(URI.create("http://localhost:" + PORT + "/bookstore/books2"));
                 rc.setMethod(rc.getHeaders().getFirst("THEMETHOD").toString());
+                if ("GET".equals(expectedMethod)) {
+                    rc.getHeaders().putSingle("Content-Type", "text/xml");
+                }
             } else {
                 expectedMethod = "POST";
             }
@@ -681,7 +694,11 @@ public class JAXRS20ClientServerBookTest extends AbstractBusClientServerTestBase
             if (!expectedMethod.equals(method)) {
                 throw new RuntimeException();
             }
-            rc.setEntity(new Book("book", ((Book)rc.getEntity()).getId() + 5));
+            if ("GET".equals(expectedMethod)) {
+                rc.setEntity(new Book("book", 560L));
+            } else {
+                rc.setEntity(new Book("book", ((Book)rc.getEntity()).getId() + 5));
+            }
         }