Return-Path: X-Original-To: apmail-cxf-issues-archive@www.apache.org Delivered-To: apmail-cxf-issues-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C241DF3A8 for ; Fri, 22 Mar 2013 06:45:17 +0000 (UTC) Received: (qmail 43438 invoked by uid 500); 22 Mar 2013 06:45:17 -0000 Delivered-To: apmail-cxf-issues-archive@cxf.apache.org Received: (qmail 43394 invoked by uid 500); 22 Mar 2013 06:45:17 -0000 Mailing-List: contact issues-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 issues@cxf.apache.org Received: (qmail 43385 invoked by uid 99); 22 Mar 2013 06:45:17 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Mar 2013 06:45:17 +0000 Date: Fri, 22 Mar 2013 06:45:17 +0000 (UTC) From: "Parwiz Rezai (JIRA)" To: issues@cxf.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (CXF-4912) cxf rest client always picks the first ResponseExceptionMapper for a method with different exception throws MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CXF-4912?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Parwiz Rezai updated CXF-4912: ------------------------------ Description: I have two differnt exceptions: {code:borderStyle=solid} public class Exception1 extends Exception { // blah blah } public class Exception2 extends Exception { // blah blah } {code} {code:title=Exception1ResponseMapper.java|borderStyle=solid} import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.MappingJsonFactory; import java.io.InputStream; import javax.ws.rs.core.Response; import org.apache.cxf.jaxrs.client.ResponseExceptionMapper; public class Exception1ResponseMapper implements ResponseExceptionMapper { @Override public Exception1 fromResponse(Response response) { try { MappingJsonFactory factory = new MappingJsonFactory(); JsonParser parser = factory.createJsonParser((InputStream) response.getEntity()); Exception1 exception = parser.readValueAs(Exception1.class); return exception; } catch (Exception ex) { return new Exception1("Could not deserialize server side exception: " + ex.getMessage()); } } {code} {code:title=Exception2ResponseMapper.java|borderStyle=solid} import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.MappingJsonFactory; import java.io.InputStream; import javax.ws.rs.core.Response; import org.apache.cxf.jaxrs.client.ResponseExceptionMapper; public class Exception2ResponseMapper implements ResponseExceptionMapper { @Override public Exception2 fromResponse(Response response) { try { MappingJsonFactory factory = new MappingJsonFactory(); JsonParser parser = factory.createJsonParser((InputStream) response.getEntity()); Exception2 exception = parser.readValueAs(Exception2.class); // do some specific work for exception 2 only return exception; } catch (Exception ex) { return new Exception2("Could not deserialize server side exception: " + ex.getMessage()); } } {code} so one mapper does something different than the other one. now my service method: {code:borderStyle=solid} @Path("/cool") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public interface MyService { @GET SomeCoolObject myMethod() throws Exception2, Exception1; } @Service("myService") public class MyServiceImpl implements MyService { public SomeCoolObject myMethod() throws Exception2, Exception1 { throw new Exception1("hey this exception will still go exception 2 mapper.. why?"); } } {code} {code:title=creating client proxy|borderStyle=solid} List providers = new ArrayList(); providers.add(new com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider()); providers.add(new Exception1ResponseMapper()); providers.add(new Exception2ResponseMapper()); MyService serviceProxy = JAXRSClientFactory.create("http://localhost:8080/", MyService.class, providers); {code} The selection for response mapper will always pick the first exception listed and invoke the mapper for that guy.. it will never invoke Exception1ResponseMapper even though our exception is of type Exception1.. I think the code needs to lookup the mapper based on type as well instead of generic first mapper found for that service. was: I have two differnt exceptions: {code:borderStyle=solid} public class Exception1 extends Exception { // blah blah } public class Exception2 extends Exception { // blah blah } {code} {code:title=Exception1ResponseMapper.java|borderStyle=solid} import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.MappingJsonFactory; import java.io.InputStream; import javax.ws.rs.core.Response; import org.apache.cxf.jaxrs.client.ResponseExceptionMapper; public class Exception1ResponseMapper implements ResponseExceptionMapper { @Override public Exception1 fromResponse(Response response) { try { MappingJsonFactory factory = new MappingJsonFactory(); JsonParser parser = factory.createJsonParser((InputStream) response.getEntity()); Exception1 exception = parser.readValueAs(Exception1.class); return exception; } catch (Exception ex) { return new Exception1("Could not deserialize server side exception: " + ex.getMessage()); } } {code} {code:title=Exception2ResponseMapper.java|borderStyle=solid} import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.MappingJsonFactory; import java.io.InputStream; import javax.ws.rs.core.Response; import org.apache.cxf.jaxrs.client.ResponseExceptionMapper; public class Exception2ResponseMapper implements ResponseExceptionMapper { @Override public Exception2 fromResponse(Response response) { try { MappingJsonFactory factory = new MappingJsonFactory(); JsonParser parser = factory.createJsonParser((InputStream) response.getEntity()); Exception2 exception = parser.readValueAs(Exception2.class); // do some specific work for exception 2 only return exception; } catch (Exception ex) { return new Exception2("Could not deserialize server side exception: " + ex.getMessage()); } } {code} so one mapper does something different than the other one. now my service method: {code:borderStyle=solid} @Path("/cool") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public interface MyService { @GET SomeCoolObject myMethod() throws Exception2, Exception1; } @Service("myService") public class MyServiceImpl implements MyService { public SomeCoolObject myMethod() throws Exception2, Exception1 { throw new Exception1("hey this exception will still go exception 2 mapper.. why?"); } } {code} The selection for response mapper will always pick the first exception listed and invoke the mapper for that guy.. it will never invoke Exception1ResponseMapper even though our exception is of type Exception1.. I think the code needs to lookup the mapper based on type as well instead of generic first mapper found for that service. > cxf rest client always picks the first ResponseExceptionMapper for a method with different exception throws > ----------------------------------------------------------------------------------------------------------- > > Key: CXF-4912 > URL: https://issues.apache.org/jira/browse/CXF-4912 > Project: CXF > Issue Type: Bug > Components: JAX-RS > Affects Versions: 2.7.3 > Environment: tomcat 6.33, java 1.6_34, spring 3.2.1.RELEASE. > Reporter: Parwiz Rezai > > I have two differnt exceptions: > {code:borderStyle=solid} > public class Exception1 extends Exception { > // blah blah > } > public class Exception2 extends Exception { > // blah blah > } > {code} > {code:title=Exception1ResponseMapper.java|borderStyle=solid} > import com.fasterxml.jackson.core.JsonParser; > import com.fasterxml.jackson.databind.MappingJsonFactory; > import java.io.InputStream; > import javax.ws.rs.core.Response; > import org.apache.cxf.jaxrs.client.ResponseExceptionMapper; > public class Exception1ResponseMapper implements ResponseExceptionMapper { > @Override > public Exception1 fromResponse(Response response) { > try { > MappingJsonFactory factory = new MappingJsonFactory(); > JsonParser parser = factory.createJsonParser((InputStream) response.getEntity()); > Exception1 exception = parser.readValueAs(Exception1.class); > return exception; > } catch (Exception ex) { > return new Exception1("Could not deserialize server side exception: " + ex.getMessage()); > } > } > {code} > {code:title=Exception2ResponseMapper.java|borderStyle=solid} > import com.fasterxml.jackson.core.JsonParser; > import com.fasterxml.jackson.databind.MappingJsonFactory; > import java.io.InputStream; > import javax.ws.rs.core.Response; > import org.apache.cxf.jaxrs.client.ResponseExceptionMapper; > public class Exception2ResponseMapper implements ResponseExceptionMapper { > @Override > public Exception2 fromResponse(Response response) { > try { > MappingJsonFactory factory = new MappingJsonFactory(); > JsonParser parser = factory.createJsonParser((InputStream) response.getEntity()); > Exception2 exception = parser.readValueAs(Exception2.class); > // do some specific work for exception 2 only > return exception; > } catch (Exception ex) { > return new Exception2("Could not deserialize server side exception: " + ex.getMessage()); > } > } > {code} > so one mapper does something different than the other one. > now my service method: > {code:borderStyle=solid} > @Path("/cool") > @Consumes(MediaType.APPLICATION_JSON) > @Produces(MediaType.APPLICATION_JSON) > public interface MyService { > @GET > SomeCoolObject myMethod() throws Exception2, Exception1; > } > @Service("myService") > public class MyServiceImpl implements MyService { > public SomeCoolObject myMethod() throws Exception2, Exception1 { > throw new Exception1("hey this exception will still go exception 2 mapper.. why?"); > } > } > {code} > {code:title=creating client proxy|borderStyle=solid} > List providers = new ArrayList(); > providers.add(new com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider()); > providers.add(new Exception1ResponseMapper()); > providers.add(new Exception2ResponseMapper()); > MyService serviceProxy = JAXRSClientFactory.create("http://localhost:8080/", MyService.class, providers); > {code} > The selection for response mapper will always pick the first > exception listed and invoke the mapper for that guy.. it will never > invoke Exception1ResponseMapper even though our exception is of type > Exception1.. > I think the code needs to lookup the mapper based on type as well > instead of generic first mapper found for that service. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira