cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-6045] Registering BodyWriters early
Date Mon, 13 Oct 2014 12:16:08 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes 54790282c -> 5b8284a57


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

Branch: refs/heads/2.7.x-fixes
Commit: 5b8284a57d668faeffbdb54d68be57919aa62163
Parents: 5479028
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Mon Oct 13 12:41:14 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Mon Oct 13 13:15:47 2014 +0100

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


http://git-wip-us.apache.org/repos/asf/cxf/blob/5b8284a5/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
index f5c88ae..79ed860 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
@@ -117,6 +117,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) {
@@ -656,7 +657,6 @@ 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);

http://git-wip-us.apache.org/repos/asf/cxf/blob/5b8284a5/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
index 4d39095..f155faa 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
@@ -94,6 +94,7 @@ public class WebClient extends AbstractClient {
     protected WebClient(ClientState state) {
         super(state);
         cfg.getInInterceptors().add(new ClientAsyncResponseInterceptor());
+        cfg.getOutInterceptors().add(new BodyWriter());
     }
     
     
@@ -1102,9 +1103,6 @@ public class WebClient extends AbstractClient {
         reqContext.put(RESPONSE_CLASS, responseClass);
         reqContext.put(RESPONSE_TYPE, outGenericType);
         
-        if (body != null) {
-            m.getInterceptorChain().add(new BodyWriter());
-        }
         setPlainOperationNameProperty(m, httpMethod + ":" + uri.toString());
         return m;
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/5b8284a5/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientRequestContextImpl.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientRequestContextImpl.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientRequestContextImpl.java
index b91b1e4..ba66513 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientRequestContextImpl.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientRequestContextImpl.java
@@ -105,7 +105,7 @@ public class ClientRequestContextImpl extends AbstractRequestContextImpl
     public void setEntity(Object entity, Annotation[] anns, MediaType mt) {
         if (mt != null) {
             MultivaluedMap<String, Object> headers = getHeaders();
-            headers.putSingle(HttpHeaders.CONTENT_TYPE, mt);
+            headers.putSingle(HttpHeaders.CONTENT_TYPE, mt.toString());
             m.put(Message.CONTENT_TYPE, mt.toString());
         }
         if (anns != null) {
@@ -126,9 +126,8 @@ public class ClientRequestContextImpl extends AbstractRequestContextImpl
             } else {
                 type = entity.getClass();
             }
-        }
-        if (type != null) {
             m.put(Type.class, type);
+            m.remove("org.apache.cxf.empty.request");
         }
     }
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/5b8284a5/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 26a8fe6..bd1db99 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
@@ -275,6 +275,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 {
@@ -554,9 +564,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";
             }
@@ -565,7 +578,11 @@ public class JAXRS20ClientServerBookTest extends AbstractBusClientServerTestBase
             if (!expectedMethod.equals(method)) {
                 throw new RuntimeException();
             }
-            rc.setEntity(new Book("book", ((Book)rc.getEntity()).getId() + 5), null, null);
+            if ("GET".equals(expectedMethod)) {
+                rc.setEntity(new Book("book", 560L), null, MediaType.TEXT_XML_TYPE);
+            } else {
+                rc.setEntity(new Book("book", ((Book)rc.getEntity()).getId() + 5), null,
null);
+            }
         }
 
                 


Mime
View raw message