Package org.apache.http.nio.protocol.HttpAsyncClientProtocolHandler

Examples of org.apache.http.nio.protocol.HttpAsyncClientProtocolHandler.HttpExchange


    }

    @Test
    public void testRequestContentIOException() throws Exception {
        IOException ioex = new IOException();
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        httpExchange.setHandler(this.exchangeHandler);
        this.connContext.setAttribute(HttpAsyncClientProtocolHandler.HTTP_EXCHANGE, httpExchange);
        Mockito.doThrow(ioex).when(this.exchangeHandler).produceContent(this.encoder, this.conn);

        this.protocolHandler.outputReady(this.conn, this.encoder);
View Full Code Here


        Mockito.verify(this.exchangeHandler).failed(ioex);
    }

    @Test
    public void testBasicResponse() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        HttpRequest request = new BasicHttpRequest("GET", "/");
        httpExchange.setRequest(request);
        httpExchange.setHandler(this.exchangeHandler);
        this.connContext.setAttribute(HttpAsyncClientProtocolHandler.HTTP_EXCHANGE, httpExchange);
        BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
        Mockito.when(this.conn.getHttpResponse()).thenReturn(response);

        this.protocolHandler.responseReceived(this.conn);

        Assert.assertSame(response, httpExchange.getResponse());
        Assert.assertEquals(MessageState.BODY_STREAM, httpExchange.getResponseState());
    }
View Full Code Here

        Assert.assertEquals(MessageState.BODY_STREAM, httpExchange.getResponseState());
    }

    @Test
    public void testResponseContinue() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        httpExchange.setRequestState(MessageState.ACK_EXPECTED);
        httpExchange.setTimeout(1000);
        BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
        request.setEntity(NStringEntity.create("stuff"));
        httpExchange.setRequest(request);
        httpExchange.setHandler(this.exchangeHandler);
        this.connContext.setAttribute(HttpAsyncClientProtocolHandler.HTTP_EXCHANGE, httpExchange);
        BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 100, "Continue");
        Mockito.when(this.conn.getHttpResponse()).thenReturn(response);

        this.protocolHandler.responseReceived(this.conn);

        Assert.assertNull(httpExchange.getResponse());
        Assert.assertEquals(MessageState.ACK, httpExchange.getRequestState());
        Assert.assertEquals(MessageState.READY, httpExchange.getResponseState());
        Mockito.verify(this.conn).setSocketTimeout(1000);
        Mockito.verify(this.conn).requestOutput();
    }
View Full Code Here

        Mockito.verify(this.conn).requestOutput();
    }

    @Test
    public void testResponseContinueOutOfSequence() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        httpExchange.setRequestState(MessageState.COMPLETED);
        BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
        request.setEntity(NStringEntity.create("stuff"));
        httpExchange.setRequest(request);
        httpExchange.setHandler(this.exchangeHandler);
        this.connContext.setAttribute(HttpAsyncClientProtocolHandler.HTTP_EXCHANGE, httpExchange);
        BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 100, "Continue");
        Mockito.when(this.conn.getHttpResponse()).thenReturn(response);

        this.protocolHandler.responseReceived(this.conn);

        Assert.assertNull(httpExchange.getResponse());
        Assert.assertEquals(MessageState.COMPLETED, httpExchange.getRequestState());
        Mockito.verify(this.conn, Mockito.never()).requestOutput();
    }
View Full Code Here

        Mockito.verify(this.conn, Mockito.never()).requestOutput();
    }

    @Test
    public void testResponseUnsupported1xx() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        httpExchange.setRequestState(MessageState.ACK_EXPECTED);
        httpExchange.setTimeout(1000);
        BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
        request.setEntity(NStringEntity.create("stuff"));
        httpExchange.setRequest(request);
        httpExchange.setHandler(this.exchangeHandler);
        this.connContext.setAttribute(HttpAsyncClientProtocolHandler.HTTP_EXCHANGE, httpExchange);
        BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 111, "WTF?");
        Mockito.when(this.conn.getHttpResponse()).thenReturn(response);

        this.protocolHandler.responseReceived(this.conn);

        Assert.assertNull(httpExchange.getResponse());
        Assert.assertEquals(MessageState.ACK_EXPECTED, httpExchange.getRequestState());
        Mockito.verify(this.conn).shutdown();
        Mockito.verify(this.exchangeHandler).failed(Mockito.any(HttpException.class));
    }
View Full Code Here

        Mockito.verify(this.exchangeHandler).failed(Mockito.any(HttpException.class));
    }

    @Test
    public void testResponseExpectationFailed() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        httpExchange.setRequestState(MessageState.ACK_EXPECTED);
        httpExchange.setTimeout(1000);
        BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
        request.setEntity(NStringEntity.create("stuff"));
        httpExchange.setRequest(request);
        httpExchange.setHandler(this.exchangeHandler);
        this.connContext.setAttribute(HttpAsyncClientProtocolHandler.HTTP_EXCHANGE, httpExchange);
        BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 403, "Unauthorized");
        Mockito.when(this.conn.getHttpResponse()).thenReturn(response);

        this.protocolHandler.responseReceived(this.conn);

        Assert.assertSame(response, httpExchange.getResponse());
        Assert.assertEquals(MessageState.COMPLETED, httpExchange.getRequestState());
        Assert.assertEquals(MessageState.BODY_STREAM, httpExchange.getResponseState());
        Mockito.verify(this.conn).setSocketTimeout(1000);
        Mockito.verify(this.conn).resetOutput();
    }
