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/03/25 16:31:03 UTC

svn commit: r758303 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ rt/transports/http/src/main/java/org/apache/cxf/transport/http/ systests/src/test/java/org/apache/cx...

Author: sergeyb
Date: Wed Mar 25 15:30:49 2009
New Revision: 758303

URL: http://svn.apache.org/viewvc?rev=758303&view=rev
Log:
Updates to HttpConduit to handle DELETE and empty PUTs

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.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/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=758303&r1=758302&r2=758303&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java Wed Mar 25 15:30:49 2009
@@ -231,22 +231,25 @@
     }
 
     private static Object checkResultObject(Object result, String subResourcePath) {
+        
+
+        //the result becomes the object that will handle the request
+        if (result != null) {
+            if (result instanceof MessageContentsList) {
+                result = ((MessageContentsList)result).get(0);
+            } else if (result instanceof List) {
+                result = ((List)result).get(0);
+            } else if (result.getClass().isArray()) {
+                result = ((Object[])result)[0];
+            }
+        }
         if (result == null) {
             org.apache.cxf.common.i18n.Message errorM =
                 new org.apache.cxf.common.i18n.Message("NULL_SUBRESOURCE",
                                                        BUNDLE,
                                                        subResourcePath);
-            LOG.severe(errorM.toString());
-            throw new WebApplicationException(500);
-        }
-
-        //the result becomes the object that will handle the request
-        if (result instanceof MessageContentsList) {
-            result = ((MessageContentsList)result).get(0);
-        } else if (result instanceof List) {
-            result = ((List)result).get(0);
-        } else if (result.getClass().isArray()) {
-            result = ((Object[])result)[0];
+            LOG.info(errorM.toString());
+            throw new WebApplicationException(404);
         }
 
         return result;

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=758303&r1=758302&r2=758303&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 Wed Mar 25 15:30:49 2009
@@ -437,6 +437,9 @@
         if (method.getReturnType() == Void.class) { 
             return null;
         }
+        if (method.getReturnType() == Response.class) {
+            return r;
+        }
         
         return readBody(r, connect, inMessage, method.getReturnType(), 
                         method.getGenericReturnType(), method.getDeclaredAnnotations());

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java?rev=758303&r1=758302&r2=758303&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java Wed Mar 25 15:30:49 2009
@@ -544,7 +544,10 @@
             needToCacheRequest = true;
             LOG.log(Level.FINE, "AutoRedirect is turned on.");
         }
-        if (!connection.getRequestMethod().equals("GET")
+        // DELETE does not work and empty PUTs cause misleading exceptions
+        // if chunking is enabled
+        // TODO : ensure chunking can be enabled for non-empty PUTs - if requested
+        if (connection.getRequestMethod().equals("POST")
             && getClient().isAllowChunking()) {
             //TODO: The chunking mode be configured or at least some
             // documented client constant.
@@ -1866,8 +1869,11 @@
             // Trust is okay, set up for writing the request.
             
             // If this is a GET method we must not touch the output
-            // stream as this automagically turns the request into a POST.
-            if ("GET".equals(connection.getRequestMethod())) {
+            // stream as this automatically turns the request into a POST.
+            // Nor it should be done in case of DELETE - strangely, empty PUTs
+            // work ok 
+            if ("GET".equals(connection.getRequestMethod())
+                || "DELETE".equals(connection.getRequestMethod())) {
                 return;
             }
             

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=758303&r1=758302&r2=758303&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 Wed Mar 25 15:30:49 2009
@@ -375,6 +375,24 @@
     }
     
     @PUT
+    @Path("/books/{id}")
+    public Response createBook(@PathParam("id") Long id) {
+        Book b = books.get(id);
+
+        Response r;
+        if (b == null) {
+            Book newBook = new Book();
+            newBook.setId(id);
+            books.put(newBook.getId(), newBook);
+            r = Response.ok().build();
+        } else {
+            r = Response.notModified().build();
+        }
+
+        return r;
+    }
+    
+    @PUT
     @Path("/bookswithdom/")
     public DOMSource updateBook(DOMSource ds) {
         XMLUtils.printDOM(ds.getNode());

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=758303&r1=758302&r2=758303&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 Wed Mar 25 15:30:49 2009
@@ -24,6 +24,8 @@
 import java.net.URL;
 import java.net.URLConnection;
 
+import javax.ws.rs.core.Response;
+
 import org.apache.commons.httpclient.Header;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.methods.DeleteMethod;
@@ -223,13 +225,34 @@
     @Test
     public void testGetBook123WebClient() throws Exception {
         BookStore bs = JAXRSClientFactory.create("http://localhost:9080", BookStore.class);
-        // just to verify the interface call goes through CGLIB proxy too
-        assertEquals("http://localhost:9080", WebClient.client(bs).getBaseURI().toString());
         Book b = bs.getBook("123");
         assertEquals(b.getId(), 123);
     }
     
     @Test
+    public void testDeleteWithWebClient() throws Exception {
+        BookStore bs = JAXRSClientFactory.create("http://localhost:9080", BookStore.class);
+        Response r = bs.deleteBook("123");
+        assertEquals(200, r.getStatus());
+    }
+    
+    @Test
+    public void testCreatePut() throws Exception {
+        BookStore bs = JAXRSClientFactory.create("http://localhost:9080", BookStore.class);
+        Response r = bs.createBook(777L);
+        assertEquals(200, r.getStatus());
+    }
+    
+    @Test
+    public void testUpdateWithWebClient() throws Exception {
+        BookStore bs = JAXRSClientFactory.create("http://localhost:9080", BookStore.class);
+        Book book = new Book();
+        book.setId(888);
+        bs.updateBook(book);
+        assertEquals(304, WebClient.client(bs).getResponse().getStatus());
+    }
+    
+    @Test
     public void testGetBookTypeAndWildcard() throws Exception {
         getAndCompareAsStrings("http://localhost:9080/bookstore/books/123",
                                "resources/expected_get_book123.txt",