Package org.apache.http

Examples of org.apache.http.HttpMessage


        public int fillBuffer(final ReadableByteChannel channel) throws IOException {
            return this.parser.fillBuffer(channel);
        }

        public HttpMessage parse() throws IOException, HttpException {
            HttpMessage message = this.parser.parse();
            if (message != null && headerlog.isDebugEnabled()) {
                HttpRequest request = (HttpRequest) message;
                headerlog.debug(">> " + request.getRequestLine().toString());
                Header[] headers = request.getAllHeaders();
                for (int i = 0; i < headers.length; i++) {
View Full Code Here


        public int fillBuffer(final ReadableByteChannel channel) throws IOException {
            return this.parser.fillBuffer(channel);
        }

        public HttpMessage parse() throws IOException, HttpException {
            HttpMessage message = this.parser.parse();
            if (message != null && headerlog.isDebugEnabled()) {
                HttpResponse response = (HttpResponse) message;
                headerlog.debug("<< " + response.getStatusLine().toString());
                Header[] headers = response.getAllHeaders();
                for (int i = 0; i < headers.length; i++) {
View Full Code Here

        }
    }

    public void testEntityNeitherContentLengthNorTransferEncoding() throws Exception {
        ContentLengthStrategy lenStrategy = new LaxContentLengthStrategy();
        HttpMessage message = new HttpMessageMockup();

        // lenient mode
        assertEquals(ContentLengthStrategy.IDENTITY, lenStrategy.determineLength(message));
    }
View Full Code Here

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

    public void testBasicProperties() {
        HttpMessage message = new HttpMessageMockup();
        assertNotNull(message.getParams());
        assertNotNull(message.headerIterator());
        Header[] headers = message.getAllHeaders();
        assertNotNull(headers);
        assertEquals(0, headers.length);
    }
View Full Code Here

        assertNotNull(headers);
        assertEquals(0, headers.length);
    }

    public void testBasicHeaderOps() {
        HttpMessage message = new HttpMessageMockup();
        assertFalse(message.containsHeader("whatever"));
       
        message.addHeader("name", "1");
        message.addHeader("name", "2");
       
        Header[] headers = message.getAllHeaders();
        assertNotNull(headers);
        assertEquals(2, headers.length);
       
        Header h = message.getFirstHeader("name");
        assertNotNull(h);
        assertEquals("1", h.getValue());

        message.setHeader("name", "3");
        h = message.getFirstHeader("name");
        assertNotNull(h);
        assertEquals("3", h.getValue());
        h = message.getLastHeader("name");
        assertNotNull(h);
        assertEquals("2", h.getValue());
       
        // Should have no effect
        message.addHeader(null);
        message.setHeader(null);
       
        headers = message.getHeaders("name");
        assertNotNull(headers);
        assertEquals(2, headers.length);
        assertEquals("3", headers[0].getValue());
        assertEquals("2", headers[1].getValue());

        message.addHeader("name", "4");
       
        headers[1] = new BasicHeader("name", "5");
        message.setHeaders(headers);
       
        headers = message.getHeaders("name");
        assertNotNull(headers);
        assertEquals(2, headers.length);
        assertEquals("3", headers[0].getValue());
        assertEquals("5", headers[1].getValue());
       
        message.setHeader("whatever", null);
        message.removeHeaders("name");
        message.removeHeaders(null);
        headers = message.getAllHeaders();
        assertNotNull(headers);
        assertEquals(1, headers.length);
        assertEquals(null, headers[0].getValue());

        message.removeHeader(message.getFirstHeader("whatever"));
        headers = message.getAllHeaders();
        assertNotNull(headers);
        assertEquals(0, headers.length);
    }
View Full Code Here

        assertNotNull(headers);
        assertEquals(0, headers.length);
    }

    public void testParameters() {
        HttpMessage message = new HttpMessageMockup();
        assertNotNull(message.getParams());
        HttpParams params = new BasicHttpParams();
        message.setParams(params);
        assertTrue(params == message.getParams());
    }
View Full Code Here

        message.setParams(params);
        assertTrue(params == message.getParams());
    }

    public void testInvalidInput() {
        HttpMessage message = new HttpMessageMockup();
        try {
            message.setParams(null);
            fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
            // expected
        }
        try {
            message.addHeader(null, null);
            fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
            // expected
        }
        try {
            message.setHeader(null, null);
            fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
            // expected
        }
    }
View Full Code Here

        junit.textui.TestRunner.main(testCaseName);
    }

    public void testEntityWithChunkTransferEncoding() throws Exception {
        ContentLengthStrategy lenStrategy = new StrictContentLengthStrategy();
        HttpMessage message = new HttpMessageMockup();
        message.addHeader("Transfer-Encoding", "Chunked");

        assertEquals(ContentLengthStrategy.CHUNKED, lenStrategy.determineLength(message));
    }
View Full Code Here

        assertEquals(ContentLengthStrategy.CHUNKED, lenStrategy.determineLength(message));
    }

    public void testEntityWithIdentityTransferEncoding() throws Exception {
        ContentLengthStrategy lenStrategy = new StrictContentLengthStrategy();
        HttpMessage message = new HttpMessageMockup();
        message.addHeader("Transfer-Encoding", "Identity");

        assertEquals(ContentLengthStrategy.IDENTITY, lenStrategy.determineLength(message));
    }
View Full Code Here

        assertEquals(ContentLengthStrategy.IDENTITY, lenStrategy.determineLength(message));
    }
   
    public void testEntityWithInvalidTransferEncoding() throws Exception {
        ContentLengthStrategy lenStrategy = new StrictContentLengthStrategy();
        HttpMessage message = new HttpMessageMockup();
        message.addHeader("Transfer-Encoding", "whatever");

        try {
            lenStrategy.determineLength(message);
            fail("ProtocolException should have been thrown");
        } catch (ProtocolException ex) {
View Full Code Here

TOP

Related Classes of org.apache.http.HttpMessage

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.