Package org.apache.http.entity.mime.content

Examples of org.apache.http.entity.mime.content.StringBody


        multipart.setParent(message);
        BodyPart p1 = new BodyPart();
        Header h1 = new Header();
        h1.addField(Field.parse("Content-Type: text/plain"));
        p1.setHeader(h1);
        p1.setBody(new StringBody("this stuff"));
        BodyPart p2 = new BodyPart();
        Header h2 = new Header();
        h2.addField(Field.parse("Content-Type: text/plain"));
        p2.setHeader(h2);
        p2.setBody(new StringBody("that stuff"));
        BodyPart p3 = new BodyPart();
        Header h3 = new Header();
        h3.addField(Field.parse("Content-Type: text/plain"));
        p3.setHeader(h3);
        p3.setBody(new StringBody("all kind of stuff"));

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


       
        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);
        multipart.addBodyPart(p3);
       
View Full Code Here

       
        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);
       
        ByteArrayOutputStream out1 = new ByteArrayOutputStream();
View Full Code Here

        assertNull(p2);
    }

    public void testRepeatable() throws Exception {
        MultipartEntity entity = new MultipartEntity();
        entity.addPart("p1", new StringBody("blah blah"));
        entity.addPart("p2", new StringBody("yada yada"));
        assertTrue(entity.isRepeatable());
        assertFalse(entity.isChunked());
        assertFalse(entity.isStreaming());

        long len = entity.getContentLength();
View Full Code Here

    @Test
    public void testMultipartFormStringParts() throws Exception {
        HttpMultipart multipart = new HttpMultipart("form-data", "foo");
        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);
        multipart.addBodyPart(p3);
View Full Code Here

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

        ByteArrayOutputStream out1 = new ByteArrayOutputStream();
View Full Code Here

public class TestMultipartContentBody {

    @Test
    public void testStringBody() throws Exception {
        StringBody b1 = new StringBody("text");
        Assert.assertEquals(4, b1.getContentLength());

        Charset defCharset = Charset.defaultCharset();

        Assert.assertEquals(defCharset.name(), b1.getCharset());

        Assert.assertNull(b1.getFilename());
        Assert.assertEquals("text/plain", b1.getMimeType());
        Assert.assertEquals("text", b1.getMediaType());
        Assert.assertEquals("plain", b1.getSubType());

        Assert.assertEquals(MIME.ENC_8BIT, b1.getTransferEncoding());

        StringBody b2 = new StringBody("more text", "text/other", MIME.DEFAULT_CHARSET);
        Assert.assertEquals(9, b2.getContentLength());
        Assert.assertEquals(MIME.DEFAULT_CHARSET.name(), b2.getCharset());

        Assert.assertNull(b2.getFilename());
        Assert.assertEquals("text/other", b2.getMimeType());
        Assert.assertEquals("text", b2.getMediaType());
        Assert.assertEquals("other", b2.getSubType());

        Assert.assertEquals(MIME.ENC_8BIT, b2.getTransferEncoding());
    }
View Full Code Here

              "application/zip"));
      entity.addPart("dsym", new FileBody(
          new File(appPath + "/" + properties.get("appName") + ".dSYM.zip"),
          "application/zip"));     
      entity.addPart("notes",
          new StringBody(properties.get("releaseNotes"),
              "text/plain", Charset.forName("UTF-8")));     
      post.setEntity(entity);
                 
      // Run the request
      HttpResponse response = client.execute(post);
View Full Code Here

                            .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())){
View Full Code Here

        //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())
            .withHeader("Accept","text/rdf+nt")
            .withEntity(contentItem)
View Full Code Here

TOP

Related Classes of org.apache.http.entity.mime.content.StringBody

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.