Web Server: Custom URL Rewrite Rule Tutorial

From Resin 4.0 Wiki

(Difference between revisions)
Jump to: navigation, search
Line 1: Line 1:
 
{{Config}} {{WebServer}} {{Cookbook}}
 
{{Config}} {{WebServer}} {{Cookbook}}
 +
 +
=== WEB-INF/resin-web.xml ===
  
 
  <web-app xmlns="<nowiki>http://caucho.com/ns/resin</nowiki>"
 
  <web-app xmlns="<nowiki>http://caucho.com/ns/resin</nowiki>"
Line 8: Line 10:
 
  </web-app>
 
  </web-app>
  
=== MyDebugFilterChain.java ===
+
=== qa/MyDebugFilterChain.java ===
  
 
  package qa;
 
  package qa;

Revision as of 00:00, 25 January 2012

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

WEB-INF/resin-web.xml

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

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

</web-app>

qa/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