Web Server: Custom URL Rewrite Rule Tutorial

From Resin 4.0 Wiki

Revision as of 00:00, 25 January 2012 by Ferg (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Gears-48.pngWeb-48.pngCookbook-48.png

<web-app xmlns="http://caucho.com/ns/resin"
         xmlns:resin="urn:java:org.example.mypkg">

  <mypkg:MyDebugRewrite regexp="^/test/" target="/new/"/>

</web-app>

MyDebugFilterChain.java

package qa;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class TestFilterChain implements FilterChain {
  private String _target;

  public TestFilterChain(String target)
  {
    _target = target;
  }

  public void doFilter(ServletRequest request,
                       ServletResponse response)
    throws ServletException, IOException
  {
    HttpServletRequest req = (HttpServletRequest) request;

    PrintWriter out = response.getWriter();

    out.println("URI: " + req.getRequestURI());
    out.println("target: " + _target);
  }
}

MyDebugRewrite.java

package qa;
import javax.servlet.*;
import javax.servlet.http.*;
import com.caucho.rewrite.*;

public class Test extends AbstractTargetDispatchRule
{
  @Override
  public FilterChain createDispatch(DispatcherType type,
                                    String uri,
                                    String queryString,
                                    String target,
                                    FilterChain next)
  {
    return new TestFilterChain(target);
  }
}
Personal tools
TOOLBOX
LANGUAGES