Class RewriteHandler

java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.ContainerLifeCycle
org.eclipse.jetty.server.Handler.Abstract
org.eclipse.jetty.server.Handler.AbstractContainer
org.eclipse.jetty.server.Handler.Wrapper
org.eclipse.jetty.rewrite.handler.RewriteHandler
All Implemented Interfaces:
org.eclipse.jetty.server.Handler, org.eclipse.jetty.server.Handler.Container, org.eclipse.jetty.server.Handler.Singleton, org.eclipse.jetty.server.Request.Handler, org.eclipse.jetty.util.component.Container, org.eclipse.jetty.util.component.Destroyable, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.util.component.Dumpable.DumpableContainer, org.eclipse.jetty.util.component.LifeCycle, org.eclipse.jetty.util.thread.Invocable

public class RewriteHandler extends org.eclipse.jetty.server.Handler.Wrapper

RewriteHandler rewrites incoming requests through a set of Rules.

RewriteHandler can rewrite the request URI, but also HTTP cookies and HTTP headers. When a rule matches, RewriteHandler can perform actions such as redirect to a different URI or directly produce a response with a configurable HTTP status code.

Rules can be grouped into a RuleContainer, which is itself a Rule. If the container rule matches (for example, virtual host name when using VirtualHostRuleContainer), then the contained rules will be applied.

Rules are applied in the same sequence they are added to the container. If a rule matches, it applies some logic (typically wrapping the request), and the next rule is invoked (with the wrapped request), until a terminating rule is found, or all the rules have been processed.

Request URI matching is performed either via Servlet pattern matching (using PatternRule subclasses), via regular expression matching (using RegexRule subclasses), or by a custom implementation of Rule.

  • Nested Class Summary

    Nested classes/interfaces inherited from class org.eclipse.jetty.server.Handler.Abstract

    org.eclipse.jetty.server.Handler.Abstract.NonBlocking

    Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener, org.eclipse.jetty.util.component.AbstractLifeCycle.StopException

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container

    org.eclipse.jetty.util.component.Container.InheritedListener, org.eclipse.jetty.util.component.Container.Listener

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable

    org.eclipse.jetty.util.component.Dumpable.DumpableContainer

    Nested classes/interfaces inherited from interface org.eclipse.jetty.server.Handler

    org.eclipse.jetty.server.Handler.Abstract, org.eclipse.jetty.server.Handler.AbstractContainer, org.eclipse.jetty.server.Handler.Collection, org.eclipse.jetty.server.Handler.Container, org.eclipse.jetty.server.Handler.Sequence, org.eclipse.jetty.server.Handler.Singleton, org.eclipse.jetty.server.Handler.Wrapper

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.thread.Invocable

    org.eclipse.jetty.util.thread.Invocable.Callable, org.eclipse.jetty.util.thread.Invocable.InvocationType, org.eclipse.jetty.util.thread.Invocable.ReadyTask, org.eclipse.jetty.util.thread.Invocable.Task

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle

    org.eclipse.jetty.util.component.LifeCycle.Listener
  • Field Summary

    Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    FAILED, STARTED, STARTING, STOPPED, STOPPING

    Fields inherited from interface org.eclipse.jetty.util.component.Dumpable

    KEY

    Fields inherited from interface org.eclipse.jetty.util.thread.Invocable

    __nonBlocking, NOOP
  • Constructor Summary

    Constructors
    Constructor
    Description
     
     
    RewriteHandler(org.eclipse.jetty.server.Handler handler)
     
    RewriteHandler(org.eclipse.jetty.server.Handler handler, RuleContainer rules)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addRule(Rule rule)
    Adds a Rule to the existing ones.
     
     
     
    boolean
    handle(org.eclipse.jetty.server.Request request, org.eclipse.jetty.server.Response response, org.eclipse.jetty.util.Callback callback)
     
    void
    setOriginalPathAttribute(String originalPathAttribute)
     
    void
    setRules(List<Rule> rules)
    Sets the list of rules, discarding the previous ones.

    Methods inherited from class org.eclipse.jetty.server.Handler.Wrapper

    getHandler, getInvocationType, setHandler

    Methods inherited from class org.eclipse.jetty.server.Handler.AbstractContainer

    findContainerOf, getDescendant, getDescendants, isDynamic, setDynamic, setServer

    Methods inherited from class org.eclipse.jetty.server.Handler.Abstract

    destroy, doStart, doStop, getServer

    Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle

    addBean, addBean, addEventListener, addManaged, contains, dump, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeans

    Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop, toString

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface org.eclipse.jetty.util.component.Container

    getCachedBeans, getEventListeners

    Methods inherited from interface org.eclipse.jetty.util.component.Destroyable

    destroy

    Methods inherited from interface org.eclipse.jetty.util.component.Dumpable

    dumpSelf

    Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer

    isDumpable

    Methods inherited from interface org.eclipse.jetty.server.Handler

    getServer, setServer

    Methods inherited from interface org.eclipse.jetty.server.Handler.Container

    getContainer, getDescendant, getDescendants, getDescendants

    Methods inherited from interface org.eclipse.jetty.server.Handler.Singleton

    getHandlers, getTail, insertHandler, setHandler

    Methods inherited from interface org.eclipse.jetty.util.component.LifeCycle

    addEventListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, start, stop
  • Constructor Details

    • RewriteHandler

      public RewriteHandler()
    • RewriteHandler

      public RewriteHandler(RuleContainer rules)
    • RewriteHandler

      public RewriteHandler(org.eclipse.jetty.server.Handler handler)
    • RewriteHandler

      public RewriteHandler(org.eclipse.jetty.server.Handler handler, RuleContainer rules)
  • Method Details

    • getRuleContainer

      public RuleContainer getRuleContainer()
      Returns:
      the RuleContainer used by this handler
    • getRules

      public List<Rule> getRules()
      Returns:
      the list of Rules.
    • setRules

      public void setRules(List<Rule> rules)

      Sets the list of rules, discarding the previous ones.

      Parameters:
      rules - the list of Rules to set
    • addRule

      public void addRule(Rule rule)

      Adds a Rule to the existing ones.

      Parameters:
      rule - the rule to add to the rules list
    • getOriginalPathAttribute

      public String getOriginalPathAttribute()
      See Also:
    • setOriginalPathAttribute

      public void setOriginalPathAttribute(String originalPathAttribute)
      See Also:
    • handle

      public boolean handle(org.eclipse.jetty.server.Request request, org.eclipse.jetty.server.Response response, org.eclipse.jetty.util.Callback callback) throws Exception
      Specified by:
      handle in interface org.eclipse.jetty.server.Request.Handler
      Overrides:
      handle in class org.eclipse.jetty.server.Handler.Wrapper
      Throws:
      Exception