cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-7459] Avoiding defaulting to application/xml if no CT is set
Date Wed, 02 Aug 2017 11:11:18 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 46bb02fe8 -> 16ddd3ee1


[CXF-7459] Avoiding defaulting to application/xml if no CT is set


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

Branch: refs/heads/3.1.x-fixes
Commit: 16ddd3ee156066074b26834a91b6d2ba520d7c93
Parents: 46bb02f
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Wed Aug 2 11:59:02 2017 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Wed Aug 2 12:10:54 2017 +0100

----------------------------------------------------------------------
 .../org/apache/cxf/jaxrs/client/AbstractClient.java     | 10 +++++++---
 .../org/apache/cxf/jaxrs/client/ClientProxyImpl.java    |  2 --
 .../java/org/apache/cxf/jaxrs/client/WebClient.java     |  6 ++----
 .../jaxrs/JAXRSClientServerProxySpringBookTest.java     |  2 +-
 .../systest/jaxrs/JAXRSClientServerSpringBookTest.java  | 12 ++++++------
 .../cxf/systest/jaxrs/JAXRSLocalTransportTest.java      |  2 +-
 .../org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java |  4 ++--
 .../org/apache/cxf/systest/jaxrs/jms/JAXRSJmsTest.java  |  2 +-
 8 files changed, 20 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/16ddd3ee/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 30e032f..d3360af 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
