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

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


        return StringBody(UTF8.String(b));
    }

    public final static StringBody StringBody(final String s) {
        try {
            return new StringBody(s, charset);
        } catch (final UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
    }
View Full Code Here


    public static void main(final String[] args) {
        String url = null;
        // prepare Parts
        final Map<String,ContentBody> newparts = new LinkedHashMap<String,ContentBody>();
        try {
            newparts.put("foo", new StringBody("FooBar"));
            newparts.put("bar", new StringBody("BarFoo"));
        } catch (final UnsupportedEncodingException e) {
            System.out.println(e.getStackTrace());
        }
        final HTTPClient client = new HTTPClient();
        client.setUserAgent("foobar");
View Full Code Here

               String parameterName = arg.getName();
               if (arg.isSkippable(parameterName)){
                   continue;
               }
               FormBodyPart formPart;
               StringBody stringBody = new StringBody(arg.getValue(),
                       Charset.forName(contentEncoding == null ? "US-ASCII" : contentEncoding));
               formPart = new FormBodyPart(arg.getName(), stringBody);                  
               multiPart.addPart(formPart);
            }
View Full Code Here

        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("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

   
    public void uninstallBundle(String symbolicName, File f) throws Exception {
        final long bundleId = getBundleId(symbolicName);
       
        final MultipartEntity entity = new MultipartEntity();
        entity.addPart("action",new StringBody("uninstall"));
        executor.execute(
                builder.buildPostRequest(CONSOLE_BUNDLES_PATH+"/"+bundleId)
                .withCredentials(username, password)
                .withEntity(entity)
        ).assertStatus(200);
View Full Code Here

    /** Install a bundle using the Felix webconsole HTTP interface, with a specific start level */
    public void installBundle(File f, boolean startBundle, int startLevel) throws Exception {
       
        // Setup request for Felix Webconsole bundle install
        final MultipartEntity entity = new MultipartEntity();
        entity.addPart("action",new StringBody("install"));
        if(startBundle) {
            entity.addPart("bundlestart", new StringBody("true"));
        }
        entity.addPart("bundlefile", new FileBody(f));
       
        if(startLevel > 0) {
            entity.addPart("bundlestartlevel", new StringBody(String.valueOf(startLevel)));
            log.info("Installing bundle {} at start level {}", f.getName(), startLevel);
        } else {
            log.info("Installing bundle {} at default start level", f.getName());
        }
       
View Full Code Here

        // To start the bundle we POST action=start to its URL
        final String path = getBundlePath(symbolicName, null);
        log.info("Starting bundle {} via {}", symbolicName, path);
       
        final MultipartEntity entity = new MultipartEntity();
        entity.addPart("action",new StringBody("start"));
        executor.execute(
                builder.buildPostRequest(path)
                .withCredentials(username, password)
                .withEntity(entity)
        ).assertStatus(200);
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.