Merge branch 'master' of ssh://git.eclipse.org/gitroot/jetty/org.eclipse.jetty.project

This commit is contained in:
Greg Wilkins 2011-11-15 23:20:09 +11:00
commit 67bd6f5868
3 changed files with 48 additions and 19 deletions

View File

@ -63,6 +63,7 @@ import org.eclipse.jetty.util.TypeUtil;
*/
public class MultiPartFilter implements Filter
{
public final static String CONTENT_TYPE_SUFFIX=".org.eclipse.jetty.servlet.contentType";
private final static String FILES ="org.eclipse.jetty.servlet.MultiPartFilter.files";
private File tempdir;
private boolean _deleteFiles;
@ -132,8 +133,11 @@ public class MultiPartFilter implements Filter
String content_disposition=null;
String content_transfer_encoding=null;
outer:while(!lastPart)
{
String type_content=null;
while(true)
{
// read a line
@ -155,7 +159,9 @@ public class MultiPartFilter implements Filter
if(key.equals("content-disposition"))
content_disposition=value;
else if(key.equals("content-transfer-encoding"))
content_transfer_encoding=value;
content_transfer_encoding=value;
else if (key.equals("content-type"))
type_content = value;
}
}
// Extract content-disposition
@ -207,6 +213,8 @@ public class MultiPartFilter implements Filter
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)
{
@ -330,6 +338,8 @@ public class MultiPartFilter implements Filter
{
bytes = ((ByteArrayOutputStream)out).toByteArray();
params.add(name,bytes);
if (type_content != null)
params.add(name+CONTENT_TYPE_SUFFIX, type_content);
}
}

View File

@ -15,6 +15,7 @@ package org.eclipse.jetty.servlets;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;
import java.io.File;
import java.io.FileInputStream;
@ -39,6 +40,21 @@ public class MultipartFilterTest
private File _dir;
private ServletTester tester;
public static class TestServlet extends DumpServlet
{
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
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);
}
}
@Before
public void setUp() throws Exception
{
@ -51,7 +67,7 @@ public class MultipartFilterTest
tester=new ServletTester();
tester.setContextPath("/context");
tester.setResourceBase(_dir.getCanonicalPath());
tester.addServlet(DumpServlet.class, "/");
tester.addServlet(TestServlet.class, "/");
FilterHolder multipartFilter = tester.addFilter(MultiPartFilter.class,"/*",FilterMapping.DEFAULT);
multipartFilter.setInitParameter("deleteFiles", "true");
tester.start();
@ -94,6 +110,7 @@ public class MultipartFilterTest
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
}
@Test
public void testPost() throws Exception
{
@ -125,6 +142,7 @@ public class MultipartFilterTest
assertTrue(response.getContent().indexOf("brown cow")>=0);
}
@Test
public void testEncodedPost() throws Exception
{

View File

@ -37,6 +37,7 @@ import org.eclipse.jetty.util.DateCache;
*/
public class StdErrLog implements Logger
{
private static final String EOL = System.getProperty("line.separator");
private static DateCache _dateCache;
private static Properties __props = Log.__props;
@ -551,19 +552,19 @@ public class StdErrLog implements Logger
}
else
{
buffer.append('\n');
buffer.append(EOL);
format(buffer,thrown.toString());
StackTraceElement[] elements = thrown.getStackTrace();
for (int i = 0; elements != null && i < elements.length; i++)
{
buffer.append("\n\tat ");
buffer.append(EOL).append("\tat ");
format(buffer,elements[i].toString());
}
Throwable cause = thrown.getCause();
if (cause != null && cause != thrown)
{
buffer.append("\nCaused by: ");
buffer.append(EOL).append("Caused by: ");
format(buffer,cause);
}
}