Package org.apache.http.entity.mime

Examples of org.apache.http.entity.mime.FormBodyPart


        } finally {
            writer.close();
        }

        HttpMultipart multipart = new HttpMultipart("form-data", Charset.forName("UTF-8"), "foo");
        FormBodyPart p1 = new FormBodyPart(
                "field1",
                new InputStreamBody(new FileInputStream(tmpfile), s1 + ".tmp"));
        FormBodyPart p2 = new FormBodyPart(
                "field2",
                new InputStreamBody(new FileInputStream(tmpfile), s2 + ".tmp"));

        multipart.addBodyPart(p1);
        multipart.addBodyPart(p2);
View Full Code Here


    public void testMultipartFormStringPartsMultiCharsets() throws Exception {
        String s1 = constructString(SWISS_GERMAN_HELLO);
        String s2 = constructString(RUSSIAN_HELLO);

        HttpMultipart multipart = new HttpMultipart("form-data", "foo");
        FormBodyPart p1 = new FormBodyPart(
                "field1",
                new StringBody(s1, Charset.forName("ISO-8859-1")));
        FormBodyPart p2 = new FormBodyPart(
                "field2",
                new StringBody(s2, Charset.forName("KOI8-R")));

        multipart.addBodyPart(p1);
        multipart.addBodyPart(p2);
View Full Code Here

                mediaType.getType(),mediaType.getSubtype(),charset.toString(),CONTENT_ITEM_BOUNDARY);
            httpHeaders.putSingle(HttpHeaders.CONTENT_TYPE,contentType);
            HttpMultipart entity = new HttpMultipart("from-data", charset ,CONTENT_ITEM_BOUNDARY);
            //(2) serialising the metadata
            if(!isOmitMetadata(properties)){
                entity.addBodyPart(new FormBodyPart("metadata", new ClerezzaContentBody(
                    ci.getUri().getUnicodeString(), ci.getMetadata(),
                    rdfFormat)));
            }
            //(3) serialising the Content (Bloby)
            //(3.a) Filter based on parameter
            List<Entry<UriRef,Blob>> includedBlobs = filterBlobs(ci, properties);
            //(3.b) Serialise the filtered
            if(!includedBlobs.isEmpty()) {
                HttpMultipart content = new HttpMultipart("alternate", UTF8 ,"contentParts");
                for(Entry<UriRef,Blob> entry : includedBlobs){
                    content.addBodyPart(new FormBodyPart(entry.getKey().getUnicodeString(),
                        new BlobContentBody(entry.getValue()))); //no file name
                }
                //add all the blobs
                entity.addBodyPart(new FormBodyPart("content",new MultipartContentBody(content, null)));
            } //else no content to include
            Set<String> includeContentParts = getIncludedContentPartURIs(properties);
            if(includeContentParts != null){
                //(4) serialise EnhancementProperties
                if(includeContentParts.isEmpty() || includeContentParts.contains(
                    ENHANCEMENT_PROPERTIES_URI.getUnicodeString())) {
                    JSONObject object;
                    try {
                        object = toJson(properties);
                    } catch (JSONException e) {
                        throw new WebApplicationException(e,
                            Response.status(Response.Status.INTERNAL_SERVER_ERROR)
                            .entity("Unable to convert EnhancementProperties to " +
                                "JSON (values : "+properties+")!").build());
                    }
                    entity.addBodyPart(new FormBodyPart(
                        ENHANCEMENT_PROPERTIES_URI.getUnicodeString(),
                        new StringBody(object.toString(),MediaType.APPLICATION_JSON,UTF8)));
                }
                //(5) additional RDF metadata stored in contentParts
                for(Entry<UriRef,TripleCollection> entry : getContentParts(ci, TripleCollection.class).entrySet()){
                    if(includeContentParts.isEmpty() || includeContentParts.contains(
                        entry.getKey())){
                        entity.addBodyPart(new FormBodyPart(entry.getKey().getUnicodeString(),
                            new ClerezzaContentBody(null, //no file name
                                entry.getValue(),rdfFormat)));
                    } // else ignore this content part
                }
            }
