Package org.apache.http.nio.protocol.HttpAsyncService

Examples of org.apache.http.nio.protocol.HttpAsyncService.State


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

    @Test
    public void testResponseNotModified() throws Exception {
        final State state = new State();
        final HttpContext exchangeContext = new BasicHttpContext();
        final HttpRequest request = new BasicHttpRequest("HEAD", "/", HttpVersion.HTTP_1_1);
        final Incoming incoming = new Incoming(
                request, this.requestHandler, this.requestConsumer, exchangeContext);
        state.setIncoming(incoming);
        state.setRequestState(MessageState.COMPLETED);
        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
                HttpStatus.SC_NOT_MODIFIED, "Not modified");
        final Outgoing outgoing = new Outgoing(
                request, response, this.responseProducer, exchangeContext);
        state.setOutgoing(outgoing);
        state.setResponseState(MessageState.INIT);
        this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state);

        response.setEntity(new NStringEntity("stuff"));
        Mockito.when(this.responseProducer.generateResponse()).thenReturn(response);
        Mockito.when(this.reuseStrategy.keepAlive(response, exchangeContext)).thenReturn(Boolean.TRUE);

        this.protocolHandler.responseReady(this.conn);

        Assert.assertEquals(MessageState.READY, state.getResponseState());

        Mockito.verify(this.httpProcessor).process(response, exchangeContext);
        Mockito.verify(this.conn).submitResponse(response);
        Mockito.verify(this.responseProducer).responseCompleted(exchangeContext);
        Mockito.verify(this.conn).requestInput();
View Full Code Here


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

    @Test
    public void testResponseContinue() throws Exception {
        final State state = new State();
        final HttpContext exchangeContext = new BasicHttpContext();
        final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/",
                HttpVersion.HTTP_1_1);
        final Incoming incoming = new Incoming(
                request, this.requestHandler, this.requestConsumer, exchangeContext);
        state.setIncoming(incoming);
        state.setRequestState(MessageState.ACK_EXPECTED);
        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
                HttpStatus.SC_CONTINUE, "Continue");
        final Outgoing outgoing = new Outgoing(
                request, response, this.responseProducer, exchangeContext);
        state.setOutgoing(outgoing);
        this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state);

        Mockito.when(this.responseProducer.generateResponse()).thenReturn(response);

        this.protocolHandler.responseReady(this.conn);

        Assert.assertEquals(MessageState.BODY_STREAM, state.getRequestState());
        Assert.assertEquals(MessageState.READY, state.getResponseState());

        Mockito.verify(this.conn).requestInput();
        Mockito.verify(this.conn).submitResponse(Mockito.argThat(new ArgumentMatcher<HttpResponse>() {

            @Override
View Full Code Here

        }));
    }

    @Test
    public void testResponseFailedExpectation() throws Exception {
        final State state = new State();
        final HttpContext exchangeContext = new BasicHttpContext();
        final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/",
                HttpVersion.HTTP_1_1);
        final Incoming incoming = new Incoming(
                request, this.requestHandler, this.requestConsumer, exchangeContext);
        state.setIncoming(incoming);
        state.setRequestState(MessageState.ACK_EXPECTED);
        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
                417, "Expectation failed");
        final Outgoing outgoing = new Outgoing(
                request, response, this.responseProducer, exchangeContext);
        state.setOutgoing(outgoing);
        this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state);

        response.setEntity(new NStringEntity("stuff"));
        Mockito.when(this.responseProducer.generateResponse()).thenReturn(response);

        this.protocolHandler.responseReady(this.conn);

        Assert.assertEquals(MessageState.READY, state.getRequestState());
        Assert.assertEquals(MessageState.BODY_STREAM, state.getResponseState());

        Mockito.verify(this.conn).resetInput();
        Mockito.verify(this.httpProcessor).process(response, exchangeContext);
        Mockito.verify(this.conn).submitResponse(response);
        Mockito.verify(this.responseProducer, Mockito.never()).responseCompleted(exchangeContext);
View Full Code Here

        Mockito.verify(this.responseProducer, Mockito.never()).responseCompleted(exchangeContext);
    }

    @Test
    public void testResponsePipelinedEmpty() throws Exception {
        final State state = new State();

        state.setRequestState(MessageState.READY);
        this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state);

        this.protocolHandler.responseReady(this.conn);

        Assert.assertEquals(MessageState.READY, state.getRequestState());
        Assert.assertEquals(MessageState.READY, state.getResponseState());
        Assert.assertNull(state.getOutgoing());

        Mockito.verify(conn).suspendOutput();
        Mockito.verifyNoMoreInteractions(requestHandler);
    }
View Full Code Here

        Mockito.verifyNoMoreInteractions(requestHandler);
    }

    @Test
    public void testResponseHandlePipelinedRequest() throws Exception {
        final State state = new State();
        final Queue<PipelineEntry> pipeline = state.getPipeline();

        final HttpContext exchangeContext = new BasicHttpContext();
        final HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
        final PipelineEntry entry = new PipelineEntry(request, request, null, requestHandler, exchangeContext);
        pipeline.add(entry);

        state.setRequestState(MessageState.READY);
        this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state);

        this.protocolHandler.responseReady(this.conn);

        Assert.assertEquals(MessageState.READY, state.getRequestState());
        Assert.assertEquals(MessageState.INIT, state.getResponseState());
        Assert.assertNull(state.getOutgoing());

        final ArgumentCaptor<HttpAsyncExchange> argCaptor = ArgumentCaptor.forClass(HttpAsyncExchange.class);
        Mockito.verify(this.requestHandler).handle(Mockito.same(request),
                argCaptor.capture(), Mockito.same(exchangeContext));
        final HttpAsyncExchange exchange = argCaptor.getValue();
