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 17:25:02 UTC
svn commit: r758331 - in /cxf/branches/2.1.x-fixes: ./
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/...
Author: sergeyb
Date: Wed Mar 25 16:24:48 2009
New Revision: 758331
URL: http://svn.apache.org/viewvc?rev=758331&view=rev
Log:
Merged revisions 758303 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r758303 | sergeyb | 2009-03-25 15:30:49 +0000 (Wed, 25 Mar 2009) | 1 line
Updates to HttpConduit to handle DELETE and empty PUTs
........
Modified:
cxf/branches/2.1.x-fixes/ (props changed)
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
cxf/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Propchange: cxf/branches/2.1.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Mar 25 16:24:48 2009
@@ -1 +1 @@
-/cxf/trunk:753380,753397,753421,754585,755365,757499,757859,757899,757935,757951,758195
+/cxf/trunk:753380,753397,753421,754585,755365,757499,757859,757899,757935,757951,758195,758303
Propchange: cxf/branches/2.1.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=758331&r1=758330&r2=758331&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java (original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java Wed Mar 25 16:24:48 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/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=758331&r1=758330&r2=758331&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java (original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java Wed Mar 25 16:24:48 2009
@@ -428,6 +428,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/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java?rev=758331&r1=758330&r2=758331&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java (original)
+++ cxf/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java Wed Mar 25 16:24:48 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.
@@ -1863,8 +1866,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/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=758331&r1=758330&r2=758331&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Wed Mar 25 16:24:48 2009
@@ -374,6 +374,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/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=758331&r1=758330&r2=758331&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java (original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java Wed Mar 25 16:24:48 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;
@@ -224,13 +226,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(), 123L);
}
@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",