cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r789013 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ systests/src/test/java/org/apache/cxf/systest/jaxrs/
Date Sat, 27 Jun 2009 20:52:50 GMT
Author: sergeyb
Date: Sat Jun 27 20:52:49 2009
New Revision: 789013

URL: http://svn.apache.org/viewvc?rev=789013&view=rev
Log:
CXF-2322 : applying a patch on behalf of Eamonn Dwyer with minor updates, thanks

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=789013&r1=789012&r2=789013&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
Sat Jun 27 20:52:49 2009
@@ -297,7 +297,7 @@
         currentBuilder = new UriBuilderImpl(uri);
     }
     
-    protected ResponseBuilder setResponseBuilder(HttpURLConnection conn) throws Throwable
{
+    protected ResponseBuilder setResponseBuilder(HttpURLConnection conn, Message inMessage)
throws Throwable {
         
         if (conn == null) {
             throw new WebApplicationException(); 
@@ -321,9 +321,13 @@
                 }
             }
         }
+        InputStream mStream = null;
+        if (inMessage != null) {
+            mStream = inMessage.getContent(InputStream.class);
+        }
         if (status >= 400) {
             try {
-                InputStream errorStream = conn.getErrorStream();
+                InputStream errorStream = mStream == null ? conn.getErrorStream() : mStream;
                 if (errorStream != null) {
                     responseBuilder.entity(IOUtils.readStringFromStream(errorStream));
                 }
@@ -332,7 +336,8 @@
             }
         } else {
             try {
-                responseBuilder.entity(conn.getInputStream());
+                InputStream stream = mStream == null ? conn.getInputStream() : mStream;
+                responseBuilder.entity(stream);
             } catch (Exception ex) {
                 // it may that the successful response has no response body
             }
@@ -551,7 +556,7 @@
     protected void setInInterceptors(List<Interceptor> interceptors) {
         inInterceptors = interceptors;
     }
-
+    
     protected void setOutInterceptors(List<Interceptor> interceptors) {
         outInterceptors = interceptors;
     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=789013&r1=789012&r2=789013&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
Sat Jun 27 20:52:49 2009
@@ -392,11 +392,11 @@
         
     }
     
-    protected Object handleResponse(HttpURLConnection connect, Message inMessage, OperationResourceInfo
ori) 
+    protected Object handleResponse(HttpURLConnection connect, Message outMessage, OperationResourceInfo
ori) 
         throws Throwable {
-        Response r = setResponseBuilder(connect).clone().build();
+        Response r = setResponseBuilder(connect, outMessage.getExchange().getInMessage()).clone().build();
         Method method = ori.getMethodToInvoke();
-        checkResponse(method, r, inMessage);
+        checkResponse(method, r, outMessage);
         if (method.getReturnType() == Void.class) { 
             return null;
         }
@@ -406,7 +406,7 @@
             return r;
         }
         
-        return readBody(r, connect, inMessage, method.getReturnType(), 
+        return readBody(r, connect, outMessage, method.getReturnType(), 
                         method.getGenericReturnType(), method.getDeclaredAnnotations());
     }
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=789013&r1=789012&r2=789013&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java Sat
Jun 27 20:52:49 2009
@@ -486,12 +486,12 @@
         return handleResponse(connect, m, responseClass);
     }
     
-    protected Response handleResponse(HttpURLConnection conn, Message m, Class<?> responseClass)
{
+    protected Response handleResponse(HttpURLConnection conn, Message outMessage, Class<?>
responseClass) {
         try {
-            ResponseBuilder rb = setResponseBuilder(conn).clone();
+            ResponseBuilder rb = setResponseBuilder(conn, outMessage.getExchange().getInMessage()).clone();
             Response currentResponse = rb.clone().build();
             
-            Object entity = readBody(currentResponse, conn, m, responseClass, responseClass,
+            Object entity = readBody(currentResponse, conn, outMessage, responseClass, responseClass,
                                      new Annotation[]{});
             rb.entity(entity);
             

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java?rev=789013&r1=789012&r2=789013&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java Sat
Jun 27 20:52:49 2009
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.systest.jaxrs;
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.InputStream;
 import java.net.URL;
@@ -40,13 +41,18 @@
 import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.commons.httpclient.methods.RequestEntity;
 import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
+import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
 import org.apache.cxf.jaxrs.client.ResponseExceptionMapper;
 import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.jaxrs.ext.form.Form;
 import org.apache.cxf.jaxrs.ext.xml.XMLSource;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 
 import org.junit.BeforeClass;
@@ -160,6 +166,19 @@
         }
     }
     
+    @Test
+    public void testOtherInterceptorDrainingStream() throws Exception {
+
+        String baseAddress = "http://localhost:9092/test/services/rest";
+        JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); 
+        bean.setAddress(baseAddress);
+        bean.getInInterceptors().add(new TestStreamDrainInterptor());
+        WebClient client = bean.createWebClient();
+        client.path("/bookstore/123").accept(MediaType.APPLICATION_XML_TYPE);
+        Book b = client.get(Book.class);
+        assertEquals(123, b.getId());
+        assertEquals("CXF in Action", b.getName());
+    }    
     
     @Test
     public void testGetBookSubresourceClient() throws Exception {
@@ -408,4 +427,30 @@
         }
         
     }
+    
+    @Ignore 
+    public class TestStreamDrainInterptor extends AbstractPhaseInterceptor<Message>
{
+        public TestStreamDrainInterptor() {
+            super(Phase.RECEIVE);
+        }
+
+        public void handleMessage(Message message) throws Fault {
+            InputStream is = message.getContent(InputStream.class);
+            if (is == null) {
+                return;
+            }
+            byte[] payload;
+            try {
+                // input stream will be closed by readBytesFromStream()
+                payload = IOUtils.readBytesFromStream(is);
+                assertTrue("payload was null", payload != null);
+                assertTrue("payload was EMPTYR", payload.length > 0);
+                message.setContent(InputStream.class, new ByteArrayInputStream(payload));
+            } catch (Exception e) {
+                String error = "Failed to read the stream properly due to " + e.getMessage();
+                assertFalse(error, e != null);
+            } 
+        }
+
+    }
 }



Mime
View raw message