Examples of MultipartEntity


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

      final HttpPost httpPost = new HttpPost(url.toNormalform(true, false, true, false));

        setHost(vhost); // overwrite resolved IP, needed for shared web hosting DO NOT REMOVE, see http://en.wikipedia.org/wiki/Shared_web_hosting_service
      if (vhost == null) setHost("127.0.0.1");

        final MultipartEntity multipartEntity = new MultipartEntity();
        for (final Entry<String,ContentBody> part : post.entrySet())
            multipartEntity.addPart(part.getKey(), part.getValue());
        // statistics
        this.upbytes = multipartEntity.getContentLength();

        if (usegzip) {
            httpPost.setEntity(new GzipCompressingEntity(multipartEntity));
        } else {
            httpPost.setEntity(multipartEntity);
View Full Code Here

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

            if(contentEncoding != null && contentEncoding.length() == 0) {
                contentEncoding = null;
            }

            // Write the request to our own stream
            MultipartEntity multiPart = new MultipartEntity(
                    getDoBrowserCompatibleMultipart() ? HttpMultipartMode.BROWSER_COMPATIBLE : HttpMultipartMode.STRICT);
            // Create the parts
            // Add any parameters
            PropertyIterator args = getArguments().iterator();
            while (args.hasNext()) {
               HTTPArgument arg = (HTTPArgument) args.next().getObjectValue();
               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);
            }

            // Add any files
            // Cannot retrieve parts once added to the MultiPartEntity, so have to save them here.
            ViewableFileBody[] fileBodies = new ViewableFileBody[files.length];
            for (int i=0; i < files.length; i++) {
                HTTPFileArg file = files[i];
                fileBodies[i] = new ViewableFileBody(new File(file.getPath()), file.getMimeType());
                multiPart.addPart(file.getParamName(),fileBodies[i]);
            }

            post.setEntity(multiPart);

            if (multiPart.isRepeatable()){
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                for(ViewableFileBody fileBody : fileBodies){
                    fileBody.hideFileData = true;
                }
                multiPart.writeTo(bos);
                for(ViewableFileBody fileBody : fileBodies){
                    fileBody.hideFileData = false;
                }
                bos.flush();
                // We get the posted bytes using the encoding used to create it
View Full Code Here

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

    public static Test suite() {
        return new TestSuite(TestMultipartFormHttpEntity.class);
    }

    public void testExplictContractorParams() throws Exception {
        MultipartEntity entity = new MultipartEntity(
                HttpMultipartMode.BROWSER_COMPATIBLE,
                "whatever",
                CharsetUtil.getCharset("UTF-8"));

        assertNull(entity.getContentEncoding());
        assertNotNull(entity.getContentType());
        Header header = entity.getContentType();
        HeaderElement[] elems = header.getElements();
        assertNotNull(elems);
        assertEquals(1, elems.length);

        HeaderElement elem = elems[0];
View Full Code Here

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

        assertNotNull(p2);
        assertEquals("UTF-8", p2.getValue());
    }

    public void testImplictContractorParams() throws Exception {
        MultipartEntity entity = new MultipartEntity();
        assertNull(entity.getContentEncoding());
        assertNotNull(entity.getContentType());
        Header header = entity.getContentType();
        HeaderElement[] elems = header.getElements();
        assertNotNull(elems);
        assertEquals(1, elems.length);

        HeaderElement elem = elems[0];
View Full Code Here

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

        NameValuePair p2 = elem.getParameterByName("charset");
        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();
        assertTrue(len == entity.getContentLength());

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        entity.writeTo(out);
        out.close();

        byte[] bytes = out.toByteArray();
        assertNotNull(bytes);
        assertTrue(bytes.length == len);

        assertTrue(len == entity.getContentLength());

        out = new ByteArrayOutputStream();
        entity.writeTo(out);
        out.close();

        bytes = out.toByteArray();
        assertNotNull(bytes);
        assertTrue(bytes.length == len);
View Full Code Here

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

        assertNotNull(bytes);
        assertTrue(bytes.length == len);
    }

    public void testNonRepeatable() throws Exception {
        MultipartEntity entity = new MultipartEntity();
        entity.addPart("p1", new InputStreamBody(
                new ByteArrayInputStream("blah blah".getBytes()), null));
        entity.addPart("p2", new InputStreamBody(
                new ByteArrayInputStream("yada yada".getBytes()), null));
        assertFalse(entity.isRepeatable());
        assertTrue(entity.isChunked());
        assertTrue(entity.isStreaming());

        assertTrue(entity.getContentLength() == -1);
    }
View Full Code Here

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

    }
   
    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

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

   
    /** 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

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

    public void startBundle(String symbolicName) throws Exception {
        // 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

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

     * @return The actual path of the node that was created
     */
    public String createNode(String path, Map<String, Object> properties) throws UnsupportedEncodingException, IOException {
        String actualPath = null;
       
        final MultipartEntity entity = new MultipartEntity();
       
        // Add Sling POST options
        entity.addPart(":redirect",new StringBody("*"));
        entity.addPart(":displayExtension",new StringBody(""));
       
        // Add user properties
        if(properties != null) {
            for(Map.Entry<String, Object> e : properties.entrySet()) {
                entity.addPart(e.getKey(), new StringBody(e.getValue().toString()));
            }
        }
       
        final HttpResponse response =
            executor.execute(
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.