Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Bartel2014-10-21 21:56:10 -0400
committerJan Bartel2014-10-21 21:56:59 -0400
commit592265c21fe1300efe42375d8fd15e39486db5a3 (patch)
tree1259db5223422248950baeb5a67af6f4661410d5 /jetty-servlets
parent8bf6b2c62c814c5d8e160bc41a5a0089e4a4c9d9 (diff)
downloadorg.eclipse.jetty.project-592265c21fe1300efe42375d8fd15e39486db5a3.tar.gz
org.eclipse.jetty.project-592265c21fe1300efe42375d8fd15e39486db5a3.tar.xz
org.eclipse.jetty.project-592265c21fe1300efe42375d8fd15e39486db5a3.zip
447627 MultiPart file always created when "filename" set in Content-Disposition
Diffstat (limited to 'jetty-servlets')
-rw-r--r--jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java5
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java27
2 files changed, 26 insertions, 6 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 c56919187b..c2bc646190 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
@@ -60,6 +60,10 @@ import org.eclipse.jetty.util.log.Logger;
/**
* Multipart Form Data Filter.
* <p>
+ * This class is ONLY needed if you cannot use the Servlet 3.0 APIs for
+ * configuring and handling multipart requests. See javax.servlet.http.HttpServletRequest.getParts(). If
+ * you use the new servlet apis then you should REMOVE this filter from your webapp.
+ * <p>
* This class decodes the <code>multipart/form-data</code> stream sent by a HTML form that uses a file input
* item. Any files sent are stored to a temporary file and a File object added to the request
* as an attribute. All other values are made available via the normal getParameter API and
@@ -89,6 +93,7 @@ import org.eclipse.jetty.util.log.Logger;
* To limit the size of the multipart request.
* </dd>
* </dl>
+ * @deprecated See servlet 3.0 apis like javax.servlet.http.HttpServletRequest.getParts()
*/
public class MultiPartFilter implements Filter
{
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 8eb9470c9e..165dedd73b 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
@@ -23,6 +23,7 @@ import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@@ -60,12 +61,24 @@ public class MultipartFilterTest
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
- assertNotNull(req.getParameter("fileName"));
- assertEquals(getServletContext().getAttribute("fileName"), req.getParameter("fileName"));
- assertNotNull(req.getParameter("desc"));
- assertEquals(getServletContext().getAttribute("desc"), req.getParameter("desc"));
- assertNotNull(req.getParameter("title"));
- assertEquals(getServletContext().getAttribute("title"), req.getParameter("title"));
+ //we have configured the multipart filter to always store to disk (file size threshold == 1)
+ //but fileName has no filename param, so only the attribute should be set
+ assertNull(req.getParameter("fileName"));
+ assertNotNull(req.getAttribute("fileName"));
+ File f = (File)req.getAttribute("fileName");
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ IO.copy(new FileInputStream(f), baos);
+ assertEquals(getServletContext().getAttribute("fileName"), baos.toString());
+ assertNull(req.getParameter("desc"));
+ assertNotNull(req.getAttribute("desc"));
+ baos = new ByteArrayOutputStream();
+ IO.copy(new FileInputStream((File)req.getAttribute("desc")), baos);
+ assertEquals(getServletContext().getAttribute("desc"), baos.toString());
+ assertNull(req.getParameter("title"));
+ assertNotNull(req.getAttribute("title"));
+ baos = new ByteArrayOutputStream();
+ IO.copy(new FileInputStream((File)req.getAttribute("title")), baos);
+ assertEquals(getServletContext().getAttribute("title"), baos.toString());
super.doPost(req, resp);
}
}
@@ -77,6 +90,7 @@ public class MultipartFilterTest
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
assertNotNull(req.getParameter("fileup"));
+ System.err.println("Fileup="+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);
@@ -101,6 +115,7 @@ public class MultipartFilterTest
tester.getContext().setAttribute("javax.servlet.context.tempdir", _dir);
FilterHolder multipartFilter = tester.getContext().addFilter(MultiPartFilter.class,"/*", EnumSet.of(DispatcherType.REQUEST));
multipartFilter.setInitParameter("deleteFiles", "true");
+ multipartFilter.setInitParameter("fileOutputBuffer", "1"); //write a file if there's more than 1 byte content
tester.start();
}

Back to the top