Package org.apache.http

Examples of org.apache.http.HeaderElement


        NameValuePair param1 = new BasicNameValuePair("param", "regular_stuff");
        NameValuePair param2 = new BasicNameValuePair("param", "this\\that");
        NameValuePair param3 = new BasicNameValuePair("param", "this,that");
        NameValuePair param4 = new BasicNameValuePair("param", null);
        NameValuePair[] params = new NameValuePair[] {param1, param2, param3, param4};
        HeaderElement element = new BasicHeaderElement("name", "value", params);
       
        assertEquals("name=value; param=regular_stuff; param=\"this\\\\that\"; param=\"this,that\"; param",
                BasicHeaderElement.format(element));
    }
View Full Code Here


    public void testElementArrayFormatting() throws Exception {
        NameValuePair param1 = new BasicNameValuePair("param", "regular_stuff");
        NameValuePair param2 = new BasicNameValuePair("param", "this\\that");
        NameValuePair param3 = new BasicNameValuePair("param", "this,that");
        NameValuePair param4 = new BasicNameValuePair("param", null);
        HeaderElement element1 = new BasicHeaderElement("name1", "value1", new NameValuePair[] {param1});
        HeaderElement element2 = new BasicHeaderElement("name2", "value2", new NameValuePair[] {param2});
        HeaderElement element3 = new BasicHeaderElement("name3", "value3", new NameValuePair[] {param3});
        HeaderElement element4 = new BasicHeaderElement("name4", "value4", new NameValuePair[] {param4});
        HeaderElement element5 = new BasicHeaderElement("name5", null);
        HeaderElement[] elements = new HeaderElement[] {element1, element2, element3, element4, element5};
       
        assertEquals("name1=value1; param=regular_stuff, name2=value2; " +
                "param=\"this\\\\that\", name3=value3; param=\"this,that\", " +
                "name4=value4; param, name5",
View Full Code Here

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

        HeaderElement elem = elems[0];
        assertEquals("multipart/form-data", elem.getName());
        NameValuePair p1 = elem.getParameterByName("boundary");
        assertNotNull(p1);

        String boundary = p1.getValue();
        assertNotNull(boundary);

        assertTrue(boundary.length() >= 30);
        assertTrue(boundary.length() <= 40);

        NameValuePair p2 = elem.getParameterByName("charset");
        assertNull(p2);
    }
View Full Code Here

            return null;
        }
        HeaderElement[] elements = BasicHeaderValueParser.parseElements(s.substring(7), null);
        Map<String, String> map = new HashMap<String, String>(elements.length);
        for (int i = 0; i < elements.length; i++) {
            HeaderElement element = elements[i];
            map.put(element.getName(), element.getValue());
        }
        return map;
    }
View Full Code Here

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

        HeaderElement elem = elems[0];
        assertEquals("multipart/form-data", elem.getName());
        NameValuePair p1 = elem.getParameterByName("boundary");
        assertNotNull(p1);
        assertEquals("whatever", p1.getValue());
        NameValuePair p2 = elem.getParameterByName("charset");
        assertNotNull(p2);
        assertEquals("UTF-8", p2.getValue());
    }
View Full Code Here

    @Deprecated
    public static String getContentCharSet(final HttpEntity entity) throws ParseException {
        Args.notNull(entity, "Entity");
        String charset = null;
        if (entity.getContentType() != null) {
            final HeaderElement values[] = entity.getContentType().getElements();
            if (values.length > 0) {
                final NameValuePair param = values[0].getParameterByName("charset");
                if (param != null) {
                    charset = param.getValue();
                }
View Full Code Here

    @Deprecated
    public static String getContentMimeType(final HttpEntity entity) throws ParseException {
        Args.notNull(entity, "Entity");
        String mimeType = null;
        if (entity.getContentType() != null) {
            final HeaderElement values[] = entity.getContentType().getElements();
            if (values.length > 0) {
                mimeType = values[0].getName();
            }
        }
        return mimeType;
View Full Code Here

        HttpResponse result = impl.execute(host, req2);
        verifyMocks();

        if (HttpStatus.SC_PARTIAL_CONTENT == result.getStatusLine().getStatusCode()) {
            if (result.getFirstHeader("Content-Range") == null) {
                HeaderElement elt = result.getFirstHeader("Content-Type").getElements()[0];
                Assert.assertTrue("multipart/byteranges".equalsIgnoreCase(elt.getName()));
                Assert.assertNotNull(elt.getParameterByName("boundary"));
                Assert.assertNotNull(elt.getParameterByName("boundary").getValue());
                Assert.assertFalse("".equals(elt.getParameterByName("boundary").getValue().trim()));
            }
        }
    }
View Full Code Here

            return null;
        }
        HeaderElement[] elements = BasicHeaderValueParser.parseElements(s.substring(7), null);
        Map<String, String> map = new HashMap<String, String>(elements.length);
        for (int i = 0; i < elements.length; i++) {
            HeaderElement element = elements[i];
            map.put(element.getName(), element.getValue());
        }
        return map;
    }
View Full Code Here

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

        HeaderElement elem = elems[0];
        assertEquals("multipart/form-data", elem.getName());
        NameValuePair p1 = elem.getParameterByName("boundary");
        assertNotNull(p1);
        assertEquals("whatever", p1.getValue());
        NameValuePair p2 = elem.getParameterByName("charset");
        assertNotNull(p2);
        assertEquals("UTF-8", p2.getValue());
    }
View Full Code Here

TOP

Related Classes of org.apache.http.HeaderElement

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.