何をしようとしていますか?例外がスローされたときにサーブレットフィルタが機能しない
私は、クライアントが、私が試してみました何その後続の要求に
を使用することができ、サーバー側からの新しいタイムスタンプトークンを生成しようとしていますか?
は、私の周りREST
呼び出しをラップし、
@WebFilter(urlPatterns = "/rest/secure")
public class SecurityFilter implements Filter {
private static final Pattern PATTERN = Pattern.compile(":");
private static final Logger LOGGER = LoggerFactory.getLogger(SecurityFilter.class);
@Override
public void init(final FilterConfig filterConfig) throws ServletException {
//LOGGER.info("initializing SecurityFilter");
}
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
final HttpServletResponse httpServletResponse = (HttpServletResponse) response;
final String authToken = getAuthenticationHeaderValue((HttpServletRequest) request);
try {
validateAuthToken(authToken);
} catch (IllegalArgumentException tokenNotValidException) {
LOGGER.error("invalid token");
httpServletResponse.sendError(401);
}
try {
chain.doFilter(request, response);
} catch (Exception e) {
LOGGER.error("exception: " + e.getMessage());
}finally {
final String newAuthToken = generateNewAuthToken(authToken);
httpServletResponse.addHeader(AUTH_TOKEN, newAuthToken);
LOGGER.info("added new security token: " + newAuthToken);
}
}
のように見えて、私のエンドポイントの1つに、私は私がすべてのREST
ベースの仕事のためRESTEasy
を使用しています
@PUT
public Response updateUser() {
throw new IllegalArgumentException("just for test purposes");
}
を行うサーブレットフィルタを持っています。
私もREST
ベースの例外
@ExceptionMapping.List({
@ExceptionMapping(exceptionType = IllegalArgumentException.class, status = 400, useExceptionMessage = true),
@ExceptionMapping(exceptionType = PersistenceException.class, status = 400, useExceptionMessage = true),
@ExceptionMapping(exceptionType = ConstraintViolationException.class, status = 400, useExceptionMessage = true),
@ExceptionMapping(exceptionType = ValidationException.class, status = 400, useExceptionMessage = true),
@ExceptionMapping(exceptionType = NoResultException.class, status = 404, useExceptionMessage = true),
@ExceptionMapping(exceptionType = IllegalStateException.class, status = 406, useExceptionMessage = true),
@ExceptionMapping(exceptionType = NoClassDefFoundError.class, status = 404, useExceptionMessage = true),
@ExceptionMapping(exceptionType = UnsupportedOperationException.class, status = 400, useExceptionMessage = true),
})
@ApplicationPath("/rest")
public class MarketApplicationConfiguration extends Application {
}
問題へのサーバーの例外をマップするためにSeam REST
ライブラリを使用していますか?
- エンドポイントが例外をスローすると、コールバックは決してフィルタコードに返されません。
は - 私はしかしIllegalArgumentException
がSeam REST
例外マッピングに基づいてHTTP 400
にマッピングされていることをテストすることができますが、それはの場合にSecurityFilter
コードに戻されることはありません -
try {
chain.doFilter(request, response);
} catch (Exception e) {
LOGGER.error("exception: " + e.getMessage());
}finally {
final String newAuthToken = generateNewAuthToken(authToken);
httpServletResponse.addHeader(AUTH_TOKEN, newAuthToken);
LOGGER.info("added new security token: " + newAuthToken);
}
を次のように私はtry/catch/finally
を使用する場合にも、ありますサーバー例外。
必須ですか?
- アプリケーションが例外をスローしてクライアントが使用できるようにしても、サーバートークンを生成したい
- 例外が発生した場合、どうすればSecurityFilter
経由で応答をルーティングできますか?
+1で詳細を取得することができます。 –