ServletFilter 内で特定の Exception を throw し、ExceptionMapper でハンドリングする方法を探しています。
現在、以下のようなコードを実装しております。
java
1public class MyFilter implements Filter { 2 3 @Override 4 public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { 5 6 SecurityContext securityContext 7 = (SecurityContext) request.getAttribute(SecurityContext.class.getName()); 8 9 if(securityContext == null) { 10 throw new ApiAuthErrorException("AAA0000001E"); 11 } 12 13 chain.doFilter(request, response); 14 } 15}
java
1public class ApiAuthErrorExceptionMapper implements ExceptionMapper<ApiAuthErrorException> { 2 3 @Override 4 public Response toResponse(ApiAuthErrorException e) { 5 6 return Response.status(Response.Status.UNAUTHORIZED) 7 .type(MediaType.APPLICATION_JSON) 8 .entity(new ErrorInfo()) 9 .build(); 10 } 11}
ExceptionMapper が正常に呼ばれることは、Service のエンドポイントで ApiAuthErrorException を throw することで確認しております。
ServletFilter からの throw に ExceptionMapper が反応しないことが現在の問題になります。
ServletFilter から ExceptionMapper を呼ぶ方法をご教示ください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。