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

        String sessionCookie = null;
        Header[] headers = request.getHeaders(HTTPConstants.HEADER_COOKIE);
        for (int i = 0; i < headers.length; i++) {
            HeaderElement[] elements = headers[i].getElements();
            for (int e = 0; e < elements.length; e++) {
                HeaderElement element = elements[e];
                if (Constants.SESSION_COOKIE.equalsIgnoreCase(element.getName()) ||
                        Constants.SESSION_COOKIE_JSESSIONID.equalsIgnoreCase(element.getName())) {
                    sessionCookie = element.getValue();
                }
            }
        }
        context.setAttribute(HTTPConstants.COOKIE_STRING, sessionCookie);
    }
View Full Code Here

        HeaderElementIterator hei =
                new BasicHeaderElementIterator(
                        new BasicHeaderIterator(headers, "Name"));

        Assert.assertTrue(hei.hasNext());
        HeaderElement elem = hei.next();
        Assert.assertEquals("The two header values must be equal",
                "value0", elem.getName());

        Assert.assertTrue(hei.hasNext());
        elem = hei.next();
        Assert.assertEquals("The two header values must be equal",
                "value1", elem.getName());

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

        };

        HeaderElementIterator hei =
                new BasicHeaderElementIterator(new BasicHeaderIterator(headers, "Name"));

        HeaderElement elem = hei.next();
        Assert.assertEquals("The two header values must be equal",
                "value0", elem.getName());
        elem = hei.next();
        Assert.assertEquals("The two header values must be equal",
                "value1", elem.getName());
        elem = hei.next();
        Assert.assertEquals("The two header values must be equal",
                "cookie1", elem.getName());
        Assert.assertEquals("The two header values must be equal",
                "1", elem.getValue());

        elem = hei.next();
        Assert.assertEquals("The two header values must be equal",
                "cookie2", elem.getName());
        Assert.assertEquals("The two header values must be equal",
                "2", elem.getValue());
    }
View Full Code Here

            throw new IllegalArgumentException("Parser cursor may not be null");
        }

        List elements = new ArrayList();
        while (!cursor.atEnd()) {
            HeaderElement element = parseHeaderElement(buffer, cursor);
            if (!(element.getName().length() == 0 && element.getValue() == null)) {
                elements.add(element);
            }
        }
        return (HeaderElement[])
            elements.toArray(new HeaderElement[elements.size()]);
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

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

        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

        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.