You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by ahazelton <ah...@axeda.com> on 2011/02/10 20:50:16 UTC

ExceptionMapper causing subsequent ClassCastExceptions

I have a service method like this:
  @Override
  @POST
  @Path("/model/create")
  public Long createModel(Model model)
  {
    ...
  }

I registered an exception mapper like this:
public class CustomWebApplicationExceptionMapper extends
AbstractRestExceptionMapper implements
ExceptionMapper<WebApplicationException> {
  @Override
  public Response toResponse(WebApplicationException exception)
  {
       Response response =
Response.status(Response.Status.BAD_REQUEST).type(MediaType.APPLICATION_XML).entity(someString).build();
      return response;
    }
    ...
  }
}

And registered the mapper as a jaxrs:provider:
   <jaxrs:providers>
      ...
      <ref bean="CustomWebApplicationExceptionMapper"/>
   </jaxrs:providers>

I have verified that in the debugger my exception mapper is getting called
and the expected response generated.  Unfortunately when this response is
sent back to the client the JAXRSOutInterceptor is triggering a
ClassCastException.  It appears to be because the service method returns a
Long and the Response object is a String.  I changed the service method
return type above from a Long to a String and the class cast goes away.

How can I use an ExceptionMapper for any method, regardless of its return
type?

-- 
View this message in context: http://cxf.547215.n5.nabble.com/ExceptionMapper-causing-subsequent-ClassCastExceptions-tp3379990p3379990.html
Sent from the cxf-issues mailing list archive at Nabble.com.

Fwd: ExceptionMapper causing subsequent ClassCastExceptions

Posted by Sergey Beryozkin <sb...@gmail.com>.
Forwarding to the users list...


---------- Forwarded message ----------
From: Sergey Beryozkin <sb...@gmail.com>
Date: Fri, Feb 11, 2011 at 10:32 AM
Subject: Re: ExceptionMapper causing subsequent ClassCastExceptions
To: dev@cxf.apache.org


Hi

I believe this issue has been fixed recently, can you try CXF 2.3.2 please ?

Cheers, Sergey

On Thu, Feb 10, 2011 at 7:50 PM, ahazelton <ah...@axeda.com> wrote:
>
> I have a service method like this:
>  @Override
>  @POST
>  @Path("/model/create")
>  public Long createModel(Model model)
>  {
>    ...
>  }
>
> I registered an exception mapper like this:
> public class CustomWebApplicationExceptionMapper extends
> AbstractRestExceptionMapper implements
> ExceptionMapper<WebApplicationException> {
>  @Override
>  public Response toResponse(WebApplicationException exception)
>  {
>       Response response =
> Response.status(Response.Status.BAD_REQUEST).type(MediaType.APPLICATION_XML).entity(someString).build();
>      return response;
>    }
>    ...
>  }
> }
>
> And registered the mapper as a jaxrs:provider:
>   <jaxrs:providers>
>      ...
>      <ref bean="CustomWebApplicationExceptionMapper"/>
>   </jaxrs:providers>
>
> I have verified that in the debugger my exception mapper is getting called
> and the expected response generated.  Unfortunately when this response is
> sent back to the client the JAXRSOutInterceptor is triggering a
> ClassCastException.  It appears to be because the service method returns a
> Long and the Response object is a String.  I changed the service method
> return type above from a Long to a String and the class cast goes away.
>
> How can I use an ExceptionMapper for any method, regardless of its return
> type?
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/ExceptionMapper-causing-subsequent-ClassCastExceptions-tp3379990p3379990.html
> Sent from the cxf-issues mailing list archive at Nabble.com.
>

Re: ExceptionMapper causing subsequent ClassCastExceptions

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

I believe this issue has been fixed recently, can you try CXF 2.3.2 please ?

Cheers, Sergey

On Thu, Feb 10, 2011 at 7:50 PM, ahazelton <ah...@axeda.com> wrote:
>
> I have a service method like this:
>  @Override
>  @POST
>  @Path("/model/create")
>  public Long createModel(Model model)
>  {
>    ...
>  }
>
> I registered an exception mapper like this:
> public class CustomWebApplicationExceptionMapper extends
> AbstractRestExceptionMapper implements
> ExceptionMapper<WebApplicationException> {
>  @Override
>  public Response toResponse(WebApplicationException exception)
>  {
>       Response response =
> Response.status(Response.Status.BAD_REQUEST).type(MediaType.APPLICATION_XML).entity(someString).build();
>      return response;
>    }
>    ...
>  }
> }
>
> And registered the mapper as a jaxrs:provider:
>   <jaxrs:providers>
>      ...
>      <ref bean="CustomWebApplicationExceptionMapper"/>
>   </jaxrs:providers>
>
> I have verified that in the debugger my exception mapper is getting called
> and the expected response generated.  Unfortunately when this response is
> sent back to the client the JAXRSOutInterceptor is triggering a
> ClassCastException.  It appears to be because the service method returns a
> Long and the Response object is a String.  I changed the service method
> return type above from a Long to a String and the class cast goes away.
>
> How can I use an ExceptionMapper for any method, regardless of its return
> type?
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/ExceptionMapper-causing-subsequent-ClassCastExceptions-tp3379990p3379990.html
> Sent from the cxf-issues mailing list archive at Nabble.com.
>