use of org.glassfish.jersey.media.multipart.FormDataMultiPart in project jersey by jersey.
the class MultipartFeatureTest method testPostFormData.
@Test
public void testPostFormData() {
final WebTarget target = target().path("echo");
FormDataMultiPart formData = new FormDataMultiPart().field("input", TestFormDATA);
final Response response = target.request().post(Entity.entity(formData, MediaType.MULTIPART_FORM_DATA_TYPE));
assertThat(response.getStatus(), is(200));
assertThat(response.readEntity(String.class), is(TestFormDATA));
}
use of org.glassfish.jersey.media.multipart.FormDataMultiPart in project jersey by jersey.
the class MultiPartWebAppTest method testXmlJAXBPart.
@Test
public void testXmlJAXBPart() {
final WebTarget target = target().path("form/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 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));
}
Aggregations