Search in sources :

Example 66 with MediaType

use of javax.ws.rs.core.MediaType in project jersey by jersey.

the class FormDataMultiPartBufferTest method testConsumesFormDataResource.

@Test
public void testConsumesFormDataResource() {
    MultiPartBean bean = new MultiPartBean("myname", "myvalue");
    FormDataMultiPart entity = new FormDataMultiPart().field("foo", "bar").field("baz", "bop").field("bean", bean, new MediaType("x-application", "x-format"));
    String response = target().path("ConsumesFormDataResource").request("text/plain").put(Entity.entity(entity, "multipart/form-data"), String.class);
    if (!response.startsWith("SUCCESS:")) {
        fail("Response is '" + response + "'");
    }
}
Also used : FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) MediaType(javax.ws.rs.core.MediaType) Test(org.junit.Test)

Example 67 with MediaType

use of javax.ws.rs.core.MediaType in project jersey by jersey.

the class FormDataMultiPartReaderWriterTest method testProducesFormDataResource.

@Test
public void testProducesFormDataResource() throws Exception {
    final Invocation.Builder request = target().path("ProducesFormDataResource").request("multipart/form-data");
    final FormDataMultiPart result = request.get(FormDataMultiPart.class);
    checkMediaType(new MediaType("multipart", "form-data"), result.getMediaType());
    assertEquals(3, result.getFields().size());
    assertNotNull(result.getField("foo"));
    assertEquals("bar", result.getField("foo").getValue());
    assertNotNull(result.getField("baz"));
    assertEquals("bop", result.getField("baz").getValue());
    assertNotNull(result.getField("bean"));
    final MultiPartBean bean = result.getField("bean").getValueAs(MultiPartBean.class);
    assertNotNull(bean);
    assertEquals("myname", bean.getName());
    assertEquals("myvalue", bean.getValue());
    result.cleanup();
}
Also used : Invocation(javax.ws.rs.client.Invocation) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) MediaType(javax.ws.rs.core.MediaType) Test(org.junit.Test)

Example 68 with MediaType

use of javax.ws.rs.core.MediaType in project jersey by jersey.

the class MultiPartReaderWriterTest method testFour.

@Test
public void testFour() {
    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").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 69 with MediaType

use of javax.ws.rs.core.MediaType in project jersey by jersey.

the class MultiPartReaderWriterTest method testOne.

@Test
public void testOne() {
    final WebTarget target = target().path("multipart/one");
    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());
        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 70 with MediaType

use of javax.ws.rs.core.MediaType in project jersey by jersey.

the class MultiPartReaderWriterTest method testTen.

/**
     * Zero length body part.
     */
@Test
public void testTen() {
    final WebTarget target = target().path("multipart/ten");
    final MultiPartBean bean = new MultiPartBean("myname", "myvalue");
    final MultiPart entity = new MultiPart().bodyPart(bean, new MediaType("x-application", "x-format")).bodyPart("", MediaType.APPLICATION_OCTET_STREAM_TYPE);
    final String response = target.request("text/plain").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)

Aggregations

MediaType (javax.ws.rs.core.MediaType)477 Test (org.junit.Test)184 Path (javax.ws.rs.Path)44 Produces (javax.ws.rs.Produces)44 ByteArrayInputStream (java.io.ByteArrayInputStream)42 WebApplicationException (javax.ws.rs.WebApplicationException)41 IOException (java.io.IOException)40 Response (javax.ws.rs.core.Response)40 InputStream (java.io.InputStream)38 ArrayList (java.util.ArrayList)31 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)31 Type (java.lang.reflect.Type)30 Consumes (javax.ws.rs.Consumes)27 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)27 GET (javax.ws.rs.GET)25 OutputStream (java.io.OutputStream)23 Annotation (java.lang.annotation.Annotation)23 HashSet (java.util.HashSet)22 Locale (java.util.Locale)22 HashMap (java.util.HashMap)21