Package org.glassfish.jersey.media.multipart

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


    @Test
    public void testXmlJAXBPart() {
        final WebTarget target = target().path("form/xml-jaxb-part");

        final FormDataMultiPart mp = new FormDataMultiPart();
        mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("bean").fileName("bean").build(),
                new Bean("BEAN"),
                MediaType.APPLICATION_XML_TYPE));
        mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("string").fileName("string").build(),
                "STRING"));

        final String s = target.request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), String.class);
        assertEquals("STRING:string,BEAN:bean", s);
    }
View Full Code Here


    @Test
    public void testFieldInjectedXmlJAXBPart() {
        final WebTarget target = target().path("form-field-injected/xml-jaxb-part");

        final FormDataMultiPart mp = new FormDataMultiPart();
        mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("bean").fileName("bean").build(),
                new Bean("BEAN"),
                MediaType.APPLICATION_XML_TYPE));
        mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("string").fileName("string").build(),
                "STRING"));

        final String s = target.request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), String.class);
        assertEquals("STRING:string,BEAN:bean", s);
    }
View Full Code Here

    public void testSpecificListAsParameter() throws Exception {
        final MyObject object = new MyObject("object");
        final List<MyObject> list = Arrays.asList(new MyObject("list1"), new MyObject("list2"));

        final FormDataMultiPart mp = new FormDataMultiPart();
        mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("object").fileName("object").build(),
                object, MediaType.APPLICATION_JSON_TYPE));
        mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("list").fileName("list").build(),
                list, MediaType.APPLICATION_JSON_TYPE));

        final Response response = target("listAsParameter")
                .request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE));
View Full Code Here

                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});
View Full Code Here

        @Override
        protected FormDataContentDisposition get(HttpContext context) {
            FormDataMultiPart formDataMultiPart = getEntity(context);

            FormDataBodyPart formDataBodyPart = formDataMultiPart.getField(name);
            if (formDataBodyPart == null) {
                return null;
            }

            return formDataMultiPart.getField(name).getFormDataContentDisposition();
View Full Code Here

        protected Object get(HttpContext context) {
            // Return the field value for the field specified by the sourceName property.
            final FormDataMultiPart formDataMultiPart = getEntity(context);

            List<FormDataBodyPart> formDataBodyParts = formDataMultiPart.getFields(parameter.getSourceName());
            FormDataBodyPart formDataBodyPart = (formDataBodyParts != null) ? formDataBodyParts.get(0) : null;

            MediaType mediaType = (formDataBodyPart != null) ? formDataBodyPart.getMediaType() : MediaType.TEXT_PLAIN_TYPE;

            MessageBodyWorkers messageBodyWorkers = context.getRequestContext().getWorkers();

            MessageBodyReader reader = messageBodyWorkers.getMessageBodyReader(
                    parameter.getRawType(),
                    parameter.getType(),
                    parameter.getAnnotations(),
                    mediaType);

            if (reader != null && !isPrimitiveType(parameter.getRawType())) {
                InputStream in;
                if (formDataBodyPart == null) {
                    if (parameter.getDefaultValue() != null) {
                        // Convert default value to bytes.
                        in = new ByteArrayInputStream(parameter.getDefaultValue().getBytes());
                    } else {
                        return null;
                    }
                } else {
                    in = ((BodyPartEntity) formDataBodyPart.getEntity()).getInputStream();
                }


                try {
                    //noinspection unchecked
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.
View Full Code Here

TOP

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

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.