use of org.glassfish.jersey.media.multipart.FormDataMultiPart in project jersey by jersey.
the class MultiPartWebAppTest method testFieldInjectedXmlJAXBPart.
@Test
public void testFieldInjectedXmlJAXBPart() {
final WebTarget target = target().path("form-field-injected/xml-jaxb-part");
final FormDataMultiPart mp = new FormDataMultiPart();
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("bean").fileName("bean").build(), new Bean("BEAN"), MediaType.APPLICATION_XML_TYPE));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("string").fileName("string").build(), "STRING"));
final String s = target.request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), String.class);
assertEquals("STRING:string,BEAN:bean", s);
}
use of org.glassfish.jersey.media.multipart.FormDataMultiPart in project jersey by jersey.
the class Jersey2846ITCase method _test.
public void _test(final String path, final int status, final Object entity) throws Exception {
final String tempDir = System.getProperty("java.io.tmpdir");
// Get number of matching MIME*tmp files (the number should be the same at the end of the test).
final int expectedTempFiles = matchingTempFiles(tempDir);
final FormDataMultiPart multipart = new FormDataMultiPart();
final FormDataBodyPart bodypart = new FormDataBodyPart(FormDataContentDisposition.name("file").fileName("file").build(), entity, MediaType.TEXT_PLAIN_TYPE);
multipart.bodyPart(bodypart);
final Response response = target().path(path).request().post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA));
// Get Response ...
assertThat(response.getStatus(), is(status));
// Wait a second to make sure the files don't exist.
Thread.sleep(1000);
// Make sure that the message and it's parts have been closed and temporary files deleted.
assertThat("Temporary files were not deleted", matchingTempFiles(tempDir), is(expectedTempFiles));
}
use of org.glassfish.jersey.media.multipart.FormDataMultiPart in project jersey by jersey.
the class Jersey1667ITCase method testJersey1667Fix.
/**
* Reproducer method for JERSEY-1667.
*/
@Test
public void testJersey1667Fix() {
final WebTarget target = target().path("part-file-name");
char[] chars = new char[10 * 1024];
Arrays.fill(chars, 'a');
final String body = new String(chars);
final FormDataMultiPart multiPart = new FormDataMultiPart();
final FormDataBodyPart bodyPart = new FormDataBodyPart(FormDataContentDisposition.name("part").fileName("file").build(), body);
multiPart.bodyPart(bodyPart);
final Response response = target.request().post(Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE));
assertThat(response.getStatus(), equalTo(500));
}
use of org.glassfish.jersey.media.multipart.FormDataMultiPart in project jersey by jersey.
the class FormDataMultiPartReaderWriterTest method testFileSize.
/**
* JERSEY-2862 reproducer. Make sure that mimepull is able to move it's temporary file to the one created by Jersey.
* Reproducible only on Windows. Entity size has to be bigger than 8192 to make sure mimepull creates temporary file.
*/
@Test
public void testFileSize() throws Exception {
final FormDataMultiPart multipart = new FormDataMultiPart();
final byte[] content = new byte[2 * 8192];
final FormDataBodyPart bodypart = new FormDataBodyPart(FormDataContentDisposition.name("file").fileName("file").build(), content, MediaType.TEXT_PLAIN_TYPE);
multipart.bodyPart(bodypart);
final Response response = target().path("FileResource").path("FileSize").request().post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA));
assertThat("Temporary file has wrong size.", response.readEntity(int.class), is(content.length));
}
use of org.glassfish.jersey.media.multipart.FormDataMultiPart in project jersey by jersey.
the class FormDataMultiPartReaderWriterTest method testPrimitivesFormDataParamResource.
@Test
public void testPrimitivesFormDataParamResource() {
final Invocation.Builder request = target().path("PrimitivesFormDataParamResource").request("text/plain");
final FormDataMultiPart entity = new FormDataMultiPart().field("bP", "true").field("bT", "true").field("bP_default", "false").field("bT_default", "false");
final String response = request.put(Entity.entity(entity, "multipart/form-data"), String.class);
assertEquals("OK", response);
}
Aggregations