Search in sources :

Example 26 with HttpProcessor

use of org.apache.hc.core5.http.protocol.HttpProcessor in project httpcomponents-core by apache.

the class TestHttpRequestExecutor method testBasicExecution.

@Test
public void testBasicExecution() throws Exception {
    final HttpProcessor httprocessor = Mockito.mock(HttpProcessor.class);
    final HttpClientConnection conn = Mockito.mock(HttpClientConnection.class);
    final HttpRequestExecutor executor = new HttpRequestExecutor();
    final HttpCoreContext context = HttpCoreContext.create();
    final ClassicHttpRequest request = new BasicClassicHttpRequest(Method.GET, "/");
    executor.preProcess(request, httprocessor, context);
    Mockito.verify(httprocessor).process(request, request.getEntity(), context);
    Mockito.when(conn.receiveResponseHeader()).thenReturn(new BasicClassicHttpResponse(200, "OK"));
    final ClassicHttpResponse response = executor.execute(request, conn, context);
    Mockito.verify(conn).sendRequestHeader(request);
    Mockito.verify(conn).flush();
    Mockito.verify(conn).receiveResponseHeader();
    Mockito.verify(conn).receiveResponseEntity(response);
    executor.postProcess(response, httprocessor, context);
    Mockito.verify(httprocessor).process(response, response.getEntity(), context);
    Assertions.assertSame(request, context.getRequest());
    Assertions.assertSame(response, context.getResponse());
}
Also used : BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) ClassicHttpResponse(org.apache.hc.core5.http.ClassicHttpResponse) BasicClassicHttpRequest(org.apache.hc.core5.http.message.BasicClassicHttpRequest) ClassicHttpRequest(org.apache.hc.core5.http.ClassicHttpRequest) BasicClassicHttpRequest(org.apache.hc.core5.http.message.BasicClassicHttpRequest) HttpProcessor(org.apache.hc.core5.http.protocol.HttpProcessor) HttpClientConnection(org.apache.hc.core5.http.io.HttpClientConnection) HttpCoreContext(org.apache.hc.core5.http.protocol.HttpCoreContext) BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) Test(org.junit.jupiter.api.Test)

Example 27 with HttpProcessor

use of org.apache.hc.core5.http.protocol.HttpProcessor in project httpcomponents-core by apache.

the class TestHttpRequestExecutor method testExecutionEntityEnclosingRequestWithExpectContinueFailure.

@Test
public void testExecutionEntityEnclosingRequestWithExpectContinueFailure() throws Exception {
    final HttpProcessor httprocessor = Mockito.mock(HttpProcessor.class);
    final HttpClientConnection conn = Mockito.mock(HttpClientConnection.class);
    final HttpRequestExecutor executor = new HttpRequestExecutor();
    final HttpCoreContext context = HttpCoreContext.create();
    final ClassicHttpRequest request = new BasicClassicHttpRequest(Method.POST, "/");
    request.addHeader(HttpHeaders.EXPECT, HeaderElements.CONTINUE);
    final HttpEntity entity = Mockito.mock(HttpEntity.class);
    request.setEntity(entity);
    executor.preProcess(request, httprocessor, context);
    Mockito.verify(httprocessor).process(request, request.getEntity(), context);
    Mockito.when(conn.receiveResponseHeader()).thenReturn(new BasicClassicHttpResponse(402, "OK"));
    Mockito.when(conn.isDataAvailable(ArgumentMatchers.any(Timeout.class))).thenReturn(Boolean.TRUE);
    final ClassicHttpResponse response = executor.execute(request, conn, context);
    Mockito.verify(conn).sendRequestHeader(request);
    Mockito.verify(conn, Mockito.never()).sendRequestEntity(request);
    Mockito.verify(conn).terminateRequest(request);
    Mockito.verify(conn, Mockito.times(2)).flush();
    Mockito.verify(conn).isDataAvailable(Timeout.ofMilliseconds(3000));
    Mockito.verify(conn).receiveResponseHeader();
    Mockito.verify(conn).receiveResponseEntity(response);
    executor.postProcess(response, httprocessor, context);
    Mockito.verify(httprocessor).process(response, response.getEntity(), context);
}
Also used : BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) ClassicHttpResponse(org.apache.hc.core5.http.ClassicHttpResponse) BasicClassicHttpRequest(org.apache.hc.core5.http.message.BasicClassicHttpRequest) ClassicHttpRequest(org.apache.hc.core5.http.ClassicHttpRequest) BasicClassicHttpRequest(org.apache.hc.core5.http.message.BasicClassicHttpRequest) HttpEntity(org.apache.hc.core5.http.HttpEntity) HttpProcessor(org.apache.hc.core5.http.protocol.HttpProcessor) HttpClientConnection(org.apache.hc.core5.http.io.HttpClientConnection) Timeout(org.apache.hc.core5.util.Timeout) HttpCoreContext(org.apache.hc.core5.http.protocol.HttpCoreContext) BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) Test(org.junit.jupiter.api.Test)

