You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by eanbiso <bi...@hotmail.it> on 2013/02/15 09:19:56 UTC

How to throw an exception from "public Response handleRequest(Message m, ClassResourceInfo resourceClass)"

Hi all,
I have this problem using cxf dispatching behavior.
I have developed an Interceptor that implements the
org.apache.cxf.jaxrs.ext.RequestHandler interface.
In its "public Response handleRequest(Message m, ClassResourceInfo
resourceClass)" method I throw an exception (e.g. a WebServiceException) or
a Fault. I have not apparent problems but, on the client side, the client
receives a different exception (a ServerWebApplicationException) with the
error message empty.
Here the code:

Server side:
public class RestInterceptor implements RequestHandler {
        ......
	@Override
	public Response handleRequest(Message m, ClassResourceInfo resourceClass){
        .....
             throw new WebServiceException("Failure in the dispatching ws
invocation!");
        .....
        }
}

ServerWebApplicationException received on client side:
	Status : 500
	Headers : 
	Content-Length : 0
	Connection : close
	Server : Jetty(7.x.y-SNAPSHOT)

	cause=null
	detailMessage=null
	errorMessage=""
	.....
 
I received the same exception also if I throw a Fault.
What is the problem? I have to use another exception? Why?
Thanks a lot,

Andrea



--
View this message in context: http://cxf.547215.n5.nabble.com/How-to-throw-an-exception-from-public-Response-handleRequest-Message-m-ClassResourceInfo-resourceCla-tp5723225.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: How to throw an exception from "public Response handleRequest(Message m, ClassResourceInfo resourceClass)"

Posted by Sergey Beryozkin <sb...@gmail.com>.
On 15/02/13 10:29, eanbiso wrote:
> Thanks a lot for the explanation!
>
> Is ti possible to register the JAX-RS ExceptionMapper in the interceptor?
> How can I do it?
> Sorry but I'm not very expert with cxf!
have a look here please
http://cxf.apache.org/docs/jaxrs-services-configuration.html

you can register it as jaxrs:provider

>
> Another question: I want to receive an exception on the client side...if I
> return a Response from the handler (in place of the exception) will the
> client receive an exception or not?

First of all, as I said you can either throw the exception and map it or 
in the case of the interceptor - simply return Response.

On the client side: is CXF used there ? if CXF RS proxy based client is 
used then you can register ResponseExceptionMapper and map the error to 
some custom exception, otherwise, if proxy or WebClient is used and 
typed response is expected (example, Book) then the error will be mapped 
by the runtime to one of WebApplicationException subclasses

See more on client API:
http://cxf.apache.org/docs/jax-rs-client-api.html

Sergey

> Thanks,
>
> Andrea
>
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/How-to-throw-an-exception-from-public-Response-handleRequest-Message-m-ClassResourceInfo-resourceCla-tp5723225p5723231.html
> Sent from the cxf-user mailing list archive at Nabble.com.


Re: How to throw an exception from "public Response handleRequest(Message m, ClassResourceInfo resourceClass)"

Posted by eanbiso <bi...@hotmail.it>.
Thanks a lot for the explanation!

Is ti possible to register the JAX-RS ExceptionMapper in the interceptor?
How can I do it?
Sorry but I'm not very expert with cxf!

Another question: I want to receive an exception on the client side...if I
return a Response from the handler (in place of the exception) will the
client receive an exception or not? 
Thanks,

Andrea




--
View this message in context: http://cxf.547215.n5.nabble.com/How-to-throw-an-exception-from-public-Response-handleRequest-Message-m-ClassResourceInfo-resourceCla-tp5723225p5723231.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: How to throw an exception from "public Response handleRequest(Message m, ClassResourceInfo resourceClass)"

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 15/02/13 08:19, eanbiso wrote:
> Hi all,
> I have this problem using cxf dispatching behavior.
> I have developed an Interceptor that implements the
> org.apache.cxf.jaxrs.ext.RequestHandler interface.
> In its "public Response handleRequest(Message m, ClassResourceInfo
> resourceClass)" method I throw an exception (e.g. a WebServiceException) or
> a Fault. I have not apparent problems but, on the client side, the client
> receives a different exception (a ServerWebApplicationException) with the
> error message empty.
> Here the code:
>
> Server side:
> public class RestInterceptor implements RequestHandler {
>          ......
> 	@Override
> 	public Response handleRequest(Message m, ClassResourceInfo resourceClass){
>          .....
>               throw new WebServiceException("Failure in the dispatching ws
> invocation!");
>          .....
>          }
> }
>
> ServerWebApplicationException received on client side:
> 	Status : 500
> 	Headers :
> 	Content-Length : 0
> 	Connection : close
> 	Server : Jetty(7.x.y-SNAPSHOT)
>
> 	cause=null
> 	detailMessage=null
> 	errorMessage=""
> 	.....
>
> I received the same exception also if I throw a Fault.
> What is the problem? I have to use another exception? Why?
> Thanks a lot,
>
When the exception escapes in the JAX-RS chain it is propagated by 
default to the underlying container and thus you see just 500.
What you can do is to register a JAX-RS ExceptionMapper and map a given 
exception to JAX-RS Response as required, or you can simply return 
Response from your handler and it will block the invocation and return 
this custom Response to the client

HTH, Sergey

> Andrea
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/How-to-throw-an-exception-from-public-Response-handleRequest-Message-m-ClassResourceInfo-resourceCla-tp5723225.html
> Sent from the cxf-user mailing list archive at Nabble.com.


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com