简体   繁体   中英

ExceptionMapper not work in grizzly

Sorry for my poor English. I'm using grizzly and jersey to build a web application.

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. 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. What should i do

Make sure you have the RESPONSE_SET_STATUS_OVER_SEND_ERROR property set.

I had the same problem with grizzly and it was capturing my catching my 400 and sending back the default generic servlet error page. This was the solution for jersey 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();
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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