3

I'm using the undertow security framework to handle an http request. Details on that can be seen here : http://undertow.io/undertow-docs/undertow-docs-1.3.0/index.html#security.

My handler chain uses an error handler first with a try catch block that is designed to catch any errors during the handling of the http request. This worked prior to implementing the undertow security handlers.

public void handleRequest(HttpServerExchange exchange) throws Exception {
    try {
        next.handleRequest(exchange);
    } catch ( Exception e ) {
        //code
    }

It will hit the error handler first, then it will go through the security handlers which will dispatch the request. Then it reaches MyLogicHandler which will throw an exception based on a null parameter.

Any exception thrown will be caught by the try/catch seen here : https://github.com/undertow-io/undertow/blob/master/core/src/main/java/io/undertow/server/Connectors.java#L199

This always throws a 500 error, which is not what I want. The purpose of the ErrorHandler is to let me set the response code based on the types of errors.

Is there a way to get my ErrorHandler to catch exceptions in requests that are dispatched to the XNIO worker threads?

Adam Perez
  • 31
  • 1

0 Answers0