View Full Code Here

            "content", //the name MUST BE "content"
            new MultipartContentBody(content));
        //now add the content (ordering is important, because the first
        //part will be assumed the original document and all following are
        //assumed alternate - transformed - versions
        content.addBodyPart(new FormBodyPart(
            "http://www.example.com/test.html", //the id of the content
            new StringBody(HTML_CONTENT, "text/html", UTF8)));
        content.addBodyPart(new FormBodyPart(
            "http://www.example.com/test.txt",
            new StringBody(extraTextConent, "text/plain", UTF8)));
       
        String receivedContent = executor.execute(
            builder.buildPostRequest(getEndpoint())
View Full Code Here

                Field.parse("Content-Type: multipart/form-data; boundary=foo"));
        message.setHeader(header);
       
        HttpMultipart multipart = new HttpMultipart();
        multipart.setParent(message);
        FormBodyPart p1 = new FormBodyPart(
                "field1",
                new StringBody("this stuff"));
        FormBodyPart p2 = new FormBodyPart(
                "field2",
                new StringBody("that stuff", Charset.forName("US-ASCII")));
        FormBodyPart p3 = new FormBodyPart(
                "field3",
                new StringBody("all kind of stuff"));
       
        multipart.addBodyPart(p1);
        multipart.addBodyPart(p2);
View Full Code Here

            writer.close();
        }
       
        HttpMultipart multipart = new HttpMultipart();
        multipart.setParent(message);
        FormBodyPart p1 = new FormBodyPart(
                "field1",
                new FileBody(tmpfile));
        FormBodyPart p2 = new FormBodyPart(
                "field2",
                new InputStreamBody(new FileInputStream(tmpfile), "file.tmp"));
       
        multipart.addBodyPart(p1);
        multipart.addBodyPart(p2);
View Full Code Here

            writer.close();
        }
       
        HttpMultipart multipart = new HttpMultipart();
        multipart.setParent(message);
        FormBodyPart p1 = new FormBodyPart(
                "field1",
                new FileBody(tmpfile));
        FormBodyPart p2 = new FormBodyPart(
                "field2",
                new InputStreamBody(new FileInputStream(tmpfile), "file.tmp"));
       
        multipart.addBodyPart(p1);
        multipart.addBodyPart(p2);
View Full Code Here

            writer.close();
        }
       
        HttpMultipart multipart = new HttpMultipart();
        multipart.setParent(message);
        FormBodyPart p1 = new FormBodyPart(
                "field1",
                new InputStreamBody(new FileInputStream(tmpfile), s1 + ".tmp"));
        FormBodyPart p2 = new FormBodyPart(
                "field2",
                new InputStreamBody(new FileInputStream(tmpfile), s2 + ".tmp"));
       
        multipart.addBodyPart(p1);
        multipart.addBodyPart(p2);
View Full Code Here

                Field.parse("Content-Type: multipart/form-data; boundary=foo"));
        message.setHeader(header);
       
        HttpMultipart multipart = new HttpMultipart();
        multipart.setParent(message);
        FormBodyPart p1 = new FormBodyPart(
                "field1",
                new StringBody(s1, Charset.forName("ISO-8859-1")));
        FormBodyPart p2 = new FormBodyPart(
                "field2",
                new StringBody(s2, Charset.forName("KOI8-R")));
       
        multipart.addBodyPart(p1);
        multipart.addBodyPart(p2);
View Full Code Here

               HTTPArgument arg = (HTTPArgument) args.next().getObjectValue();
               String parameterName = arg.getName();
               if (arg.isSkippable(parameterName)){
                   continue;
               }
               FormBodyPart formPart;
               StringBody stringBody = new StringBody(arg.getValue(), charset);
               formPart = new FormBodyPart(arg.getName(), stringBody);                  
               multiPart.addPart(formPart);
            }

            // Add any files
            // Cannot retrieve parts once added to the MultiPartEntity, so have to save them here.
View Full Code Here

TOP

Related Classes of org.apache.http.entity.mime.FormBodyPart

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.