[BUG 291589]

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@978 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Athena Yao 2009-10-07 12:06:36 +00:00
parent 35dfcc2d4b
commit 17b94b6dc0
8 changed files with 212 additions and 42 deletions

View File

@ -11,6 +11,7 @@ jetty-7.0.1-SNAPSHOT
+ JETTY-1114 unsynchronised WebAppClassloader.getResource(String)
+ Fixed XSS issue in CookieDump demo servlet.
+ 291340 Race condition in onException() notifications
+ 291589 Update jetty-rewrite demo
jetty-7.0.0
+ 289958 StatisticsServlet incorrectly adds StatisticsHandler

View File

@ -31,46 +31,86 @@
<Call name="addRule">
<Arg>
<New class="org.eclipse.jetty.rewrite.handler.HeaderPatternRule">
<Set name="pattern">/favicon.ico</Set>
<Set name="name">Cache-Control</Set>
<Set name="value">Max-Age=3600,public</Set>
<Set name="terminating">true</Set>
<Set name="pattern">/favicon.ico</Set>
<Set name="name">Cache-Control</Set>
<Set name="value">Max-Age=3600,public</Set>
<Set name="terminating">true</Set>
</New>
</Arg>
</Call>
<!-- use legacy API for some rewrites -->
<Call name="addRewriteRule">
<Arg>/some/old/context/*</Arg>
<Arg>/test/dump/newcontext</Arg>
</Call>
<Call name="addRewriteRule">
<Arg>/test/dump/rewrite/*</Arg>
<Arg>/test/dump/rewritten</Arg>
</Call>
<Call name="addRewriteRule">
<Arg>/test/dump/rewrite/protect/*</Arg>
<Arg/>
</Call>
<Call name="addRewriteRule">
<Arg>/test/*</Arg>
<Arg/>
</Call>
<Call name="addRewriteRule">
<Arg>/*</Arg>
<Arg>/test</Arg>
<!-- redirect from the welcome page to a specific page -->
<Call name="addRule">
<Arg>
<New class="org.eclipse.jetty.rewrite.handler.RewritePatternRule">
<Set name="pattern">/rewrite/</Set>
<Set name="replacement">/rewrite/info.html</Set>
</New>
</Arg>
</Call>
<!-- add a regex rule -->
<!-- replace the entire request URI -->
<Call name="addRule">
<Arg>
<New class="org.eclipse.jetty.rewrite.handler.RewritePatternRule">
<Set name="pattern">/some/old/context</Set>
<Set name="replacement">/rewritten/newcontext</Set>
</New>
</Arg>
</Call>
<!-- replace the beginning of the request URI -->
<Call name="addRule">
<Arg>
<New class="org.eclipse.jetty.rewrite.handler.RewritePatternRule">
<Set name="pattern">/rewrite/for/*</Set>
<Set name="replacement">/rewritten/</Set>
</New>
</Arg>
</Call>
<!-- reverse the order of the path sections -->
<Call name="addRule">
<Arg>
<New class="org.eclipse.jetty.rewrite.handler.RewriteRegexRule">
<Set name="regex">/test/dump/regex/([^/]*)/(.*)</Set>
<Set name="replacement">/test/dump/$2/$1</Set>
<Set name="regex">(.*?)/reverse/([^/]*)/(.*)</Set>
<Set name="replacement">$1/reverse/$3/$2</Set>
</New>
</Arg>
</Call>
<!-- add a cookie to each path visited -->
<Call name="addRule">
<Arg>
<New class="org.eclipse.jetty.rewrite.handler.CookiePatternRule">
<Set name="pattern">/*</Set>
<Set name="name">visited</Set>
<Set name="value">yes</Set>
</New>
</Arg>
</Call>
<!-- actual redirect, instead of internal rewrite -->
<Call name="addRule">
<Arg>
<New class="org.eclipse.jetty.rewrite.handler.RedirectPatternRule">
<Set name="pattern">/redirect/*</Set>
<Set name="location">/redirected</Set>
</New>
</Arg>
</Call>
<!-- add a response rule -->
<Call name="addRule">
<Arg>
<New class="org.eclipse.jetty.rewrite.handler.ResponsePatternRule">
<Set name="pattern">/400Error</Set>
<Set name="code">400</Set>
<Set name="reason">ResponsePatternRule Demo</Set>
</New>
</Arg>
</Call>
</New>
</Set>

View File

@ -0,0 +1,76 @@
// ========================================================================
// Copyright (c) 2009 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package com.acme;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import org.eclipse.jetty.util.log.Log;
/* ------------------------------------------------------------ */
/** Test Servlet Rewrite
*
*
*/
public class RewriteServlet extends HttpServlet
{
/* ------------------------------------------------------------ */
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
doGet(req, res);
}
/* ------------------------------------------------------------ */
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
ServletOutputStream out = res.getOutputStream();
out.println("<html><body><table>");
out.println("<tr><th>Original request URI: </th><td>" + req.getAttribute("requestedPath") + "</td></tr>");
out.println("<tr><th>Rewritten request URI: </th><td>" + req.getRequestURI() + "</td></tr>");
Cookie cookie = null;
for(Cookie c: req.getCookies())
{
if (c.getName().equals("visited"))
{
cookie = c;
break;
}
}
if (cookie!=null)
out.println("<tr><th>Previously visited: </th></td><td>" + cookie.getValue()+"</td></tr>");
out.println("</table></body></html>");
}
/* ------------------------------------------------------------ */
@Override
public String getServletInfo()
{
return "Rewrite sServlet";
}
}

