Interface Handler


public interface Handler
Handler which is responsible for processing request and response. This type is introduced to provide a unified way for injecting various logic on verification of requests sent via HTTP. Handlers are called before servlet who will receive request, thus they can not mutate servlet response, but they can generate its own response depending on actual needs. Pay attention to error handling - as a proper executions might report exceptions, but fault path handled in handleError(HttpServletRequest, HttpServletResponse, HandlerContext) method must remain silent and take care of all issues which might occur while handling error.
Author:
Ɓukasz Dywicki - Initial contribution
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns priority of this handler.
    void
    handle(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, HandlerContext context)
    Method dedicated for processing incoming request and checking its contents.
    void
    handleError(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, HandlerContext context)
    Method which is called only if any of handle(HttpServletRequest, HttpServletResponse, HandlerContext) method invocations thrown unexpected Exception.
  • Method Details

    • getPriority

      int getPriority()
      Returns priority of this handler. Priority is any integer where 0 means earliest in the queue. The higher the number is, the later Handler will be called.
      Returns:
      Handler execution priority.
    • handle

      void handle(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, HandlerContext context) throws Exception
      Method dedicated for processing incoming request and checking its contents.
      Parameters:
      request - Http request.
      response - Http response.
      context - Handler execution context.
      Throws:
      Exception - any error reported during processing will suspend execution of following handlers. Handlers will be then asked to handle error via handleError(HttpServletRequest, HttpServletResponse, HandlerContext) method.
    • handleError

      void handleError(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, HandlerContext context)
      Method which is called only if any of handle(HttpServletRequest, HttpServletResponse, HandlerContext) method invocations thrown unexpected Exception. Each handler might decide if it wants to handle error. If not then it should just let next handler in the queue do its job via HandlerContext.execute(HttpServletRequest, HttpServletResponse) call.
      Parameters:
      request - Http request.
      response - Http response.
      context - Handler execution context.