View Full Code Here

        Mockito.verify(this.conn).resetOutput();
    }

    @Test
    public void testEarlyResponse() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        httpExchange.setRequestState(MessageState.BODY_STREAM);
        httpExchange.setTimeout(1000);
        BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
        request.setEntity(NStringEntity.create("stuff"));
        httpExchange.setRequest(request);
        httpExchange.setHandler(this.exchangeHandler);
        this.connContext.setAttribute(HttpAsyncClientProtocolHandler.HTTP_EXCHANGE, httpExchange);
        BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 403, "Unauthorized");
        Mockito.when(this.conn.getHttpResponse()).thenReturn(response);

        this.protocolHandler.responseReceived(this.conn);

        Assert.assertSame(response, httpExchange.getResponse());
        Assert.assertEquals(MessageState.COMPLETED, httpExchange.getRequestState());
        Assert.assertEquals(MessageState.BODY_STREAM, httpExchange.getResponseState());
        Mockito.verify(this.conn).suspendOutput();
        Mockito.verify(this.conn).resetOutput();
        Assert.assertFalse(httpExchange.isValid());
    }
View Full Code Here

        Assert.assertFalse(httpExchange.isValid());
    }

    @Test
    public void testResponseToHead() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        HttpRequest request = new BasicHttpRequest("HEAD", "/");
        httpExchange.setRequest(request);
        httpExchange.setHandler(this.exchangeHandler);
        this.connContext.setAttribute(HttpAsyncClientProtocolHandler.HTTP_EXCHANGE, httpExchange);
        BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
        Mockito.when(this.conn.getHttpResponse()).thenReturn(response);
        Mockito.when(this.reuseStrategy.keepAlive(response, this.exchangeContext)).thenReturn(true);
        Mockito.when(this.exchangeHandler.getConnectionReuseStrategy()).thenReturn(this.reuseStrategy);

        this.protocolHandler.responseReceived(this.conn);

        Assert.assertEquals(MessageState.READY, httpExchange.getResponseState());
        Assert.assertEquals(MessageState.READY, httpExchange.getRequestState());
        Assert.assertNull(httpExchange.getRequest());
        Assert.assertNull(httpExchange.getResponse());
        Mockito.verify(this.exchangeHandler).responseReceived(response);
        Mockito.verify(this.conn).resetInput();
        Mockito.verify(this.conn, Mockito.never()).close();
    }
View Full Code Here

        Mockito.verify(this.conn, Mockito.never()).close();
    }

    @Test
    public void testResponseToConnect() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        HttpRequest request = new BasicHttpRequest("Connect", "/");
        httpExchange.setRequest(request);
        httpExchange.setHandler(this.exchangeHandler);
        this.connContext.setAttribute(HttpAsyncClientProtocolHandler.HTTP_EXCHANGE, httpExchange);
        BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
        Mockito.when(this.conn.getHttpResponse()).thenReturn(response);
        Mockito.when(this.reuseStrategy.keepAlive(response, this.exchangeContext)).thenReturn(true);
        Mockito.when(this.exchangeHandler.getConnectionReuseStrategy()).thenReturn(this.reuseStrategy);

        this.protocolHandler.responseReceived(this.conn);

        Assert.assertEquals(MessageState.READY, httpExchange.getResponseState());
        Assert.assertEquals(MessageState.READY, httpExchange.getRequestState());
        Assert.assertNull(httpExchange.getRequest());
        Assert.assertNull(httpExchange.getResponse());
        Mockito.verify(this.exchangeHandler).responseReceived(response);
        Mockito.verify(this.conn).resetInput();
        Mockito.verify(this.conn, Mockito.never()).close();
    }
View Full Code Here

        Mockito.verify(this.conn, Mockito.never()).close();
    }

    @Test
    public void testResponseNotModified() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        HttpRequest request = new BasicHttpRequest("Connect", "/");
        httpExchange.setRequest(request);
        httpExchange.setHandler(this.exchangeHandler);
        this.connContext.setAttribute(HttpAsyncClientProtocolHandler.HTTP_EXCHANGE, httpExchange);
        BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
                HttpStatus.SC_NOT_MODIFIED, "Not modified");
        Mockito.when(this.conn.getHttpResponse()).thenReturn(response);
        Mockito.when(this.reuseStrategy.keepAlive(response, this.exchangeContext)).thenReturn(true);
        Mockito.when(this.exchangeHandler.getConnectionReuseStrategy()).thenReturn(this.reuseStrategy);

        this.protocolHandler.responseReceived(this.conn);

        Assert.assertEquals(MessageState.READY, httpExchange.getResponseState());
        Assert.assertEquals(MessageState.READY, httpExchange.getRequestState());
        Assert.assertNull(httpExchange.getRequest());
        Assert.assertNull(httpExchange.getResponse());
        Mockito.verify(this.exchangeHandler).responseReceived(response);
        Mockito.verify(this.conn).resetInput();
        Mockito.verify(this.conn, Mockito.never()).close();
    }
View Full Code Here

TOP

Related Classes of org.apache.http.nio.protocol.HttpAsyncClientProtocolHandler.HttpExchange

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.