Package org.apache.http.nio.protocol.HttpAsyncServiceHandler

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


        Mockito.verify(this.cancellable).cancel();
    }

    @Test
    public void testHttpExceptionHandling() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        httpExchange.setRequestState(MessageState.READY);
        httpExchange.setResponseState(MessageState.READY);
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);

        HttpException httpex = new HttpException();
        this.protocolHandler.exception(this.conn, httpex);

        Assert.assertEquals(MessageState.READY, httpExchange.getRequestState());
        Assert.assertEquals(MessageState.BODY_STREAM, httpExchange.getResponseState());
        Assert.assertNotNull(httpExchange.getResponseProducer());
        Assert.assertNotNull(httpExchange.getResponse());
        Assert.assertEquals(500, httpExchange.getResponse().getStatusLine().getStatusCode());
    }
View Full Code Here


        Assert.assertEquals(500, httpExchange.getResponse().getStatusLine().getStatusCode());
    }

    @Test
    public void testHttpExceptionHandlingRuntimeException() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        HttpContext exchangeContext = httpExchange.getContext();
        httpExchange.setRequestState(MessageState.READY);
        httpExchange.setResponseState(MessageState.READY);
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);

        Mockito.doThrow(new RuntimeException()).when(this.httpProcessor).process(
                Mockito.any(HttpResponse.class), Mockito.eq(exchangeContext));
        try {
View Full Code Here

        }
    }

    @Test
    public void testHttpExceptionHandlingIOException() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        HttpContext exchangeContext = httpExchange.getContext();
        httpExchange.setRequestState(MessageState.READY);
        httpExchange.setResponseState(MessageState.READY);
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);

        Mockito.doThrow(new IOException()).when(this.httpProcessor).process(
                Mockito.any(HttpResponse.class), Mockito.eq(exchangeContext));
        HttpException httpex = new HttpException();
View Full Code Here

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

    @Test
    public void testHttpExceptionHandlingResponseSubmitted() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        httpExchange.setRequestState(MessageState.READY);
        httpExchange.setResponseState(MessageState.READY);
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);
        Mockito.when(this.conn.isResponseSubmitted()).thenReturn(true);

        HttpException httpex = new HttpException();
        this.protocolHandler.exception(this.conn, httpex);

        Assert.assertEquals(MessageState.READY, httpExchange.getRequestState());
        Assert.assertEquals(MessageState.READY, httpExchange.getResponseState());
        Mockito.verify(this.conn).close();
    }
View Full Code Here

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

    @Test
    public void testIOExceptionHandling() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        httpExchange.setRequestState(MessageState.READY);
        httpExchange.setResponseState(MessageState.READY);
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);

        IOException httpex = new IOException();
        this.protocolHandler.exception(this.conn, httpex);

        Assert.assertEquals(MessageState.READY, httpExchange.getRequestState());
        Assert.assertEquals(MessageState.READY, httpExchange.getResponseState());
        Mockito.verify(this.conn).shutdown();
    }
View Full Code Here

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

    @Test
    public void testBasicRequest() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        HttpContext exchangeContext = httpExchange.getContext();
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);

        BasicHttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
        Mockito.when(this.conn.getHttpRequest()).thenReturn(request);
        Mockito.when(this.requestHandler.processRequest(
                request, exchangeContext)).thenReturn(this.requestConsumer);
        Mockito.when(this.requestConsumer.getException()).thenReturn(null);
        Object data = new Object();
        Mockito.when(this.requestConsumer.getResult()).thenReturn(data);
        Mockito.when(this.requestHandler.handle(
                Mockito.eq(data),
                Mockito.any(HttpAsyncResponseTrigger.class),
                Mockito.eq(exchangeContext))).thenReturn(this.cancellable);

        this.protocolHandler.requestReceived(this.conn);

        Assert.assertEquals(MessageState.COMPLETED, httpExchange.getRequestState());
        Assert.assertEquals(MessageState.READY, httpExchange.getResponseState());

        Assert.assertSame(request, httpExchange.getRequest());
        Assert.assertSame(this.requestHandler, httpExchange.getRequestHandler());
        Assert.assertSame(this.requestConsumer, httpExchange.getRequestConsumer());
        Assert.assertSame(request, exchangeContext.getAttribute(ExecutionContext.HTTP_REQUEST));
        Assert.assertSame(this.conn, exchangeContext.getAttribute(ExecutionContext.HTTP_CONNECTION));

        Mockito.verify(this.httpProcessor).process(request, exchangeContext);
        Mockito.verify(this.requestConsumer).requestReceived(request);
        Mockito.verify(this.conn).suspendInput();
        Mockito.verify(this.requestConsumer).requestCompleted(exchangeContext);
        Mockito.verify(this.requestHandler).handle(
                Mockito.eq(data),
                Mockito.any(HttpAsyncResponseTrigger.class),
                Mockito.eq(exchangeContext));
        Assert.assertSame(this.cancellable, httpExchange.getAsyncProcess());
    }
