use of javax.servlet.http.Part in project jetty.project by eclipse.
the class MultiPartInputStreamTest method testCorrectlyEncodedMSFilename.
@Test
public void testCorrectlyEncodedMSFilename() throws Exception {
String contents = "--AaB03x\r\n" + "content-disposition: form-data; name=\"stuff\"; filename=\"" + "c:\\\\this\\\\really\\\\is\\\\some\\\\path\\\\to\\\\a\\\\file.txt" + "\"\r\n" + "Content-Type: text/plain\r\n" + "\r\n" + "stuff" + "aaa" + "\r\n" + "--AaB03x--\r\n";
MultipartConfigElement config = new MultipartConfigElement(_dirname, 1024, 3072, 50);
MultiPartInputStreamParser mpis = new MultiPartInputStreamParser(new ByteArrayInputStream(contents.getBytes()), _contentType, config, _tmpDir);
mpis.setDeleteOnExit(true);
Collection<Part> parts = mpis.getParts();
assertThat(parts.size(), is(1));
assertThat(((MultiPartInputStreamParser.MultiPart) parts.iterator().next()).getSubmittedFileName(), is("c:\\this\\really\\is\\some\\path\\to\\a\\file.txt"));
}
use of javax.servlet.http.Part in project jetty.project by eclipse.
the class MultiPartInputStreamTest method testBase64EncodedContent.
@Test
public void testBase64EncodedContent() throws Exception {
String contentWithEncodedPart = "--AaB03x\r\n" + "Content-disposition: form-data; name=\"other\"\r\n" + "Content-Type: text/plain\r\n" + "\r\n" + "other" + "\r\n" + "--AaB03x\r\n" + "Content-disposition: form-data; name=\"stuff\"; filename=\"stuff.txt\"\r\n" + "Content-Transfer-Encoding: base64\r\n" + "Content-Type: application/octet-stream\r\n" + "\r\n" + B64Code.encode("hello jetty") + "\r\n" + "--AaB03x\r\n" + "Content-disposition: form-data; name=\"final\"\r\n" + "Content-Type: text/plain\r\n" + "\r\n" + "the end" + "\r\n" + "--AaB03x--\r\n";
MultipartConfigElement config = new MultipartConfigElement(_dirname, 1024, 3072, 50);
MultiPartInputStreamParser mpis = new MultiPartInputStreamParser(new ByteArrayInputStream(contentWithEncodedPart.getBytes()), _contentType, config, _tmpDir);
mpis.setDeleteOnExit(true);
Collection<Part> parts = mpis.getParts();
assertEquals(3, parts.size());
Part p1 = mpis.getPart("other");
assertNotNull(p1);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IO.copy(p1.getInputStream(), baos);
assertEquals("other", baos.toString("US-ASCII"));
Part p2 = mpis.getPart("stuff");
assertNotNull(p2);
baos = new ByteArrayOutputStream();
IO.copy(p2.getInputStream(), baos);
assertEquals("hello jetty", baos.toString("US-ASCII"));
Part p3 = mpis.getPart("final");
assertNotNull(p3);
baos = new ByteArrayOutputStream();
IO.copy(p3.getInputStream(), baos);
assertEquals("the end", baos.toString("US-ASCII"));
}
use of javax.servlet.http.Part in project jetty.project by eclipse.
the class MultiPartInputStreamTest method testBadlyEncodedMSFilename.
@Test
public void testBadlyEncodedMSFilename() throws Exception {
String contents = "--AaB03x\r\n" + "content-disposition: form-data; name=\"stuff\"; filename=\"" + "c:\\this\\really\\is\\some\\path\\to\\a\\file.txt" + "\"\r\n" + "Content-Type: text/plain\r\n" + "\r\n" + "stuff" + "aaa" + "\r\n" + "--AaB03x--\r\n";
MultipartConfigElement config = new MultipartConfigElement(_dirname, 1024, 3072, 50);
MultiPartInputStreamParser mpis = new MultiPartInputStreamParser(new ByteArrayInputStream(contents.getBytes()), _contentType, config, _tmpDir);
mpis.setDeleteOnExit(true);
Collection<Part> parts = mpis.getParts();
assertThat(parts.size(), is(1));
assertThat(((MultiPartInputStreamParser.MultiPart) parts.iterator().next()).getSubmittedFileName(), is("c:\\this\\really\\is\\some\\path\\to\\a\\file.txt"));
}
use of javax.servlet.http.Part in project jetty.project by eclipse.
the class MultiPartInputStreamTest method testQuotedPrintableEncoding.
@Test
public void testQuotedPrintableEncoding() throws Exception {
String contentWithEncodedPart = "--AaB03x\r\n" + "Content-disposition: form-data; name=\"other\"\r\n" + "Content-Type: text/plain\r\n" + "\r\n" + "other" + "\r\n" + "--AaB03x\r\n" + "Content-disposition: form-data; name=\"stuff\"; filename=\"stuff.txt\"\r\n" + "Content-Transfer-Encoding: quoted-printable\r\n" + "Content-Type: text/plain\r\n" + "\r\n" + "truth=3Dbeauty" + "\r\n" + "--AaB03x--\r\n";
MultipartConfigElement config = new MultipartConfigElement(_dirname, 1024, 3072, 50);
MultiPartInputStreamParser mpis = new MultiPartInputStreamParser(new ByteArrayInputStream(contentWithEncodedPart.getBytes()), _contentType, config, _tmpDir);
mpis.setDeleteOnExit(true);
Collection<Part> parts = mpis.getParts();
assertEquals(2, parts.size());
Part p1 = mpis.getPart("other");
assertNotNull(p1);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IO.copy(p1.getInputStream(), baos);
assertEquals("other", baos.toString("US-ASCII"));
Part p2 = mpis.getPart("stuff");
assertNotNull(p2);
baos = new ByteArrayOutputStream();
IO.copy(p2.getInputStream(), baos);
assertEquals("truth=beauty", baos.toString("US-ASCII"));
}
use of javax.servlet.http.Part in project jetty.project by eclipse.
the class MultiPartInputStreamTest method testFileTooBig.
@Test
public void testFileTooBig() throws Exception {
MultipartConfigElement config = new MultipartConfigElement(_dirname, 40, 1024, 30);
MultiPartInputStreamParser mpis = new MultiPartInputStreamParser(new ByteArrayInputStream(_multi.getBytes()), _contentType, config, _tmpDir);
mpis.setDeleteOnExit(true);
Collection<Part> parts = null;
try {
parts = mpis.getParts();
fail("stuff.txt should have been larger than maxFileSize");
} catch (IllegalStateException e) {
assertTrue(e.getMessage().startsWith("Multipart Mime part"));
}
}
Aggregations