Search in sources :

Example 6 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 7 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 8 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)

Example 9 with FormDataMultiPart

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

Example 10 with FormDataMultiPart

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

Aggregations

FormDataMultiPart (org.glassfish.jersey.media.multipart.FormDataMultiPart)32 Test (org.junit.Test)25 FormDataBodyPart (org.glassfish.jersey.media.multipart.FormDataBodyPart)16 Response (javax.ws.rs.core.Response)10 Invocation (javax.ws.rs.client.Invocation)9 WebTarget (javax.ws.rs.client.WebTarget)7 JerseyTest (org.glassfish.jersey.test.JerseyTest)7 MediaType (javax.ws.rs.core.MediaType)6 File (java.io.File)5 MultiPart (org.glassfish.jersey.media.multipart.MultiPart)5 Client (javax.ws.rs.client.Client)3 PayaraClientException (fish.payara.arquillian.container.payara.clientutils.PayaraClientException)2 JerseyClientBuilder (io.dropwizard.client.JerseyClientBuilder)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 List (java.util.List)2 DeploymentException (org.jboss.arquillian.container.spi.client.container.DeploymentException)2 ErrorMessage (io.dropwizard.jersey.errors.ErrorMessage)1 FileOutputStream (java.io.FileOutputStream)1 Map (java.util.Map)1