Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jetty-servlets/src')
-rw-r--r--jetty-servlets/src/main/java/org/eclipse/jetty/servlets/DoSFilter.java5
-rw-r--r--jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java415
-rw-r--r--jetty-servlets/src/main/java/org/eclipse/jetty/servlets/ProxyServlet.java4
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java14
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AsyncProxyServer.java6
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/CloseableDoSFilterTest.java1
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/CrossOriginFilterTest.java33
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/DoSFilterJMXTest.java2
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/DoSFilterTest.java3
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/IncludableGzipFilterTest.java2
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java26
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/PutFilterTest.java4
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/QoSFilterTest.java8
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/TransparentProxyTest.java140
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java4
15 files changed, 277 insertions, 390 deletions
diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/DoSFilter.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/DoSFilter.java
index ebc99d52cc..d2e2b02c22 100644
--- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/DoSFilter.java
+++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/DoSFilter.java
@@ -346,7 +346,6 @@ public class DoSFilter implements Filter
}
// We are over the limit.
- LOG.warn("DOS ALERT: ip=" + request.getRemoteAddr() + ",session=" + request.getRequestedSessionId() + ",user=" + request.getUserPrincipal());
// So either reject it, delay it or throttle it
long delayMs = getDelayMs();
@@ -356,6 +355,7 @@ public class DoSFilter implements Filter
case -1:
{
// Reject this request
+ LOG.warn("DOS ALERT: Request rejected ip=" + request.getRemoteAddr() + ",session=" + request.getRequestedSessionId() + ",user=" + request.getUserPrincipal());
if (insertHeaders)
response.addHeader("DoSFilter", "unavailable");
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
@@ -364,12 +364,14 @@ public class DoSFilter implements Filter
case 0:
{
// fall through to throttle code
+ LOG.warn("DOS ALERT: Request throttled ip=" + request.getRemoteAddr() + ",session=" + request.getRequestedSessionId() + ",user=" + request.getUserPrincipal());
request.setAttribute(__TRACKER, tracker);
break;
}
default:
{
// insert a delay before throttling the request
+ LOG.warn("DOS ALERT: Request delayed="+delayMs+"ms ip=" + request.getRemoteAddr() + ",session=" + request.getRequestedSessionId() + ",user=" + request.getUserPrincipal());
if (insertHeaders)
response.addHeader("DoSFilter", "delayed");
Continuation continuation = ContinuationSupport.getContinuation(request);
@@ -713,6 +715,7 @@ public class DoSFilter implements Filter
public void destroy()
{
+ LOG.debug("Destroy {}",this);
_running = false;
_timerThread.interrupt();
_requestTimeoutQ.cancelAll();
diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java
index c872e936fa..976fc5aa6d 100644
--- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java
+++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java
@@ -18,18 +18,17 @@
package org.eclipse.jetty.servlets;
+import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
-import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
-import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
@@ -41,18 +40,21 @@ import java.util.Map;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
+import javax.servlet.MultipartConfigElement;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.http.Part;
-import org.eclipse.jetty.util.B64Code;
+
+import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.LazyList;
import org.eclipse.jetty.util.MultiMap;
+import org.eclipse.jetty.util.MultiPartInputStream;
import org.eclipse.jetty.util.QuotedStringTokenizer;
-import org.eclipse.jetty.util.ReadLineInputStream;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@@ -76,16 +78,22 @@ import org.eclipse.jetty.util.log.Logger;
* The init parameter deleteFiles controls if uploaded files are automatically deleted after the request
* completes.
*
+ * Use init parameter "maxFileSize" to set the max size file that can be uploaded.
+ *
+ * Use init parameter "maxRequestSize" to limit the size of the multipart request.
+ *
*/
public class MultiPartFilter implements Filter
{
private static final Logger LOG = Log.getLogger(MultiPartFilter.class);
public final static String CONTENT_TYPE_SUFFIX=".org.eclipse.jetty.servlet.contentType";
- private final static String FILES ="org.eclipse.jetty.servlet.MultiPartFilter.files";
+ private final static String MULTIPART = "org.eclipse.jetty.servlet.MultiPartFile.multiPartInputStream";
private File tempdir;
private boolean _deleteFiles;
private ServletContext _context;
private int _fileOutputBuffer = 0;
+ private long _maxFileSize = -1L;
+ private long _maxRequestSize = -1L;
private int _maxFormKeys = Integer.getInteger("org.eclipse.jetty.server.Request.maxFormKeys",1000).intValue();
/* ------------------------------------------------------------------------------- */
@@ -99,6 +107,13 @@ public class MultiPartFilter implements Filter
String fileOutputBuffer = filterConfig.getInitParameter("fileOutputBuffer");
if(fileOutputBuffer!=null)
_fileOutputBuffer = Integer.parseInt(fileOutputBuffer);
+ String maxFileSize = filterConfig.getInitParameter("maxFileSize");
+ if (maxFileSize != null)
+ _maxFileSize = Long.parseLong(maxFileSize.trim());
+ String maxRequestSize = filterConfig.getInitParameter("maxRequestSize");
+ if (maxRequestSize != null)
+ _maxRequestSize = Long.parseLong(maxRequestSize.trim());
+
_context=filterConfig.getServletContext();
String mfks = filterConfig.getInitParameter("maxFormKeys");
if (mfks!=null)
@@ -120,27 +135,14 @@ public class MultiPartFilter implements Filter
return;
}
- InputStream in = new ReadLineInputStream(request.getInputStream());
+ InputStream in = new BufferedInputStream(request.getInputStream());
String content_type=srequest.getContentType();
-
- // TODO - handle encodings
- String contentTypeBoundary = "";
- int bstart = content_type.indexOf("boundary=");
- if (bstart >= 0)
- {
- int bend = content_type.indexOf(";", bstart);
- bend = (bend < 0? content_type.length(): bend);
- contentTypeBoundary = QuotedStringTokenizer.unquote(value(content_type.substring(bstart,bend)).trim());
- }
-
- String boundary="--"+contentTypeBoundary;
-
- byte[] byteBoundary=(boundary+"--").getBytes(StringUtil.__ISO_8859_1);
- MultiMap params = new MultiMap();
- for (Iterator i = request.getParameterMap().entrySet().iterator();i.hasNext();)
+ //Get current parameters so we can merge into them
+ MultiMap<String> params = new MultiMap<String>();
+ for (Iterator<Map.Entry<String,String[]>> i = request.getParameterMap().entrySet().iterator();i.hasNext();)
{
- Map.Entry entry=(Map.Entry)i.next();
+ Map.Entry<String,String[]> entry=i.next();
Object value=entry.getValue();
if (value instanceof String[])
params.addValues(entry.getKey(),(String[])value);
@@ -148,255 +150,42 @@ public class MultiPartFilter implements Filter
params.add(entry.getKey(),value);
}
+ MultipartConfigElement config = new MultipartConfigElement(tempdir.getCanonicalPath(), _maxFileSize, _maxRequestSize, _fileOutputBuffer);
+ MultiPartInputStream mpis = new MultiPartInputStream(in, content_type, config, tempdir);
+ mpis.setDeleteOnExit(_deleteFiles);
+ request.setAttribute(MULTIPART, mpis);
+
try
{
- // Get first boundary
- String line=((ReadLineInputStream)in).readLine();
-
- if (line == null)
- throw new IOException("Missing content for multipart request");
-
- line = line.trim();
- boolean badFormatLogged = false;
- while (line != null && !line.equals(boundary))
+ Collection<Part> parts = mpis.getParts();
+ if (parts != null)
{
- if (!badFormatLogged)
- {
- LOG.warn("Badly formatted multipart request");
- badFormatLogged = true;
- }
- line=((ReadLineInputStream)in).readLine();
- line=(line==null?line:line.trim());
- }
-
- if (line == null)
- throw new IOException("Missing initial multi part boundary");
-
- // Read each part
- boolean lastPart=false;
- String content_disposition=null;
- String content_transfer_encoding=null;
-
-
- outer:while(!lastPart && params.size()<_maxFormKeys)
- {
- String type_content=null;
-
- while(true)
- {
- // read a line
- line=((ReadLineInputStream)in).readLine();
-
- //No more input
- if (line==null)
- break outer;
-
- // If blank line, end of part headers
- if("".equals(line))
- break;
-
- // place part header key and value in map
- int c=line.indexOf(':',0);
- if(c>0)
- {
- String key=line.substring(0,c).trim().toLowerCase(Locale.ENGLISH);
- String value=line.substring(c+1,line.length()).trim();
- if(key.equals("content-disposition"))
- content_disposition=value;
- else if(key.equals("content-transfer-encoding"))
- content_transfer_encoding=value;
- else if (key.equals("content-type"))
- type_content = value;
- }
- }
- // Extract content-disposition
- boolean form_data=false;
- if(content_disposition==null)
- {
- throw new IOException("Missing content-disposition");
- }
-
- LOG.debug("Content-Disposition: {}", content_disposition);
- QuotedStringTokenizer tok=new QuotedStringTokenizer(content_disposition,";",false,true);
- String name=null;
- String filename=null;
- while(tok.hasMoreTokens())
- {
- String t=tok.nextToken().trim();
- String tl=t.toLowerCase();
- if(t.startsWith("form-data"))
- form_data=true;
- else if(tl.startsWith("name="))
- name=value(t);
- else if(tl.startsWith("filename="))
- filename=filenameValue(t);
- }
-
- // Check disposition
- if(!form_data)
- {
- continue;
- }
- //It is valid for reset and submit buttons to have an empty name.
- //If no name is supplied, the browser skips sending the info for that field.
- //However, if you supply the empty string as the name, the browser sends the
- //field, with name as the empty string. So, only continue this loop if we
- //have not yet seen a name field.
- if(name==null)
- {
- continue;
- }
-
- OutputStream out=null;
- File file=null;
- try
+ Iterator<Part> itor = parts.iterator();
+ while (itor.hasNext() && params.size() < _maxFormKeys)
{
- if (filename!=null && filename.length()>0)
+ Part p = itor.next();
+ MultiPartInputStream.MultiPart mp = (MultiPartInputStream.MultiPart)p;
+ if (mp.getFile() != null)
{
- LOG.debug("filename = \"{}\"", filename);
- file = File.createTempFile("MultiPart", "", tempdir);
- out = new FileOutputStream(file);
- if(_fileOutputBuffer>0)
- out = new BufferedOutputStream(out, _fileOutputBuffer);
- request.setAttribute(name,file);
- params.add(name, filename);
- if (type_content != null)
- params.add(name+CONTENT_TYPE_SUFFIX, type_content);
-
- if (_deleteFiles)
+ request.setAttribute(mp.getName(),mp.getFile());
+ if (mp.getContentDispositionFilename() != null)
{
- file.deleteOnExit();
- ArrayList files = (ArrayList)request.getAttribute(FILES);
- if (files==null)
- {
- files=new ArrayList();
- request.setAttribute(FILES,files);
- }
- files.add(file);
- }
+ params.add(mp.getName(), mp.getContentDispositionFilename());
+ if (mp.getContentType() != null)
+ params.add(mp.getName()+CONTENT_TYPE_SUFFIX, mp.getContentType());
+ }
}
else
{
- out=new ByteArrayOutputStream();
- }
-
-
- if ("base64".equalsIgnoreCase(content_transfer_encoding))
- {
- in = new Base64InputStream(in);
- }
- else if ("quoted-printable".equalsIgnoreCase(content_transfer_encoding))
- {
- in = new FilterInputStream(in)
- {
- @Override
- public int read() throws IOException
- {
- int c = in.read();
- if (c >= 0 && c == '=')
- {
- int hi = in.read();
- int lo = in.read();
- if (hi < 0 || lo < 0)
- {
- throw new IOException("Unexpected end to quoted-printable byte");
- }
- char[] chars = new char[] { (char)hi, (char)lo };
- c = Integer.parseInt(new String(chars),16);
- }
- return c;
- }
- };
- }
-
- int state=-2;
- int c;
- boolean cr=false;
- boolean lf=false;
-
- // loop for all lines`
- while(true)
- {
- int b=0;
- while((c=(state!=-2)?state:in.read())!=-1)
- {
- state=-2;
- // look for CR and/or LF
- if(c==13||c==10)
- {
- if(c==13)
- {
- in.mark(1);
- int tmp=in.read();
- if (tmp!=10)
- in.reset();
- else
- state=tmp;
- }
- break;
- }
- // look for boundary
- if(b>=0&&b<byteBoundary.length&&c==byteBoundary[b])
- b++;
- else
- {
- // this is not a boundary
- if(cr)
- out.write(13);
- if(lf)
- out.write(10);
- cr=lf=false;
- if(b>0)
- out.write(byteBoundary,0,b);
- b=-1;
- out.write(c);
- }
- }
- // check partial boundary
- if((b>0&&b<byteBoundary.length-2)||(b==byteBoundary.length-1))
- {
- if(cr)
- out.write(13);
- if(lf)
- out.write(10);
- cr=lf=false;
- out.write(byteBoundary,0,b);
- b=-1;
- }
- // boundary match
- if(b>0||c==-1)
- {
- if(b==byteBoundary.length)
- lastPart=true;
- if(state==10)
- state=-2;
- break;
- }
- // handle CR LF
- if(cr)
- out.write(13);
- if(lf)
- out.write(10);
- cr=(c==13);
- lf=(c==10||state==10);
- if(state==10)
- state=-2;
+ ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ IO.copy(p.getInputStream(), bytes);
+ params.add(p.getName(), bytes.toByteArray());
+ if (p.getContentType() != null)
+ params.add(p.getName()+CONTENT_TYPE_SUFFIX, p.getContentType());
}
}
- finally
- {
- out.close();
- }
-
- if (file==null)
- {
- byte[] bytes = ((ByteArrayOutputStream)out).toByteArray();
- params.add(name,bytes);
- if (type_content != null)
- params.add(name+CONTENT_TYPE_SUFFIX, type_content);
- }
}
-
+
// handle request
chain.doFilter(new Wrapper(srequest,params),response);
}
@@ -405,64 +194,30 @@ public class MultiPartFilter implements Filter
deleteFiles(request);
}
}
-
+
+
+ /* ------------------------------------------------------------ */
private void deleteFiles(ServletRequest request)
{
- ArrayList files = (ArrayList)request.getAttribute(FILES);
- if (files!=null)
+ if (!_deleteFiles)
+ return;
+
+ MultiPartInputStream mpis = (MultiPartInputStream)request.getAttribute(MULTIPART);
+ if (mpis != null)
{
- Iterator iter = files.iterator();
- while (iter.hasNext())
+ try
{
- File file=(File)iter.next();
- try
- {
- file.delete();
- }
- catch(Exception e)
- {
- _context.log("failed to delete "+file,e);
- }
+ mpis.deleteParts();
+ }
+ catch (Exception e)
+ {
+ _context.log("Error deleting multipart tmp files", e);
}
}
+ request.removeAttribute(MULTIPART);
}
- /* ------------------------------------------------------------ */
- private String value(String nameEqualsValue)
- {
- int idx = nameEqualsValue.indexOf('=');
- String value = nameEqualsValue.substring(idx+1).trim();
- return QuotedStringTokenizer.unquoteOnly(value);
- }
-
-
- /* ------------------------------------------------------------ */
- private String filenameValue(String nameEqualsValue)
- {
- int idx = nameEqualsValue.indexOf('=');
- String value = nameEqualsValue.substring(idx+1).trim();
-
- if (value.matches(".??[a-z,A-Z]\\:\\\\[^\\\\].*"))
- {
- //incorrectly escaped IE filenames that have the whole path
- //we just strip any leading & trailing quotes and leave it as is
- char first=value.charAt(0);
- if (first=='"' || first=='\'')
- value=value.substring(1);
- char last=value.charAt(value.length()-1);
- if (last=='"' || last=='\'')
- value = value.substring(0,value.length()-1);
-
- return value;
- }
- else
- //unquote the string, but allow any backslashes that don't
- //form a valid escape sequence to remain as many browsers
- //even on *nix systems will not escape a filename containing
- //backslashes
- return QuotedStringTokenizer.unquoteOnly(value, true);
- }
-
+
/* ------------------------------------------------------------------------------- */
/**
* @see javax.servlet.Filter#destroy()
@@ -533,11 +288,12 @@ public class MultiPartFilter implements Filter
@Override
public Map getParameterMap()
{
- Map<String, String> cmap = new HashMap<String,String>();
+ Map<String, String[]> cmap = new HashMap<String,String[]>();
for ( Object key : _params.keySet() )
{
- cmap.put((String)key,getParameter((String)key));
+ String[] a = LazyList.toStringArray(getParameter((String)key));
+ cmap.put((String)key,a);
}
return Collections.unmodifiableMap(cmap);
@@ -595,37 +351,4 @@ public class MultiPartFilter implements Filter
_encoding=enc;
}
}
-
- private static class Base64InputStream extends InputStream
- {
- BufferedReader _in;
- String _line;
- byte[] _buffer;
- int _pos;
-
- public Base64InputStream (InputStream in)
- {
- _in = new BufferedReader(new InputStreamReader(in));
- }
-
- @Override
- public int read() throws IOException
- {
- if (_buffer==null || _pos>= _buffer.length)
- {
- _line = _in.readLine();
- if (_line==null)
- return -1;
- if (_line.startsWith("--"))
- _buffer=(_line+"\r\n").getBytes();
- else if (_line.length()==0)
- _buffer="\r\n".getBytes();
- else
- _buffer=B64Code.decode(_line);
-
- _pos=0;
- }
- return _buffer[_pos++];
- }
- }
}
diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/ProxyServlet.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/ProxyServlet.java
index 67fdbd7175..9ec35e718d 100644
--- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/ProxyServlet.java
+++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/ProxyServlet.java
@@ -561,7 +561,7 @@ public class ProxyServlet implements Servlet
String connectionHdr = request.getHeader("Connection");
if (connectionHdr != null)
{
- connectionHdr = connectionHdr.toLowerCase();
+ connectionHdr = connectionHdr.toLowerCase(Locale.ENGLISH);
if (connectionHdr.indexOf("keep-alive") < 0 && connectionHdr.indexOf("close") < 0)
connectionHdr = null;
}
@@ -579,7 +579,7 @@ public class ProxyServlet implements Servlet
{
// TODO could be better than this!
String hdr = (String)enm.nextElement();
- String lhdr = hdr.toLowerCase();
+ String lhdr = hdr.toLowerCase(Locale.ENGLISH);
if ("transfer-encoding".equals(lhdr))
{
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java
index 0722d750b2..e15bb9a2ab 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java
@@ -23,7 +23,8 @@ import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.net.Socket;
-
+import java.util.EnumSet;
+import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
@@ -35,6 +36,7 @@ import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.testing.ServletTester;
import org.eclipse.jetty.util.IO;
+import org.eclipse.jetty.util.log.Log;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -62,7 +64,7 @@ public abstract class AbstractDoSFilterTest
_tester.setContextPath("/ctx");
_tester.addServlet(TestServlet.class, "/*");
- _dosFilter = _tester.addFilter(filter, "/dos/*", 0);
+ _dosFilter = _tester.addFilter(filter, "/dos/*", EnumSet.allOf(DispatcherType.class));
_dosFilter.setInitParameter("maxRequestsPerSec", "4");
_dosFilter.setInitParameter("delayMs", "200");
_dosFilter.setInitParameter("throttledRequests", "1");
@@ -71,7 +73,7 @@ public abstract class AbstractDoSFilterTest
_dosFilter.setInitParameter("remotePort", "false");
_dosFilter.setInitParameter("insertHeaders", "true");
- _timeoutFilter = _tester.addFilter(filter, "/timeout/*", 0);
+ _timeoutFilter = _tester.addFilter(filter, "/timeout/*", EnumSet.allOf(DispatcherType.class));
_timeoutFilter.setInitParameter("maxRequestsPerSec", "4");
_timeoutFilter.setInitParameter("delayMs", "200");
_timeoutFilter.setInitParameter("throttledRequests", "1");
@@ -178,8 +180,8 @@ public abstract class AbstractDoSFilterTest
String last="GET /ctx/dos/test HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n";
String responses = doRequests(request+request+request+request+request,2,1100,1100,last);
- assertEquals(11,count(responses,"HTTP/1.1 200 OK"));
assertEquals(2,count(responses,"DoSFilter: delayed"));
+ assertEquals(11,count(responses,"HTTP/1.1 200 OK"));
}
@Test
@@ -209,7 +211,7 @@ public abstract class AbstractDoSFilterTest
String request="GET /ctx/dos/test HTTP/1.1\r\nHost: localhost\r\n\r\n";
String last="GET /ctx/dos/test HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n";
String responses = doRequests(request+request+request+request,1,0,0,last);
- //System.out.println("responses are " + responses);
+ System.out.println("responses are " + responses);
assertEquals("200 OK responses", 5,count(responses,"HTTP/1.1 200 OK"));
assertEquals("delayed responses", 1,count(responses,"DoSFilter: delayed"));
assertEquals("throttled responses", 1,count(responses,"DoSFilter: throttled"));
@@ -246,6 +248,8 @@ public abstract class AbstractDoSFilterTest
String last="GET /ctx/dos/test HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n";
String responses = doRequests(request+request+request+request,1,0,0,last);
+ System.err.println("RESPONSES: \n"+responses);
+
assertEquals(4,count(responses,"HTTP/1.1 200 OK"));
assertEquals(1,count(responses,"HTTP/1.1 503"));
assertEquals(1,count(responses,"DoSFilter: delayed"));
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AsyncProxyServer.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AsyncProxyServer.java
index 171656c8ab..cc07c6119c 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AsyncProxyServer.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AsyncProxyServer.java
@@ -18,6 +18,10 @@
package org.eclipse.jetty.servlets;
+import java.util.EnumSet;
+
+import javax.servlet.DispatcherType;
+
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
@@ -37,7 +41,7 @@ public class AsyncProxyServer
ServletHandler handler=new ServletHandler();
server.setHandler(handler);
- //FilterHolder gzip = handler.addFilterWithMapping("org.eclipse.jetty.servlets.GzipFilter","/*",0);
+ //FilterHolder gzip = handler.addFilterWithMapping("org.eclipse.jetty.servlet.GzipFilter","/*",EnumSet.of(DispatcherType.REQUEST,DispatcherType.ASYNC));
//gzip.setAsyncSupported(true);
//gzip.setInitParameter("minGzipSize","256");
ServletHolder proxy = handler.addServletWithMapping("org.eclipse.jetty.servlets.ProxyServlet","/");
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/CloseableDoSFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/CloseableDoSFilterTest.java
index 1dc4239e17..4d38d7255f 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/CloseableDoSFilterTest.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/CloseableDoSFilterTest.java
@@ -18,6 +18,7 @@
package org.eclipse.jetty.servlets;
+
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/CrossOriginFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/CrossOriginFilterTest.java
index 842e9af782..8d96e836bf 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/CrossOriginFilterTest.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/CrossOriginFilterTest.java
@@ -19,8 +19,11 @@
package org.eclipse.jetty.servlets;
import java.io.IOException;
+import java.util.EnumSet;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
+
+import javax.servlet.DispatcherType;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@@ -56,7 +59,7 @@ public class CrossOriginFilterTest
@Test
public void testRequestWithNoOriginArrivesToApplication() throws Exception
{
- tester.getContext().addFilter(CrossOriginFilter.class, "/*", FilterMapping.DEFAULT);
+ tester.getContext().addFilter(CrossOriginFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
final CountDownLatch latch = new CountDownLatch(1);
tester.getContext().addServlet(new ServletHolder(new ResourceServlet(latch)), "/*");
@@ -76,7 +79,7 @@ public class CrossOriginFilterTest
FilterHolder filterHolder = new FilterHolder(new CrossOriginFilter());
String origin = "http://localhost";
filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, origin);
- tester.getContext().addFilter(filterHolder, "/*", FilterMapping.DEFAULT);
+ tester.getContext().addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
CountDownLatch latch = new CountDownLatch(1);
tester.getContext().addServlet(new ServletHolder(new ResourceServlet(latch)), "/*");
@@ -100,7 +103,7 @@ public class CrossOriginFilterTest
FilterHolder filterHolder = new FilterHolder(new CrossOriginFilter());
String origin = "http://subdomain.example.com";
filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "http://*.example.com");
- tester.getContext().addFilter(filterHolder, "/*", FilterMapping.DEFAULT);
+ tester.getContext().addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
CountDownLatch latch = new CountDownLatch(1);
tester.getContext().addServlet(new ServletHolder(new ResourceServlet(latch)), "/*");
@@ -123,7 +126,7 @@ public class CrossOriginFilterTest
FilterHolder filterHolder = new FilterHolder(new CrossOriginFilter());
String origin = "http://subdomain.subdomain.example.com";
filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "http://*.example.com");
- tester.getContext().addFilter(filterHolder, "/*", FilterMapping.DEFAULT);
+ tester.getContext().addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
CountDownLatch latch = new CountDownLatch(1);
tester.getContext().addServlet(new ServletHolder(new ResourceServlet(latch)), "/*");
@@ -146,7 +149,7 @@ public class CrossOriginFilterTest
FilterHolder filterHolder = new FilterHolder(new CrossOriginFilter());
String origin = "http://localhost";
filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, origin);
- tester.getContext().addFilter(filterHolder, "/*", FilterMapping.DEFAULT);
+ tester.getContext().addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
CountDownLatch latch = new CountDownLatch(1);
tester.getContext().addServlet(new ServletHolder(new ResourceServlet(latch)), "/*");
@@ -170,7 +173,7 @@ public class CrossOriginFilterTest
String origin = "http://localhost";
String otherOrigin = origin.replace("localhost", "127.0.0.1");
filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, origin + "," + otherOrigin);
- tester.getContext().addFilter(filterHolder, "/*", FilterMapping.DEFAULT);
+ tester.getContext().addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
CountDownLatch latch = new CountDownLatch(1);
tester.getContext().addServlet(new ServletHolder(new ResourceServlet(latch)), "/*");
@@ -193,7 +196,7 @@ public class CrossOriginFilterTest
{
FilterHolder filterHolder = new FilterHolder(new CrossOriginFilter());
filterHolder.setInitParameter(CrossOriginFilter.ALLOW_CREDENTIALS_PARAM, "false");
- tester.getContext().addFilter(filterHolder, "/*", FilterMapping.DEFAULT);
+ tester.getContext().addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
CountDownLatch latch = new CountDownLatch(1);
tester.getContext().addServlet(new ServletHolder(new ResourceServlet(latch)), "/*");
@@ -218,7 +221,7 @@ public class CrossOriginFilterTest
// will contain the CORS response headers.
FilterHolder filterHolder = new FilterHolder(new CrossOriginFilter());
- tester.getContext().addFilter(filterHolder, "/*", FilterMapping.DEFAULT);
+ tester.getContext().addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
CountDownLatch latch = new CountDownLatch(1);
tester.getContext().addServlet(new ServletHolder(new ResourceServlet(latch)), "/*");
@@ -243,7 +246,7 @@ public class CrossOriginFilterTest
// will contain the CORS response headers.
FilterHolder filterHolder = new FilterHolder(new CrossOriginFilter());
- tester.getContext().addFilter(filterHolder, "/*", FilterMapping.DEFAULT);
+ tester.getContext().addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
CountDownLatch latch = new CountDownLatch(1);
tester.getContext().addServlet(new ServletHolder(new ResourceServlet(latch)), "/*");
@@ -265,7 +268,7 @@ public class CrossOriginFilterTest
{
FilterHolder filterHolder = new FilterHolder(new CrossOriginFilter());
filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "PUT");
- tester.getContext().addFilter(filterHolder, "/*", FilterMapping.DEFAULT);
+ tester.getContext().addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
CountDownLatch latch = new CountDownLatch(1);
tester.getContext().addServlet(new ServletHolder(new ResourceServlet(latch)), "/*");
@@ -304,7 +307,7 @@ public class CrossOriginFilterTest
FilterHolder filterHolder = new FilterHolder(new CrossOriginFilter());
filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "GET,HEAD,POST,PUT,DELETE");
filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, "X-Requested-With,Content-Type,Accept,Origin,X-Custom");
- tester.getContext().addFilter(filterHolder, "/*", FilterMapping.DEFAULT);
+ tester.getContext().addFilter(filterHolder, "/*",EnumSet.of(DispatcherType.REQUEST));
CountDownLatch latch = new CountDownLatch(1);
tester.getContext().addServlet(new ServletHolder(new ResourceServlet(latch)), "/*");
@@ -345,7 +348,7 @@ public class CrossOriginFilterTest
{
FilterHolder filterHolder = new FilterHolder(new CrossOriginFilter());
filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "GET,HEAD,POST,PUT,DELETE");
- tester.getContext().addFilter(filterHolder, "/*", FilterMapping.DEFAULT);
+ tester.getContext().addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
CountDownLatch latch = new CountDownLatch(1);
tester.getContext().addServlet(new ServletHolder(new ResourceServlet(latch)), "/*");
@@ -370,7 +373,7 @@ public class CrossOriginFilterTest
public void testCrossOriginFilterDisabledForWebSocketUpgrade() throws Exception
{
FilterHolder filterHolder = new FilterHolder(new CrossOriginFilter());
- tester.getContext().addFilter(filterHolder, "/*", FilterMapping.DEFAULT);
+ tester.getContext().addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
CountDownLatch latch = new CountDownLatch(1);
tester.getContext().addServlet(new ServletHolder(new ResourceServlet(latch)), "/*");
@@ -394,7 +397,7 @@ public class CrossOriginFilterTest
{
FilterHolder filterHolder = new FilterHolder(new CrossOriginFilter());
filterHolder.setInitParameter("exposedHeaders", "Content-Length");
- tester.getContext().addFilter(filterHolder, "/*", FilterMapping.DEFAULT);
+ tester.getContext().addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
CountDownLatch latch = new CountDownLatch(1);
tester.getContext().addServlet(new ServletHolder(new ResourceServlet(latch)), "/*");
@@ -416,7 +419,7 @@ public class CrossOriginFilterTest
FilterHolder filterHolder = new FilterHolder(new CrossOriginFilter());
filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "PUT");
filterHolder.setInitParameter(CrossOriginFilter.CHAIN_PREFLIGHT_PARAM, "false");
- tester.getContext().addFilter(filterHolder, "/*", FilterMapping.DEFAULT);
+ tester.getContext().addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
CountDownLatch latch = new CountDownLatch(1);
tester.getContext().addServlet(new ServletHolder(new ResourceServlet(latch)), "/*");
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/DoSFilterJMXTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/DoSFilterJMXTest.java
index cd2ba3a857..c7ac0c09eb 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/DoSFilterJMXTest.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/DoSFilterJMXTest.java
@@ -24,10 +24,10 @@ import java.util.Set;
import javax.management.Attribute;
import javax.management.MBeanServer;
import javax.management.ObjectName;
+import javax.servlet.DispatcherType;
import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.server.Connector;
-import org.eclipse.jetty.server.DispatcherType;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.servlet.FilterHolder;
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/DoSFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/DoSFilterTest.java
index 5fefd52879..274b7f1045 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/DoSFilterTest.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/DoSFilterTest.java
@@ -48,7 +48,8 @@ public class DoSFilterTest extends AbstractDoSFilterTest
@Override
public void closeConnection(HttpServletRequest request, HttpServletResponse response, Thread thread)
{
- try {
+ try
+ {
response.getWriter().append("DoSFilter: timeout");
super.closeConnection(request,response,thread);
}
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/IncludableGzipFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/IncludableGzipFilterTest.java
index 97a664d41f..26c2c7fa1b 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/IncludableGzipFilterTest.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/IncludableGzipFilterTest.java
@@ -104,7 +104,7 @@ public class IncludableGzipFilterTest
tester.setContextPath("/context");
tester.setResourceBase(testdir.getDir().getCanonicalPath());
tester.addServlet(org.eclipse.jetty.servlet.DefaultServlet.class, "/");
- FilterHolder holder = tester.addFilter(IncludableGzipFilter.class,"/*",0);
+ FilterHolder holder = tester.addFilter(IncludableGzipFilter.class,"/*",null);
holder.setInitParameter("mimeTypes","text/plain");
tester.start();
}
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java
index 5f12d70442..046b464624 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java
@@ -18,14 +18,21 @@
package org.eclipse.jetty.servlets;
-import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
+import static org.hamcrest.Matchers.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.io.OutputStream;
import java.io.PrintWriter;
+import java.net.Socket;
+import java.net.URL;
+import java.util.EnumSet;
+import java.util.Enumeration;
+import java.util.Map;
+import javax.servlet.DispatcherType;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@@ -36,6 +43,7 @@ import org.eclipse.jetty.servlet.FilterMapping;
import org.eclipse.jetty.testing.HttpTester;
import org.eclipse.jetty.testing.ServletTester;
import org.eclipse.jetty.util.IO;
+import org.eclipse.jetty.util.QuotedStringTokenizer;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -70,7 +78,6 @@ public class MultipartFilterTest
assertNotNull(req.getParameter("fileup"));
assertNotNull(req.getParameter("fileup"+MultiPartFilter.CONTENT_TYPE_SUFFIX));
assertEquals(req.getParameter("fileup"+MultiPartFilter.CONTENT_TYPE_SUFFIX), "application/octet-stream");
-
super.doPost(req, resp);
}
@@ -91,7 +98,8 @@ public class MultipartFilterTest
tester.setContextPath("/context");
tester.setResourceBase(_dir.getCanonicalPath());
tester.addServlet(TestServlet.class, "/");
- FilterHolder multipartFilter = tester.addFilter(MultiPartFilter.class,"/*",FilterMapping.DEFAULT);
+ tester.setAttribute("javax.servlet.context.tempdir", _dir);
+ FilterHolder multipartFilter = tester.addFilter(MultiPartFilter.class,"/*", EnumSet.of(DispatcherType.REQUEST));
multipartFilter.setInitParameter("deleteFiles", "true");
tester.start();
}
@@ -130,7 +138,7 @@ public class MultipartFilterTest
response.parse(tester.getResponses(request.generate()));
assertTrue(response.getMethod()==null);
- assertEquals(HttpServletResponse.SC_OK,response.getStatus());
+ assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,response.getStatus());
}
@@ -754,17 +762,13 @@ public class MultipartFilterTest
*/
public static class TestServletParameterMap extends DumpServlet
{
-
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
- String content = (String)req.getParameterMap().get("\"strup\"Content-Type: application/octet-stream");
-
- assertThat(content, containsString("How now brown cow."));
-
+ String[] content = req.getParameterMap().get("\"strup\"Content-Type: application/octet-stream");
+ assertThat (content[0], containsString("How now brown cow."));
super.doPost(req, resp);
- }
-
+ }
}
/**
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/PutFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/PutFilterTest.java
index d4e6933748..438e30718a 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/PutFilterTest.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/PutFilterTest.java
@@ -26,6 +26,8 @@ import java.io.FileInputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.URL;
+import java.util.EnumSet;
+import javax.servlet.DispatcherType;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Locale;
@@ -59,7 +61,7 @@ public class PutFilterTest
tester.setContextPath("/context");
tester.setResourceBase(_dir.getCanonicalPath());
tester.addServlet(org.eclipse.jetty.servlet.DefaultServlet.class, "/");
- FilterHolder holder = tester.addFilter(PutFilter.class,"/*",0);
+ FilterHolder holder = tester.addFilter(PutFilter.class,"/*",EnumSet.of(DispatcherType.REQUEST));
holder.setInitParameter("delAllowed","true");
// Bloody Windows does not allow file renaming
if (!System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows"))
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/QoSFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/QoSFilterTest.java
index 8f7f8043fe..5a7fa26ff7 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/QoSFilterTest.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/QoSFilterTest.java
@@ -23,9 +23,10 @@ import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.net.URL;
+import java.util.EnumSet;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-
+import javax.servlet.DispatcherType;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
@@ -99,7 +100,7 @@ public class QoSFilterTest
FilterHolder holder = new FilterHolder(QoSFilter2.class);
holder.setAsyncSupported(true);
holder.setInitParameter(QoSFilter.MAX_REQUESTS_INIT_PARAM, ""+MAX_QOS);
- _tester.getContext().getServletHandler().addFilterWithMapping(holder,"/*",FilterMapping.DEFAULT);
+ _tester.getContext().getServletHandler().addFilterWithMapping(holder,"/*",EnumSet.of(DispatcherType.REQUEST,DispatcherType.ASYNC));
for(int i = 0; i < NUM_CONNECTIONS; ++i )
{
@@ -117,8 +118,7 @@ public class QoSFilterTest
FilterHolder holder = new FilterHolder(QoSFilter2.class);
holder.setAsyncSupported(true);
holder.setInitParameter(QoSFilter.MAX_REQUESTS_INIT_PARAM, ""+MAX_QOS);
- _tester.getContext().getServletHandler().addFilterWithMapping(holder,"/*",FilterMapping.DEFAULT);
-
+ _tester.getContext().getServletHandler().addFilterWithMapping(holder,"/*",EnumSet.of(DispatcherType.REQUEST,DispatcherType.ASYNC));
for(int i = 0; i < NUM_CONNECTIONS; ++i )
{
new Thread(new Worker2(i)).start();
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/TransparentProxyTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/TransparentProxyTest.java
new file mode 100644
index 0000000000..10467ebdde
--- /dev/null
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/TransparentProxyTest.java
@@ -0,0 +1,140 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2013 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.servlets;
+
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.nio.SelectChannelConnector;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * TransparentProxyTest
+ *
+ *
+ */
+public class TransparentProxyTest
+{
+
+
+ protected Server server;
+ protected Server proxyServer;
+
+ public static class ServletA extends HttpServlet {
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ resp.setContentType("text/plain");
+ resp.getWriter().println("ok");
+ }
+ }
+
+ @Before
+ public void setUp () throws Exception
+ {
+ //set up the target server
+ server = new Server();
+ SelectChannelConnector connector = new SelectChannelConnector();
+ connector.setPort(8080);
+ server.addConnector(connector);
+ ServletContextHandler handler = new ServletContextHandler(server, "/");
+ handler.addServlet(ServletA.class, "/a");
+ server.setHandler(handler);
+ server.start();
+
+
+ //set up the server that proxies to the target server
+ proxyServer = new Server();
+ SelectChannelConnector proxyConnector = new SelectChannelConnector();
+ proxyConnector.setPort(8081);
+ proxyServer.addConnector(proxyConnector);
+ ServletContextHandler proxyHandler = new ServletContextHandler(proxyServer, "/");
+ proxyHandler.addServlet(new ServletHolder(new ProxyServlet.Transparent("/", "http", "127.0.0.1", 8080, "/")), "/");
+ proxyServer.setHandler(proxyHandler);
+ proxyServer.start();
+
+ }
+
+
+ @After
+ public void tearDown() throws Exception
+ {
+ server.stop();
+ proxyServer.stop();
+ }
+
+
+ @Test
+ public void testDirectNoContentType() throws Exception
+ {
+ // Direct request without Content-Type set works
+ URL url = new URL("http://localhost:8080/a");
+ HttpURLConnection con = (HttpURLConnection) url.openConnection();
+ assertEquals(200, con.getResponseCode());
+ }
+
+
+ @Test
+ public void testDirectWithContentType() throws Exception
+ {
+ // Direct request with Content-Type works
+ URL url = new URL("http://localhost:8080/a");
+ HttpURLConnection con = (HttpURLConnection) url.openConnection();
+ con.addRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
+ assertEquals(200, con.getResponseCode());
+ }
+
+ @Test
+ public void testProxiedWithoutContentType() throws Exception
+ {
+ // Proxied request without Content-Type set works
+ URL url = new URL("http://localhost:8081/a");
+ HttpURLConnection con = (HttpURLConnection) url.openConnection();
+ assertEquals(200, con.getResponseCode());
+ System.err.println (con.getContentType());
+ }
+
+ @Test
+ public void testProxiedWithContentType() throws Exception
+ {
+ // Proxied request with Content-Type set fails
+
+ URL url = new URL("http://localhost:8081/a");
+ HttpURLConnection con = (HttpURLConnection) url.openConnection();
+ con.addRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
+ assertEquals(200, con.getResponseCode());
+ System.err.println(con.getContentType());
+
+ }
+}
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java
index 4a034d4c88..5b92a940d3 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java
@@ -35,11 +35,13 @@ import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.security.DigestOutputStream;
import java.security.MessageDigest;
+import java.util.EnumSet;
import java.util.Enumeration;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream;
import java.util.zip.Inflater;
+import javax.servlet.DispatcherType;
import java.util.zip.InflaterInputStream;
import javax.servlet.Servlet;
@@ -474,7 +476,7 @@ public class GzipTester
ServletHolder servletHolder = servletTester.addServlet(servletClass,"/");
servletHolder.setInitParameter("baseDir",testdir.getDir().getAbsolutePath());
servletHolder.setInitParameter("etags","true");
- FilterHolder holder = servletTester.addFilter(gzipFilterClass,"/*",0);
+ FilterHolder holder = servletTester.addFilter(gzipFilterClass,"/*",EnumSet.allOf(DispatcherType.class));
holder.setInitParameter("vary","Accept-Encoding");
return holder;
}

Back to the top