Example 28 with HttpProcessor

use of org.apache.hc.core5.http.protocol.HttpProcessor in project httpcomponents-core by apache.

the class TestHttpRequestExecutor method testExecutionEntityEnclosingRequest.

@Test
public void testExecutionEntityEnclosingRequest() throws Exception {
    final HttpProcessor httprocessor = Mockito.mock(HttpProcessor.class);
    final HttpClientConnection conn = Mockito.mock(HttpClientConnection.class);
    final HttpRequestExecutor executor = new HttpRequestExecutor();
    final HttpCoreContext context = HttpCoreContext.create();
    final ClassicHttpRequest request = new BasicClassicHttpRequest(Method.POST, "/");
    final HttpEntity entity = Mockito.mock(HttpEntity.class);
    request.setEntity(entity);
    executor.preProcess(request, httprocessor, context);
    Mockito.verify(httprocessor).process(request, request.getEntity(), context);
    Mockito.when(conn.receiveResponseHeader()).thenReturn(new BasicClassicHttpResponse(200, "OK"));
    final ClassicHttpResponse response = executor.execute(request, conn, context);
    Mockito.verify(conn).sendRequestHeader(request);
    Mockito.verify(conn).sendRequestEntity(request);
    Mockito.verify(conn).flush();
    Mockito.verify(conn).receiveResponseHeader();
    Mockito.verify(conn).receiveResponseEntity(response);
    executor.postProcess(response, httprocessor, context);
    Mockito.verify(httprocessor).process(response, response.getEntity(), context);
}
Also used : BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) ClassicHttpResponse(org.apache.hc.core5.http.ClassicHttpResponse) BasicClassicHttpRequest(org.apache.hc.core5.http.message.BasicClassicHttpRequest) ClassicHttpRequest(org.apache.hc.core5.http.ClassicHttpRequest) BasicClassicHttpRequest(org.apache.hc.core5.http.message.BasicClassicHttpRequest) HttpEntity(org.apache.hc.core5.http.HttpEntity) HttpProcessor(org.apache.hc.core5.http.protocol.HttpProcessor) HttpClientConnection(org.apache.hc.core5.http.io.HttpClientConnection) HttpCoreContext(org.apache.hc.core5.http.protocol.HttpCoreContext) BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) Test(org.junit.jupiter.api.Test)

Example 29 with HttpProcessor

use of org.apache.hc.core5.http.protocol.HttpProcessor in project httpcomponents-core by apache.

the class TestHttpRequestExecutor method testExecutionEntityEnclosingRequestWithExpectContinueSuccess.

@Test
public void testExecutionEntityEnclosingRequestWithExpectContinueSuccess() throws Exception {
    final HttpProcessor httprocessor = Mockito.mock(HttpProcessor.class);
    final HttpClientConnection conn = Mockito.mock(HttpClientConnection.class);
    final HttpRequestExecutor executor = new HttpRequestExecutor();
    final HttpCoreContext context = HttpCoreContext.create();
    final ClassicHttpRequest request = new BasicClassicHttpRequest(Method.POST, "/");
    request.addHeader(HttpHeaders.EXPECT, HeaderElements.CONTINUE);
    final HttpEntity entity = Mockito.mock(HttpEntity.class);
    request.setEntity(entity);
    executor.preProcess(request, httprocessor, context);
    Mockito.verify(httprocessor).process(request, request.getEntity(), context);
    Mockito.when(conn.receiveResponseHeader()).thenReturn(new BasicClassicHttpResponse(100, "Continue"), new BasicClassicHttpResponse(200, "OK"));
    Mockito.when(conn.isDataAvailable(ArgumentMatchers.any(Timeout.class))).thenReturn(Boolean.TRUE);
    final ClassicHttpResponse response = executor.execute(request, conn, context);
    Mockito.verify(conn).sendRequestHeader(request);
    Mockito.verify(conn).sendRequestEntity(request);
    Mockito.verify(conn, Mockito.times(2)).flush();
    Mockito.verify(conn).isDataAvailable(Timeout.ofMilliseconds(3000));
    Mockito.verify(conn, Mockito.times(2)).receiveResponseHeader();
    Mockito.verify(conn).receiveResponseEntity(response);
    executor.postProcess(response, httprocessor, context);
    Mockito.verify(httprocessor).process(response, response.getEntity(), context);
}
Also used : BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) ClassicHttpResponse(org.apache.hc.core5.http.ClassicHttpResponse) BasicClassicHttpRequest(org.apache.hc.core5.http.message.BasicClassicHttpRequest) ClassicHttpRequest(org.apache.hc.core5.http.ClassicHttpRequest) BasicClassicHttpRequest(org.apache.hc.core5.http.message.BasicClassicHttpRequest) HttpEntity(org.apache.hc.core5.http.HttpEntity) HttpProcessor(org.apache.hc.core5.http.protocol.HttpProcessor) HttpClientConnection(org.apache.hc.core5.http.io.HttpClientConnection) Timeout(org.apache.hc.core5.util.Timeout) HttpCoreContext(org.apache.hc.core5.http.protocol.HttpCoreContext) BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) Test(org.junit.jupiter.api.Test)

