I want to subclass RuntimeExceptionsa custom json format by making the servlet container without dropping stacktrace to the client.
I follow this question: JAX-RS (Jersey) custom exception with XML or JSON . When called:
try {
doSomething(parameters);
}
catch(RuntimeException e) {
throw new MyCustomException(500 , e.getMessage() , Status.INTERNAL_SERVER_ERROR);
}
When I intentionally load the wrong parameters (and the trigger RuntimeExceptionthrown doSomething()), I did not see MyCustomExceptionMapper. Instead, servlet containers are unloaded:
The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
api.MyCustomException: (underlaying msgs)
MyCustomExceptionMapperreally registered in javax.ws.rs.core.Application:
@Override
public Set<Class<?>> getClasses()
{
Set<Class<?>> set = new HashSet<Class<?>>();
set.add(other classes);
set.add(MyCustomExceptionMapper.class);
return set;
}
What did I miss?
Thank you so much!
Environment: JAX-RS, jersey-server 1.5
class spec:
class MyCustomException extends RuntimeException
@Provider
class MyCustomExceptionMapper implements ExceptionMapper<MyCustomException>
updated :
I suspect it is Application.getClasses()never called, so I am adding a few println messages:
@Override
public Set<Class<?>> getClasses()
{
System.out.println("\n\n\n\n ApiConfig getClasses");
}
!
, ApiConfig web.xml:
<context-param>
<param-name>javax.ws.rs.core.Application</param-name>
<param-value>destiny.web.api.ApiConfig</param-value>
</context-param>
?