Package com.sun.jersey.multipart

Examples of com.sun.jersey.multipart.FormDataBodyPart


        Set<String> keys = new HashSet<String>();

        for (BodyPart bpart : data.getBodyParts()) {
            log.debug("Found body part of type {}", bpart.getClass());
            if (bpart instanceof FormDataBodyPart) {
                FormDataBodyPart dbp = (FormDataBodyPart) bpart;
                String name = dbp.getName();
                log.debug("Detected form parameter \"{}\".", name);
                if (name.equals("file")) {
                    file = bpart.getEntityAs(File.class);
                } else {
                    String value = dbp.getValue();
                    if (name.equals("format") && !value.equals("auto")) {
                        log.debug(" -- Expected format : {}", value);
                        format = value;
                    } else if (name.equals("url")) try {
                        URI.create(value); // To throw 400 if malformed.
View Full Code Here


        builder = addApplicationKeyHeader(builder);
        if (platformParameters.requireResponseBody()) {
            builder.accept(mediaType);
        }
        FormDataMultiPart form = new FormDataMultiPart();
        form.bodyPart(new FormDataBodyPart("file", content, MediaType.APPLICATION_OCTET_STREAM_TYPE));
        return parseResponseWithoutId(responseClass, builder.post(ClientResponse.class, form), CREATED.getStatusCode());

    }
View Full Code Here

        builder = addApplicationKeyHeader(builder);
        if (platformParameters.requireResponseBody()) {
            builder.accept(mediaType);
        }
        FormDataMultiPart form = new FormDataMultiPart();
        form.bodyPart(new FormDataBodyPart("file", content, MediaType.APPLICATION_OCTET_STREAM_TYPE));
        return parseResponseWithoutId(responseClass, builder.put(ClientResponse.class, form), OK.getStatusCode());
    }
View Full Code Here

    @Test
    public void testPart() {
        WebResource webResource = resource().path("form/part");

        FormDataMultiPart mp = new FormDataMultiPart();
        FormDataBodyPart p = new FormDataBodyPart(FormDataContentDisposition.name("part").build(), "CONTENT");
        mp.bodyPart(p);

        String s = webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(String.class, mp);
        Assert.assertEquals("CONTENT", s);
    }
View Full Code Here

    @Test
    public void testPartWithFileName() {
        WebResource webResource = resource().path("form/part-file-name");

        FormDataMultiPart mp = new FormDataMultiPart();
        FormDataBodyPart p = new FormDataBodyPart(FormDataContentDisposition.name("part").fileName("file").build(), "CONTENT");
        mp.bodyPart(p);

        String s = webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(String.class, mp);
        Assert.assertEquals("CONTENT:file", s);
    }
View Full Code Here

    @Test
    public void testXmlJAXBPart() {
        WebResource webResource = resource().path("form/xml-jaxb-part");

        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"));

        String s = webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(String.class, mp);
        Assert.assertEquals("STRING:string,BEAN:bean", s);
    }
View Full Code Here

        }

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

            // Configure providers
View Full Code Here

  public static ClientResponse addPhoto(WebResource resource, String filename, String auth) {
    File file = new File(filename);

    FormDataMultiPart form = new FormDataMultiPart();
    form.bodyPart(new FormDataBodyPart("csrf", "csrf"));
    form.bodyPart(new FileDataBodyPart("file", file));

    return resource
        .path("addphoto.jsp")
        .cookie(new Cookie(WebHelper.AUTH_COOKIE, auth, "/", "127.0.0.1", 1))
View Full Code Here

      String description) throws UniformInterfaceException,
      ClientHandlerException, FileNotFoundException, ParseException,
      RequestException {
    FormDataMultiPart part = new FormDataMultiPart();
    if (description != null) {
      part.bodyPart(new FormDataBodyPart("description", description));
    }
    part.bodyPart(new FileDataBodyPart("file", file,
        MediaType.APPLICATION_OCTET_STREAM_TYPE));
    ClientResponse response = (ClientResponse) webResource
        .accept(MediaType.APPLICATION_XML)
View Full Code Here

        // In this case we setup the parameter from a multipart request
        File file = null;
        for (BodyPart bpart : data.getBodyParts()) {
            log.debug("is a {}", bpart.getClass());
            if (bpart instanceof FormDataBodyPart) {
                FormDataBodyPart dbp = (FormDataBodyPart) bpart;
                if (dbp.getName().equals("file")) {
                    file = bpart.getEntityAs(File.class);
                }
                // We put all the parameters field
                // XXX We supports here only simple fields
                // We do NOT support the sent of additional files, for
                // example
                if (dbp.isSimple()) {
                    if (this.parameters.containsKey(dbp.getName())) {
                        this.parameters.get(dbp.getName()).add(dbp.getValue());
                    } else {
                        List<String> values = new ArrayList<String>();
                        values.add(dbp.getValue());
                        this.parameters.put(dbp.getName(), values);
                    }
                }
            }
        }
        // Then add the file
View Full Code Here

TOP

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