cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Antoine Reilles (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CXF-4969) ExceptionMapper not used for exception in resource setter
Date Tue, 16 Apr 2013 20:59:16 GMT

    [ https://issues.apache.org/jira/browse/CXF-4969?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13633345#comment-13633345
] 

Antoine Reilles commented on CXF-4969:
--------------------------------------

My issue is that when defining a rest resource like this:
@Path("b/{name}")
public class Service {
  String name;
  @PathParam("name")
  public void setName(String argname) {
    name = argname;
    if ("fail_in_inject".equals(name)) {
      throw new WebApplicationException(400);
    }
  }  
  @GET
  public String serve() {
    return "OK: "+name;
  }
}
where I expect to validate the PathParam "name", for instance checking the resource is present,
and twrowinf a WebApplicationException with 404 status otherwise. I want to perform this check
at setter level (or in the resource constructor) so that each service in the resource benefits
from the check.
When the WebApplicationException is raised in the setName method, cxf intercepts the exception,
and replaces it with an internal error those only message is "injection failed", with the
setter name. This prevents from using @PathParam or @queryParam annotated setter methods to
provide meaningful error messages to the client.
                
> ExceptionMapper not used for exception in resource setter
> ---------------------------------------------------------
>
>                 Key: CXF-4969
>                 URL: https://issues.apache.org/jira/browse/CXF-4969
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.6.7
>         Environment: tomee-1.6.0-SNAPSHOT
>            Reporter: Antoine Reilles
>         Attachments: testexceptions-src.zip, testexceptions.war
>
>
> I'm trying to use the cxf extension that allows to map exceptions to reponses. The issue
I have is that exceptions raised in setXX methods annontated with @PathParam for example are
caught and produce an internal server error. This prevents from performing usefull parameter
validation from the setter methods, where they could benefit to all services.
> Attached in a sample application that defines a custom mapper, and raises exceptions
either in a setter or a service method.
> Once deployed, I do get for:
> http://localhost/testexceptions/a/b/fail_in_inject
> where the exception is raised at the setter level an HTTP 500 response, with entity
> <ns1:XMLFault 
>     xmlns:ns1="http://cxf.apache.org/bindings/xformat">
>     <ns1:faultstring 
>         xmlns:ns1="http://cxf.apache.org/bindings/xformat">javax.ws.rs.WebApplicationException
>     </ns1:faultstring>
> </ns1:XMLFault>
> and a stack in the server logs, when
> http://localhost/testexceptions/a/b/fail_in_serve
> where the exception is raised at service level correctly returns HTTP 400
> One sould be able to use the setter methods (or the resource constructor) to perform
parameters validation, and property return errors.
> Tested with tomee 1.6.0, which ships with cxf-2.6.7

--
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

Mime
View raw message