Search in sources :

Example 36 with MultiPart

use of org.glassfish.jersey.media.multipart.MultiPart in project jersey by jersey.

the class MultiPartReaderWriterTest method testFourBiz.

@Test
public void testFourBiz() {
    final WebTarget target = target().path("multipart/four");
    final MultiPartBean bean = new MultiPartBean("myname", "myvalue");
    final MultiPart entity = new MultiPart().bodyPart("This is the first segment", new MediaType("text", "plain")).bodyPart(bean, new MediaType("x-application", "x-format"));
    final String response = target.request("text/plain").header("Content-Type", "multipart/mixed").put(Entity.entity(entity, "multipart/mixed"), String.class);
    if (!response.startsWith("SUCCESS:")) {
        fail("Response is '" + response + "'");
    }
}
Also used : MultiPart(org.glassfish.jersey.media.multipart.MultiPart) MediaType(javax.ws.rs.core.MediaType) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test)

Example 37 with MultiPart

use of org.glassfish.jersey.media.multipart.MultiPart in project jersey by jersey.

the class MultiPartReaderWriterTest method testThirteen.

/**
     * Call clean up explicitly.
     */
@Test
public void testThirteen() {
    final WebTarget target = target().path("multipart/thirteen");
    final MultiPart entity = new MultiPart().bodyPart("CONTENT", MediaType.TEXT_PLAIN_TYPE);
    final String response = target.request("multipart/mixed").put(Entity.entity(entity, "multipart/mixed"), String.class);
    assertEquals("cleanup", response);
}
Also used : MultiPart(org.glassfish.jersey.media.multipart.MultiPart) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test)

Example 38 with MultiPart

use of org.glassfish.jersey.media.multipart.MultiPart in project jersey by jersey.

the class MultiPartReaderWriterTest method testETag.

@Test
public void testETag() {
    final WebTarget target = target().path("multipart/etag");
    try {
        final MultiPart result = target.request("multipart/mixed").get(MultiPart.class);
        checkMediaType(new MediaType("multipart", "mixed"), result.getMediaType());
        assertEquals(1, result.getBodyParts().size());
        final BodyPart part = result.getBodyParts().get(0);
        checkMediaType(new MediaType("text", "plain"), part.getMediaType());
        checkEntity("This is the only segment", (BodyPartEntity) part.getEntity());
        assertEquals("\"value\"", part.getHeaders().getFirst("ETag"));
        result.getParameterizedHeaders();
        result.cleanup();
    } catch (final IOException | ParseException e) {
        e.printStackTrace(System.out);
        fail("Caught exception: " + e);
    }
}
Also used : BodyPart(org.glassfish.jersey.media.multipart.BodyPart) MultiPart(org.glassfish.jersey.media.multipart.MultiPart) MediaType(javax.ws.rs.core.MediaType) WebTarget(javax.ws.rs.client.WebTarget) IOException(java.io.IOException) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 39 with MultiPart

use of org.glassfish.jersey.media.multipart.MultiPart in project jersey by jersey.

the class MultiPartReaderWriterTest method testThree.

@Test
public void testThree() {
    final WebTarget target = target().path("multipart/three");
    try {
        final MultiPart result = target.request("multipart/mixed").get(MultiPart.class);
        checkMediaType(new MediaType("multipart", "mixed"), result.getMediaType());
        assertEquals(2, result.getBodyParts().size());
        final BodyPart part1 = result.getBodyParts().get(0);
        checkMediaType(new MediaType("text", "plain"), part1.getMediaType());
        checkEntity("This is the first segment", (BodyPartEntity) part1.getEntity());
        final BodyPart part2 = result.getBodyParts().get(1);
        checkMediaType(new MediaType("x-application", "x-format"), part2.getMediaType());
        final MultiPartBean entity = part2.getEntityAs(MultiPartBean.class);
        assertEquals("myname", entity.getName());
        assertEquals("myvalue", entity.getValue());
        result.getParameterizedHeaders();
        result.cleanup();
    } catch (final IOException | ParseException e) {
        e.printStackTrace(System.out);
        fail("Caught exception: " + e);
    }
}
Also used : BodyPart(org.glassfish.jersey.media.multipart.BodyPart) MultiPart(org.glassfish.jersey.media.multipart.MultiPart) MediaType(javax.ws.rs.core.MediaType) WebTarget(javax.ws.rs.client.WebTarget) IOException(java.io.IOException) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 40 with MultiPart

use of org.glassfish.jersey.media.multipart.MultiPart in project jersey by jersey.

the class MultiPartReaderWriterTest method testTwelve.

/**
     * Echo back the multipart that was sent.
     */
@Test
public void testTwelve() throws Exception {
    final WebTarget target = target().path("multipart/twelve");
    final MultiPart entity = new MultiPart().bodyPart("CONTENT", MediaType.TEXT_PLAIN_TYPE);
    final MultiPart response = target.request("multipart/mixed").put(Entity.entity(entity, "multipart/mixed"), MultiPart.class);
    final String actual = response.getBodyParts().get(0).getEntityAs(String.class);
    assertEquals("CONTENT", actual);
    response.cleanup();
}
Also used : MultiPart(org.glassfish.jersey.media.multipart.MultiPart) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test)

Aggregations

MultiPart (org.glassfish.jersey.media.multipart.MultiPart)63 WebTarget (javax.ws.rs.client.WebTarget)42 ProcessingException (javax.ws.rs.ProcessingException)28 BatfishException (org.batfish.common.BatfishException)28 JSONObject (org.codehaus.jettison.json.JSONObject)20 Test (org.junit.Test)16 Nullable (javax.annotation.Nullable)15 MediaType (javax.ws.rs.core.MediaType)15 BodyPart (org.glassfish.jersey.media.multipart.BodyPart)11 FormDataBodyPart (org.glassfish.jersey.media.multipart.FormDataBodyPart)11 Response (javax.ws.rs.core.Response)10 FormDataMultiPart (org.glassfish.jersey.media.multipart.FormDataMultiPart)10 Client (javax.ws.rs.client.Client)7 StreamDataBodyPart (org.glassfish.jersey.media.multipart.file.StreamDataBodyPart)7 IOException (java.io.IOException)5 ParseException (java.text.ParseException)5 FileDataBodyPart (org.glassfish.jersey.media.multipart.file.FileDataBodyPart)5 JerseyClientBuilder (io.dropwizard.client.JerseyClientBuilder)3 File (java.io.File)3 Path (javax.ws.rs.Path)3