Class IncludeExcludeBasedFilter

java.lang.Object
org.eclipse.jetty.servlets.IncludeExcludeBasedFilter
All Implemented Interfaces:
javax.servlet.Filter
Direct Known Subclasses:
HeaderFilter

public abstract class IncludeExcludeBasedFilter extends Object implements javax.servlet.Filter
Include Exclude Based Filter

This is an abstract filter which helps with filtering based on include/exclude of paths, mime types, and/or http methods.

Use the shouldFilter(HttpServletRequest, HttpServletResponse) method to determine if a request/response should be filtered. If mime types are used, it should be called after FilterChain.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse) since the mime type may not be written until then. Supported init params:

  • includedPaths - CSV of path specs to include
  • excludedPaths - CSV of path specs to exclude
  • includedMimeTypes - CSV of mime types to include
  • excludedMimeTypes - CSV of mime types to exclude
  • includedHttpMethods - CSV of http methods to include
  • excludedHttpMethods - CSV of http methods to exclude

Path spec rules:

  • If the spec starts with '^' the spec is assumed to be a regex based path spec and will match with normal Java regex rules.
  • If the spec starts with '/' the spec is assumed to be a Servlet url-pattern rules path spec for either an exact match or prefix based match.
  • If the spec starts with '*.' the spec is assumed to be a Servlet url-pattern rules path spec for a suffix based match.
  • All other syntaxes are unsupported.

CSVs are parsed with StringUtil.csvSplit(String)

See Also:
  • PathSpecSet
  • IncludeExcludeSet
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    protected String
    guessMimeType(javax.servlet.http.HttpServletRequest httpRequest, javax.servlet.http.HttpServletResponse httpResponse)
     
    void
    init(javax.servlet.FilterConfig filterConfig)
     
    protected boolean
    shouldFilter(javax.servlet.http.HttpServletRequest httpRequest, javax.servlet.http.HttpServletResponse httpResponse)
     
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface javax.servlet.Filter

    doFilter
  • Constructor Details

    • IncludeExcludeBasedFilter

      public IncludeExcludeBasedFilter()
  • Method Details

    • init

      public void init(javax.servlet.FilterConfig filterConfig) throws javax.servlet.ServletException
      Specified by:
      init in interface javax.servlet.Filter
      Throws:
      javax.servlet.ServletException
    • guessMimeType

      protected String guessMimeType(javax.servlet.http.HttpServletRequest httpRequest, javax.servlet.http.HttpServletResponse httpResponse)
    • shouldFilter

      protected boolean shouldFilter(javax.servlet.http.HttpServletRequest httpRequest, javax.servlet.http.HttpServletResponse httpResponse)
    • destroy

      public void destroy()
      Specified by:
      destroy in interface javax.servlet.Filter
    • toString

      public String toString()
      Overrides:
      toString in class Object