ExceptionMapper在grizzly中不起作用

抱歉我的英语不好。 我正在使用灰熊和jersey来构建一个Web应用程序。

我这样实施

ErrorModel errorModel = new ErrorModel("1", "1", "1"); WebApplicationException applicationException = (WebApplicationException) exception; return Response.status(applicationException.getResponse().getStatus()).type(MediaType.APPLICATION_JSON_TYPE).entity(errorModel).build(); 

当我访问一个不存在的页面时。 我发现它抛出WebApplicationException。 所以我调试并发现正在调用此方法并返回上面的响应。 但最后http响应是一个由grizzly构建的html页面。 我该怎么办

确保设置了RESPONSE_SET_STATUS_OVER_SEND_ERROR属性。

我有同样的问题与灰熊,它捕获我捕捉我的400并发送回默认的通用servlet错误页面。 这是jersey2的解决方案。

 public class RestApplication extends ResourceConfig { private static final Logger logger = Logger.getLogger(RestApplication.class.getName()); public RestApplication() { // Set this property so that the 400 will still send the entity correctly. property(ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR, "true"); registerModules(); } 
Interesting Posts