Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 66168F31A for ; Tue, 26 Mar 2013 12:30:12 +0000 (UTC) Received: (qmail 11440 invoked by uid 500); 26 Mar 2013 12:30:12 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 11276 invoked by uid 500); 26 Mar 2013 12:30:10 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 11257 invoked by uid 99); 26 Mar 2013 12:30:09 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Mar 2013 12:30:09 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Mar 2013 12:30:07 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id AB46923888FD; Tue, 26 Mar 2013 12:29:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1461083 - in /cxf/branches/2.5.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/ Date: Tue, 26 Mar 2013 12:29:47 -0000 To: commits@cxf.apache.org From: sergeyb@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130326122947.AB46923888FD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sergeyb Date: Tue Mar 26 12:29:47 2013 New Revision: 1461083 URL: http://svn.apache.org/r1461083 Log: Merged revisions 1461046 via svnmerge from https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes ................ r1461046 | sergeyb | 2013-03-26 13:16:43 +0300 (Tue, 26 Mar 2013) | 16 lines Merged revisions 1461039 via svnmerge from https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes ................ r1461039 | sergeyb | 2013-03-26 12:50:00 +0300 (Tue, 26 Mar 2013) | 9 lines Merged revisions 1461035 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk ........ r1461035 | sergeyb | 2013-03-26 12:29:24 +0300 (Tue, 26 Mar 2013) | 1 line [CXF-4912] Getting multiple declared exceptions checked by the client proxy, patch on behalf of Parwiz Rezai applied with minor modifications ........ ................ ................ Modified: cxf/branches/2.5.x-fixes/ (props changed) cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java Propchange: cxf/branches/2.5.x-fixes/ ------------------------------------------------------------------------------ --- svn:mergeinfo (added) +++ svn:mergeinfo Tue Mar 26 12:29:47 2013 @@ -0,0 +1,3 @@ +/cxf/branches/2.6.x-fixes:1461046 +/cxf/branches/2.7.x-fixes:1461039 +/cxf/trunk:1461035 Propchange: cxf/branches/2.5.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=1461083&r1=1461082&r2=1461083&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java (original) +++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java Tue Mar 26 12:29:47 2013 @@ -266,11 +266,17 @@ public class ClientProxyImpl extends Abs if (m.getReturnType() == Response.class && m.getExceptionTypes().length == 0) { return; } - ResponseExceptionMapper mapper = findExceptionMapper(m, inMessage); - if (mapper != null) { - t = mapper.fromResponse(r); - if (t != null) { - throw t; + Class[] exTypes = m.getExceptionTypes(); + if (exTypes.length == 0) { + exTypes = new Class[]{ServerWebApplicationException.class}; + } + for (Class exType : exTypes) { + ResponseExceptionMapper mapper = findExceptionMapper(inMessage, exType); + if (mapper != null) { + t = mapper.fromResponse(r); + if (t != null) { + throw t; + } } } @@ -296,15 +302,9 @@ public class ClientProxyImpl extends Abs } } - private static ResponseExceptionMapper findExceptionMapper(Method m, Message message) { + private static ResponseExceptionMapper findExceptionMapper(Message message, Class exType) { ProviderFactory pf = ProviderFactory.getInstance(message); - for (Class exType : m.getExceptionTypes()) { - ResponseExceptionMapper mapper = pf.createResponseExceptionMapper(exType); - if (mapper != null) { - return mapper; - } - } - return null; + return pf.createResponseExceptionMapper(exType); } private MultivaluedMap setRequestHeaders(MultivaluedMap headers, Modified: cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1461083&r1=1461082&r2=1461083&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original) +++ cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Tue Mar 26 12:29:47 2013 @@ -236,6 +236,24 @@ public class BookStore { } @GET + @Path("multipleexceptions") + public Response getBookWithExceptions(@QueryParam("exception") boolean notReturned) + throws BookNotFoundFault, BookNotReturnedException { + if (notReturned) { + throw new WebApplicationException(Response.status(404).header("Status", "notReturned").build()); + } else { + throw new WebApplicationException(Response.status(404).header("Status", "notFound").build()); + } + } + + @GET + @Path("multipleexceptions2") + public Response getBookWithExceptions2(@QueryParam("exception") boolean notReturned) + throws BookNotReturnedException, BookNotFoundFault { + return getBookWithExceptions(notReturned); + } + + @GET @Path("propogateExceptionVar/{i}") public Book propogateExceptionWithVar() throws BookNotFoundFault { return null; @@ -990,6 +1008,15 @@ public class BookStore { return echoBookNameAndHeader(httpHeaders.getRequestHeader("CustomHeader").get(0), name); } + @POST + @Path("/booksecho3") + @Consumes("text/plain") + @Produces("text/plain") + public Response echoBookNameAndHeader3(String name) { + return echoBookNameAndHeader(httpHeaders.getRequestHeader("customheader").get(0), name); + } + + @GET @Path("/cd/{CDId}/") public CD getCD() { @@ -1199,6 +1226,16 @@ public class BookStore { new Class[]{Book.class}, handler); } + + public static class BookNotReturnedException extends RuntimeException { + + private static final long serialVersionUID = 4935423670510083220L; + + public BookNotReturnedException(String errorMessage) { + super(errorMessage); + } + + } } Modified: cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1461083&r1=1461082&r2=1461083&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java (original) +++ cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java Tue Mar 26 12:29:47 2013 @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -53,6 +54,7 @@ import org.apache.cxf.io.CachedOutputStr import org.apache.cxf.jaxrs.client.ClientWebApplicationException; 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.ResponseReader; import org.apache.cxf.jaxrs.client.ServerWebApplicationException; import org.apache.cxf.jaxrs.client.WebClient; @@ -64,6 +66,7 @@ import org.apache.cxf.phase.AbstractPhas import org.apache.cxf.phase.Phase; import org.apache.cxf.systest.jaxrs.BookStore.BookInfo; import org.apache.cxf.systest.jaxrs.BookStore.BookInfoInterface; +import org.apache.cxf.systest.jaxrs.BookStore.BookNotReturnedException; import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase; import org.junit.BeforeClass; @@ -339,6 +342,51 @@ public class JAXRSClientServerBookTest e } @Test + public void testBookWithMultipleExceptions() throws Exception { + List providers = new LinkedList(); + providers.add(new NotReturnedExceptionMapper()); + providers.add(new NotFoundExceptionMapper()); + BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT, + BookStore.class, + providers); + try { + store.getBookWithExceptions(true); + fail(); + } catch (BookNotReturnedException ex) { + assertEquals("notReturned", ex.getMessage()); + } + try { + store.getBookWithExceptions(false); + fail(); + } catch (BookNotFoundFault ex) { + assertEquals("notFound", ex.getMessage()); + } + + } + + @Test + public void testBookWithMultipleExceptions2() throws Exception { + List providers = new LinkedList(); + providers.add(new NotReturnedExceptionMapper()); + providers.add(new NotFoundExceptionMapper()); + BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT, + BookStore.class, + providers); + try { + store.getBookWithExceptions2(true); + fail(); + } catch (BookNotReturnedException ex) { + assertEquals("notReturned", ex.getMessage()); + } + try { + store.getBookWithExceptions2(false); + fail(); + } catch (BookNotFoundFault ex) { + assertEquals("notFound", ex.getMessage()); + } + } + + @Test public void testTempRedirectWebClient() throws Exception { WebClient client = WebClient.create("http://localhost:" + PORT + "/bookstore/tempredirect"); Response r = client.type("*/*").get(); @@ -1045,6 +1093,15 @@ public class JAXRSClientServerBookTest e } @Test + public void testGetBookLowCaseHeader() throws Exception { + WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/booksecho3"); + wc.type("text/plain").accept("text/plain").header("CustomHeader", "custom"); + String name = wc.post("book", String.class); + assertEquals("book", name); + assertEquals("custom", wc.getResponse().getMetadata().getFirst("CustomHeader").toString()); + } + + @Test public void testGetBookSimple() throws Exception { WebClient wc = WebClient.create("http://localhost:" + PORT + "/simplebooks/simple"); Book book = wc.get(Book.class); @@ -1919,4 +1976,29 @@ public class JAXRSClientServerBookTest e } } + public static class NotReturnedExceptionMapper implements ResponseExceptionMapper { + + public BookNotReturnedException fromResponse(Response r) { + String status = r.getMetadata().getFirst("Status").toString(); + if ("notReturned".equals(status)) { + return new BookNotReturnedException(status); + } else { + return null; + } + } + + } + + public static class NotFoundExceptionMapper implements ResponseExceptionMapper { + + public BookNotFoundFault fromResponse(Response r) { + String status = r.getMetadata().getFirst("Status").toString(); + if ("notFound".equals(status)) { + return new BookNotFoundFault(status); + } else { + return null; + } + } + + } }