I think (on the basis of my experiments) that exception providers are looked up by exact class match, rather than by inheritance match, so an exception provider that handles RuntimeException will only fire if the app throws a raw RuntimeException that's not the case with the class you've showed us. I have some theories about how to fix this (e.g. , with a custom filter handler, or possibly some use of AOP) but nothing final yet.
Up vote 0 down vote favorite share g+ share fb share tw.
I want to wrap underlaying RuntimeExceptions to a custom json format , making the servlet container won't dump the stacktrace to client. I follow this question : JAX-RS (Jersey) custom exception with XML or JSON . When calling : try { doSomething(parameters); } catch(RuntimeException e) { throw new MyCustomException(500 , e.getMessage() , Status.
INTERNAL_SERVER_ERROR); } When I intentionally feed wrong parameters (and trigger RuntimeException thrown by doSomething() ) , I didn't see MyCustomExceptionMapper working. Instead , the servlet container dumps : The RuntimeException could not be mapped to a response, re-throwing to the HTTP container api. MyCustomException: (underlaying msgs) The MyCustomExceptionMapper is indeed registered in the javax.ws.rs.core.
Application : @Override public Set> getClasses() { Set> set = new HashSet>(); set. Add(other classes); set. Add(MyCustomExceptionMapper.
Class); return set; } What did I miss? Thanks a lot! Environment : JAX-RS , jersey-server 1.5 classes spec : class MyCustomException extends RuntimeException @Provider class MyCustomExceptionMapper implements ExceptionMapper updated : I suspect that Application.getClasses() is never called , so I add some println messages : @Override public Set> getClasses() { System.out.
Println("\n\n\n\n ApiConfig getClasses"); } And in deed , it's never shown! I am sure this ApiConfig is in the web. Xml : javax.ws.rs.core.
Application destiny.web.api. ApiConfig But why it seems Jersey never calls it? Jersey jax-rs link|improve this question edited Apr 25 '11 at 4:47 asked Apr 25 '11 at 4:18smallufo600622 73% accept rate.
I think (on the basis of my experiments) that exception providers are looked up by exact class match, rather than by inheritance match, so an exception provider that handles RuntimeException will only fire if the app throws a raw RuntimeException; that's not the case with the class you've showed us. I have some theories about how to fix this (e.g. , with a custom filter handler, or possibly some use of AOP) but nothing final yet. In relation to the second half of your question, I just don't know.
What I do know is that Apache CXF (the JAX-RS implementation I've worked with) has/had some failings in this area, and that I thus stick to registering all my @Providers by hand in the app's Spring config. I offer that as experience….
I found the solution. All I have to do is annotate MyCustomExceptionMapper with Spring's @Repository. And remove the section in web.
Xml (not needed) javax.ws.rs.core. Application destiny.web.api. ApiConfig Because Spring will lookup all @Repository and find a @Provider , and Jersey will make use of it.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.