Class XServletFilterConsistency

  • All Implemented Interfaces:
    IXServletLowLevelFilter

    public class XServletFilterConsistency
    extends Object
    implements IXServletLowLevelFilter
    Handle special content related stuff that needs to be processed for every servlet. Currently handled are:
    • Request fallback charset
    • Response fallback charset
    Since:
    9.0.0
    Author:
    Philip Helger
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void afterRequest​(javax.servlet.http.HttpServletRequest aHttpRequest, javax.servlet.http.HttpServletResponse aHttpResponse, com.helger.http.EHttpVersion eHttpVersion, com.helger.commons.http.EHttpMethod eHttpMethod, boolean bInvokeHandler, Throwable aCaughtException, boolean bIsHandledAsync)
      Invoked after an XServlet request was handled.
      com.helger.commons.state.EContinue beforeRequest​(javax.servlet.http.HttpServletRequest aHttpRequest, javax.servlet.http.HttpServletResponse aHttpResponse, com.helger.http.EHttpVersion eHttpVersion, com.helger.commons.http.EHttpMethod eHttpMethod)
      Invoked before an XServlet request is handled.
      protected void checkCharacterEncoding​(String sRequestURL, String sCharacterEncoding, int nStatusCode, com.helger.commons.http.EHttpMethod eHttpMethod)  
      protected void checkContentType​(String sRequestURL, String sContentType, int nStatusCode, com.helger.commons.http.EHttpMethod eHttpMethod)  
      protected void checkHeaders​(String sRequestURL, com.helger.commons.http.HttpHeaderMap aHeaders, int nStatusCode, com.helger.commons.http.EHttpMethod eHttpMethod)  
      protected void checkStatusCode​(String sRequestURL, int nStatusCode, com.helger.commons.http.EHttpMethod eHttpMethod)  
      static boolean isSilentMode()  
      static boolean setSilentMode​(boolean bSilentMode)
      Enable or disable certain regular log messages.
    • Constructor Detail

      • XServletFilterConsistency

        protected XServletFilterConsistency()
    • Method Detail

      • isSilentMode

        public static boolean isSilentMode()
        Returns:
        true if logging is disabled, false if it is enabled.
        Since:
        9.1.7
      • setSilentMode

        public static boolean setSilentMode​(boolean bSilentMode)
        Enable or disable certain regular log messages.
        Parameters:
        bSilentMode - true to disable logging, false to enable logging
        Returns:
        The previous value of the silent mode.
        Since:
        9.1.7
      • beforeRequest

        @Nonnull
        public com.helger.commons.state.EContinue beforeRequest​(@Nonnull
                                                                javax.servlet.http.HttpServletRequest aHttpRequest,
                                                                @Nonnull
                                                                javax.servlet.http.HttpServletResponse aHttpResponse,
                                                                @Nonnull
                                                                com.helger.http.EHttpVersion eHttpVersion,
                                                                @Nonnull
                                                                com.helger.commons.http.EHttpMethod eHttpMethod)
        Description copied from interface: IXServletLowLevelFilter
        Invoked before an XServlet request is handled. This method is created before the request is created! Exceptions occurring in this method will be propagated to the outside, so be careful :)
        Specified by:
        beforeRequest in interface IXServletLowLevelFilter
        Parameters:
        aHttpRequest - HTTP servlet request. Never null.
        aHttpResponse - HTTP servlet response. Never null.
        eHttpVersion - HTTP version. Never null.
        eHttpMethod - HTTP method. Never null.
        Returns:
        EContinue.CONTINUE to continue processing, or EContinue.BREAK if this request should not be processed, in which case the HttpServletResponse must contain a valid response!
      • checkStatusCode

        @OverrideOnDemand
        protected void checkStatusCode​(@Nonnull
                                       String sRequestURL,
                                       int nStatusCode,
                                       @Nonnull
                                       com.helger.commons.http.EHttpMethod eHttpMethod)
        Parameters:
        sRequestURL - The request URL.
        nStatusCode - The response status code.
        eHttpMethod - Used HTTP Method
      • checkCharacterEncoding

        @OverrideOnDemand
        protected void checkCharacterEncoding​(@Nonnull
                                              String sRequestURL,
                                              @Nullable
                                              String sCharacterEncoding,
                                              int nStatusCode,
                                              @Nonnull
                                              com.helger.commons.http.EHttpMethod eHttpMethod)
        Parameters:
        sRequestURL - The request URL.
        sCharacterEncoding - The response character encoding.
        nStatusCode - The response status code.
        eHttpMethod - Used HTTP Method
      • checkContentType

        @OverrideOnDemand
        protected void checkContentType​(@Nonnull
                                        String sRequestURL,
                                        @Nullable
                                        String sContentType,
                                        int nStatusCode,
                                        @Nonnull
                                        com.helger.commons.http.EHttpMethod eHttpMethod)
        Parameters:
        sRequestURL - The request URL.
        sContentType - The response content type.
        nStatusCode - The response status code.
        eHttpMethod - Used HTTP Method
      • checkHeaders

        @OverrideOnDemand
        protected void checkHeaders​(@Nonnull
                                    String sRequestURL,
                                    @Nonnull
                                    com.helger.commons.http.HttpHeaderMap aHeaders,
                                    int nStatusCode,
                                    @Nonnull
                                    com.helger.commons.http.EHttpMethod eHttpMethod)
        Parameters:
        sRequestURL - The request URL.
        aHeaders - All response HTTP headers.
        nStatusCode - The response status code.
        eHttpMethod - Used HTTP Method
      • afterRequest

        public void afterRequest​(@Nonnull
                                 javax.servlet.http.HttpServletRequest aHttpRequest,
                                 @Nonnull
                                 javax.servlet.http.HttpServletResponse aHttpResponse,
                                 @Nonnull
                                 com.helger.http.EHttpVersion eHttpVersion,
                                 @Nonnull
                                 com.helger.commons.http.EHttpMethod eHttpMethod,
                                 boolean bInvokeHandler,
                                 @Nullable
                                 Throwable aCaughtException,
                                 boolean bIsHandledAsync)
        Description copied from interface: IXServletLowLevelFilter
        Invoked after an XServlet request was handled. After is always called, even if before request was canceled (in a finally)! Exceptions occurring in this method will be propagated to the outside, so be careful :)
        Note: the response cannot be modified in implementations of this method - they should be considered read-only. Also HTTP headers can usually NOT be modified in this method.
        Specified by:
        afterRequest in interface IXServletLowLevelFilter
        Parameters:
        aHttpRequest - HTTP servlet request. Never null.
        aHttpResponse - HTTP servlet response. Never null.
        eHttpVersion - HTTP version. Never null.
        eHttpMethod - HTTP method. Never null.
        bInvokeHandler - true if the main handler was invoked, false if IXServletLowLevelFilter.beforeRequest(HttpServletRequest, HttpServletResponse, EHttpVersion, EHttpMethod) avoided the execution of the request.
        aCaughtException - An optionally caught exception. May be null. The exception was already logged, so please don't log it again!
        bIsHandledAsync - true if the request is handled asynchronously