cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1503447 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Mon, 15 Jul 2013 20:11:04 GMT
Author: sergeyb
Date: Mon Jul 15 20:11:04 2013
New Revision: 1503447

URL: http://svn.apache.org/r1503447
Log:
[CXF-5129] Update to HttpServletResponseFilter to get content-type not lost in some cases

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpServletResponseFilter.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpServletResponseFilter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpServletResponseFilter.java?rev=1503447&r1=1503446&r2=1503447&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpServletResponseFilter.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpServletResponseFilter.java
Mon Jul 15 20:11:04 2013
@@ -41,6 +41,21 @@ public class HttpServletResponseFilter e
     }
     
     @Override
+    public void setContentType(String ct) {
+        super.setContentType(ct);
+        m.getExchange().put(Message.CONTENT_TYPE, ct);
+    }
+    
+    @Override
+    public void addHeader(String name, String value) {
+        if (Message.CONTENT_TYPE.equals(name)) {
+            setContentType(value);
+        } else {
+            super.addHeader(name, value);
+        }
+    }
+    
+    @Override
     public ServletOutputStream getOutputStream() throws IOException {
         return new ServletOutputStreamFilter(super.getOutputStream(), m);
     }

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1503447&r1=1503446&r2=1503447&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Mon
Jul 15 20:11:04 2013
@@ -169,6 +169,17 @@ public class BookStore {
         return doGetBook("123");
     }
     
+    @GET
+    @Path("/httpresponse")
+    public void getBookDesciptionHttpResponse(@Context HttpServletResponse response) {
+        response.setContentType("text/plain");
+        try {
+            response.getOutputStream().write("Good Book".getBytes());
+        } catch (IOException ex) {
+            throw new WebApplicationException(ex);
+        }
+    }
+    
     @RETRIEVE
     @Path("/retrieve")
     @Produces("application/xml")

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1503447&r1=1503446&r2=1503447&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Mon Jul 15 20:11:04 2013
@@ -59,6 +59,7 @@ import org.apache.commons.httpclient.met
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.interceptor.LoggingInInterceptor;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
@@ -99,6 +100,16 @@ public class JAXRSClientServerBookTest e
         Response r = wc.form(new Form());
         assertEquals("empty form", r.readEntity(String.class));
     }
+    
+    @Test
+    public void testGetBookDescriptionHttpResponse() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/httpresponse";
+        WebClient wc = WebClient.create(address);
+        WebClient.getConfig(wc).getInInterceptors().add(new LoggingInInterceptor());
+        Response r = wc.get();
+        assertEquals("text/plain", r.getMediaType().toString());
+        assertEquals("Good Book", r.readEntity(String.class));
+    }
 
     @Test
     public void testGetCustomBookResponse() {



Mime
View raw message