@@ -470,9 +470,13 @@ public abstract class AbstractClient implements Client {
         
         @SuppressWarnings("unchecked")
         Class<T> theClass = (Class<T>)cls;
-        
-        MediaType contentType = JAXRSUtils.toMediaType(headers.getFirst("Content-Type").toString());

-        
+
+        Object contentTypeHeader = headers.getFirst("Content-Type");
+        if (contentTypeHeader == null) {
+            contentTypeHeader = MediaType.WILDCARD;
+        }
+        MediaType contentType = JAXRSUtils.toMediaType(contentTypeHeader.toString());
+
         List<WriterInterceptor> writers = ClientProviderFactory.getInstance(outMessage)
             .createMessageBodyWriterInterceptor(theClass, type, anns, contentType, outMessage,
null);
         if (writers != null) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/16ddd3ee/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 985d209..af7e0af 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
@@ -358,8 +358,6 @@ public class ClientProxyImpl extends AbstractClient implements
                 List<MediaType> consumeTypes = ori.getConsumeTypes();
                 if (!consumeTypes.isEmpty() && !consumeTypes.get(0).equals(MediaType.WILDCARD_TYPE))
{
                     ctType = JAXRSUtils.mediaTypeToString(ori.getConsumeTypes().get(0));
-                } else if (bodyClass != null) {
-                    ctType = MediaType.APPLICATION_XML;
                 }
                 if (ctType != null) {
                     headers.putSingle(HttpHeaders.CONTENT_TYPE, ctType);

http://git-wip-us.apache.org/repos/asf/cxf/blob/16ddd3ee/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 8f49f0d..efe03bf 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
@@ -956,10 +956,8 @@ public class WebClient extends AbstractClient {
     
     private MultivaluedMap<String, String> prepareHeaders(Class<?> responseClass,
Object body) {
         MultivaluedMap<String, String> headers = getHeaders();
-        if (headers.getFirst(HttpHeaders.CONTENT_TYPE) == null && body != null) {
-            String contentType = body instanceof Form ? MediaType.APPLICATION_FORM_URLENCODED

-                                     : MediaType.APPLICATION_XML;
-            headers.putSingle(HttpHeaders.CONTENT_TYPE, contentType);
+        if (headers.getFirst(HttpHeaders.CONTENT_TYPE) == null && body instanceof
Form) {
+            headers.putSingle(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED);
         }
         
         if (responseClass != null && responseClass != Response.class 

http://git-wip-us.apache.org/repos/asf/cxf/blob/16ddd3ee/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java
index 40d8b7a..fb5b435 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java
@@ -139,7 +139,7 @@ public class JAXRSClientServerProxySpringBookTest extends AbstractBusClientServe
         URL url = new URL("http://localhost:" + PORT + "/test/5/bookstorestorage/thosebooks");
         WebClient wc = WebClient.create(url.toString(), 
                                         Collections.singletonList(new CustomJaxbElementProvider()));
-        Response r = wc.post(new Book("proxy", 333L));
+        Response r = wc.type("application/xml").post(new Book("proxy", 333L));
         Book book = r.readEntity(Book.class);
         assertEquals(333L, book.getId());
         String ct = r.getHeaderString("Content-Type");

http://git-wip-us.apache.org/repos/asf/cxf/blob/16ddd3ee/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
index 8a79a9c..e636e43 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
@@ -504,7 +504,7 @@ public class JAXRSClientServerSpringBookTest extends AbstractBusClientServerTest
         String endpointAddress =
             "http://localhost:" + PORT + "/the/thebooks9/depth"; 
         WebClient wc = WebClient.create(endpointAddress);
-        Response r = wc.post(new Book("CXF", 123L));
+        Response r = wc.type("application/xml").post(new Book("CXF", 123L));
         assertEquals(413, r.getStatus());
     }
     
@@ -513,7 +513,7 @@ public class JAXRSClientServerSpringBookTest extends AbstractBusClientServerTest
         String endpointAddress =
             "http://localhost:" + PORT + "/the/thebooks9stax/depth"; 
         WebClient wc = WebClient.create(endpointAddress);
-        Response r = wc.post(new Book("CXF", 123L));
+        Response r = wc.type("application/xml").post(new Book("CXF", 123L));
         assertEquals(413, r.getStatus());
     }
     
@@ -523,7 +523,7 @@ public class JAXRSClientServerSpringBookTest extends AbstractBusClientServerTest
             "http://localhost:" + PORT + "/the/thebooks9/depth-source"; 
         WebClient wc = WebClient.create(endpointAddress);
         WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(1000000L);
-        Response r = wc.post(new Book("CXF", 123L));
+        Response r = wc.type("application/xml").post(new Book("CXF", 123L));
         assertEquals(413, r.getStatus());
     }
     
@@ -532,7 +532,7 @@ public class JAXRSClientServerSpringBookTest extends AbstractBusClientServerTest
         String endpointAddress =
             "http://localhost:" + PORT + "/the/thebooks9stax/depth-source"; 
         WebClient wc = WebClient.create(endpointAddress);
-        Response r = wc.post(new Book("CXF", 123L));
+        Response r = wc.type("application/xml").post(new Book("CXF", 123L));
         assertEquals(413, r.getStatus());
     }
     
@@ -541,7 +541,7 @@ public class JAXRSClientServerSpringBookTest extends AbstractBusClientServerTest
         String endpointAddress =
             "http://localhost:" + PORT + "/the/thebooks9/depth-dom"; 
         WebClient wc = WebClient.create(endpointAddress);
-        Response r = wc.post(new Book("CXF", 123L));
+        Response r = wc.type("application/xml").post(new Book("CXF", 123L));
         assertEquals(413, r.getStatus());
     }
     
@@ -550,7 +550,7 @@ public class JAXRSClientServerSpringBookTest extends AbstractBusClientServerTest
         String endpointAddress =
             "http://localhost:" + PORT + "/the/thebooks9stax/depth-dom"; 
         WebClient wc = WebClient.create(endpointAddress);
-        Response r = wc.post(new Book("CXF", 123L));
+        Response r = wc.type("application/xml").post(new Book("CXF", 123L));
         assertEquals(413, r.getStatus());
     }
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/16ddd3ee/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
index 678df1d..37ff6e5 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
@@ -219,7 +219,7 @@ public class JAXRSLocalTransportTest extends AbstractBusClientServerTestBase
{
         WebClient localClient = WebClient.create("local://books");
         localClient.accept("text/xml");
         localClient.path("bookstore/books");
-        Book book = localClient.post(new Book("New", 124L), Book.class);
+        Book book = localClient.type("application/xml").post(new Book("New", 124L), Book.class);
         assertEquals(124L, book.getId());
     }
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/16ddd3ee/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
index e31fa3e..136ac97 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
@@ -217,7 +217,7 @@ public class JAXRSSoapBookTest extends AbstractBusClientServerTestBase
{
         WebClient client = WebClient.create(address);
         WebClient.getConfig(client).getInInterceptors().add(in);
         WebClient.getConfig(client).getOutInterceptors().add(out);
-        Book2 book = client.accept("text/xml").post(new Book2(), Book2.class);
+        Book2 book = client.type("application/xml").accept("text/xml").post(new Book2(),
Book2.class);
         assertEquals(124L, book.getId());
     }
     
@@ -227,7 +227,7 @@ public class JAXRSSoapBookTest extends AbstractBusClientServerTestBase
{
         String address = "http://localhost:" + PORT 
                          + "/test/v2/rest-transform/bookstore/books";
         WebClient client = WebClient.create(address);
-        Book book = client.accept("text/xml").post(new Book(), Book.class);
+        Book book = client.type("application/xml").accept("text/xml").post(new Book(), Book.class);
         assertEquals(124L, book.getId());
     }
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/16ddd3ee/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jms/JAXRSJmsTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jms/JAXRSJmsTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jms/JAXRSJmsTest.java
index 9567618..95d29e6 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jms/JAXRSJmsTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jms/JAXRSJmsTest.java
@@ -109,7 +109,7 @@ public class JAXRSJmsTest extends AbstractBusClientServerTestBase {
         WebClient.getConfig(client).getRequestContext()
             .put(org.apache.cxf.message.Message.REQUEST_URI, "/bookstore/oneway");
         client.header("OnewayRequest", "true");
-        Response r = client.put(new Book("OneWay From WebClient", 129L));
+        Response r = client.type("application/xml").put(new Book("OneWay From WebClient",
129L));
         assertEquals(202, r.getStatus());
         assertFalse(r.hasEntity());
         


Mime
View raw message