简体   繁体   English

ExceptionMapper在灰熊中不起作用

[英]ExceptionMapper not work in grizzly

Sorry for my poor English. 对不起,我的英语不好。 I'm using grizzly and jersey to build a web application. 我正在使用grizzly和jersey来构建Web应用程序。

And I implement like this 我这样实现

        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();

When I visited a page which does not exist. 当我访问一个不存在的页面时。 I found that it throw a WebApplicationException. 我发现它引发了WebApplicationException。 So I debug and found this method is being called and return the response above. 因此,我进行了调试,发现正在调用此方法并返回上面的响应。 But finally the http response is a html page which is build by grizzly. 但最后,http响应是由grizzly构建的html页面。 What should i do 我该怎么办

Make sure you have the RESPONSE_SET_STATUS_OVER_SEND_ERROR property set. 确保设置了RESPONSE_SET_STATUS_OVER_SEND_ERROR属性。

I had the same problem with grizzly and it was capturing my catching my 400 and sending back the default generic servlet error page. 我在灰熊遇到了同样的问题,它捕获了我的400,并发回了默认的通用servlet错误页面。 This was the solution for jersey 2. 这是球衣2的解决方案。

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();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM