Search in sources :

Example 1 with FormDataMultiPart

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));
}
Also used : Response(javax.ws.rs.core.Response) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 2 with FormDataMultiPart

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);
}
Also used : FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 3 with FormDataMultiPart

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);
}
Also used : FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 4 with FormDataMultiPart

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));
}
Also used : Response(javax.ws.rs.core.Response) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart)

Example 5 with FormDataMultiPart

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));
}
Also used : Response(javax.ws.rs.core.Response) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Aggregations

FormDataMultiPart (org.glassfish.jersey.media.multipart.FormDataMultiPart)48 FormDataBodyPart (org.glassfish.jersey.media.multipart.FormDataBodyPart)27 Test (org.junit.Test)27 Response (javax.ws.rs.core.Response)19 MediaType (javax.ws.rs.core.MediaType)14 Invocation (javax.ws.rs.client.Invocation)10 File (java.io.File)9 WebTarget (javax.ws.rs.client.WebTarget)9 JerseyTest (org.glassfish.jersey.test.JerseyTest)8 MultiPart (org.glassfish.jersey.media.multipart.MultiPart)7 FileDataBodyPart (org.glassfish.jersey.media.multipart.file.FileDataBodyPart)7 InputStream (java.io.InputStream)6 List (java.util.List)5 Map (java.util.Map)5 HashMap (java.util.HashMap)4 Client (javax.ws.rs.client.Client)4 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 Collections (java.util.Collections)3