Package org.apache.http

Examples of org.apache.http.HttpMessage


        }
    }

    public void testChunkedTransferEncodingMustBeLast() throws Exception {
        SessionInputBuffer datareceiver = new SessionInputBufferMockup("0\r\n", "US-ASCII");
        HttpMessage message = new HttpMessageMockup();
       
        // lenient mode
        message.getParams().setBooleanParameter(CoreProtocolPNames.STRICT_TRANSFER_ENCODING, false);
        message.addHeader("Content-Type", "unknown");
        message.addHeader("Transfer-Encoding", "chunked, identity");
        message.addHeader("Content-Length", "plain wrong");
        EntityDeserializer entitygen = new EntityDeserializer(
                new LaxContentLengthStrategy());
        HttpEntity entity = entitygen.deserialize(datareceiver, message);
        assertNotNull(entity);
        assertEquals(-1, entity.getContentLength());
        assertFalse(entity.isChunked());
        assertFalse(entity.getContent() instanceof ChunkedInputStream);

        // strict mode
        message.getParams().setBooleanParameter(CoreProtocolPNames.STRICT_TRANSFER_ENCODING, true);
        try {
            entitygen.deserialize(datareceiver, message);
            fail("ProtocolException should have been thrown");
        } catch (ProtocolException ex) {
            // expected
View Full Code Here


        }
    }

    public void testEntityWithContentLength() throws Exception {
        SessionInputBuffer datareceiver = new SessionInputBufferMockup(new byte[] {});
        HttpMessage message = new HttpMessageMockup();
       
        // lenient mode
        message.getParams().setBooleanParameter(CoreProtocolPNames.STRICT_TRANSFER_ENCODING, false);
        message.addHeader("Content-Type", "unknown");
        message.addHeader("Content-Length", "0");
        EntityDeserializer entitygen = new EntityDeserializer(
                new LaxContentLengthStrategy());
        HttpEntity entity = entitygen.deserialize(datareceiver, message);
        assertNotNull(entity);
        assertEquals(0, entity.getContentLength());
View Full Code Here

        assertTrue(entity.getContent() instanceof ContentLengthInputStream);
    }

    public void testEntityWithMultipleContentLength() throws Exception {
        SessionInputBuffer datareceiver = new SessionInputBufferMockup(new byte[] {'0'});
        HttpMessage message = new HttpMessageMockup();

        // lenient mode
        message.getParams().setBooleanParameter(CoreProtocolPNames.STRICT_TRANSFER_ENCODING, false);
        message.addHeader("Content-Type", "unknown");
        message.addHeader("Content-Length", "0");
        message.addHeader("Content-Length", "0");
        message.addHeader("Content-Length", "1");
        EntityDeserializer entitygen = new EntityDeserializer(
                new LaxContentLengthStrategy());
        HttpEntity entity = entitygen.deserialize(datareceiver, message);
        assertNotNull(entity);
        assertEquals(1, entity.getContentLength());
        assertFalse(entity.isChunked());
        InputStream instream = entity.getContent();
        assertNotNull(instream);
        assertTrue(instream instanceof ContentLengthInputStream);
       
        // strict mode
        message.getParams().setBooleanParameter(CoreProtocolPNames.STRICT_TRANSFER_ENCODING, true);
        try {
            entitygen.deserialize(datareceiver, message);
            fail("ProtocolException should have been thrown");
        } catch (ProtocolException ex) {
            // expected
View Full Code Here

    protected abstract HttpMessage parseHead(SessionInputBuffer sessionBuffer)
        throws IOException, HttpException, ParseException;

    public HttpMessage parse() throws IOException, HttpException {
        HttpMessage message = null;
        try {
            message = parseHead(this.sessionBuffer);
        } catch (ParseException px) {
            throw new ProtocolException(px.getMessage(), px);
        }
        Header[] headers = AbstractMessageParser.parseHeaders(
                this.sessionBuffer,
                this.maxHeaderCount,
                this.maxLineLen,
                this.lineParser);
        message.setHeaders(headers);
        return message;
    }
View Full Code Here

        }
    }

    public void testEntityWithChunkTransferEncoding() throws Exception {
        HttpDataTransmitter datatransmitter = new HttpDataTransmitterMockup();
        HttpMessage message = new HttpMessageMockup();
        message.addHeader(new Header("Transfer-Encoding", "Chunked"));

        DefaultEntitySerializer entitywriter = new DefaultEntitySerializer();
        OutputStream outstream = entitywriter.doSerialize(datatransmitter, message);
        assertNotNull(outstream);
        assertTrue(outstream instanceof ChunkedOutputStream);
View Full Code Here

        assertTrue(outstream instanceof ChunkedOutputStream);
    }

    public void testEntityWithIdentityTransferEncoding() throws Exception {
        HttpDataTransmitter datatransmitter = new HttpDataTransmitterMockup();
        HttpMessage message = new HttpMessageMockup();
        message.addHeader(new Header("Transfer-Encoding", "Identity"));

        DefaultEntitySerializer entitywriter = new DefaultEntitySerializer();
        OutputStream outstream = entitywriter.doSerialize(datatransmitter, message);
        assertNotNull(outstream);
        assertTrue(outstream instanceof IdentityOutputStream);
View Full Code Here

        assertTrue(outstream instanceof IdentityOutputStream);
    }
   
    public void testEntityWithInvalidTransferEncoding() throws Exception {
        HttpDataTransmitter datatransmitter = new HttpDataTransmitterMockup();
        HttpMessage message = new HttpMessageMockup();
        message.addHeader(new Header("Transfer-Encoding", "whatever"));

        DefaultEntitySerializer entitywriter = new DefaultEntitySerializer();
        try {
            entitywriter.doSerialize(datatransmitter, message);
            fail("ProtocolException should have been thrown");
View Full Code Here

        }
    }
   
    public void testEntityWithInvalidChunkEncodingAndHTTP10() throws Exception {
        HttpDataTransmitter datatransmitter = new HttpDataTransmitterMockup();
        HttpMessage message = new HttpMessageMockup();
        message.getParams().setParameter(HttpProtocolParams.PROTOCOL_VERSION,
                HttpVersion.HTTP_1_0);
        message.addHeader(new Header("Transfer-Encoding", "chunked"));

        DefaultEntitySerializer entitywriter = new DefaultEntitySerializer();
        try {
            entitywriter.doSerialize(datatransmitter, message);
            fail("ProtocolException should have been thrown");
View Full Code Here

        }
    }
   
    public void testEntityWithContentLength() throws Exception {
        HttpDataTransmitter datatransmitter = new HttpDataTransmitterMockup();
        HttpMessage message = new HttpMessageMockup();
        message.addHeader(new Header("Content-Length", "100"));
        DefaultEntitySerializer entitywriter = new DefaultEntitySerializer();
        OutputStream outstream = entitywriter.doSerialize(datatransmitter, message);
        assertNotNull(outstream);
        assertTrue(outstream instanceof ContentLengthOutputStream);
    }
View Full Code Here

        assertTrue(outstream instanceof ContentLengthOutputStream);
    }
   
    public void testEntityWithInvalidContentLength() throws Exception {
        HttpDataTransmitter datatransmitter = new HttpDataTransmitterMockup();
        HttpMessage message = new HttpMessageMockup();
        message.addHeader(new Header("Content-Length", "whatever"));

        DefaultEntitySerializer entitywriter = new DefaultEntitySerializer();
        try {
            entitywriter.doSerialize(datatransmitter, message);
            fail("ProtocolException should have been thrown");
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.