Package org.glassfish.jersey.media.multipart

Examples of org.glassfish.jersey.media.multipart.MultiPart


    @Test
    public void testMultiPartFeatureOnClient() throws Exception {
        final Client client = ClientBuilder.newClient(new ClientConfig().connectorProvider(new TestConnector()))
                .register(MultiPartFeature.class);

        final MultiPart entity = new FormDataMultiPart()
                .bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("part").build(), "CONTENT"));

        final Response response = client.target("http://localhost").request()
                .post(Entity.entity(entity, MediaType.MULTIPART_FORM_DATA_TYPE));
View Full Code Here


    @Test
    public void testOne() {
        final WebTarget target = target().path("multipart/one");

        try {
            MultiPart result = target.request("multipart/mixed").get(MultiPart.class);
            checkMediaType(new MediaType("multipart", "mixed"), result.getMediaType());
            assertEquals(1, result.getBodyParts().size());
            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 (IOException e) {
            e.printStackTrace(System.out);
            fail("Caught exception: " + e);
        } catch (ParseException e) {
            e.printStackTrace(System.out);
View Full Code Here

    @Test
    public void testETag() {
        final WebTarget target = target().path("multipart/etag");

        try {
            MultiPart result = target.request("multipart/mixed").get(MultiPart.class);
            checkMediaType(new MediaType("multipart", "mixed"), result.getMediaType());
            assertEquals(1, result.getBodyParts().size());
            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 (IOException e) {
            e.printStackTrace(System.out);
            fail("Caught exception: " + e);
        } catch (ParseException e) {
            e.printStackTrace(System.out);
View Full Code Here

    @Test
    public void testTwo() {
        final WebTarget target = target().path("multipart/two");
        try {
            MultiPart result = target.request("multipart/mixed").get(MultiPart.class);
            checkMediaType(new MediaType("multipart", "mixed"), result.getMediaType());
            assertEquals(2, result.getBodyParts().size());
            BodyPart part1 = result.getBodyParts().get(0);
            checkMediaType(new MediaType("text", "plain"), part1.getMediaType());
            checkEntity("This is the first segment", (BodyPartEntity) part1.getEntity());
            BodyPart part2 = result.getBodyParts().get(1);
            checkMediaType(new MediaType("text", "xml"), part2.getMediaType());
            checkEntity("<outer><inner>value</inner></outer>", (BodyPartEntity) part2.getEntity());

            result.getParameterizedHeaders();
            result.cleanup();
        } catch (IOException e) {
            e.printStackTrace(System.out);
            fail("Caught exception: " + e);
        } catch (ParseException e) {
            e.printStackTrace(System.out);
View Full Code Here

    @Test
    public void testThree() {
        final WebTarget target = target().path("multipart/three");
        try {
            MultiPart result = target.request("multipart/mixed").get(MultiPart.class);
            checkMediaType(new MediaType("multipart", "mixed"), result.getMediaType());
            assertEquals(2, result.getBodyParts().size());
            BodyPart part1 = result.getBodyParts().get(0);
            checkMediaType(new MediaType("text", "plain"), part1.getMediaType());
            checkEntity("This is the first segment", (BodyPartEntity) part1.getEntity());
            BodyPart part2 = result.getBodyParts().get(1);
            checkMediaType(new MediaType("x-application", "x-format"), part2.getMediaType());
            MultiPartBean entity = part2.getEntityAs(MultiPartBean.class);
            assertEquals("myname", entity.getName());
            assertEquals("myvalue", entity.getValue());

            result.getParameterizedHeaders();
            result.cleanup();
        } catch (IOException e) {
            e.printStackTrace(System.out);
            fail("Caught exception: " + e);
        } catch (ParseException e) {
            e.printStackTrace(System.out);
View Full Code Here

    @Test
    public void testFour() {
        final WebTarget target = target().path("multipart/four");

        MultiPartBean bean = new MultiPartBean("myname", "myvalue");
        MultiPart entity = new MultiPart().
                bodyPart("This is the first segment", new MediaType("text", "plain")).
                bodyPart(bean, new MediaType("x-application", "x-format"));
        String response = target.request("text/plain").put(Entity.entity(entity, "multipart/mixed"), String.class);
        if (!response.startsWith("SUCCESS:")) {
            fail("Response is '" + response + "'");
View Full Code Here

    @Test
    public void testFourBiz() {
        final WebTarget target = target().path("multipart/four");

        MultiPartBean bean = new MultiPartBean("myname", "myvalue");
        MultiPart entity = new MultiPart().
                bodyPart("This is the first segment", new MediaType("text", "plain")).
                bodyPart(bean, new MediaType("x-application", "x-format"));
        String response = target.request("text/plain").header("Content-Type", "multipart/mixed").
                put(Entity.entity(entity, "multipart/mixed"), String.class);
        if (!response.startsWith("SUCCESS:")) {
View Full Code Here

    @Test(expected = ProcessingException.class)
    public void testSix() {
        target()
                .path("multipart/six")
                .request("text/plain")
                .post(Entity.entity(new MultiPart(), "multipart/mixed"), String.class);

        fail("Should have thrown an exception about zero body parts");
    }
View Full Code Here

    @Test
    public void testTen() {
        final WebTarget target = target().path("multipart/ten");

        MultiPartBean bean = new MultiPartBean("myname", "myvalue");
        MultiPart entity = new MultiPart().
                bodyPart(bean, new MediaType("x-application", "x-format")).
                bodyPart("", MediaType.APPLICATION_OCTET_STREAM_TYPE);
        String response = target.request("text/plain").put(Entity.entity(entity, "multipart/mixed"), String.class);
        ;
        if (!response.startsWith("SUCCESS:")) {
View Full Code Here

     */
    @Test
    public void testTwelve() throws Exception {
        final WebTarget target = target().path("multipart/twelve");

        MultiPart entity = new MultiPart().bodyPart("CONTENT", MediaType.TEXT_PLAIN_TYPE);
        MultiPart response = target.request("multipart/mixed").put(Entity.entity(entity, "multipart/mixed"), MultiPart.class);
        String actual = response.getBodyParts().get(0).getEntityAs(String.class);
        assertEquals("CONTENT", actual);
        response.cleanup();
    }
View Full Code Here

TOP

Related Classes of org.glassfish.jersey.media.multipart.MultiPart

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.