The specific processing that you mention for web application exceptions is defined only in the context of the JAX-RS container, which, incidentally, does not match the Servlet container. p>
Web filters are handled by the Servlet container, which does not know and does not care that the JAX-RS container exists on the same application server. He also does not know and does not care about web application exceptions. Therefore, when you drop WAE from a filter, it is handled in the same way as any other exception (a server error with a stack trace or a pre-configured error page if you install it in your web application).
It seems to me that if you indicate an error to the client, you can simply do this from the filter by writing directly to the response stream. But if you are trying to use some existing JAX-RS logic, then a specific solution (RESTEasy) would have to mark the request as erroneous in your filter, and then create WAE in JAX-RS using the provider class. Example:
@WebFilter(urlPatterns = "*") public class ForwardingFilter implements Filter { @Override public void destroy() { return; } @Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
Since the provider exists in the JAX-RS territory, the web application exception is handled in accordance with the rules of section 3.3.4 of the JAX-RS specification, and you get the desired response on the client side.
* EDIT: *
The bottom line does not have a standard Java EE that is (currently) required to handle servlet exceptions in a centralized way, similar to what is available in JAX-RS. Since you are using JBoss / RestEASY, you can use the JBoss Seam Catch library to get pretty close.
@HandlesExceptions public class ExceptionHandler { public void handleServletException( final @Handles @WebRequest CaughtException<ServletException> caught, @Context final HttpServletResponse response) { try { response.sendError(500, "An error occured"); } catch (final IOException ioe) { System.err.println("Dumb IO Exception: " + ioe); } } }
The above illustrates an exception handler as described in the Seam Catch documentation. Please note that the library is in a huge stream right now, so you will want to use it only as a last resort.