3

My exception mapper looks like below

@Provider
public class DAExceptionMapper implements ExceptionMapper<DAException> {
    @Override
    public @ResponseBody Response toResponse(DAException exception) {
    }
}

public class DAException extends Exception {
}

I'm using Spring 3.2.5 with Jersey 2.15 on Jetty 8.1.14.

I'm can't find why my exception mapper is not getting registered with Spring. I get 500 when I throw a custom DAException in my application. I tried all solutions in https://java.net/jira/browse/JERSEY-2063. None of them worked.

I currently don't have any beans for exception registered in spring context xml. My application doesn't set resources through program.

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is DAException [responseStatus=Unauthorized, errorMessage=ErrorMessage [errorMessage=User is not allowed to access this resource.], errorDescription=User is not allowed to access this resource.]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
TechCrunch
  • 2,924
  • 5
  • 45
  • 79

1 Answers1

0

Have you implemented the toResponse method?

@Provider
public class DAExceptionMapper implements
        ExceptionMapper<DAException> {
    @Override
    public Response toResponse(DAException ex) {
        return Response.status(404).entity(ex.getMessage()).type("text/plain")
                .build();
    }
}

There's also this but it sounds like this is related to jersey versions > 2.5 toResponse in jersey ExceptionMapper does not get invoked

Community
  • 1
  • 1
stringy05
  • 6,511
  • 32
  • 38
  • Sorry for not updating complete class. But I had toResponse in my class. Also, I tried all solutions in the page link you provided. Adding Singleton or Service annotation also did not work. – TechCrunch Feb 01 '15 at 23:28