Example 30 with HttpProcessor

use of org.apache.hc.core5.http.protocol.HttpProcessor in project httpcomponents-core by apache.

the class TestHttpRequestExecutor method testExecutionEntityEnclosingRequestWithExpectContinueNoResponse.

@Test
public void testExecutionEntityEnclosingRequestWithExpectContinueNoResponse() throws Exception {
    final HttpProcessor httprocessor = Mockito.mock(HttpProcessor.class);
    final HttpClientConnection conn = Mockito.mock(HttpClientConnection.class);
    final HttpRequestExecutor executor = new HttpRequestExecutor();
    final HttpCoreContext context = HttpCoreContext.create();
    final ClassicHttpRequest request = new BasicClassicHttpRequest(Method.POST, "/");
    request.addHeader(HttpHeaders.EXPECT, HeaderElements.CONTINUE);
    final HttpEntity entity = Mockito.mock(HttpEntity.class);
    request.setEntity(entity);
    executor.preProcess(request, httprocessor, context);
    Mockito.verify(httprocessor).process(request, request.getEntity(), context);
    Mockito.when(conn.receiveResponseHeader()).thenReturn(new BasicClassicHttpResponse(200, "OK"));
    Mockito.when(conn.isDataAvailable(ArgumentMatchers.any(Timeout.class))).thenReturn(Boolean.FALSE);
    final ClassicHttpResponse response = executor.execute(request, conn, context);
    Mockito.verify(conn).sendRequestHeader(request);
    Mockito.verify(conn).sendRequestEntity(request);
    Mockito.verify(conn, Mockito.times(2)).flush();
    Mockito.verify(conn).isDataAvailable(Timeout.ofMilliseconds(3000));
    Mockito.verify(conn).receiveResponseHeader();
    Mockito.verify(conn).receiveResponseEntity(response);
    executor.postProcess(response, httprocessor, context);
    Mockito.verify(httprocessor).process(response, response.getEntity(), context);
}
Also used : BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) ClassicHttpResponse(org.apache.hc.core5.http.ClassicHttpResponse) BasicClassicHttpRequest(org.apache.hc.core5.http.message.BasicClassicHttpRequest) ClassicHttpRequest(org.apache.hc.core5.http.ClassicHttpRequest) BasicClassicHttpRequest(org.apache.hc.core5.http.message.BasicClassicHttpRequest) HttpEntity(org.apache.hc.core5.http.HttpEntity) HttpProcessor(org.apache.hc.core5.http.protocol.HttpProcessor) HttpClientConnection(org.apache.hc.core5.http.io.HttpClientConnection) Timeout(org.apache.hc.core5.util.Timeout) HttpCoreContext(org.apache.hc.core5.http.protocol.HttpCoreContext) BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) Test(org.junit.jupiter.api.Test)

Aggregations

HttpProcessor (org.apache.hc.core5.http.protocol.HttpProcessor)17 HttpCoreContext (org.apache.hc.core5.http.protocol.HttpCoreContext)16 HttpClientConnection (org.apache.hc.core5.http.io.HttpClientConnection)12 ClassicHttpResponse (org.apache.hc.core5.http.ClassicHttpResponse)11 ClassicHttpRequest (org.apache.hc.core5.http.ClassicHttpRequest)10 Test (org.junit.jupiter.api.Test)10 BasicClassicHttpRequest (org.apache.hc.core5.http.message.BasicClassicHttpRequest)8 BasicClassicHttpResponse (org.apache.hc.core5.http.message.BasicClassicHttpResponse)8 InetSocketAddress (java.net.InetSocketAddress)7 HttpResponse (org.apache.hc.core5.http.HttpResponse)7 Timeout (org.apache.hc.core5.util.Timeout)7 HttpEntity (org.apache.hc.core5.http.HttpEntity)5 HttpHost (org.apache.hc.core5.http.HttpHost)5 Message (org.apache.hc.core5.http.Message)5 IOSession (org.apache.hc.core5.reactor.IOSession)5 Supplier (org.apache.hc.core5.function.Supplier)4 DefaultAsyncResponseExchangeHandlerFactory (org.apache.hc.core5.http.nio.support.DefaultAsyncResponseExchangeHandlerFactory)4 RequestHandlerRegistry (org.apache.hc.core5.http.protocol.RequestHandlerRegistry)4 IOEventHandlerFactory (org.apache.hc.core5.reactor.IOEventHandlerFactory)4 List (java.util.List)3