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

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


       
        HttpMultipart multipart = new HttpMultipart("form-data");
        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("form-data");
        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

         
          Map<String, String> postMap = request.getPostMap();
          for (String key : postMap.keySet()) {
            String value = postMap.get(key);
            value = value==null ? "" : value;
            entity.addPart(key, new StringBody(value, Charset.forName(charset)));
          }
         
          Map<String, File> fileMap = request.getFileMap();
          for (String key : fileMap.keySet()) {
            File value = fileMap.get(key);
View Full Code Here

                try {
                    if (!multiPart) {
                        enclodingRequest.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
                    } else {
                        for (NameValuePair nvp : nvps) {
                            multipartEntity.addPart(nvp.getName(), new StringBody(nvp.getValue()));
                        }
                        enclodingRequest.setEntity(multipartEntity);
                    }
                } catch (UnsupportedEncodingException e) {
                    LOG.severe("Could not find UTF-8 encoding, something is really wrong", e);
View Full Code Here

public class TestMultipartContentBody {

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

        Assert.assertEquals("ISO-8859-1", 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());

        final StringBody b2 = new StringBody("more text",
                ContentType.create("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

        Assert.assertEquals(MIME.ENC_8BIT, b2.getTransferEncoding());
    }

    @Test(expected=IllegalArgumentException.class)
    public void testStringBodyInvalidConstruction1() throws Exception {
        new StringBody(null, ContentType.DEFAULT_TEXT);
    }
View Full Code Here

        new StringBody(null, ContentType.DEFAULT_TEXT);
    }

    @Test(expected=IllegalArgumentException.class)
    public void testStringBodyInvalidConstruction2() throws Exception {
        new StringBody("stuff", (ContentType) null);
    }
View Full Code Here

      this.mimeType = mimeType;
    }
   
    void addPart(MultipartEntityBuilder builder) {
      if (stringData != null) {
        builder.addPart(name, new StringBody(stringData, ContentType.create(mimeType)));
      }
      if (fileData != null) {
        builder.addPart(name, new FileBody(fileData, ContentType.create(mimeType)));
      }
     
View Full Code Here

      request = new HttpGet(url);
    }
    else if(method.equals("POST"))
    {
      MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
      entity.addPart("text", new StringBody(body));

      request = new HttpPost(url);

      ((HttpPost) request).setEntity(entity);
    }
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.