cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1521946 - in /cxf/branches/2.7.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
Date Wed, 11 Sep 2013 17:27:37 GMT
Author: sergeyb
Date: Wed Sep 11 17:27:36 2013
New Revision: 1521946

URL: http://svn.apache.org/r1521946
Log:
Merged revisions 1521943 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1521943 | sergeyb | 2013-09-11 18:17:55 +0100 (Wed, 11 Sep 2013) | 1 line
  
  [CXF-5135] Resetting buffered streams after a client reader returns an object can have side-effects
........

Modified:
    cxf/branches/2.7.x-fixes/   (props changed)
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1521943

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java?rev=1521946&r1=1521945&r2=1521946&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
Wed Sep 11 17:27:36 2013
@@ -315,20 +315,20 @@ public final class ResponseImpl extends 
                                                     responseMessage.getExchange().getOutMessage());
             if (readers != null) {
                 try {
+                    if (entityBufferred) {
+                        InputStream.class.cast(entity).reset();
+                    }
+                    
                     responseMessage.put(Message.PROTOCOL_HEADERS, this.getMetadata());
                     lastEntity = JAXRSUtils.readFromMessageBodyReader(readers, cls, t, 
                                                                            anns, 
                                                                            InputStream.class.cast(entity),

                                                                            mediaType, 
                                                                            responseMessage);
-                    if (!entityBufferred) {
-                        if (responseStreamCanBeClosed(cls)) {
-                            InputStream.class.cast(entity).close();
-                            entity = null;
-                        }
-                    } else {
-                        InputStream.class.cast(entity).reset();
-                    }
+                    if (!entityBufferred && responseStreamCanBeClosed(cls)) {
+                        InputStream.class.cast(entity).close();
+                        entity = null;
+                    } 
                     
                     return cls.cast(lastEntity);
                 } catch (Exception ex) {

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java?rev=1521946&r1=1521945&r2=1521946&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
Wed Sep 11 17:27:36 2013
@@ -30,8 +30,22 @@ import javax.ws.rs.core.NewCookie;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.Status;
 import javax.ws.rs.core.Response.StatusType;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMResult;
 
+import org.w3c.dom.Document;
+
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.jaxrs.provider.ProviderFactory;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.ExchangeImpl;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.staxutils.StaxUtils;
+import org.easymock.EasyMock;
 
 import org.junit.Assert;
 import org.junit.Test;
@@ -40,6 +54,64 @@ import org.junit.Test;
 public class ResponseImplTest extends Assert {
     
     @Test
+    public void testReadBufferedStaxUtils() throws Exception {
+        ResponseImpl r = new ResponseImpl(200);
+        Source responseSource = readResponseSource(r);
+        Document doc = StaxUtils.read(responseSource);
+        assertEquals("Response", doc.getDocumentElement().getLocalName());
+    }
+    
+    @Test
+    public void testReadBufferedStaxSource() throws Exception {
+        ResponseImpl r = new ResponseImpl(200);
+        Source responseSource = readResponseSource(r);
+        Transformer trans = TransformerFactory.newInstance().newTransformer();
+        DOMResult res = new DOMResult();
+        trans.transform(responseSource, res);
+        Document doc = (Document)res.getNode();
+        assertEquals("Response", doc.getDocumentElement().getLocalName());
+    }
+    
+    private Source readResponseSource(ResponseImpl r) {
+        String content = "<Response " 
+            + " xmlns=\"urn:oasis:names:tc:xacml:2.0:context:schema:os\"" 
+            + " xmlns:ns2=\"urn:oasis:names:tc:xacml:2.0:policy:schema:os\">"
+            + "<Result><Decision>Permit</Decision><Status><StatusCode"

+            + " Value=\"urn:oasis:names:tc:xacml:1.0:status:ok\"/></Status></Result></Response>";
+        
+        
+        MultivaluedMap<String, Object> headers = new MetadataMap<String, Object>();
+        headers.putSingle("Content-Type", "text/xml");
+        r.addMetadata(headers);
+        r.setEntity(new ByteArrayInputStream(content.getBytes()), null);
+        r.setMessage(createMessage());
+        r.bufferEntity();
+        return r.readEntity(Source.class);
+    }
+    
+    private Message createMessage() {
+        ProviderFactory factory = ProviderFactory.getInstance();
+        Message m = new MessageImpl();
+        m.put("org.apache.cxf.http.case_insensitive_queries", false);
+        Exchange e = new ExchangeImpl();
+        m.setExchange(e);
+        e.setInMessage(m);
+        e.setOutMessage(new MessageImpl());
+        Endpoint endpoint = EasyMock.createMock(Endpoint.class);
+        endpoint.getEndpointInfo();
+        EasyMock.expectLastCall().andReturn(null).anyTimes();
+        endpoint.size();
+        EasyMock.expectLastCall().andReturn(0).anyTimes();
+        endpoint.isEmpty();
+        EasyMock.expectLastCall().andReturn(true).anyTimes();
+        endpoint.get(ProviderFactory.class.getName());
+        EasyMock.expectLastCall().andReturn(factory).anyTimes();
+        EasyMock.replay(endpoint);
+        e.put(Endpoint.class, endpoint);
+        return m;
+    }
+    
+    @Test
     public void testResourceImpl() {
         String entity = "bar";
         ResponseImpl ri = new ResponseImpl(200, entity);



Mime
View raw message