You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ff...@apache.org on 2020/02/25 22:09:03 UTC

[cxf] branch 3.3.x-fixes updated: [CXF-8223]Be able to read empty entity from a Response with 202

This is an automated email from the ASF dual-hosted git repository.

ffang pushed a commit to branch 3.3.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/3.3.x-fixes by this push:
     new 21a19f9  [CXF-8223]Be able to read empty entity from a Response with 202
21a19f9 is described below

commit 21a19f97ff261e8cc7774d131823276ceaba05b9
Author: Freeman Fang <fr...@gmail.com>
AuthorDate: Tue Feb 25 17:07:46 2020 -0500

    [CXF-8223]Be able to read empty entity from a Response with 202
    
    (cherry picked from commit 024fcd0fe0f2f08b3f77c2a96d475a1bf38da1d7)
---
 core/src/main/java/org/apache/cxf/message/Message.java   |  7 +++++++
 .../java/org/apache/cxf/transport/http/HTTPConduit.java  |  7 +++++--
 .../java/org/apache/cxf/systest/jaxrs/BookStore.java     |  9 +++++++++
 .../cxf/systest/jaxrs/JAXRSClientServerBookTest.java     | 16 ++++++++++------
 4 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/core/src/main/java/org/apache/cxf/message/Message.java b/core/src/main/java/org/apache/cxf/message/Message.java
index aa4dbe3..bcb8e04 100644
--- a/core/src/main/java/org/apache/cxf/message/Message.java
+++ b/core/src/main/java/org/apache/cxf/message/Message.java
@@ -86,6 +86,13 @@ public interface Message extends StringMap {
      */
     String PROCESS_ONEWAY_RESPONSE = "org.apache.cxf.transport.processOneWayResponse";
 
+    
+    /**
+     * Boolean property specifying if 202 response is partial/oneway response.
+     * Default value is true
+     */
+    String PROCESS_202_RESPONSE_ONEWAY_OR_PARTIAL = "org.apache.cxf.transport.process202Response";
+
     /**
      * Boolean property specifying if the thread which runs a request is
      * different to the thread which created this Message.
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
index 5def17af..a4d7193 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
@@ -1636,8 +1636,10 @@ public abstract class HTTPConduit
             }
             propagateConduit(exchange, inMessage);
 
-            if (!doProcessResponse(outMessage, responseCode)
-                || HttpURLConnection.HTTP_ACCEPTED == responseCode) {
+            if ((!doProcessResponse(outMessage, responseCode)
+                || HttpURLConnection.HTTP_ACCEPTED == responseCode)
+                && MessageUtils.getContextualBoolean(outMessage, 
+                    Message.PROCESS_202_RESPONSE_ONEWAY_OR_PARTIAL, true)) {
                 in = getPartialResponse();
                 if (in == null
                     || !MessageUtils.getContextualBoolean(outMessage, Message.PROCESS_ONEWAY_RESPONSE, false)) {
@@ -1658,6 +1660,7 @@ public abstract class HTTPConduit
                         }
                     }
                     exchange.put("IN_CHAIN_COMPLETE", Boolean.TRUE);
+                    
                     exchange.setInMessage(inMessage);
                     return;
                 }
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
index ca53ff7..17898b9 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
@@ -1704,6 +1704,15 @@ public class BookStore {
         return Response.accepted(name).build();
     }
 
+    
+    @POST
+    @Path("/empty202")
+    @Consumes("text/plain")
+    @Produces("text/plain")
+    public Response empty202(String name) {
+        return Response.accepted().build();
+    }
+
 
     @GET
     @Path("/cd/{CDId}/")
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 0ae1c33..389cbaf 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
@@ -70,6 +70,7 @@ import org.apache.cxf.jaxrs.ext.xml.XMLSource;
 import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
 import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
 import org.apache.cxf.jaxrs.provider.XSLTJaxbProvider;
+import org.apache.cxf.message.Message;
 import org.apache.cxf.systest.jaxrs.BookStore.BookInfo;
 import org.apache.cxf.systest.jaxrs.BookStore.BookInfoInterface;
 import org.apache.cxf.systest.jaxrs.BookStore.BookNotReturnedException;
@@ -2015,38 +2016,41 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase {
         assertEquals(202, r.getStatus());
         assertEquals("book", r.readEntity(String.class));
     }
-
+    @Test
+    public void testEmpty202() throws Exception {
+        WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/empty202");
+        WebClient.getConfig(wc).getRequestContext().put(Message.PROCESS_202_RESPONSE_ONEWAY_OR_PARTIAL, false);
+        wc.type("text/plain").accept("text/plain");
+        Response r = wc.post("book");
+        assertEquals(202, r.getStatus());
+        assertEquals("", r.readEntity(String.class));
+    }
     @Test
     public void testGetBookSimple() throws Exception {
         WebClient wc = WebClient.create("http://localhost:" + PORT + "/simplebooks/simple");
         Book book = wc.get(Book.class);
         assertEquals(444L, book.getId());
     }
-
     @Test(expected = ResponseProcessingException.class)
     public void testEmptyJSON() {
         doTestEmptyResponse("application/json");
     }
-
     @Test(expected = ResponseProcessingException.class)
     public void testEmptyJAXB() {
         doTestEmptyResponse("application/xml");
     }
-
     private void doTestEmptyResponse(String mt) {
         WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/emptybook");
         WebClient.getConfig(wc).getInInterceptors().add(new BookServer.ReplaceStatusInterceptor());
         wc.accept(mt);
         wc.get(Book.class);
     }
-
     @Test(expected = ResponseProcessingException.class)
     public void testEmptyResponseProxy() {
         BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class);
         WebClient.getConfig(store).getInInterceptors().add(new BookServer.ReplaceStatusInterceptor());
         store.getEmptyBook();
     }
-
     @Test
     public void testEmptyResponseProxyNullable() {
         BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class);