How do I register my provider programmatically in jersey which implements the Exceptionmapper provided by jersey API? I don\'t want to use @Provider annotation and want to r
While @paul-samsotha's answer is correct, still there is implementation trick. I want to share it and hope it will help someone.
a) Implement your mapper:
public class MyExceptionMapper implements ExceptionMapper, ResponseErrorMapper {
...
b) make sure you declare generic type, otherwise your mapper will never be called
public class MyExceptionMapper implements ExceptionMapper/* no generic declaration */, ResponseErrorMapper {
...
and may trigger
javax.ws.rs.ProcessingException: Could not find exception type for given ExceptionMapper class: class com...MyExceptionMapper.
c) Register it as resource:
ResourceConfig config = new ResourceConfig();
config.register(new MyExceptionMapper());
or
config.register(MyExceptionMapper.class);
d) make sure you enforce processing errors as well:
config.setProperties(new LinkedHashMap() {{
put(org.glassfish.jersey.server.ServerProperties.PROCESSING_RESPONSE_ERRORS_ENABLED, true);
}});