public void handle(String pathInfo, final HttpServletRequest request, final HttpServletResponse response)
      throws Exception {
    final Handler handler = getHandler(pathInfo);

    if (handler instanceof JsonParametersAware) {
      setJsonParameters(request, handler);
    }

    request.setAttribute("handler", handler);

    ResultType result;

    try {
      logger.log(String.format("Executing: %s at URL: %s)", handler.toString(), pathInfo));
      result = handler.handle();
      addHandlerAttributesToRequest(request, handler);
      logger.log("Done: " + pathInfo);
    } catch (Exception e) {
      result = ResultType.EXCEPTION;
      Throwable toUse = e;
      if (e instanceof UndeclaredThrowableException) {
        // An exception was thrown within an invocation handler. Not smart.
        // Extract the original exception
        toUse = e.getCause().getCause();
      }

      logger.log("Exception: " + toUse.getMessage());
      request.setAttribute("exception", toUse);
      if (handler instanceof WebDriverHandler) {
        request.setAttribute("screen", ((WebDriverHandler) handler).getScreenshot());
      }
    } catch (Error e) {
      logger.log("Error: " + e.getMessage());
      result = ResultType.EXCEPTION;
      request.setAttribute("exception", e);
    }

    Set<Result> results = resultToRender.get(result);
    Result tempToUse = null;
    for (Result res : results) {
      if (tempToUse == null || res.isExactMimeTypeMatch(request.getHeader("Accept"))) {
        tempToUse = res;
      }
    }
    final Result toUse = tempToUse;

    if (handler instanceof WebDriverHandler) {
      FutureTask<ResultType> task = new FutureTask<ResultType>(new Callable<ResultType>() {
        public ResultType call() throws Exception {
          toUse.getRenderer().render(request, response, handler);
          return null;
        }
      });

      ((WebDriverHandler) handler).execute(task);
      task.get();
    } else {
      toUse.getRenderer().render(request, response, handler);
    }
  }