Package org.apache.http

Examples of org.apache.http.HeaderElement


        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


        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

        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",
                     BasicHeaderValueFormatter.formatHeaderElement(element, false, null));
    }
View Full Code Here

            }
            // Anything buffered?
            if (this.cursor != null) {
                // loop while there is data in the buffer
                while (!this.cursor.atEnd()) {
                    HeaderElement e = this.parser.parseHeaderElement(this.buffer, this.cursor);
                    if (!(e.getName().length() == 0 && e.getValue() == null)) {
                        // Found something
                        this.currentElement = e;
                        return;
                    }
                }
View Full Code Here

    public void testElementsFormatting() 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\", " +
View Full Code Here

        if (this.currentElement == null) {
            throw new NoSuchElementException("No more header elements available");
        }

        HeaderElement element = this.currentElement;
        this.currentElement = null;
        return element;
    }
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

        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

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.