|
From: Frode A. <fro...@gm...> - 2014-01-18 21:01:36
|
What is the correct behavior when a JAX-RS method throws an exception that are not mapped by a ExceptionMapper and a ContainerResponseFilter is provided?
@Path("/") @Produces(value = { MediaType.TEXT_PLAIN })
public class ApiResources {
@GET
@Path("throwIllegalArgumentException")
public String getThrowIllegalArgumentException() {
throw new IllegalArgumentException( "HELLO from throwIllegalArgumentException" );
}
@Provider
public class MonitorFilter implements ContainerResponseFilter {
@Override
public void filter( ContainerRequestContext requestContext,
ContainerResponseContext responseContext ) throws IOException {
System.out.println(“Resource returned status=“ + responseContext.getStatus());
}
}
Tested the code in wildfly-8.0.0.Alpha4 and the ContainerResponseFilter#filter method was not called. It was only called after a ExceptionMapper for IllegalArgumentException was provided.
@Provider
public class IllegalStateExceptionExceptionMapper implements ExceptionMapper<IllegalStateException> {
@Override
public Response toResponse( IllegalStateException e ) {
return Response.status( Response.Status.INTERNAL_SERVER_ERROR ).entity( e.getMessage() )
.build();
}
}
|