View File

@ -177,6 +177,18 @@
</servlet-mapping>
<servlet>
<servlet-name>Rewrite</servlet-name>
<servlet-class>com.acme.RewriteServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Rewrite</servlet-name>
<url-pattern>/rewritten/*</url-pattern>
<url-pattern>/redirected/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>SecureMode</servlet-name>
<servlet-class>com.acme.SecureModeServlet</servlet-class>

View File

@ -29,6 +29,7 @@ This is a test context that serves:
<li>a <a href="session/">Session Dump Servlet</a></li>
<li>a <a href="cookie/">Cookie Dump Servlet</a></li>
<li>a <a href="dispatch">Dispatcher Servlet</a></li>
<li>a <a href="rewrite/">Request Rewrite Servlet</a></li>
<li>a <a href="jetty/">Transparent Proxy</a> (to jetty.mortbay.org)</li>
<li>a <a href="cgi-bin/hello.sh">CGI script</a> (unix only)</li>
<li>a <a href="auth.html">Authentication</a></li>

View File

@ -1,14 +0,0 @@
<h1>Links to test the RewriteHandler</h1>
To run these tests, you should start Jetty with: <pre>
java -jar start.jar etc/jetty.xml etc/jetty-rewrite.xml
</pre>
<ul>
<li><a href="/some/old/context/info">Rewrite "/some/old/context/info" to "/test/dump/newcontext/info"</a></li>
<li><a href="/dump/info">Prepend "/test" to "/dump/info"</a></li>
<li><a href="/test/dump/rewrite/info">Rewrite "/test/dump/rewrite/info"</a></li>
<li><a href="/test/dump/rewrite/protect/info">Protect "/test/dump/rewrite/protect/*"</a></li>
<li><a href="/test/dump/regex/bar/foo">Rewrite regex "bar/foo" to "foo/bar"</a></li>
<li><a href="/dump/regex/bar/foo">Chain prepend and regex rules</a></li>
</ul>

View File

@ -0,0 +1,12 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>RewriteHandler</title>
</head>
<body>
<h1>Rewrite not enabled</h1>
<p>The rewrite handler is currently not enabled. To enable this demo, start up Jetty with:</p>
<code>java -jar start.jar OPTIONS=default,rewrite etc/jetty.xml etc/jetty-rewrite.xml</code>
</body>
</html>

View File

@ -0,0 +1,42 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>RewriteHandler</title>
</head>
<body>
<h1>Links to test the RewriteHandler</h1>
<p>All examples below were configured using <tt>etc/jetty-rewrite.xml</tt>.</p>
<h2>Internal URI rewrite</h2>
<dl>
<dt><a href="/some/old/context">Rewrite "/some/old/context" to "/rewritten/newcontext"</a></dt>
<dd>This demo shows how the entire request URI can be internally rewritten to point to another context, using simple text matching</dd>
<dt><a href="/rewrite/for/beginning">Rewrite "/rewrite/for/beginning" to "/rewritten/beginning"</a></dt>
<dd>This demo shows how the beginning of the request URI can be rewritten, while keeping the ending section</dd>
<dt><a href="/rewritten/reverse/bar/foo">Rewrite "bar/foo" to "foo/bar" using regex</a></dt>
<dd>This demo shows how sections of the request URI can be rearranged. It uses regex to parse out each section, and then return them in reverse order</dd>
<dt><a href="/rewrite/for/reverse/bar/foo">Rewrite the beginning, and reverse the path sections</a></dt>
<dd>This demo shows how rewrite patterns can be chained.</dd>
<dt><a href="/dump/reverse/bar/foo">Rewrite "bar/foo" to "foo/bar", full dump view</a></dt>
<dd>This demo rewrites "bar/foo" to "foo/bar" the same as earlier, but shows a full dump of the request</dd>
<h2>Redirect</h2>
<dt><a href="/redirect/this">Redirect "/redirect/this" to "/redirected/this"</a></dt>
<dd>This demo redirects the request in a manner visible to the user agent, instead of doing an internal rewrite.</dd>
<h2>Cookie</h2>
<dt>All pages</dt>
<dd>This demo rule sets a "visited" cookie for each page you visit. The second time you go to any of the links above, you will see an additional line, "Previously visited: yes".</dd>
<h2>Response Code</h2>
<dt><a href="/400Error">Return a 400 error status</a></dt>
<dd>This demo shows how to modify the response code of a page to an error, based on its URL</dd>
</dl>
</body>
</html>