Package org.glassfish.jersey.media.multipart

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


    @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


        @GET
        @Produces("multipart/mixed")
        public Response one() {
            MultiPart entity = new MultiPart();
            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

                        mt = new MediaType(contentType.substring(0, ind), contentType.substring(ind + 1));
                    } else {
                        mt = new MediaType(contentType, MediaType.WILDCARD);
                    }
                }
                BodyPart bp;
                if (logger.isLoggable(Level.FINEST)) {
                    logger.log(Level.FINEST, "addToMultipart[{0}]: name: {1}, type: {2}", new Object[]{index, part.getName(), mt});
                }
                if (client2Server) {
                    bp = new FormDataBodyPart(part.getName(), part, mt);
                } else {
                    bp = new BodyPart(part, mt);
                    ContentDisposition cd = ContentDisposition.type("file").fileName(part.getName()).build();
                    if (logger.isLoggable(Level.FINEST)) {
                        logger.log(Level.FINEST, "addToMultipart[{0}]: Content Disposition: {1}", new Object[]{index, cd});
                    }
                    bp.setContentDisposition(cd);
                }
                Properties props = part.getProperties();
                for (Map.Entry<Object, Object> entry : props.entrySet()) {
                    if (logger.isLoggable(Level.FINEST)) {
                        logger.log(Level.FINEST, "addToMultipart[{0}]: Header: {1}: {2}",
                                new Object[]{index, addContentPrefix((String) entry.getKey()), entry.getValue()});
                    }
                    bp.getHeaders().add(addContentPrefix((String) entry.getKey()),
                            (String) entry.getValue());
                }
                mp.bodyPart(bp);
            }
            return mp;
View Full Code Here

            String userAgent = headers.getFirst(HttpHeaders.USER_AGENT);
            fileNameFix = userAgent != null && userAgent.contains(" MSIE ");
        }

        for (MIMEPart mimePart : mimeMessage.getAttachments()) {
            BodyPart bodyPart = formData ? new FormDataBodyPart(fileNameFix) : new BodyPart();

            // Configure providers.
            bodyPart.setMessageBodyWorkers(workers);

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

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

                bodyPart.getContentDisposition();
            } catch (IllegalArgumentException ex) {
                throw new BadRequestException(ex);
            }

            // Copy data into a BodyPartEntity structure.
            bodyPart.setEntity(new BodyPartEntity(mimePart));

            // Add this BodyPart to our MultiPart.
            multiPart.getBodyParts().add(bodyPart);
        }
View Full Code Here

TOP

Related Classes of org.glassfish.jersey.media.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.