View Full Code Here

        Assert.assertEquals(200, exchange.getResponse().getStatusLine().getStatusCode());
    }

    @Test
    public void testResponseHandleFailedPipelinedRequest() throws Exception {
        final State state = new State();
        final Queue<PipelineEntry> pipeline = state.getPipeline();

        final HttpContext exchangeContext = new BasicHttpContext();
        final HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
        final Exception ex = new Exception("Opppsie");
        final PipelineEntry entry = new PipelineEntry(request, null, ex, requestHandler, exchangeContext);
        pipeline.add(entry);

        state.setRequestState(MessageState.READY);
        this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state);

        this.protocolHandler.responseReady(this.conn);

        Assert.assertEquals(MessageState.READY, state.getRequestState());
        Assert.assertEquals(MessageState.BODY_STREAM, state.getResponseState());

        final Outgoing outgoing = state.getOutgoing();
        Assert.assertNotNull(outgoing.getProducer());
        final HttpResponse response = outgoing.getResponse();
        Assert.assertNotNull(response);
        Assert.assertEquals(500, response.getStatusLine().getStatusCode());
View Full Code Here

        Mockito.verify(this.conn).submitResponse(Mockito.same(response));
    }

    @Test(expected=HttpException.class)
    public void testInvalidResponseStatus() throws Exception {
        final State state = new State();
        final HttpContext exchangeContext = new BasicHttpContext();
        final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/",
                HttpVersion.HTTP_1_1);
        final Incoming incoming = new Incoming(
                request, this.requestHandler, this.requestConsumer, exchangeContext);
        state.setIncoming(incoming);
        state.setRequestState(MessageState.COMPLETED);
        state.setResponseState(MessageState.INIT);
        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 112, "Something stupid");
        final Outgoing outgoing = new Outgoing(
                request, response, this.responseProducer, exchangeContext);
        state.setOutgoing(outgoing);
        this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state);

        Mockito.when(this.responseProducer.generateResponse()).thenReturn(response);
        Mockito.when(this.conn.isResponseSubmitted()).thenReturn(Boolean.FALSE);
View Full Code Here

        this.protocolHandler.responseReady(this.conn);
    }

    @Test(expected=HttpException.class)
    public void testInvalidResponseStatusToExpection() throws Exception {
        final State state = new State();
        final HttpContext exchangeContext = new BasicHttpContext();
        final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/",
                HttpVersion.HTTP_1_1);
        final Incoming incoming = new Incoming(
                request, this.requestHandler, this.requestConsumer, exchangeContext);
        state.setIncoming(incoming);
        state.setRequestState(MessageState.ACK_EXPECTED);
        state.setResponseState(MessageState.READY);
        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
        response.setEntity(new NStringEntity("stuff"));
        final Outgoing outgoing = new Outgoing(
                request, response, this.responseProducer, exchangeContext);
        state.setOutgoing(outgoing);
        this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state);

        Mockito.when(this.responseProducer.generateResponse()).thenReturn(response);
        Mockito.when(this.conn.isResponseSubmitted()).thenReturn(Boolean.FALSE);
View Full Code Here

        this.protocolHandler.responseReady(this.conn);
    }

    @Test
    public void testResponseTrigger() throws Exception {
        final State state = new State();
        state.setRequestState(MessageState.COMPLETED);
        state.setResponseState(MessageState.READY);
        this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state);

        final HttpContext exchangeContext = new BasicHttpContext();
        final HttpAsyncExchange httpexchanage = new HttpAsyncService.HttpAsyncExchangeImpl(
                new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1),
                new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK"),
                state, this.conn, exchangeContext);
        Assert.assertFalse(httpexchanage.isCompleted());
        httpexchanage.submitResponse(this.responseProducer);
        Assert.assertTrue(httpexchanage.isCompleted());

        Assert.assertEquals(MessageState.COMPLETED, state.getRequestState());
        Assert.assertEquals(MessageState.READY, state.getResponseState());
        final Outgoing outgoing = state.getOutgoing();
        Assert.assertNotNull(outgoing);
        Assert.assertSame(this.responseProducer, outgoing.getProducer());

        Mockito.verify(this.conn).requestOutput();
View Full Code Here

        }
    }

    @Test(expected=IllegalArgumentException.class)
    public void testResponseTriggerInvalidResponseProducer() throws Exception {
        final State state = new State();
        state.setRequestState(MessageState.ACK_EXPECTED);
        this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state);

        final HttpContext exchangeContext = new BasicHttpContext();
        final HttpAsyncExchange httpexchanage = new HttpAsyncService.HttpAsyncExchangeImpl(
                new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1),
View Full Code Here

TOP

Related Classes of org.apache.http.nio.protocol.HttpAsyncService.State

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.