[HTTPCLIENT-2124] NullPointerException in MinimalHttpClient.doExecute(HttpHost, ClassicHttpRequest, HttpContext) (#261)
This commit is contained in:
parent
1026a1e558
commit
65c6c25070
|
@ -32,6 +32,7 @@ import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.hc.client5.http.classic.methods.HttpGet;
|
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.impl.classic.HttpClients;
|
||||||
import org.apache.hc.client5.http.protocol.HttpClientContext;
|
import org.apache.hc.client5.http.protocol.HttpClientContext;
|
||||||
import org.apache.hc.core5.http.ClassicHttpRequest;
|
import org.apache.hc.core5.http.ClassicHttpRequest;
|
||||||
|
@ -71,7 +72,7 @@ public class TestMinimalClientRequestExecution extends LocalServerTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNonCompliantURI() throws Exception {
|
public void testNonCompliantURIWithContext() throws Exception {
|
||||||
this.server.registerHandler("*", new SimpleService());
|
this.server.registerHandler("*", new SimpleService());
|
||||||
this.httpclient = HttpClients.createMinimal();
|
this.httpclient = HttpClients.createMinimal();
|
||||||
final HttpHost target = start();
|
final HttpHost target = start();
|
||||||
|
@ -79,9 +80,10 @@ public class TestMinimalClientRequestExecution extends LocalServerTestBase {
|
||||||
final HttpClientContext context = HttpClientContext.create();
|
final HttpClientContext context = HttpClientContext.create();
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
final HttpGet request = new HttpGet("/");
|
final HttpGet request = new HttpGet("/");
|
||||||
final ClassicHttpResponse response = this.httpclient.execute(target, request, context);
|
try (final CloseableHttpResponse response = this.httpclient.execute(target, request, context)) {
|
||||||
EntityUtils.consume(response.getEntity());
|
EntityUtils.consume(response.getEntity());
|
||||||
Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
|
Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
|
||||||
|
}
|
||||||
|
|
||||||
final HttpRequest reqWrapper = context.getRequest();
|
final HttpRequest reqWrapper = context.getRequest();
|
||||||
Assert.assertNotNull(reqWrapper);
|
Assert.assertNotNull(reqWrapper);
|
||||||
|
@ -98,4 +100,19 @@ public class TestMinimalClientRequestExecution extends LocalServerTestBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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 @@ public class MinimalHttpClient extends CloseableHttpClient {
|
||||||
execRuntime.connectEndpoint(clientContext);
|
execRuntime.connectEndpoint(clientContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
|
clientContext.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
|
||||||
context.setAttribute(HttpClientContext.HTTP_ROUTE, route);
|
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);
|
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);
|
execRuntime.markConnectionReusable(null, TimeValue.NEG_ONE_MILLISECOND);
|
||||||
} else {
|
} else {
|
||||||
execRuntime.markConnectionNonReusable();
|
execRuntime.markConnectionNonReusable();
|
||||||
|
|
Loading…
Reference in New Issue