Examples of MultipartEntity


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

        if(request.getConnectTimeout() > 0){
          HttpConnectionParams.setConnectionTimeout(httppost.getParams(),request.getConnectTimeout());
        }
       
        if (request.getFileMap().size() > 0) {
          MultipartEntity entity = new MultipartEntity();
          String charset = request.getCharset();
         
          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);
            entity.addPart(new FormBodyPart(key, new FileBody(value, getMimeType(value))));
          }
          httppost.setEntity(entity);
        } else if(request.getPostMap().size() > 0) {
          List<NameValuePair>list=new ArrayList<NameValuePair>();
         
View Full Code Here

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

    }

    public void makeMultiPart() {
        if (!multiPart) {
            multiPart = true;
            multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        }
    }
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.