Package org.apache.http

Examples of org.apache.http.HeaderElement


        if (entity == null) {
            throw new IllegalArgumentException("HTTP entity may not be null");
        }
        String charset = null;
        if (entity.getContentType() != null) {
            HeaderElement values[] = entity.getContentType().getElements();
            if (values.length > 0) {
                NameValuePair param = values[0].getParameterByName("charset");
                if (param != null) {
                    charset = param.getValue();
                }
View Full Code Here


        if (entity == null) {
            throw new IllegalArgumentException("HTTP entity may not be null");
        }
        String mimeType = null;
        if (entity.getContentType() != null) {
            HeaderElement values[] = entity.getContentType().getElements();
            if (values.length > 0) {
                mimeType = values[0].getName();
            }
        }
        return mimeType;
View Full Code Here

        HeaderElementIterator hei =
                new BasicHeaderElementIterator(
                        new BasicHeaderIterator(headers, "Name"));
       
        assertTrue(hei.hasNext());
        HeaderElement elem = (HeaderElement) hei.next();
        assertEquals("The two header values must be equal",
                "value0", elem.getName());
       
        assertTrue(hei.hasNext());
        elem = (HeaderElement)hei.next();
        assertEquals("The two header values must be equal",
                "value1", elem.getName());

        assertFalse(hei.hasNext());
        try {
            hei.next();
            fail("NoSuchElementException should have been thrown");
View Full Code Here

        };
       
        HeaderElementIterator hei =
                new BasicHeaderElementIterator(new BasicHeaderIterator(headers, "Name"));
       
        HeaderElement elem = (HeaderElement)hei.next();
        assertEquals("The two header values must be equal",
                "value0", elem.getName());
        elem = (HeaderElement)hei.next();
        assertEquals("The two header values must be equal",
                "value1", elem.getName());
        elem = (HeaderElement)hei.next();
        assertEquals("The two header values must be equal",
                "cookie1", elem.getName());
        assertEquals("The two header values must be equal",
                "1", elem.getValue());
       
        elem = (HeaderElement)hei.next();
        assertEquals("The two header values must be equal",
                "cookie2", elem.getName());
        assertEquals("The two header values must be equal",
                "2", elem.getValue());
    }
View Full Code Here

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

    public void testConstructor3() throws Exception {
        HeaderElement element = new BasicHeaderElement("name", "value",
                new NameValuePair[] {
                    new BasicNameValuePair("param1", "value1"),
                    new BasicNameValuePair("param2", "value2")
                } );
        assertEquals("name", element.getName());
        assertEquals("value", element.getValue());
        assertEquals(2, element.getParameters().length);
        assertEquals("value1", element.getParameterByName("param1").getValue());
        assertEquals("value2", element.getParameterByName("param2").getValue());
    }
View Full Code Here

        assertEquals("value1", element.getParameterByName("param1").getValue());
        assertEquals("value2", element.getParameterByName("param2").getValue());
    }

    public void testConstructor2() throws Exception {
        HeaderElement element = new BasicHeaderElement("name", "value");
        assertEquals("name", element.getName());
        assertEquals("value", element.getValue());
        assertEquals(0, element.getParameters().length);
    }
View Full Code Here

        }
    }

    public void testParamByName() throws Exception {
        String s = "name = value; param1 = value1; param2 = value2";
        HeaderElement element = BasicHeaderValueParser.parseHeaderElement(s, null);
        assertEquals("value1", element.getParameterByName("param1").getValue());
        assertEquals("value2", element.getParameterByName("param2").getValue());
        assertNull(element.getParameterByName("param3"));
        try {
            element.getParameterByName(null);
            fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
            //expected
        }
    }
View Full Code Here

            //expected
        }
    }

    public void testHashCode() {
        HeaderElement element1 = new BasicHeaderElement("name", "value",
                new NameValuePair[] {
                    new BasicNameValuePair("param1", "value1"),
                    new BasicNameValuePair("param2", "value2")
                } );
        HeaderElement element2 = new BasicHeaderElement("name", "value",
                new NameValuePair[] {
                    new BasicNameValuePair("param2", "value2"),
                    new BasicNameValuePair("param1", "value1")
                } );
        HeaderElement element3 = new BasicHeaderElement("name", "value");
        HeaderElement element4 = new BasicHeaderElement("name", "value");
        HeaderElement element5 = new BasicHeaderElement("name", "value",
                new NameValuePair[] {
                    new BasicNameValuePair("param1", "value1"),
                    new BasicNameValuePair("param2", "value2")
                } );
        assertTrue(element1.hashCode() != element2.hashCode());
        assertTrue(element1.hashCode() != element3.hashCode());
        assertTrue(element2.hashCode() != element3.hashCode());
        assertTrue(element3.hashCode() == element4.hashCode());
        assertTrue(element1.hashCode() == element5.hashCode());
    }
View Full Code Here

        assertTrue(element3.hashCode() == element4.hashCode());
        assertTrue(element1.hashCode() == element5.hashCode());
    }
   
    public void testEquals() {
        HeaderElement element1 = new BasicHeaderElement("name", "value",
                new NameValuePair[] {
                    new BasicNameValuePair("param1", "value1"),
                    new BasicNameValuePair("param2", "value2")
                } );
        HeaderElement element2 = new BasicHeaderElement("name", "value",
                new NameValuePair[] {
                    new BasicNameValuePair("param2", "value2"),
                    new BasicNameValuePair("param1", "value1")
                } );
        HeaderElement element3 = new BasicHeaderElement("name", "value");
        HeaderElement element4 = new BasicHeaderElement("name", "value");
        HeaderElement element5 = new BasicHeaderElement("name", "value",
                new NameValuePair[] {
                    new BasicNameValuePair("param1", "value1"),
                    new BasicNameValuePair("param2", "value2")
                } );
        assertTrue(element1.equals(element1));
View Full Code Here

        assertFalse(element1.equals("name = value; param1 = value1; param2 = value2"));
    }
   
    public void testToString() {
        String s = "name=value; param1=value1; param2=value2";
        HeaderElement element = BasicHeaderValueParser.parseHeaderElement(s, null);
        assertEquals(s, element.toString());
        s = "name; param1=value1; param2=value2";
        element = BasicHeaderValueParser.parseHeaderElement(s, null);
        assertEquals(s, element.toString());
    }
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.