mirror of
https://github.com/jetty/jetty.project.git
synced 2025-03-04 12:59:30 +00:00
Merge branch 'master' of ssh://git.eclipse.org/gitroot/jetty/org.eclipse.jetty.project
This commit is contained in:
commit
04b37f02ed
@ -260,7 +260,6 @@ public class HttpParser implements Parser
|
||||
{
|
||||
_state=STATE_END;
|
||||
_handler.messageComplete(_contentPosition);
|
||||
returnBuffers();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -326,7 +325,6 @@ public class HttpParser implements Parser
|
||||
if (!isComplete() && !isIdle())
|
||||
throw new EofException();
|
||||
|
||||
returnBuffers();
|
||||
return -1;
|
||||
}
|
||||
length=_buffer.length();
|
||||
@ -440,7 +438,6 @@ public class HttpParser implements Parser
|
||||
_state=STATE_SEEKING_EOF;
|
||||
_handler.headerComplete();
|
||||
_handler.messageComplete(_contentPosition);
|
||||
returnBuffers();
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
@ -470,7 +467,6 @@ public class HttpParser implements Parser
|
||||
_state=STATE_SEEKING_EOF;
|
||||
_handler.headerComplete();
|
||||
_handler.messageComplete(_contentPosition);
|
||||
returnBuffers();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -634,7 +630,6 @@ public class HttpParser implements Parser
|
||||
_handler.headerComplete();
|
||||
_state=_persistent||(_responseStatus>=100&&_responseStatus<200)?STATE_END:STATE_SEEKING_EOF;
|
||||
_handler.messageComplete(_contentPosition);
|
||||
returnBuffers();
|
||||
return 1;
|
||||
|
||||
default:
|
||||
@ -840,7 +835,6 @@ public class HttpParser implements Parser
|
||||
{
|
||||
_state=_persistent?STATE_END:STATE_SEEKING_EOF;
|
||||
_handler.messageComplete(_contentPosition);
|
||||
returnBuffers();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -860,7 +854,6 @@ public class HttpParser implements Parser
|
||||
{
|
||||
_state=_persistent?STATE_END:STATE_SEEKING_EOF;
|
||||
_handler.messageComplete(_contentPosition);
|
||||
returnBuffers();
|
||||
}
|
||||
// TODO adjust the _buffer to keep unconsumed content
|
||||
return 1;
|
||||
@ -895,7 +888,6 @@ public class HttpParser implements Parser
|
||||
_eol=_buffer.get();
|
||||
_state=_persistent?STATE_END:STATE_SEEKING_EOF;
|
||||
_handler.messageComplete(_contentPosition);
|
||||
returnBuffers();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
@ -926,7 +918,6 @@ public class HttpParser implements Parser
|
||||
_eol=_buffer.get();
|
||||
_state=_persistent?STATE_END:STATE_SEEKING_EOF;
|
||||
_handler.messageComplete(_contentPosition);
|
||||
returnBuffers();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
|
@ -1,149 +0,0 @@
|
||||
package org.eclipse.jetty.rewrite.handler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler.Context;
|
||||
import org.eclipse.jetty.server.handler.ScopedHandler;
|
||||
import org.eclipse.jetty.util.component.AggregateLifeCycle;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** A handle that uses regular expressions to select the target.
|
||||
* <p>
|
||||
* This handler applies a list of regex to target name mappings to the URIs of requests.
|
||||
* If the regex matches the URI, then the mapped target name is used in the nested
|
||||
* call to {@link #doScope(String, Request, HttpServletRequest, HttpServletResponse)}.
|
||||
* <p>
|
||||
* This handler should be installed as the first handler in a Context. It can be configured
|
||||
* either with direct calls to {@link #addPatternTarget(String, String)} or by setting
|
||||
* the context init parameters "org.eclipse.jetty.rewrite.handler.REGEX_MAPPINGS" to a comma
|
||||
* separated list of strings in the format regex==target.
|
||||
*/
|
||||
public class RegexTargetHandler extends ScopedHandler
|
||||
{
|
||||
private final static Logger LOG = Log.getLogger(RegexTargetHandler.class);
|
||||
public final static String REGEX_MAPPINGS="org.eclipse.jetty.rewrite.handler.REGEX_MAPPINGS";
|
||||
static class RegexMapping
|
||||
{
|
||||
RegexMapping(String regex,String target)
|
||||
{
|
||||
_pattern=Pattern.compile(regex);
|
||||
_target=target;
|
||||
}
|
||||
final Pattern _pattern;
|
||||
final String _target;
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return _pattern+"=="+_target;
|
||||
}
|
||||
}
|
||||
|
||||
final private List<RegexTargetHandler.RegexMapping> _patterns = new CopyOnWriteArrayList<RegexTargetHandler.RegexMapping>();
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Add a pattern to target mapping.
|
||||
* @param pattern The regular expression pattern to match.
|
||||
* @param target The target (normally servlet name) to handle the request
|
||||
*/
|
||||
public void addPatternTarget(String pattern,String target)
|
||||
{
|
||||
_patterns.add(new RegexMapping(pattern,target));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
protected void doStart() throws Exception
|
||||
{
|
||||
super.doStart();
|
||||
|
||||
Context context = ContextHandler.getCurrentContext();
|
||||
if (context!=null)
|
||||
{
|
||||
String config=context.getInitParameter(REGEX_MAPPINGS);
|
||||
LOG.debug("{}={}",REGEX_MAPPINGS,config);
|
||||
String[] mappings=config.split("\\s*,\\s*");
|
||||
for (String mapping : mappings)
|
||||
{
|
||||
mapping=mapping.trim();
|
||||
String[] parts=mapping.split("\\s*==\\s*");
|
||||
if (parts.length==2)
|
||||
{
|
||||
String pattern=parts[0];
|
||||
String target=parts[1];
|
||||
addPatternTarget(pattern,target);
|
||||
}
|
||||
else
|
||||
LOG.warn("Bad regex mapping: "+mapping);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public void doScope(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
for (RegexTargetHandler.RegexMapping rm : _patterns)
|
||||
{
|
||||
Matcher m=rm._pattern.matcher(target);
|
||||
if (m.matches())
|
||||
{
|
||||
String new_target = rm._target;
|
||||
final String sp;
|
||||
final String pi;
|
||||
|
||||
if (m.groupCount()==1&&target.endsWith(m.group(1)))
|
||||
{
|
||||
pi=m.group(1);
|
||||
sp=target.substring(0,target.length()-pi.length());
|
||||
}
|
||||
else
|
||||
{
|
||||
sp=target;
|
||||
pi=null;
|
||||
}
|
||||
baseRequest.setServletPath(sp);
|
||||
baseRequest.setPathInfo(pi);
|
||||
baseRequest.setAttribute("org.eclipse.jetty.servlet.REGEX_PATH",target);
|
||||
super.nextScope(new_target,baseRequest,request,response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.nextScope(target,baseRequest,request,response);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
String path=(String)baseRequest.getAttribute("org.eclipse.jetty.servlet.REGEX_PATH");
|
||||
if (path==null)
|
||||
path=target;
|
||||
else
|
||||
baseRequest.setAttribute("org.eclipse.jetty.servlet.REGEX_PATH",null);
|
||||
|
||||
super.nextHandle(path,baseRequest,request,response);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void dump(Appendable out, String indent) throws IOException
|
||||
{
|
||||
AggregateLifeCycle.dumpObject(out,this);
|
||||
AggregateLifeCycle.dump(out,indent,_patterns,Collections.singletonList(getHandler()));
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -18,6 +18,7 @@ import java.util.regex.Matcher;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.http.HttpURI;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
|
||||
/**
|
||||
@ -88,15 +89,21 @@ public class RewriteRegexRule extends RegexRule implements Rule.ApplyURI
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void applyURI(Request request, String oldTarget, String newTarget) throws IOException
|
||||
{
|
||||
if (_query==null)
|
||||
{
|
||||
request.setRequestURI(newTarget);
|
||||
if (_query!=null)
|
||||
}
|
||||
else
|
||||
{
|
||||
String query=(String)request.getAttribute("org.eclipse.jetty.rewrite.handler.RewriteRegexRule.Q");
|
||||
if (_queryGroup||request.getQueryString()==null)
|
||||
|
||||
if (!_queryGroup && request.getQueryString()!=null)
|
||||
query=request.getQueryString()+"&"+query;
|
||||
HttpURI uri=new HttpURI(newTarget+"?"+query);
|
||||
request.setUri(uri);
|
||||
request.setRequestURI(newTarget);
|
||||
request.setQueryString(query);
|
||||
else
|
||||
request.setQueryString(request.getQueryString()+"&"+query);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,214 +0,0 @@
|
||||
// ========================================================================
|
||||
// Copyright (c) 2006-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 org.eclipse.jetty.rewrite.handler;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.Socket;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.Servlet;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequestWrapper;
|
||||
import javax.servlet.ServletResponseWrapper;
|
||||
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 junit.framework.Assert;
|
||||
|
||||
import org.eclipse.jetty.rewrite.handler.RegexTargetHandler;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class RegexTargetHandlerTest
|
||||
{
|
||||
private static Server __server = new Server(0);
|
||||
private static int __port;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() throws Exception
|
||||
{
|
||||
|
||||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
context.setContextPath("/");
|
||||
__server.setHandler(context);
|
||||
|
||||
// Serve some hello world servlets
|
||||
context.addServlet(DispatchServletServlet.class,"/dispatch/*");
|
||||
context.addServlet(new ServletHolder("HelloAll",new HelloServlet("Hello World")),"/*");
|
||||
context.addServlet(new ServletHolder("Italian",new HelloServlet("Buongiorno Mondo")),"/it/*");
|
||||
context.addServlet(new ServletHolder("French", new HelloServlet("Bonjour le Monde")),"/fr/*");
|
||||
|
||||
RegexTargetHandler regexHandler=new RegexTargetHandler();
|
||||
regexHandler.setHandler(context.getHandler());
|
||||
context.setHandler(regexHandler);
|
||||
|
||||
context.getInitParams().put(RegexTargetHandler.REGEX_MAPPINGS,
|
||||
" .*\\.fr==French, \n"+
|
||||
"/ciao(/.*)$==Italian");
|
||||
|
||||
__server.start();
|
||||
|
||||
__port=__server.getConnectors()[0].getLocalPort();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void shutdown() throws Exception
|
||||
{
|
||||
__server.stop();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNormal() throws Exception
|
||||
{
|
||||
String[] response=getResponse("/normal");
|
||||
assertEquals("HTTP/1.1 200 OK",response[0]);
|
||||
assertEquals("Hello World",response[1]);
|
||||
assertEquals("",response[2]);
|
||||
assertEquals("/normal",response[3]);
|
||||
|
||||
response=getResponse("/it/info");
|
||||
assertEquals("HTTP/1.1 200 OK",response[0]);
|
||||
assertEquals("Buongiorno Mondo",response[1]);
|
||||
assertEquals("/it",response[2]);
|
||||
assertEquals("/info",response[3]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFullMatch() throws Exception
|
||||
{
|
||||
String[] response=getResponse("/some/thing.fr");
|
||||
assertEquals("HTTP/1.1 200 OK",response[0]);
|
||||
assertEquals("Bonjour le Monde",response[1]);
|
||||
assertEquals("/some/thing.fr",response[2]);
|
||||
assertEquals("null",response[3]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCaptureMatch() throws Exception
|
||||
{
|
||||
String[] response=getResponse("/ciao/info");
|
||||
assertEquals("HTTP/1.1 200 OK",response[0]);
|
||||
assertEquals("Buongiorno Mondo",response[1]);
|
||||
assertEquals("/ciao",response[2]);
|
||||
assertEquals("/info",response[3]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDispatchFullMatch() throws Exception
|
||||
{
|
||||
String[] response=getResponse("/dispatch/xxx?forward=/some/thing.fr");
|
||||
assertEquals("HTTP/1.1 200 OK",response[0]);
|
||||
assertEquals("Bonjour le Monde",response[1]);
|
||||
assertEquals("/some/thing.fr",response[2]);
|
||||
assertEquals("null",response[3]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDispatchCaptureMatch() throws Exception
|
||||
{
|
||||
String[] response=getResponse("/dispatch/xxx?forward=/ciao/info");
|
||||
assertEquals("HTTP/1.1 200 OK",response[0]);
|
||||
assertEquals("Buongiorno Mondo",response[1]);
|
||||
assertEquals("/ciao",response[2]);
|
||||
assertEquals("/info",response[3]);
|
||||
}
|
||||
|
||||
|
||||
private String[] getResponse(String uri) throws Exception
|
||||
{
|
||||
Socket socket = new Socket("127.0.0.1",__port);
|
||||
|
||||
PrintWriter out = new PrintWriter(socket.getOutputStream());
|
||||
out.print("GET "+uri+" HTTP/1.0\r\n\r\n");
|
||||
out.flush();
|
||||
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||
|
||||
String[] response=new String[4];
|
||||
response[0]=in.readLine();
|
||||
//System.err.println(response[0]);
|
||||
|
||||
String line=in.readLine();
|
||||
while(line.length()>0)
|
||||
line=in.readLine();
|
||||
|
||||
response[1]=in.readLine();
|
||||
//System.err.println(response[1]);
|
||||
response[2]=in.readLine();
|
||||
//System.err.println(response[2]);
|
||||
response[3]=in.readLine();
|
||||
//System.err.println(response[3]);
|
||||
|
||||
socket.close();
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
public static class HelloServlet extends HttpServlet implements Servlet
|
||||
{
|
||||
final String _hello;
|
||||
|
||||
public HelloServlet(String hello)
|
||||
{
|
||||
_hello=hello;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
response.setStatus(200);
|
||||
response.getWriter().println(_hello);
|
||||
response.getWriter().println(request.getServletPath());
|
||||
response.getWriter().println(request.getPathInfo());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class DispatchServletServlet extends HttpServlet implements Servlet
|
||||
{
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
RequestDispatcher dispatcher = null;
|
||||
|
||||
if(request.getParameter("include")!=null)
|
||||
{
|
||||
dispatcher = getServletContext().getRequestDispatcher(request.getParameter("include"));
|
||||
dispatcher.include(new HttpServletRequestWrapper(request), new HttpServletResponseWrapper(response));
|
||||
}
|
||||
else if(request.getParameter("forward")!=null)
|
||||
{
|
||||
dispatcher = getServletContext().getRequestDispatcher(request.getParameter("forward"));
|
||||
dispatcher.forward(new HttpServletRequestWrapper(request), new HttpServletResponseWrapper(response));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -14,6 +14,10 @@ package org.eclipse.jetty.rewrite.handler;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.jetty.http.HttpURI;
|
||||
import org.eclipse.jetty.util.MultiMap;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.util.UrlEncoded;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -23,21 +27,21 @@ public class RewriteRegexRuleTest extends AbstractRuleTestCase
|
||||
{
|
||||
private String[][] _tests=
|
||||
{
|
||||
{"/foo/bar",null,".*","/replace","/replace",null},
|
||||
{"/foo/bar","n=v",".*","/replace","/replace","n=v"},
|
||||
{"/foo/bar",null,"/xxx.*","/replace",null,null},
|
||||
{"/foo/bar",null,"/(.*)/(.*)","/$2/$1/xxx","/bar/foo/xxx",null},
|
||||
{"/foo/bar",null,"/(.*)/(.*)","/test?p2=$2&p1=$1","/test","p2=bar&p1=foo"},
|
||||
{"/foo/bar","n=v","/(.*)/(.*)","/test?p2=$2&p1=$1","/test","n=v&p2=bar&p1=foo"},
|
||||
{"/foo/bar",null,"/(.*)/(.*)","/foo/bar?p2=$2&p1=$1","/foo/bar","p2=bar&p1=foo"},
|
||||
{"/foo/bar","n=v","/(.*)/(.*)","/foo/bar?p2=$2&p1=$1","/foo/bar","n=v&p2=bar&p1=foo"},
|
||||
{"/foo/bar",null,"/(foo)/(.*)(bar)","/$3/$1/xxx$2","/bar/foo/xxx",null},
|
||||
{"/foo/$bar",null,".*","/$replace","/$replace",null},
|
||||
{"/foo/$bar",null,"/foo/(.*)","/$1/replace","/$bar/replace",null},
|
||||
{"/foo/bar/info",null,"/foo/(NotHere)?([^/]*)/(.*)","/$3/other?p1=$2","/info/other","p1=bar"},
|
||||
{"/foo/bar/info",null,"/foo/(NotHere)?([^/]*)/(.*)","/$3/other?p1=$2&$Q","/info/other","p1=bar&"},
|
||||
{"/foo/bar/info","n=v","/foo/(NotHere)?([^/]*)/(.*)","/$3/other?p1=$2&$Q","/info/other","p1=bar&n=v"},
|
||||
{"/foo/bar/info","n=v","/foo/(NotHere)?([^/]*)/(.*)","/$3/other?p1=$2","/info/other","n=v&p1=bar"},
|
||||
{"/foo0/bar",null,".*","/replace","/replace",null},
|
||||
{"/foo1/bar","n=v",".*","/replace","/replace","n=v"},
|
||||
{"/foo2/bar",null,"/xxx.*","/replace",null,null},
|
||||
{"/foo3/bar",null,"/(.*)/(.*)","/$2/$1/xxx","/bar/foo3/xxx",null},
|
||||
{"/foo4/bar",null,"/(.*)/(.*)","/test?p2=$2&p1=$1","/test","p2=bar&p1=foo4"},
|
||||
{"/foo5/bar","n=v","/(.*)/(.*)","/test?p2=$2&p1=$1","/test","n=v&p2=bar&p1=foo5"},
|
||||
{"/foo6/bar",null,"/(.*)/(.*)","/foo6/bar?p2=$2&p1=$1","/foo6/bar","p2=bar&p1=foo6"},
|
||||
{"/foo7/bar","n=v","/(.*)/(.*)","/foo7/bar?p2=$2&p1=$1","/foo7/bar","n=v&p2=bar&p1=foo7"},
|
||||
{"/foo8/bar",null,"/(foo8)/(.*)(bar)","/$3/$1/xxx$2","/bar/foo8/xxx",null},
|
||||
{"/foo9/$bar",null,".*","/$replace","/$replace",null},
|
||||
{"/fooA/$bar",null,"/fooA/(.*)","/$1/replace","/$bar/replace",null},
|
||||
{"/fooB/bar/info",null,"/fooB/(NotHere)?([^/]*)/(.*)","/$3/other?p1=$2","/info/other","p1=bar"},
|
||||
{"/fooC/bar/info",null,"/fooC/(NotHere)?([^/]*)/(.*)","/$3/other?p1=$2&$Q","/info/other","p1=bar&"},
|
||||
{"/fooD/bar/info","n=v","/fooD/(NotHere)?([^/]*)/(.*)","/$3/other?p1=$2&$Q","/info/other","p1=bar&n=v"},
|
||||
{"/fooE/bar/info","n=v","/fooE/(NotHere)?([^/]*)/(.*)","/$3/other?p1=$2","/info/other","n=v&p1=bar"},
|
||||
};
|
||||
private RewriteRegexRule _rule;
|
||||
|
||||
@ -53,21 +57,36 @@ public class RewriteRegexRuleTest extends AbstractRuleTestCase
|
||||
{
|
||||
for (String[] test : _tests)
|
||||
{
|
||||
reset();
|
||||
_request.setRequestURI(null);
|
||||
|
||||
String t=test[0]+"?"+test[1]+">"+test[2]+"|"+test[3];
|
||||
_rule.setRegex(test[2]);
|
||||
_rule.setReplacement(test[3]);
|
||||
|
||||
_request.setRequestURI(test[0]);
|
||||
_request.setQueryString(test[1]);
|
||||
_request.getAttributes().clearAttributes();
|
||||
_request.setUri(new HttpURI(test[0]+(test[1]==null?"":("?"+test[1]))));
|
||||
_request.getRequestURI();
|
||||
|
||||
|
||||
String result = _rule.matchAndApply(test[0], _request, _response);
|
||||
assertEquals(t, test[4], result);
|
||||
_rule.applyURI(_request,test[0],result);
|
||||
|
||||
if (result!=null)
|
||||
{
|
||||
assertEquals(t,test[4], _request.getRequestURI());
|
||||
assertEquals(t,test[5], _request.getQueryString());
|
||||
}
|
||||
|
||||
if (test[5]!=null)
|
||||
{
|
||||
MultiMap<String> params=new MultiMap<String>();
|
||||
UrlEncoded.decodeTo(test[5],params,StringUtil.__UTF8);
|
||||
|
||||
for (String n:params.keySet())
|
||||
assertEquals(params.getString(n),_request.getParameter(n));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -78,6 +97,7 @@ public class RewriteRegexRuleTest extends AbstractRuleTestCase
|
||||
container.addRule(_rule);
|
||||
for (String[] test : _tests)
|
||||
{
|
||||
reset();
|
||||
String t=test[0]+"?"+test[1]+">"+test[2]+"|"+test[3];
|
||||
_rule.setRegex(test[2]);
|
||||
_rule.setReplacement(test[3]);
|
||||
|
@ -1233,7 +1233,7 @@ public class ServletHandler extends ScopedHandler
|
||||
{
|
||||
if(LOG.isDebugEnabled())
|
||||
LOG.debug("Not Found "+request.getRequestURI());
|
||||
response.sendError(HttpServletResponse.SC_NOT_FOUND);
|
||||
//Override to send an error back, eg with: response.sendError(HttpServletResponse.SC_NOT_FOUND);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -287,7 +287,25 @@ public class MultiMap<K> implements ConcurrentMap<K,Object>, Serializable
|
||||
*/
|
||||
public Map<K,String[]> toStringArrayMap()
|
||||
{
|
||||
HashMap<K,String[]> map = new HashMap<K,String[]>(_map.size()*3/2);
|
||||
HashMap<K,String[]> map = new HashMap<K,String[]>(_map.size()*3/2)
|
||||
{
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder b=new StringBuilder();
|
||||
b.append('{');
|
||||
for (K k:keySet())
|
||||
{
|
||||
if(b.length()>1)
|
||||
b.append(',');
|
||||
b.append(k);
|
||||
b.append('=');
|
||||
b.append(Arrays.asList(get(k)));
|
||||
}
|
||||
|
||||
b.append('}');
|
||||
return b.toString();
|
||||
}
|
||||
};
|
||||
|
||||
for(Map.Entry<K,Object> entry: _map.entrySet())
|
||||
{
|
||||
|
@ -305,7 +305,8 @@ public class WebInfConfiguration extends AbstractConfiguration
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
LOG.warn("tmpdir",e); System.exit(1);
|
||||
tmpDir = null;
|
||||
throw new IllegalStateException("Cannot create tmp dir in "+System.getProperty("java.io.tmpdir")+ " for context "+context,e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user