Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Bartel2013-06-24 03:28:34 -0400
committerJan Bartel2013-06-24 03:28:34 -0400
commit7ce05f2c495ada79d3a0aead93730962f2128315 (patch)
treee02ac89b39ebff0ca7363634ba7460305fb5e2c3 /jetty-servlets/src
parentebe98022abf5d67cd08d454af69e544f850c0609 (diff)
parenta7436bc774506be99e80bf0a88c367ce276ba42a (diff)
downloadorg.eclipse.jetty.project-7ce05f2c495ada79d3a0aead93730962f2128315.tar.gz
org.eclipse.jetty.project-7ce05f2c495ada79d3a0aead93730962f2128315.tar.xz
org.eclipse.jetty.project-7ce05f2c495ada79d3a0aead93730962f2128315.zip
Merge remote-tracking branch 'origin/jetty-8'
Conflicts: jetty-server/src/main/java/org/eclipse/jetty/server/Response.java jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java test-jetty-servlet/src/main/java/org/eclipse/jetty/testing/HttpTester.java
Diffstat (limited to 'jetty-servlets/src')
-rw-r--r--jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java30
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java61
2 files changed, 83 insertions, 8 deletions
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 8fcb8b2422..253d6d5f18 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
@@ -45,10 +45,12 @@ import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.Part;
import org.eclipse.jetty.util.IO;
+import org.eclipse.jetty.http.MimeTypes;
import org.eclipse.jetty.util.LazyList;
import org.eclipse.jetty.util.MultiMap;
import org.eclipse.jetty.util.MultiPartInputStreamParser;
import org.eclipse.jetty.util.StringUtil;
+import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@@ -259,11 +261,11 @@ public class MultiPartFilter implements Filter
{
try
{
- return new String((byte[])o,_encoding);
+ return getParameterBytesAsString(name, (byte[])o);
}
catch(Exception e)
{
- e.printStackTrace();
+ LOG.warn(e);
}
}
else if (o!=null)
@@ -282,9 +284,7 @@ public class MultiPartFilter implements Filter
for ( Object key : _params.keySet() )
{
- String[] a = LazyList.toStringArray(getParameter((String)key));
- cmap.put((String)key,a);
-
+ cmap.put((String)key,getParameterValues((String)key));
}
return Collections.unmodifiableMap(cmap);
@@ -318,7 +318,7 @@ public class MultiPartFilter implements Filter
{
try
{
- v[i]=new String((byte[])o,_encoding);
+ v[i]=getParameterBytesAsString(name, (byte[])o);
}
catch(Exception e)
{
@@ -341,5 +341,23 @@ public class MultiPartFilter implements Filter
{
_encoding=enc;
}
+
+
+ /* ------------------------------------------------------------------------------- */
+ private String getParameterBytesAsString (String name, byte[] bytes)
+ throws UnsupportedEncodingException
+ {
+ //check if there is a specific encoding for the parameter
+ Object ct = _params.getValue(name+CONTENT_TYPE_SUFFIX,0);
+ //use default if not
+ String contentType = _encoding;
+ if (ct != null)
+ {
+ String tmp = MimeTypes.getCharsetFromContentType((String)ct);
+ contentType = (tmp == null?_encoding:tmp);
+ }
+
+ return new String(bytes,contentType);
+ }
}
}
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 de080233ec..7d70908618 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
@@ -26,11 +26,13 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.EnumSet;
+import java.util.Map;
import javax.servlet.DispatcherType;
import javax.servlet.ServletException;
@@ -38,10 +40,12 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+
import org.eclipse.jetty.http.HttpTester;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.ServletTester;
import org.eclipse.jetty.util.IO;
+import org.eclipse.jetty.util.StringUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -105,6 +109,7 @@ public class MultipartFilterTest
public void tearDown() throws Exception
{
tester.stop();
+ tester=null;
}
@Test
@@ -698,7 +703,6 @@ public class MultipartFilterTest
assertTrue(response.getContent().contains("aaaa,bbbbb"));
}
-
@Test
public void testContentTypeWithCharSet() throws Exception
{
@@ -729,7 +733,7 @@ public class MultipartFilterTest
assertTrue(response.getContent().indexOf("brown cow")>=0);
}
-
+
/*
* see the testParameterMap test
*
@@ -786,6 +790,59 @@ public class MultipartFilterTest
assertTrue(response.getContent().indexOf("brown cow")>=0);
}
+ public static class TestServletCharSet extends HttpServlet
+ {
+
+ @Override
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+ {
+ //test that the multipart content bytes were converted correctly from their charset to unicode
+ String content = (String)req.getParameter("ttt");
+ assertNotNull(content);
+ assertEquals("ttt\u01FCzzz",content);
+ assertEquals("application/octet-stream; charset=UTF-8",req.getParameter("ttt"+MultiPartFilter.CONTENT_TYPE_SUFFIX));
+
+
+ //test that the parameter map retrieves values as String[]
+ Map map = req.getParameterMap();
+ Object o = map.get("ttt");
+ assertTrue(o.getClass().isArray());
+ super.doPost(req, resp);
+ }
+ }
+
+
+ @Test
+ public void testWithCharSet()
+ throws Exception
+ {
+ // generated and parsed test
+ HttpTester.Request request = HttpTester.newRequest();
+ HttpTester.Response response;
+ tester.addServlet(TestServletCharSet.class,"/test3");
+
+ // test GET
+ request.setMethod("POST");
+ request.setVersion("HTTP/1.0");
+ request.setHeader("Host","tester");
+ request.setURI("/context/test3");
+
+ String boundary="XyXyXy";
+ request.setHeader("Content-Type","multipart/form-data; boundary="+boundary);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ baos.write(("--" + boundary + "\r\n"+
+ "Content-Disposition: form-data; name=\"ttt\"\r\n"+
+ "Content-Type: application/octet-stream; charset=UTF-8\r\n\r\n").getBytes());
+ baos.write("ttt\u01FCzzz".getBytes(StringUtil.__UTF8));
+ baos.write(("\r\n--" + boundary + "--\r\n\r\n").getBytes());
+
+
+ request.setContent(baos.toByteArray());
+ response = HttpTester.parseResponse(tester.getResponses(request.generate()));
+ }
+
public static class DumpServlet extends HttpServlet
{
private static final long serialVersionUID = 201012011130L;

Back to the top