Package com.sun.jersey.multipart

Examples of com.sun.jersey.multipart.BodyPart


                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


    invoke(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        final MultiPart multiPartInput = new MultiPart();
        for (AttachmentInput attachment : myAttachments) {
          BodyPart bp = new BodyPart(attachment.getInputStream(), MediaType.APPLICATION_OCTET_STREAM_TYPE);
          FormDataContentDisposition.FormDataContentDispositionBuilder dispositionBuilder =
              FormDataContentDisposition.name(FILE_ATTACHMENT_CONTROL_NAME);
          dispositionBuilder.fileName(attachment.getFilename());
          final FormDataContentDisposition formDataContentDisposition = dispositionBuilder.build();
          bp.setContentDisposition(formDataContentDisposition);
          multiPartInput.bodyPart(bp);
        }

        postFileMultiPart(multiPartInput, attachmentsUri);
        return null;
View Full Code Here

                .path("multipart/one").accept("multipart/mixed");
        try {
            MultiPart result = builder.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);
View Full Code Here

                .path("multipart/two").accept("multipart/mixed");
        try {
            MultiPart result = builder.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);
View Full Code Here

                .path("multipart/three").accept("multipart/mixed");
        try {
            MultiPart result = builder.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();
View Full Code Here

    @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

    public Response four(MultiPart multiPart) throws IOException {
        if (!(multiPart.getBodyParts().size() == 2)) {
            return Response.ok("FAILED:  Number of body parts is " + multiPart.getBodyParts().size() + " instead of 2").build();
        }

        BodyPart part0 = multiPart.getBodyParts().get(0);
        if (!(part0.getMediaType().equals(new MediaType("text", "plain")))) {
            return Response.ok("FAILED:  First media type is " + part0.getMediaType()).build();
        }

        BodyPart part1 = multiPart.getBodyParts().get(1);
        if (!(part1.getMediaType().equals(new MediaType("x-application", "x-format")))) {
            return Response.ok("FAILED:  Second media type is " + part1.getMediaType()).build();
        }

        BodyPartEntity bpe = (BodyPartEntity) part0.getEntity();
        StringBuilder sb = new StringBuilder();
        InputStream stream = bpe.getInputStream();
        InputStreamReader reader = new InputStreamReader(stream);
        char[] buffer = new char[2048];
        while (true) {
            int n = reader.read(buffer);
            if (n < 0) {
                break;
            }
            sb.append(buffer, 0, n);
        }
        if (!sb.toString().equals("This is the first segment")) {
            return Response.ok("FAILED:  First part name = " + sb.toString()).build();
        }

        MultiPartBean bean = part1.getEntityAs(MultiPartBean.class);
        if (!bean.getName().equals("myname")) {
            return Response.ok("FAILED:  Second part name = " + bean.getName()).build();
        }
        if (!bean.getValue().equals("myvalue")) {
            return Response.ok("FAILED:  Second part value = " + bean.getValue()).build();
View Full Code Here

        if (!formData) {
            multiPart.setMediaType(mediaType);
        }

        for (MIMEPart mp : mm.getAttachments()) {
            BodyPart bodyPart = null;
            if (formData) {
                bodyPart = new FormDataBodyPart();
            } else {
                bodyPart = new BodyPart();
            }

            // Configure providers
            bodyPart.setProviders(providers);

            // Copy headers
            for (Header h : mp.getAllHeaders()) {
                bodyPart.getHeaders().add(h.getName(), h.getValue());
            }

            try {
                String contentType = bodyPart.getHeaders().getFirst("Content-Type");
                if (contentType != null)
                    bodyPart.setMediaType(MediaType.valueOf(contentType));

                bodyPart.getContentDisposition();
            } catch (IllegalArgumentException ex) {
                throw new WebApplicationException(ex, Status.BAD_REQUEST);
            }

            // Copy data into a BodyPartEntity structure
            bodyPart.setEntity(new BodyPartEntity(mp));
            // Add this BodyPart to our MultiPart
            multiPart.getBodyParts().add(bodyPart);
        }
       
        return multiPart;
View Full Code Here

    invoke(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        final MultiPart multiPartInput = new MultiPart();
        for (AttachmentInput attachment : myAttachments) {
          BodyPart bp = new BodyPart(attachment.getInputStream(), MediaType.APPLICATION_OCTET_STREAM_TYPE);
          FormDataContentDisposition.FormDataContentDispositionBuilder dispositionBuilder =
              FormDataContentDisposition.name(FILE_ATTACHMENT_CONTROL_NAME);
          dispositionBuilder.fileName(attachment.getFilename());
          final FormDataContentDisposition formDataContentDisposition = dispositionBuilder.build();
          bp.setContentDisposition(formDataContentDisposition);
          multiPartInput.bodyPart(bp);
        }

        postFileMultiPart(multiPartInput, attachmentsUri);
        return null;
View Full Code Here

    invoke(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        final MultiPart multiPartInput = new MultiPart();
        for (AttachmentInput attachment : myAttachments) {
          BodyPart bp = new BodyPart(attachment.getInputStream(), MediaType.APPLICATION_OCTET_STREAM_TYPE);
          FormDataContentDisposition.FormDataContentDispositionBuilder dispositionBuilder =
              FormDataContentDisposition.name(FILE_ATTACHMENT_CONTROL_NAME);
          dispositionBuilder.fileName(attachment.getFilename());
          final FormDataContentDisposition formDataContentDisposition = dispositionBuilder.build();
          bp.setContentDisposition(formDataContentDisposition);
          multiPartInput.bodyPart(bp);
        }

        postFileMultiPart(multiPartInput, attachmentsUri);
        return null;
View Full Code Here

TOP

Related Classes of com.sun.jersey.multipart.BodyPart

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.