cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: Adding a JAXRS test where the status and headers set from StreamingOutput
Date Thu, 21 May 2015 21:03:52 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes fb302eaf3 -> 77774b51d


Adding a JAXRS test where the status and headers set from StreamingOutput


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

Branch: refs/heads/2.7.x-fixes
Commit: 77774b51dbc4252d6e33b061f3a142c5da957e04
Parents: fb302ea
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Thu May 21 21:47:47 2015 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Thu May 21 22:03:26 2015 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/ext/MessageContextImpl.java       |  4 ++++
 .../org/apache/cxf/systest/jaxrs/BookStore.java | 23 ++++++++++++++++++++
 .../jaxrs/JAXRSClientServerBookTest.java        | 13 +++++++++++
 3 files changed, 40 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/77774b51/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
index f3ed0fd..acdfa6a 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
@@ -180,6 +180,10 @@ public class MessageContextImpl implements MessageContext {
         m.put(key.toString(), value);
         if (!MessageUtils.isRequestor(m)) {
             m.getExchange().put(key.toString(), value);
+            Message outMessage = m.getExchange().getOutMessage();
+            if (outMessage != null && outMessage != m) {
+                outMessage.put(key.toString(), value);
+            }
         }
             
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/77774b51/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
----------------------------------------------------------------------
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 792688e..c314463 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
@@ -95,7 +95,9 @@ import org.apache.cxf.jaxrs.ext.search.SearchContext;
 import org.apache.cxf.jaxrs.ext.xml.XMLInstruction;
 import org.apache.cxf.jaxrs.ext.xml.XSISchemaLocation;
 import org.apache.cxf.jaxrs.impl.ResourceContextImpl;
+import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
+import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.PhaseInterceptorChain;
 import org.apache.cxf.systest.jaxrs.BookServer20.CustomHeaderAdded;
 import org.apache.cxf.systest.jaxrs.BookServer20.PostMatchMode;
@@ -123,6 +125,8 @@ public class BookStore {
     private UriInfo ui;
     @Context 
     private ResourceContext resourceContext;
+    @Context 
+    private MessageContext messageContext;
     
     @BeanParam
     private BookBean theBookBean;
@@ -1113,6 +1117,13 @@ public class BookStore {
     }
     
     @GET
+    @Path("/books/statusFromStream")
+    @Produces("text/xml")
+    public StreamingOutput statusFromStream() {
+        return new ResponseStreamingOutputImpl();
+    }
+    
+    @GET
     @Path("/books/fail-late")
     @Produces("application/bar")
     public StreamingOutput writeToStreamAndFail() {
@@ -1582,6 +1593,18 @@ public class BookStore {
         } 
         
     }
+    private class ResponseStreamingOutputImpl implements StreamingOutput {
+        public void write(OutputStream output) throws IOException, WebApplicationException
{
+            BookStore.this.messageContext.put(Message.RESPONSE_CODE, 503);
+            MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
+            headers.putSingle("Content-Type", "text/plain");
+            headers.putSingle("CustomHeader", "CustomValue");
+            BookStore.this.messageContext.put(Message.PROTOCOL_HEADERS, headers);
+            
+            output.write("Response is not available".getBytes());
+        } 
+        
+    }
     
     private Book createCglibProxy(final Book book) {
         final InvocationHandler handler = new InvocationHandler() {

http://git-wip-us.apache.org/repos/asf/cxf/blob/77774b51/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 25ea94c..1a90cd8 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
@@ -1295,6 +1295,19 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase
{
     }
     
     @Test
+    public void testStatusAngHeadersFromStream() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/books/statusFromStream";
+        WebClient wc = WebClient.create(address);
+        wc.accept("text/xml");
+        Response r = wc.get();
+        assertEquals(503, r.getStatus());
+        assertEquals("text/plain", r.getMediaType().toString());
+        assertEquals("CustomValue", r.getHeaderString("CustomHeader"));
+        assertEquals("Response is not available", r.readEntity(String.class));
+        
+    }
+    
+    @Test
     public void testWriteAndFailEarly() throws Exception {
         getAndCompare("http://localhost:" + PORT + "/bookstore/books/fail-early",
                       "This is supposed to go on the wire",


Mime
View raw message