Skip to content
Permalink
Browse files
[HTTPCLIENT-2124] NullPointerException in MinimalHttpClient.doExecute…
…(HttpHost, ClassicHttpRequest, HttpContext) (#261)
  • Loading branch information
garydgregory authored and ok2c committed Oct 25, 2020
1 parent 1026a1e commit 65c6c250708b409bc4eca8a16a9e5e8bd9870ffc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
@@ -32,6 +32,7 @@
import java.util.Set;

import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.core5.http.ClassicHttpRequest;
@@ -71,17 +72,18 @@ public void handle(
}

@Test
public void testNonCompliantURI() throws Exception {
public void testNonCompliantURIWithContext() throws Exception {
this.server.registerHandler("*", new SimpleService());
this.httpclient = HttpClients.createMinimal();
final HttpHost target = start();

final HttpClientContext context = HttpClientContext.create();
for (int i = 0; i < 10; i++) {
final HttpGet request = new HttpGet("/");
final ClassicHttpResponse response = this.httpclient.execute(target, request, context);
EntityUtils.consume(response.getEntity());
Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
try (final CloseableHttpResponse response = this.httpclient.execute(target, request, context)) {
EntityUtils.consume(response.getEntity());
Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
}

final HttpRequest reqWrapper = context.getRequest();
Assert.assertNotNull(reqWrapper);
@@ -98,4 +100,19 @@ public void testNonCompliantURI() throws Exception {
}
}

@Test
public void testNonCompliantURIWithoutContext() throws Exception {
this.server.registerHandler("*", new SimpleService());
this.httpclient = HttpClients.createMinimal();
final HttpHost target = start();

for (int i = 0; i < 10; i++) {
final HttpGet request = new HttpGet("/");
try (final CloseableHttpResponse response = this.httpclient.execute(target, request)) {
EntityUtils.consume(response.getEntity());
Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
}
}
}

}
@@ -142,14 +142,14 @@ protected CloseableHttpResponse doExecute(
execRuntime.connectEndpoint(clientContext);
}

context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
context.setAttribute(HttpClientContext.HTTP_ROUTE, route);
clientContext.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
clientContext.setAttribute(HttpClientContext.HTTP_ROUTE, route);

httpProcessor.process(request, request.getEntity(), context);
httpProcessor.process(request, request.getEntity(), clientContext);
final ClassicHttpResponse response = execRuntime.execute(exchangeId, request, clientContext);
httpProcessor.process(response, response.getEntity(), context);
httpProcessor.process(response, response.getEntity(), clientContext);

if (reuseStrategy.keepAlive(request, response, context)) {
if (reuseStrategy.keepAlive(request, response, clientContext)) {
execRuntime.markConnectionReusable(null, TimeValue.NEG_ONE_MILLISECOND);
} else {
execRuntime.markConnectionNonReusable();

0 comments on commit 65c6c25

Please sign in to comment.