View Full Code Here

        Assert.assertSame(this.cancellable, httpExchange.getAsyncProcess());
    }

    @Test
    public void testRequestNoMatchingHandler() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        HttpContext exchangeContext = httpExchange.getContext();
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);

        BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST",
                "/stuff", HttpVersion.HTTP_1_1);
        request.setEntity(NStringEntity.create("stuff"));
        Mockito.when(this.conn.getHttpRequest()).thenReturn(request);
        Mockito.when(this.requestHandler.processRequest(
                request, exchangeContext)).thenReturn(this.requestConsumer);

        this.protocolHandler.requestReceived(this.conn);

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

        Assert.assertSame(request, httpExchange.getRequest());
        Assert.assertTrue(httpExchange.getRequestHandler() instanceof NullRequestHandler);
    }
View Full Code Here

        Assert.assertTrue(httpExchange.getRequestHandler() instanceof NullRequestHandler);
    }

    @Test
    public void testEntityEnclosingRequest() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        HttpContext exchangeContext = httpExchange.getContext();
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);

        BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/",
                HttpVersion.HTTP_1_1);
        Mockito.when(this.conn.getHttpRequest()).thenReturn(request);
        Mockito.when(this.requestHandler.processRequest(
                request, exchangeContext)).thenReturn(this.requestConsumer);

        this.protocolHandler.requestReceived(this.conn);

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

        Assert.assertSame(request, httpExchange.getRequest());
        Assert.assertSame(this.requestHandler, httpExchange.getRequestHandler());
        Assert.assertSame(this.requestConsumer, httpExchange.getRequestConsumer());
        Assert.assertSame(request, exchangeContext.getAttribute(ExecutionContext.HTTP_REQUEST));
        Assert.assertSame(this.conn, exchangeContext.getAttribute(ExecutionContext.HTTP_CONNECTION));

        Mockito.verify(this.httpProcessor).process(request, exchangeContext);
        Mockito.verify(this.requestConsumer).requestReceived(request);
View Full Code Here

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

    @Test
    public void testEntityEnclosingRequestContinueWithoutVerification() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        HttpContext exchangeContext = httpExchange.getContext();
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);

        BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/",
                HttpVersion.HTTP_1_1);
        request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
        Mockito.when(this.conn.getHttpRequest()).thenReturn(request);
        Mockito.when(this.requestHandler.processRequest(
                request, exchangeContext)).thenReturn(this.requestConsumer);

        this.protocolHandler.requestReceived(this.conn);

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

        Assert.assertSame(request, httpExchange.getRequest());
        Assert.assertSame(this.requestHandler, httpExchange.getRequestHandler());
        Assert.assertSame(this.requestConsumer, httpExchange.getRequestConsumer());
        Assert.assertSame(request, exchangeContext.getAttribute(ExecutionContext.HTTP_REQUEST));
        Assert.assertSame(this.conn, exchangeContext.getAttribute(ExecutionContext.HTTP_CONNECTION));

        Mockito.verify(this.httpProcessor).process(request, exchangeContext);
        Mockito.verify(this.requestConsumer).requestReceived(request);
View Full Code Here

    public void testEntityEnclosingRequestExpectationVerification() throws Exception {
        HttpAsyncExpectationVerifier expectationVerifier = Mockito.mock(HttpAsyncExpectationVerifier.class);
        this.protocolHandler = new HttpAsyncServiceHandler(
                this.handlerResolver, expectationVerifier, this.httpProcessor, this.reuseStrategy, this.params);

        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        HttpContext exchangeContext = httpExchange.getContext();
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);

        BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/",
                HttpVersion.HTTP_1_1);
        request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
        Mockito.when(this.conn.getHttpRequest()).thenReturn(request);
        Mockito.when(this.requestHandler.processRequest(
                request, exchangeContext)).thenReturn(this.requestConsumer);
        Mockito.when(expectationVerifier.verify(
                Mockito.eq(request),
                Mockito.any(HttpAsyncContinueTrigger.class),
                Mockito.eq(exchangeContext))).thenReturn(this.cancellable);

        this.protocolHandler.requestReceived(this.conn);

        Assert.assertEquals(MessageState.ACK_EXPECTED, httpExchange.getRequestState());
        Assert.assertEquals(MessageState.READY, httpExchange.getResponseState());

        Assert.assertSame(request, httpExchange.getRequest());
        Assert.assertSame(this.requestHandler, httpExchange.getRequestHandler());
        Assert.assertSame(this.requestConsumer, httpExchange.getRequestConsumer());
        Assert.assertSame(request, exchangeContext.getAttribute(ExecutionContext.HTTP_REQUEST));
        Assert.assertSame(this.conn, exchangeContext.getAttribute(ExecutionContext.HTTP_CONNECTION));

        Mockito.verify(this.httpProcessor).process(request, exchangeContext);
        Mockito.verify(this.requestConsumer).requestReceived(request);
        Mockito.verify(this.conn).suspendInput();
        Mockito.verify(expectationVerifier).verify(
                Mockito.eq(request),
                Mockito.any(HttpAsyncContinueTrigger.class),
                Mockito.eq(exchangeContext));
        Assert.assertSame(this.cancellable, httpExchange.getAsyncProcess());
    }
View Full Code Here

TOP

Related Classes of org.apache.http.nio.protocol.HttpAsyncServiceHandler.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.