![](/img/trans.png)
[英]Why is my ExceptionMapper getting thrown away in Jersey/Grizzly?
[英]ExceptionMapper not work in grizzly
對不起,我的英語不好。 我正在使用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錯誤頁面。 這是球衣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.