You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2009/06/22 17:59:28 UTC

svn commit: r787291 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ systests/src/test/java/org/apache/cxf/systest/jaxrs/

Author: sergeyb
Date: Mon Jun 22 15:59:28 2009
New Revision: 787291

URL: http://svn.apache.org/viewvc?rev=787291&view=rev
Log:
CXF-2291 : proper handling of Response return values in the client api

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/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.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=787291&r1=787290&r2=787291&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 Mon Jun 22 15:59:28 2009
@@ -330,6 +330,12 @@
             } catch (Exception ex) {
                 // nothing we can do really
             }
+        } else {
+            try {
+                responseBuilder.entity(conn.getInputStream());
+            } catch (Exception ex) {
+                // it may that the successful response has no response body
+            }
         }
         return responseBuilder;
     }
@@ -388,11 +394,14 @@
         if (mbr != null) {
             try {
                 return mbr.readFrom(cls, type, anns, contentType, 
-                       new MetadataMap<String, Object>(r.getMetadata(), true, true), conn.getInputStream());
+                       new MetadataMap<String, Object>(r.getMetadata(), true, true), 
+                       (InputStream)r.getEntity());
             } catch (Exception ex) {
                 throw new WebApplicationException();
             }
              
+        } else if (cls == Response.class) {
+            return r;
         } else {
             reportNoMessageHandler("NO_MSG_READER", cls);
         }

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=787291&r1=787290&r2=787291&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 Mon Jun 22 15:59:28 2009
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.jaxrs.client;
 
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.InvocationHandler;
@@ -399,7 +400,9 @@
         if (method.getReturnType() == Void.class) { 
             return null;
         }
-        if (method.getReturnType() == Response.class) {
+        if (method.getReturnType() == Response.class
+            && (r.getEntity() == null || InputStream.class.isAssignableFrom(r.getEntity().getClass())
+                && ((InputStream)r.getEntity()).available() == 0)) {
             return r;
         }
         

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=787291&r1=787290&r2=787291&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Mon Jun 22 15:59:28 2009
@@ -375,7 +375,7 @@
             throw new RuntimeException("Unexpected content type");
         }
         
-        book.setId(++bookId);
+        book.setId(bookId + 1);
         books.put(book.getId(), book);
 
         return Response.ok(book).build();

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=787291&r1=787290&r2=787291&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java Mon Jun 22 15:59:28 2009
@@ -40,6 +40,7 @@
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
 import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.jaxrs.ext.xml.XMLSource;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 
 import org.junit.BeforeClass;
@@ -67,6 +68,20 @@
                       "application/xml", 500);
     }
     
+    @Test 
+    public void testAddBookProxyResponse() {
+        BookStore store = JAXRSClientFactory.create("http://localhost:9080", BookStore.class);
+        Book b = new Book("CXF rocks", 123L);
+        Response r = store.addBook(b);
+        assertNotNull(r);
+        InputStream is = (InputStream)r.getEntity();
+        assertNotNull(is);
+        XMLSource source = new XMLSource(is);
+        source.setBuffering(true);
+        assertEquals(124L, Long.parseLong(source.getValue("Book/id")));
+        assertEquals("CXF rocks", source.getValue("Book/name"));
+    }
+    
     @Test
     public void testGetBookByURL() throws Exception {
         getAndCompareAsStrings("http://localhost:9080/bookstore/bookurl/http%3A%2F%2Ftest.com%2Frss%2F123",
@@ -242,7 +257,7 @@
     @Test
     public void testBookExists() throws Exception {
         checkBook("http://localhost:9080/bookstore/books/check/123", true);
-        checkBook("http://localhost:9080/bookstore/books/check/124", false);  
+        checkBook("http://localhost:9080/bookstore/books/check/125", false);  
         
     }