Package com.sun.jersey.multipart

Examples of com.sun.jersey.multipart.MultiPart


        headers.add("content-type", "multipart/form-data;boundary=\"Boundary_1_531119742_1349960036122\"");

        final MultiPartReaderClientSide multiPartReader = new MultiPartReaderClientSide(null, new MultiPartConfig());

        final ByteArrayInputStream stream = new ByteArrayInputStream(requestBody.getBytes());
        final MultiPart multiPart = multiPartReader.readFrom(
                MultiPart.class,
                FormDataMultiPart.class,
                new Annotation[0],
                quotedMediaType,
                headers, stream);

        final BodyPart bodyPart = multiPart.getBodyParts().get(0);
        final BufferedReader reader = new BufferedReader(
                new InputStreamReader(
                        ((BodyPartEntity)bodyPart.getEntity()).getInputStream()
                )
        );

        assertEquals(FormDataMultiPart.class, multiPart.getClass());
        assertEquals(1, multiPart.getBodyParts().size());
        assertEquals(FormDataBodyPart.class, bodyPart.getClass());
        assertEquals("CONTENT", reader.readLine());
        assertEquals("part", bodyPart.getContentDisposition().getParameters().get("name"));
    }
View Full Code Here


        }
        String expected = sb.toString();
        WebResource.Builder builder = client.resource(getUri())
                .path("multipart/eleven").accept("multipart/mixed").type("multipart/mixed");
        try {
            MultiPart entity = new MultiPart().
                    bodyPart(expected, MediaType.TEXT_PLAIN_TYPE);
            MultiPart response = builder.put(MultiPart.class, entity);
            String actual = response.getBodyParts().get(0).getEntityAs(String.class);
            assertEquals("Length for multiplier " + multiplier, expected.length(), actual.length());
            assertEquals("Content for multiplier " + multiplier, expected, actual);
            response.cleanup();
        } catch (UniformInterfaceException e) {
            report(e);
            fail("Caught exception: " + e + " for multiplier " + multiplier);
        }
    }
View Full Code Here

    @Path("one")
    @GET
    @Produces("multipart/mixed")
    public Response one() {
        MultiPart entity = new MultiPart();
        // Exercise manually adding part(s) to the bodyParts property
        BodyPart part = new BodyPart("This is the only segment", new MediaType("text", "plain"));
        entity.getBodyParts().add(part);
        return Response.ok(entity).type("multipart/mixed").build();
    }
View Full Code Here

    @Path("two")
    @GET
    @Produces("multipart/mixed")
    public Response two() {
        // Exercise builder pattern with default content type
        return Response.ok(new MultiPart().
                bodyPart("This is the first segment", new MediaType("text", "plain")).
                bodyPart("<outer><inner>value</inner></outer>", new MediaType("text", "xml"))).build();
    }
View Full Code Here

    @GET
    @Produces("multipart/mixed")
    public Response three() {
        // Exercise builder pattern with explicit content type
        MultiPartBean bean = new MultiPartBean("myname", "myvalue");
        return Response.ok(new MultiPart().
                type(new MediaType("multipart", "mixed")).
                bodyPart("This is the first segment", new MediaType("text", "plain")).
                bodyPart(bean, new MediaType("x-application", "x-format"))).build();
    }
View Full Code Here

            if (n < 0) {
                break;
            }
            sb.append(buffer, 0, n);
        }
        return Response.ok(new MultiPart().bodyPart(sb.toString(), MediaType.TEXT_PLAIN_TYPE)).
                type(new MediaType("multipart", "mixed")).build();
    }
View Full Code Here

    @GET
    @Path("etag")
    @Produces("multipart/mixed")
    public Response etag() {
        MultiPart entity = new MultiPart();
        // Exercise manually adding part(s) to the bodyParts property
        BodyPart part = new BodyPart("This is the only segment", new MediaType("text", "plain"));
        part.getHeaders().add("ETag", "\"value\"");
        entity.getBodyParts().add(part);
        return Response.ok(entity).type("multipart/mixed").build();
    }
View Full Code Here

        startServer(ProducesFormDataUsingMultiPart.class);

        WebResource.Builder builder = client.resource(getUri()).
                accept("multipart/form-data");
        try {
            MultiPart result = builder.get(MultiPart.class);
            checkMediaType(new MediaType("multipart", "form-data"), result.getMediaType());
            assertEquals(2, result.getBodyParts().size());
            BodyPart part1 = result.getBodyParts().get(0);
            checkMediaType(new MediaType("text", "plain"), part1.getMediaType());
            checkEntity("Joe Blow\r\n", (BodyPartEntity) part1.getEntity());
            String value1 = part1.getHeaders().getFirst("Content-Disposition");
            assertEquals("form-data; name=\"field1\"", value1);
            BodyPart part2 = result.getBodyParts().get(1);
            checkMediaType(new MediaType("text", "plain"), part2.getMediaType());
            checkEntity("... contents of file1.txt ...\r\n", (BodyPartEntity) part2.getEntity());
            String value2 = part2.getHeaders().getFirst("Content-Disposition");
            assertEquals("form-data; name=\"pics\"; filename=\"file1.txt\"", value2);

            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

    public static class ProducesFormDataUsingMultiPart {

        @GET
        @Produces("multipart/form-data")
        public Response get() {
            MultiPart entity = new MultiPart();
            entity.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
            BodyPart part1 = new BodyPart();
            part1.setMediaType(MediaType.TEXT_PLAIN_TYPE);
            part1.getHeaders().add("Content-Disposition", "form-data; name=\"field1\"");
            part1.setEntity("Joe Blow\r\n");
            BodyPart part2 = new BodyPart();
            part2.setMediaType(MediaType.TEXT_PLAIN_TYPE);
            part2.getHeaders().add("Content-Disposition", "form-data; name=\"pics\"; filename=\"file1.txt\"");
            part2.setEntity("... contents of file1.txt ...\r\n");
            return Response.ok(entity.bodyPart(part1).bodyPart(part2)).build();
        }
View Full Code Here

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        for (int i = 0; i < 900 * 1024; i++)
            baos.write(65);
       
        MultiPart multiPartInput = new MultiPart().
                bodyPart(new ByteArrayInputStream("01234567890123456789012345678901234567890123456789".getBytes()), MediaType.APPLICATION_OCTET_STREAM_TYPE).
                bodyPart(baos.toByteArray(), MediaType.APPLICATION_OCTET_STREAM_TYPE);

        client.resource(getUri()).
                type("multipart/mixed").post(multiPartInput);
View Full Code Here

TOP

Related Classes of com.sun.jersey.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.