You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2016/12/27 19:48:10 UTC
svn commit: r1776187 [14/21] - in /httpcomponents/httpclient/trunk: ./
httpclient5-cache/src/main/java/org/apache/hc/client5/http/cache/
httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/
httpclient5-cache/src/test/java/org/apache/h...
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/protocol/DefaultRedirectStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/protocol/DefaultRedirectStrategy.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/protocol/DefaultRedirectStrategy.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/protocol/DefaultRedirectStrategy.java Tue Dec 27 19:48:07 2016
@@ -41,20 +41,20 @@ import org.apache.hc.client5.http.protoc
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.client5.http.protocol.RedirectLocations;
import org.apache.hc.client5.http.protocol.RedirectStrategy;
-import org.apache.hc.client5.http.utils.URIBuilder;
import org.apache.hc.client5.http.utils.URIUtils;
-import org.apache.hc.core5.annotation.Immutable;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHeaders;
-import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.ProtocolException;
import org.apache.hc.core5.http.protocol.HttpContext;
+import org.apache.hc.core5.net.URIBuilder;
import org.apache.hc.core5.util.Args;
-import org.apache.hc.core5.util.Asserts;
import org.apache.hc.core5.util.TextUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -68,8 +68,8 @@ import org.apache.logging.log4j.Logger;
*
* @since 4.1
*/
-@Immutable
-public class DefaultRedirectStrategy implements RedirectStrategy {
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
+public class DefaultRedirectStrategy<T extends HttpRequest> implements RedirectStrategy {
private final Logger log = LogManager.getLogger(getClass());
@@ -100,7 +100,7 @@ public class DefaultRedirectStrategy imp
if (!response.containsHeader(HttpHeaders.LOCATION)) {
return false;
}
- final int statusCode = response.getStatusLine().getStatusCode();
+ final int statusCode = response.getCode();
switch (statusCode) {
case HttpStatus.SC_MOVED_PERMANENTLY:
case HttpStatus.SC_MOVED_TEMPORARILY:
@@ -138,11 +138,7 @@ public class DefaultRedirectStrategy imp
try {
if (!uri.isAbsolute()) {
// Resolve location URI
- final HttpHost target = clientContext.getTargetHost();
- Asserts.notNull(target, "Target host");
- final URI requestURI = new URI(request.getRequestLine().getUri());
- final URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, target, false);
- uri = URIUtils.resolve(absoluteRequestURI, uri);
+ uri = URIUtils.resolve(request.getUri(), uri);
}
} catch (final URISyntaxException ex) {
throw new ProtocolException(ex.getMessage(), ex);
@@ -185,18 +181,20 @@ public class DefaultRedirectStrategy imp
@Override
public HttpUriRequest getRedirect(
- final HttpRequest request,
+ final ClassicHttpRequest request,
final HttpResponse response,
final HttpContext context) throws HttpException {
final URI uri = getLocationURI(request, response, context);
- final int statusCode = response.getStatusLine().getStatusCode();
+ final int statusCode = response.getCode();
switch (statusCode) {
case HttpStatus.SC_MOVED_PERMANENTLY:
case HttpStatus.SC_MOVED_TEMPORARILY:
case HttpStatus.SC_SEE_OTHER:
- final String method = request.getRequestLine().getMethod().toUpperCase(Locale.ROOT);
+ final String method = request.getMethod().toUpperCase(Locale.ROOT);
if (!this.safeMethods.containsKey(method)) {
- return new HttpGet(uri);
+ final HttpGet httpGet = new HttpGet(uri);
+ httpGet.setHeaders(request.getAllHeaders());
+ return httpGet;
}
case HttpStatus.SC_TEMPORARY_REDIRECT:
default:
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/protocol/DefaultUserTokenHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/protocol/DefaultUserTokenHandler.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/protocol/DefaultUserTokenHandler.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/protocol/DefaultUserTokenHandler.java Tue Dec 27 19:48:07 2016
@@ -36,7 +36,8 @@ import org.apache.hc.client5.http.auth.A
import org.apache.hc.client5.http.io.ManagedHttpClientConnection;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.client5.http.protocol.UserTokenHandler;
-import org.apache.hc.core5.annotation.Immutable;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.http.HttpConnection;
import org.apache.hc.core5.http.protocol.HttpContext;
@@ -54,7 +55,7 @@ import org.apache.hc.core5.http.protocol
*
* @since 4.0
*/
-@Immutable
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
public class DefaultUserTokenHandler implements UserTokenHandler {
public static final DefaultUserTokenHandler INSTANCE = new DefaultUserTokenHandler();
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/BasicRouteDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/BasicRouteDirector.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/BasicRouteDirector.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/BasicRouteDirector.java Tue Dec 27 19:48:07 2016
@@ -29,7 +29,8 @@ package org.apache.hc.client5.http.impl.
import org.apache.hc.client5.http.RouteInfo;
import org.apache.hc.client5.http.routing.HttpRouteDirector;
-import org.apache.hc.core5.annotation.Immutable;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.util.Args;
/**
@@ -37,7 +38,7 @@ import org.apache.hc.core5.util.Args;
*
* @since 4.0
*/
-@Immutable
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
public class BasicRouteDirector implements HttpRouteDirector {
/**
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/DefaultProxyRoutePlanner.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/DefaultProxyRoutePlanner.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/DefaultProxyRoutePlanner.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/DefaultProxyRoutePlanner.java Tue Dec 27 19:48:07 2016
@@ -28,7 +28,8 @@
package org.apache.hc.client5.http.impl.routing;
import org.apache.hc.client5.http.SchemePortResolver;
-import org.apache.hc.core5.annotation.Immutable;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpRequest;
@@ -41,7 +42,7 @@ import org.apache.hc.core5.util.Args;
*
* @since 4.3
*/
-@Immutable
+@Contract(threading = ThreadingBehavior.IMMUTABLE_CONDITIONAL)
public class DefaultProxyRoutePlanner extends DefaultRoutePlanner {
private final HttpHost proxy;
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/DefaultRoutePlanner.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/DefaultRoutePlanner.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/DefaultRoutePlanner.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/DefaultRoutePlanner.java Tue Dec 27 19:48:07 2016
@@ -36,7 +36,8 @@ import org.apache.hc.client5.http.config
import org.apache.hc.client5.http.impl.DefaultSchemePortResolver;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.client5.http.routing.HttpRoutePlanner;
-import org.apache.hc.core5.annotation.Immutable;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpRequest;
@@ -50,7 +51,7 @@ import org.apache.hc.core5.util.Args;
*
* @since 4.3
*/
-@Immutable
+@Contract(threading = ThreadingBehavior.IMMUTABLE_CONDITIONAL)
public class DefaultRoutePlanner implements HttpRoutePlanner {
private final SchemePortResolver schemePortResolver;
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/SystemDefaultRoutePlanner.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/SystemDefaultRoutePlanner.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/SystemDefaultRoutePlanner.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/SystemDefaultRoutePlanner.java Tue Dec 27 19:48:07 2016
@@ -35,7 +35,8 @@ import java.net.URISyntaxException;
import java.util.List;
import org.apache.hc.client5.http.SchemePortResolver;
-import org.apache.hc.core5.annotation.Immutable;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpRequest;
@@ -49,7 +50,7 @@ import org.apache.hc.core5.http.protocol
*
* @since 4.3
*/
-@Immutable
+@Contract(threading = ThreadingBehavior.IMMUTABLE_CONDITIONAL)
public class SystemDefaultRoutePlanner extends DefaultRoutePlanner {
private final ProxySelector proxySelector;
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/AbstractResponseHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/AbstractResponseHandler.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/AbstractResponseHandler.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/AbstractResponseHandler.java Tue Dec 27 19:48:07 2016
@@ -30,12 +30,13 @@ package org.apache.hc.client5.http.impl.
import java.io.IOException;
import org.apache.hc.client5.http.protocol.HttpResponseException;
-import org.apache.hc.client5.http.sync.ResponseHandler;
-import org.apache.hc.core5.annotation.Immutable;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.HttpEntity;
-import org.apache.hc.core5.http.HttpResponse;
-import org.apache.hc.core5.http.StatusLine;
-import org.apache.hc.core5.http.entity.EntityUtils;
+import org.apache.hc.core5.http.HttpStatus;
+import org.apache.hc.core5.http.io.ResponseHandler;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
/**
* A generic {@link ResponseHandler} that works with the response entity
@@ -43,14 +44,14 @@ import org.apache.hc.core5.http.entity.E
* body is consumed and an {@link HttpResponseException} is thrown.
* <p>
* If this is used with
- * {@link org.apache.hc.client5.http.sync.HttpClient#execute(
- * org.apache.hc.client5.http.methods.HttpUriRequest, ResponseHandler)},
+ * {@link org.apache.hc.client5.http.sync.HttpClient#execute(org.apache.hc.core5.http.ClassicHttpRequest,
+ * ResponseHandler)},
* HttpClient may handle redirects (3xx responses) internally.
* </p>
*
* @since 4.4
*/
-@Immutable
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
public abstract class AbstractResponseHandler<T> implements ResponseHandler<T> {
/**
@@ -60,14 +61,11 @@ public abstract class AbstractResponseHa
* status code), throws an {@link HttpResponseException}.
*/
@Override
- public T handleResponse(final HttpResponse response)
- throws IOException {
- final StatusLine statusLine = response.getStatusLine();
+ public T handleResponse(final ClassicHttpResponse response) throws IOException {
final HttpEntity entity = response.getEntity();
- if (statusLine.getStatusCode() >= 300) {
+ if (response.getCode() >= HttpStatus.SC_REDIRECTION) {
EntityUtils.consume(entity);
- throw new HttpResponseException(statusLine.getStatusCode(),
- statusLine.getReasonPhrase());
+ throw new HttpResponseException(response.getCode(), response.getReasonPhrase());
}
return entity == null ? null : handleEntity(entity);
}
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/BackoffStrategyExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/BackoffStrategyExec.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/BackoffStrategyExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/BackoffStrategyExec.java Tue Dec 27 19:48:07 2016
@@ -31,20 +31,21 @@ import java.io.IOException;
import java.lang.reflect.UndeclaredThrowableException;
import org.apache.hc.client5.http.HttpRoute;
-import org.apache.hc.client5.http.methods.CloseableHttpResponse;
import org.apache.hc.client5.http.methods.HttpExecutionAware;
-import org.apache.hc.client5.http.methods.HttpRequestWrapper;
+import org.apache.hc.client5.http.methods.RoutedHttpRequest;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.client5.http.sync.BackoffManager;
import org.apache.hc.client5.http.sync.ConnectionBackoffStrategy;
-import org.apache.hc.core5.annotation.Immutable;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.util.Args;
/**
* @since 4.3
*/
-@Immutable
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
public class BackoffStrategyExec implements ClientExecChain {
private final ClientExecChain requestExecutor;
@@ -65,17 +66,17 @@ public class BackoffStrategyExec impleme
}
@Override
- public CloseableHttpResponse execute(
- final HttpRoute route,
- final HttpRequestWrapper request,
+ public ClassicHttpResponse execute(
+ final RoutedHttpRequest request,
final HttpClientContext context,
final HttpExecutionAware execAware) throws IOException, HttpException {
- Args.notNull(route, "HTTP route");
Args.notNull(request, "HTTP request");
Args.notNull(context, "HTTP context");
- CloseableHttpResponse out = null;
+ final HttpRoute route = request.getRoute();
+
+ ClassicHttpResponse out = null;
try {
- out = this.requestExecutor.execute(route, request, context, execAware);
+ out = this.requestExecutor.execute(request, context, execAware);
} catch (final Exception ex) {
if (out != null) {
out.close();
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/BasicCredentialsProvider.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/BasicCredentialsProvider.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/BasicCredentialsProvider.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/BasicCredentialsProvider.java Tue Dec 27 19:48:07 2016
@@ -32,7 +32,8 @@ import java.util.concurrent.ConcurrentHa
import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.Credentials;
import org.apache.hc.client5.http.auth.CredentialsStore;
-import org.apache.hc.core5.annotation.ThreadSafe;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.http.protocol.HttpContext;
import org.apache.hc.core5.util.Args;
@@ -41,7 +42,7 @@ import org.apache.hc.core5.util.Args;
*
* @since 4.0
*/
-@ThreadSafe
+@Contract(threading = ThreadingBehavior.SAFE)
public class BasicCredentialsProvider implements CredentialsStore {
private final ConcurrentHashMap<AuthScope, Credentials> credMap;
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ClientExecChain.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ClientExecChain.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ClientExecChain.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ClientExecChain.java Tue Dec 27 19:48:07 2016
@@ -29,11 +29,10 @@ package org.apache.hc.client5.http.impl.
import java.io.IOException;
-import org.apache.hc.client5.http.HttpRoute;
-import org.apache.hc.client5.http.methods.CloseableHttpResponse;
import org.apache.hc.client5.http.methods.HttpExecutionAware;
-import org.apache.hc.client5.http.methods.HttpRequestWrapper;
+import org.apache.hc.client5.http.methods.RoutedHttpRequest;
import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.HttpException;
/**
@@ -43,7 +42,7 @@ import org.apache.hc.core5.http.HttpExce
* <p>
* Important: please note it is required for decorators that implement post execution aspects
* or response post-processing of any sort to release resources associated with the response
- * by calling {@link CloseableHttpResponse#close()} methods in case of an I/O, protocol or
+ * by calling {@link ClassicHttpResponse#close()} methods in case of an I/O, protocol or
* runtime exception, or in case the response is not propagated to the caller.
* </p>
*
@@ -55,7 +54,6 @@ public interface ClientExecChain {
* Executes th request either by transmitting it to the target server or
* by passing it onto the next executor in the request execution chain.
*
- * @param route connection route.
* @param request current request.
* @param clientContext current HTTP context.
* @param execAware receiver of notifications of blocking I/O operations.
@@ -66,9 +64,8 @@ public interface ClientExecChain {
* @throws HttpException in case of an HTTP protocol error
* (usually this type of exceptions are non-recoverable).
*/
- CloseableHttpResponse execute(
- HttpRoute route,
- HttpRequestWrapper request,
+ ClassicHttpResponse execute(
+ RoutedHttpRequest request,
HttpClientContext clientContext,
HttpExecutionAware execAware) throws IOException, HttpException;
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/CloseableHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/CloseableHttpClient.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/CloseableHttpClient.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/CloseableHttpClient.java Tue Dec 27 19:48:07 2016
@@ -30,18 +30,19 @@ package org.apache.hc.client5.http.impl.
import java.io.Closeable;
import java.io.IOException;
import java.net.URI;
+import java.net.URISyntaxException;
-import org.apache.hc.client5.http.methods.CloseableHttpResponse;
-import org.apache.hc.client5.http.methods.HttpUriRequest;
import org.apache.hc.client5.http.protocol.ClientProtocolException;
import org.apache.hc.client5.http.sync.HttpClient;
-import org.apache.hc.client5.http.sync.ResponseHandler;
import org.apache.hc.client5.http.utils.URIUtils;
-import org.apache.hc.core5.annotation.ThreadSafe;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.HttpEntity;
+import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHost;
-import org.apache.hc.core5.http.HttpRequest;
-import org.apache.hc.core5.http.entity.EntityUtils;
+import org.apache.hc.core5.http.io.ResponseHandler;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.protocol.HttpContext;
import org.apache.hc.core5.util.Args;
import org.apache.logging.log4j.LogManager;
@@ -52,13 +53,13 @@ import org.apache.logging.log4j.Logger;
*
* @since 4.3
*/
-@ThreadSafe
+@Contract(threading = ThreadingBehavior.SAFE)
public abstract class CloseableHttpClient implements HttpClient, Closeable {
private final Logger log = LogManager.getLogger(getClass());
- protected abstract CloseableHttpResponse doExecute(HttpHost target, HttpRequest request,
- HttpContext context) throws IOException;
+ protected abstract CloseableHttpResponse doExecute(HttpHost target, ClassicHttpRequest request,
+ HttpContext context) throws IOException;
/**
* {@inheritDoc}
@@ -66,7 +67,7 @@ public abstract class CloseableHttpClien
@Override
public CloseableHttpResponse execute(
final HttpHost target,
- final HttpRequest request,
+ final ClassicHttpRequest request,
final HttpContext context) throws IOException {
return doExecute(target, request, context);
}
@@ -76,19 +77,22 @@ public abstract class CloseableHttpClien
*/
@Override
public CloseableHttpResponse execute(
- final HttpUriRequest request,
+ final ClassicHttpRequest request,
final HttpContext context) throws IOException {
Args.notNull(request, "HTTP request");
return doExecute(determineTarget(request), request, context);
}
- private static HttpHost determineTarget(final HttpUriRequest request) throws ClientProtocolException {
+ private static HttpHost determineTarget(final ClassicHttpRequest request) throws ClientProtocolException {
// A null target may be acceptable if there is a default target.
// Otherwise, the null target is detected in the director.
HttpHost target = null;
-
- final URI requestURI = request.getURI();
- if (requestURI.isAbsolute()) {
+ URI requestURI = null;
+ try {
+ requestURI = request.getUri();
+ } catch (URISyntaxException ignore) {
+ }
+ if (requestURI != null && requestURI.isAbsolute()) {
target = URIUtils.extractHost(requestURI);
if (target == null) {
throw new ClientProtocolException("URI does not specify a valid host name: "
@@ -103,7 +107,7 @@ public abstract class CloseableHttpClien
*/
@Override
public CloseableHttpResponse execute(
- final HttpUriRequest request) throws IOException {
+ final ClassicHttpRequest request) throws IOException {
return execute(request, (HttpContext) null);
}
@@ -113,7 +117,7 @@ public abstract class CloseableHttpClien
@Override
public CloseableHttpResponse execute(
final HttpHost target,
- final HttpRequest request) throws IOException {
+ final ClassicHttpRequest request) throws IOException {
return doExecute(target, request, null);
}
@@ -133,7 +137,7 @@ public abstract class CloseableHttpClien
* @throws ClientProtocolException in case of an http protocol error
*/
@Override
- public <T> T execute(final HttpUriRequest request,
+ public <T> T execute(final ClassicHttpRequest request,
final ResponseHandler<? extends T> responseHandler) throws IOException {
return execute(request, responseHandler, null);
}
@@ -156,7 +160,7 @@ public abstract class CloseableHttpClien
* @throws ClientProtocolException in case of an http protocol error
*/
@Override
- public <T> T execute(final HttpUriRequest request,
+ public <T> T execute(final ClassicHttpRequest request,
final ResponseHandler<? extends T> responseHandler, final HttpContext context)
throws IOException {
final HttpHost target = determineTarget(request);
@@ -183,7 +187,7 @@ public abstract class CloseableHttpClien
* @throws ClientProtocolException in case of an http protocol error
*/
@Override
- public <T> T execute(final HttpHost target, final HttpRequest request,
+ public <T> T execute(final HttpHost target, final ClassicHttpRequest request,
final ResponseHandler<? extends T> responseHandler) throws IOException {
return execute(target, request, responseHandler, null);
}
@@ -210,7 +214,7 @@ public abstract class CloseableHttpClien
* @throws ClientProtocolException in case of an http protocol error
*/
@Override
- public <T> T execute(final HttpHost target, final HttpRequest request,
+ public <T> T execute(final HttpHost target, final ClassicHttpRequest request,
final ResponseHandler<? extends T> responseHandler, final HttpContext context) throws IOException {
Args.notNull(responseHandler, "Response handler");
@@ -220,7 +224,7 @@ public abstract class CloseableHttpClien
final HttpEntity entity = response.getEntity();
EntityUtils.consume(entity);
return result;
- } catch (final ClientProtocolException t) {
+ } catch (final HttpException t) {
// Try to salvage the underlying connection in case of a protocol exception
final HttpEntity entity = response.getEntity();
try {
@@ -230,7 +234,7 @@ public abstract class CloseableHttpClien
// important and will be thrown to the caller.
this.log.warn("Error consuming content after an exception.", t2);
}
- throw t;
+ throw new ClientProtocolException(t);
}
}
}
Copied: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/CloseableHttpResponse.java (from r1772287, httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpResponseProxy.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/CloseableHttpResponse.java?p2=httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/CloseableHttpResponse.java&p1=httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpResponseProxy.java&r1=1772287&r2=1776187&rev=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpResponseProxy.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/CloseableHttpResponse.java Tue Dec 27 19:48:07 2016
@@ -27,184 +27,188 @@
package org.apache.hc.client5.http.impl.sync;
+import java.io.Closeable;
import java.io.IOException;
import java.util.Iterator;
import java.util.Locale;
-import org.apache.hc.client5.http.methods.CloseableHttpResponse;
-import org.apache.hc.core5.annotation.NotThreadSafe;
+import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpEntity;
-import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.ProtocolException;
import org.apache.hc.core5.http.ProtocolVersion;
-import org.apache.hc.core5.http.StatusLine;
+import org.apache.hc.core5.util.Args;
/**
- * A proxy class for {@link org.apache.hc.core5.http.HttpResponse} that can be used to release client connection
- * associated with the original response.
+ * Backward compatibility with HttpClient 4.x.
*
* @since 4.3
*/
-@NotThreadSafe
-class HttpResponseProxy implements CloseableHttpResponse {
+public final class CloseableHttpResponse implements ClassicHttpResponse {
- private final HttpResponse original;
- private final ConnectionHolder connHolder;
+ private final ClassicHttpResponse response;
+ private final Closeable closeable;
- public HttpResponseProxy(final HttpResponse original, final ConnectionHolder connHolder) {
- this.original = original;
- this.connHolder = connHolder;
- ResponseEntityProxy.enchance(original, connHolder);
- }
-
- @Override
- public void close() throws IOException {
- if (this.connHolder != null) {
- this.connHolder.close();
+ public static CloseableHttpResponse adapt(final ClassicHttpResponse response) {
+ if (response == null) {
+ return null;
+ }
+ if (response instanceof CloseableHttpResponse) {
+ return (CloseableHttpResponse) response;
+ } else {
+ return new CloseableHttpResponse(response, null);
}
}
- @Override
- public StatusLine getStatusLine() {
- return original.getStatusLine();
+ public CloseableHttpResponse(final ClassicHttpResponse response, final Closeable closeable) {
+ this.response = Args.notNull(response, "Response");
+ this.closeable = closeable;
}
@Override
public int getCode() {
- return original.getCode();
+ return response.getCode();
}
@Override
- public void setStatusLine(final StatusLine statusline) {
- original.setStatusLine(statusline);
+ public HttpEntity getEntity() {
+ return response.getEntity();
}
@Override
- public void setStatusLine(final ProtocolVersion ver, final int code) {
- original.setStatusLine(ver, code);
+ public boolean containsHeader(final String name) {
+ return response.containsHeader(name);
}
@Override
- public void setStatusLine(final ProtocolVersion ver, final int code, final String reason) {
- original.setStatusLine(ver, code, reason);
+ public void setVersion(final ProtocolVersion version) {
+ response.setVersion(version);
}
@Override
- public void setStatusCode(final int code) throws IllegalStateException {
- original.setStatusCode(code);
+ public void setCode(final int code) {
+ response.setCode(code);
}
@Override
- public void setReasonPhrase(final String reason) throws IllegalStateException {
- original.setReasonPhrase(reason);
+ public String getReasonPhrase() {
+ return response.getReasonPhrase();
}
@Override
- public HttpEntity getEntity() {
- return original.getEntity();
+ public int containsHeaders(final String name) {
+ return response.containsHeaders(name);
}
@Override
public void setEntity(final HttpEntity entity) {
- original.setEntity(entity);
+ response.setEntity(entity);
}
@Override
- public Locale getLocale() {
- return original.getLocale();
+ public ProtocolVersion getVersion() {
+ return response.getVersion();
}
@Override
- public void setLocale(final Locale loc) {
- original.setLocale(loc);
+ public void setReasonPhrase(final String reason) {
+ response.setReasonPhrase(reason);
}
@Override
- public ProtocolVersion getProtocolVersion() {
- return original.getProtocolVersion();
+ public Header[] getHeaders(final String name) {
+ return response.getHeaders(name);
}
@Override
- public int containsHeaders(final String name) {
- return original.containsHeaders(name);
+ public void addHeader(final Header header) {
+ response.addHeader(header);
}
@Override
- public boolean containsHeader(final String name) {
- return original.containsHeader(name);
+ public Locale getLocale() {
+ return response.getLocale();
}
@Override
- public Header[] getHeaders(final String name) {
- return original.getHeaders(name);
+ public void addHeader(final String name, final Object value) {
+ response.addHeader(name, value);
}
@Override
- public Header getFirstHeader(final String name) {
- return original.getFirstHeader(name);
+ public void setLocale(final Locale loc) {
+ response.setLocale(loc);
}
@Override
- public Header getLastHeader(final String name) {
- return original.getLastHeader(name);
+ public Header getSingleHeader(final String name) throws ProtocolException {
+ return response.getSingleHeader(name);
}
@Override
- public Header[] getAllHeaders() {
- return original.getAllHeaders();
+ public void setHeader(final Header header) {
+ response.setHeader(header);
}
@Override
- public void addHeader(final Header header) {
- original.addHeader(header);
+ public Header getFirstHeader(final String name) {
+ return response.getFirstHeader(name);
}
@Override
- public void addHeader(final String name, final Object value) {
- original.addHeader(name, value);
+ public void setHeader(final String name, final Object value) {
+ response.setHeader(name, value);
}
@Override
- public void setHeader(final Header header) {
- original.setHeader(header);
+ public void setHeaders(final Header... headers) {
+ response.setHeaders(headers);
}
@Override
- public void setHeader(final String name, final Object value) {
- original.setHeader(name, value);
+ public void removeHeader(final Header header) {
+ response.removeHeader(header);
}
@Override
- public void setHeaders(final Header[] headers) {
- original.setHeaders(headers);
+ public void removeHeaders(final String name) {
+ response.removeHeaders(name);
}
@Override
- public void removeHeader(final Header header) {
- original.removeHeader(header);
+ public Header getLastHeader(final String name) {
+ return response.getLastHeader(name);
}
@Override
- public void removeHeaders(final String name) {
- original.removeHeaders(name);
+ public Header[] getAllHeaders() {
+ return response.getAllHeaders();
}
@Override
public Iterator<Header> headerIterator() {
- return original.headerIterator();
+ return response.headerIterator();
}
@Override
public Iterator<Header> headerIterator(final String name) {
- return original.headerIterator(name);
+ return response.headerIterator(name);
+ }
+
+ @Override
+ public void close() throws IOException {
+ try {
+ response.close();
+ } finally {
+ if (closeable != null) {
+ closeable.close();
+ }
+ }
}
@Override
public String toString() {
- final StringBuilder sb = new StringBuilder("HttpResponseProxy{");
- sb.append(original);
- sb.append('}');
- return sb.toString();
+ return response.toString();
}
}
Propchange: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/CloseableHttpResponse.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/CloseableHttpResponse.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/CloseableHttpResponse.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ConnectionHolder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ConnectionHolder.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ConnectionHolder.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ConnectionHolder.java Tue Dec 27 19:48:07 2016
@@ -34,7 +34,8 @@ import java.util.concurrent.atomic.Atomi
import org.apache.hc.client5.http.io.ConnectionReleaseTrigger;
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
-import org.apache.hc.core5.annotation.ThreadSafe;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.concurrent.Cancellable;
import org.apache.hc.core5.http.io.HttpClientConnection;
import org.apache.logging.log4j.Logger;
@@ -44,7 +45,7 @@ import org.apache.logging.log4j.Logger;
*
* @since 4.3
*/
-@ThreadSafe
+@Contract(threading = ThreadingBehavior.SAFE_CONDITIONAL)
class ConnectionHolder implements ConnectionReleaseTrigger, Cancellable, Closeable {
private final Logger log;
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/DefaultBackoffStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/DefaultBackoffStrategy.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/DefaultBackoffStrategy.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/DefaultBackoffStrategy.java Tue Dec 27 19:48:07 2016
@@ -50,7 +50,7 @@ public class DefaultBackoffStrategy impl
@Override
public boolean shouldBackoff(final HttpResponse resp) {
- return (resp.getStatusLine().getStatusCode() == HttpStatus.SC_SERVICE_UNAVAILABLE);
+ return (resp.getCode() == HttpStatus.SC_SERVICE_UNAVAILABLE);
}
}
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/DefaultHttpRequestRetryHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/DefaultHttpRequestRetryHandler.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/DefaultHttpRequestRetryHandler.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/DefaultHttpRequestRetryHandler.java Tue Dec 27 19:48:07 2016
@@ -43,7 +43,8 @@ import javax.net.ssl.SSLException;
import org.apache.hc.client5.http.methods.HttpUriRequest;
import org.apache.hc.client5.http.sync.HttpRequestRetryHandler;
-import org.apache.hc.core5.annotation.Immutable;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.protocol.HttpContext;
import org.apache.hc.core5.util.Args;
@@ -53,7 +54,7 @@ import org.apache.hc.core5.util.Args;
*
* @since 4.0
*/
-@Immutable
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
public class DefaultHttpRequestRetryHandler implements HttpRequestRetryHandler {
public static final DefaultHttpRequestRetryHandler INSTANCE = new DefaultHttpRequestRetryHandler();
@@ -174,7 +175,7 @@ public class DefaultHttpRequestRetryHand
* @since 4.2
*/
protected boolean handleAsIdempotent(final HttpRequest request) {
- final String method = request.getRequestLine().getMethod().toUpperCase(Locale.ROOT);
+ final String method = request.getMethod().toUpperCase(Locale.ROOT);
final Boolean b = this.idempotentMethods.get(method);
return b != null && b.booleanValue();
}
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/DefaultServiceUnavailableRetryStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/DefaultServiceUnavailableRetryStrategy.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/DefaultServiceUnavailableRetryStrategy.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/DefaultServiceUnavailableRetryStrategy.java Tue Dec 27 19:48:07 2016
@@ -31,7 +31,8 @@ import java.util.Date;
import org.apache.hc.client5.http.sync.ServiceUnavailableRetryStrategy;
import org.apache.hc.client5.http.utils.DateUtils;
-import org.apache.hc.core5.annotation.Immutable;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpHeaders;
import org.apache.hc.core5.http.HttpResponse;
@@ -46,7 +47,7 @@ import org.apache.hc.core5.util.Args;
*
* @since 4.2
*/
-@Immutable
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
public class DefaultServiceUnavailableRetryStrategy implements ServiceUnavailableRetryStrategy {
/**
@@ -75,8 +76,7 @@ public class DefaultServiceUnavailableRe
@Override
public boolean retryRequest(final HttpResponse response, final int executionCount, final HttpContext context) {
- return executionCount <= maxRetries &&
- response.getStatusLine().getStatusCode() == HttpStatus.SC_SERVICE_UNAVAILABLE;
+ return executionCount <= maxRetries && response.getCode() == HttpStatus.SC_SERVICE_UNAVAILABLE;
}
@Override
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/FutureRequestExecutionService.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/FutureRequestExecutionService.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/FutureRequestExecutionService.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/FutureRequestExecutionService.java Tue Dec 27 19:48:07 2016
@@ -33,16 +33,17 @@ import java.util.concurrent.atomic.Atomi
import org.apache.hc.client5.http.methods.HttpUriRequest;
import org.apache.hc.client5.http.sync.HttpClient;
-import org.apache.hc.client5.http.sync.ResponseHandler;
-import org.apache.hc.core5.annotation.ThreadSafe;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.io.ResponseHandler;
import org.apache.hc.core5.http.protocol.HttpContext;
/**
* HttpAsyncClientWithFuture wraps calls to execute with a {@link HttpRequestFutureTask}
* and schedules them using the provided executor service. Scheduled calls may be cancelled.
*/
-@ThreadSafe
+@Contract(threading = ThreadingBehavior.SAFE_CONDITIONAL)
public class FutureRequestExecutionService implements Closeable {
private final HttpClient httpclient;
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java Tue Dec 27 19:48:07 2016
@@ -93,7 +93,6 @@ import org.apache.hc.client5.http.sync.B
import org.apache.hc.client5.http.sync.ConnectionBackoffStrategy;
import org.apache.hc.client5.http.sync.HttpRequestRetryHandler;
import org.apache.hc.client5.http.sync.ServiceUnavailableRetryStrategy;
-import org.apache.hc.core5.annotation.NotThreadSafe;
import org.apache.hc.core5.http.ConnectionReuseStrategy;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpHost;
@@ -107,10 +106,10 @@ import org.apache.hc.core5.http.config.R
import org.apache.hc.core5.http.config.SocketConfig;
import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
+import org.apache.hc.core5.http.protocol.DefaultHttpProcessor;
import org.apache.hc.core5.http.protocol.HttpContext;
import org.apache.hc.core5.http.protocol.HttpProcessor;
import org.apache.hc.core5.http.protocol.HttpProcessorBuilder;
-import org.apache.hc.core5.http.protocol.ImmutableHttpProcessor;
import org.apache.hc.core5.http.protocol.RequestContent;
import org.apache.hc.core5.http.protocol.RequestTargetHost;
import org.apache.hc.core5.http.protocol.RequestUserAgent;
@@ -155,7 +154,6 @@ import org.apache.hc.core5.util.VersionI
*
* @since 4.3
*/
-@NotThreadSafe
public class HttpClientBuilder {
private HttpRequestExecutor requestExec;
@@ -786,7 +784,7 @@ public class HttpClientBuilder {
* inside an EJB container.
*
* @see #setConnectionManagerShared(boolean)
- * @see HttpClientConnectionManager#closeExpiredConnections()
+ * @see HttpClientConnectionManager#closeExpired()
*
* @since 4.4
*/
@@ -809,7 +807,7 @@ public class HttpClientBuilder {
* inside an EJB container.
*
* @see #setConnectionManagerShared(boolean)
- * @see HttpClientConnectionManager#closeExpiredConnections()
+ * @see HttpClientConnectionManager#closeExpired()
*
* @param maxIdleTime maximum time persistent connections can stay idle while kept alive
* in the connection pool. Connections whose inactivity period exceeds this value will
@@ -1011,7 +1009,7 @@ public class HttpClientBuilder {
userAgentCopy = System.getProperty("http.agent");
}
if (userAgentCopy == null) {
- userAgentCopy = VersionInfo.getUserAgent("Apache-HttpClient",
+ userAgentCopy = VersionInfo.getSoftwareInfo("Apache-HttpClient",
"org.apache.hc.client5", getClass());
}
}
@@ -1021,7 +1019,7 @@ public class HttpClientBuilder {
connManagerCopy,
reuseStrategyCopy,
keepAliveStrategyCopy,
- new ImmutableHttpProcessor(new RequestTargetHost(), new RequestUserAgent(userAgentCopy)),
+ new DefaultHttpProcessor(new RequestTargetHost(), new RequestUserAgent(userAgentCopy)),
targetAuthStrategyCopy,
proxyAuthStrategyCopy,
userTokenHandlerCopy);
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClients.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClients.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClients.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClients.java Tue Dec 27 19:48:07 2016
@@ -29,13 +29,11 @@ package org.apache.hc.client5.http.impl.
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
-import org.apache.hc.core5.annotation.Immutable;
/**
* Factory methods for {@link CloseableHttpClient} instances.
* @since 4.3
*/
-@Immutable
public class HttpClients {
private HttpClients() {
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpRequestFutureTask.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpRequestFutureTask.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpRequestFutureTask.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpRequestFutureTask.java Tue Dec 27 19:48:07 2016
@@ -112,7 +112,7 @@ public class HttpRequestFutureTask<V> ex
@Override
public String toString() {
- return request.getRequestLine().getUri();
+ return request.toString();
}
}
\ No newline at end of file
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpRequestTaskCallable.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpRequestTaskCallable.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpRequestTaskCallable.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpRequestTaskCallable.java Tue Dec 27 19:48:07 2016
@@ -31,8 +31,8 @@ import java.util.concurrent.atomic.Atomi
import org.apache.hc.client5.http.methods.HttpUriRequest;
import org.apache.hc.client5.http.sync.HttpClient;
-import org.apache.hc.client5.http.sync.ResponseHandler;
import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.io.ResponseHandler;
import org.apache.hc.core5.http.protocol.HttpContext;
class HttpRequestTaskCallable<V> implements Callable<V> {
@@ -107,7 +107,7 @@ class HttpRequestTaskCallable<V> impleme
metrics.getActiveConnections().decrementAndGet();
}
} else {
- throw new IllegalStateException("call has been cancelled for request " + request.getURI());
+ throw new IllegalStateException("call has been cancelled");
}
}
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/IdleConnectionEvictor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/IdleConnectionEvictor.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/IdleConnectionEvictor.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/IdleConnectionEvictor.java Tue Dec 27 19:48:07 2016
@@ -64,9 +64,9 @@ public final class IdleConnectionEvictor
try {
while (!Thread.currentThread().isInterrupted()) {
Thread.sleep(sleepTimeMs);
- connectionManager.closeExpiredConnections();
+ connectionManager.closeExpired();
if (maxIdleTimeMs > 0) {
- connectionManager.closeIdleConnections(maxIdleTimeMs, TimeUnit.MILLISECONDS);
+ connectionManager.closeIdle(maxIdleTimeMs, TimeUnit.MILLISECONDS);
}
}
} catch (final Exception ex) {
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/InternalHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/InternalHttpClient.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/InternalHttpClient.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/InternalHttpClient.java Tue Dec 27 19:48:07 2016
@@ -38,20 +38,23 @@ import org.apache.hc.client5.http.config
import org.apache.hc.client5.http.cookie.CookieSpecProvider;
import org.apache.hc.client5.http.cookie.CookieStore;
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
-import org.apache.hc.client5.http.methods.CloseableHttpResponse;
import org.apache.hc.client5.http.methods.Configurable;
import org.apache.hc.client5.http.methods.HttpExecutionAware;
-import org.apache.hc.client5.http.methods.HttpRequestWrapper;
+import org.apache.hc.client5.http.methods.RoutedHttpRequest;
import org.apache.hc.client5.http.protocol.ClientProtocolException;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.client5.http.routing.HttpRoutePlanner;
-import org.apache.hc.core5.annotation.ThreadSafe;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.config.Lookup;
import org.apache.hc.core5.http.protocol.BasicHttpContext;
import org.apache.hc.core5.http.protocol.HttpContext;
+import org.apache.hc.core5.net.URIAuthority;
import org.apache.hc.core5.util.Args;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -61,7 +64,7 @@ import org.apache.logging.log4j.Logger;
*
* @since 4.3
*/
-@ThreadSafe
+@Contract(threading = ThreadingBehavior.SAFE_CONDITIONAL)
class InternalHttpClient extends CloseableHttpClient implements Configurable {
private final Logger log = LogManager.getLogger(getClass());
@@ -129,7 +132,7 @@ class InternalHttpClient extends Closeab
@Override
protected CloseableHttpResponse doExecute(
final HttpHost target,
- final HttpRequest request,
+ final ClassicHttpRequest request,
final HttpContext context) throws IOException {
Args.notNull(request, "HTTP request");
HttpExecutionAware execAware = null;
@@ -137,7 +140,12 @@ class InternalHttpClient extends Closeab
execAware = (HttpExecutionAware) request;
}
try {
- final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(request, target);
+ if (request.getScheme() == null) {
+ request.setScheme(target.getSchemeName());
+ }
+ if (request.getAuthority() == null) {
+ request.setAuthority(new URIAuthority(target));
+ }
final HttpClientContext localcontext = HttpClientContext.adapt(
context != null ? context : new BasicHttpContext());
RequestConfig config = null;
@@ -148,8 +156,10 @@ class InternalHttpClient extends Closeab
localcontext.setRequestConfig(config);
}
setupContext(localcontext);
- final HttpRoute route = determineRoute(target, wrapper, localcontext);
- return this.execChain.execute(route, wrapper, localcontext, execAware);
+ final HttpRoute route = determineRoute(target, request, localcontext);
+ final ClassicHttpResponse response = this.execChain.execute(
+ RoutedHttpRequest.adapt(request, route), localcontext, execAware);
+ return CloseableHttpResponse.adapt(response);
} catch (final HttpException httpException) {
throw new ClientProtocolException(httpException);
}
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MainClientExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MainClientExec.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MainClientExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MainClientExec.java Tue Dec 27 19:48:07 2016
@@ -43,15 +43,17 @@ import org.apache.hc.client5.http.impl.i
import org.apache.hc.client5.http.impl.routing.BasicRouteDirector;
import org.apache.hc.client5.http.io.ConnectionRequest;
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
-import org.apache.hc.client5.http.methods.CloseableHttpResponse;
import org.apache.hc.client5.http.methods.HttpExecutionAware;
-import org.apache.hc.client5.http.methods.HttpRequestWrapper;
+import org.apache.hc.client5.http.methods.RoutedHttpRequest;
import org.apache.hc.client5.http.protocol.AuthenticationStrategy;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.client5.http.protocol.NonRepeatableRequestException;
import org.apache.hc.client5.http.protocol.UserTokenHandler;
import org.apache.hc.client5.http.routing.HttpRouteDirector;
-import org.apache.hc.core5.annotation.Immutable;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.ConnectionReuseStrategy;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.HttpException;
@@ -59,14 +61,18 @@ import org.apache.hc.core5.http.HttpHead
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpResponse;
-import org.apache.hc.core5.http.entity.BufferedHttpEntity;
-import org.apache.hc.core5.http.entity.EntityUtils;
+import org.apache.hc.core5.http.HttpStatus;
+import org.apache.hc.core5.http.HttpVersion;
import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
import org.apache.hc.core5.http.io.HttpClientConnection;
-import org.apache.hc.core5.http.message.BasicHttpRequest;
+import org.apache.hc.core5.http.io.entity.BufferedHttpEntity;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
+import org.apache.hc.core5.http.message.RequestLine;
+import org.apache.hc.core5.http.message.StatusLine;
+import org.apache.hc.core5.http.protocol.DefaultHttpProcessor;
import org.apache.hc.core5.http.protocol.HttpCoreContext;
import org.apache.hc.core5.http.protocol.HttpProcessor;
-import org.apache.hc.core5.http.protocol.ImmutableHttpProcessor;
import org.apache.hc.core5.http.protocol.RequestTargetHost;
import org.apache.hc.core5.util.Args;
import org.apache.logging.log4j.LogManager;
@@ -82,7 +88,7 @@ import org.apache.logging.log4j.Logger;
*
* @since 4.3
*/
-@Immutable
+@Contract(threading = ThreadingBehavior.IMMUTABLE_CONDITIONAL)
public class MainClientExec implements ClientExecChain {
private final Logger log = LogManager.getLogger(getClass());
@@ -139,19 +145,18 @@ public class MainClientExec implements C
final AuthenticationStrategy proxyAuthStrategy,
final UserTokenHandler userTokenHandler) {
this(requestExecutor, connManager, reuseStrategy, keepAliveStrategy,
- new ImmutableHttpProcessor(new RequestTargetHost()),
+ new DefaultHttpProcessor(new RequestTargetHost()),
targetAuthStrategy, proxyAuthStrategy, userTokenHandler);
}
@Override
- public CloseableHttpResponse execute(
- final HttpRoute route,
- final HttpRequestWrapper request,
+ public ClassicHttpResponse execute(
+ final RoutedHttpRequest request,
final HttpClientContext context,
final HttpExecutionAware execAware) throws IOException, HttpException {
- Args.notNull(route, "HTTP route");
Args.notNull(request, "HTTP request");
Args.notNull(context, "HTTP context");
+ final HttpRoute route = request.getRoute();
RequestEntityProxy.enhance(request);
@@ -196,7 +201,7 @@ public class MainClientExec implements C
final AuthExchange proxyAuthExchange = route.getProxyHost() != null ?
context.getAuthExchange(route.getProxyHost()) : new AuthExchange();
- HttpResponse response;
+ ClassicHttpResponse response;
for (int execCount = 1;; execCount++) {
if (execCount > 1 && !RequestEntityProxy.isRepeatable(request)) {
@@ -230,7 +235,7 @@ public class MainClientExec implements C
}
if (this.log.isDebugEnabled()) {
- this.log.debug("Executing request " + request.getRequestLine());
+ this.log.debug("Executing request " + new RequestLine(request));
}
if (!request.containsHeader(HttpHeaders.AUTHORIZATION)) {
@@ -275,7 +280,7 @@ public class MainClientExec implements C
}
if (needAuthentication(
- targetAuthExchange, proxyAuthExchange, route, response, context)) {
+ targetAuthExchange, proxyAuthExchange, route, request, response, context)) {
// Make sure the response body is fully consumed, if present
final HttpEntity entity = response.getEntity();
if (connHolder.isReusable()) {
@@ -321,9 +326,10 @@ public class MainClientExec implements C
if (entity == null || !entity.isStreaming()) {
// connection not needed and (assumed to be) in re-usable state
connHolder.releaseConnection();
- return new HttpResponseProxy(response, null);
+ return new CloseableHttpResponse(response, null);
} else {
- return new HttpResponseProxy(response, connHolder);
+ ResponseEntityProxy.enchance(response, connHolder);
+ return new CloseableHttpResponse(response, connHolder);
}
} catch (final ConnectionShutdownException ex) {
final InterruptedIOException ioex = new InterruptedIOException(
@@ -427,10 +433,11 @@ public class MainClientExec implements C
final HttpHost target = route.getTargetHost();
final HttpHost proxy = route.getProxyHost();
final AuthExchange proxyAuthExchange = context.getAuthExchange(proxy);
- HttpResponse response = null;
+ ClassicHttpResponse response = null;
final String authority = target.toHostString();
- final HttpRequest connect = new BasicHttpRequest("CONNECT", authority, request.getProtocolVersion());
+ final ClassicHttpRequest connect = new BasicClassicHttpRequest("CONNECT", authority);
+ connect.setVersion(HttpVersion.HTTP_1_1);
this.requestExecutor.preProcess(connect, this.proxyHttpProcessor, context);
@@ -448,10 +455,9 @@ public class MainClientExec implements C
response = this.requestExecutor.execute(connect, managedConn, context);
- final int status = response.getStatusLine().getStatusCode();
- if (status < 200) {
- throw new HttpException("Unexpected response to CONNECT request: " +
- response.getStatusLine());
+ final int status = response.getCode();
+ if (status < HttpStatus.SC_SUCCESS) {
+ throw new HttpException("Unexpected response to CONNECT request: " + new StatusLine(response));
}
if (config.isAuthenticationEnabled()) {
@@ -474,9 +480,8 @@ public class MainClientExec implements C
}
}
- final int status = response.getStatusLine().getStatusCode();
-
- if (status > 299) {
+ final int status = response.getCode();
+ if (status >= HttpStatus.SC_REDIRECTION) {
// Buffer response content
final HttpEntity entity = response.getEntity();
@@ -486,7 +491,7 @@ public class MainClientExec implements C
managedConn.close();
throw new TunnelRefusedException("CONNECT refused by proxy: " +
- response.getStatusLine(), response);
+ new StatusLine(response), response);
}
// How to decide on security of the tunnelled connection?
@@ -522,14 +527,12 @@ public class MainClientExec implements C
final AuthExchange targetAuthExchange,
final AuthExchange proxyAuthExchange,
final HttpRoute route,
+ final RoutedHttpRequest request,
final HttpResponse response,
final HttpClientContext context) {
final RequestConfig config = context.getRequestConfig();
if (config.isAuthenticationEnabled()) {
- HttpHost target = context.getTargetHost();
- if (target == null) {
- target = route.getTargetHost();
- }
+ HttpHost target = request.getTargetHost();
if (target.getPort() < 0) {
target = new HttpHost(
target.getHostName(),
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MinimalClientExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MinimalClientExec.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MinimalClientExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MinimalClientExec.java Tue Dec 27 19:48:07 2016
@@ -29,8 +29,6 @@ package org.apache.hc.client5.http.impl.
import java.io.IOException;
import java.io.InterruptedIOException;
-import java.net.URI;
-import java.net.URISyntaxException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
@@ -40,26 +38,21 @@ import org.apache.hc.client5.http.config
import org.apache.hc.client5.http.impl.io.ConnectionShutdownException;
import org.apache.hc.client5.http.io.ConnectionRequest;
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
-import org.apache.hc.client5.http.methods.CloseableHttpResponse;
import org.apache.hc.client5.http.methods.HttpExecutionAware;
-import org.apache.hc.client5.http.methods.HttpRequestWrapper;
-import org.apache.hc.client5.http.methods.HttpUriRequest;
+import org.apache.hc.client5.http.methods.RoutedHttpRequest;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.client5.http.protocol.RequestClientConnControl;
-import org.apache.hc.client5.http.utils.URIUtils;
-import org.apache.hc.core5.annotation.Immutable;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.ConnectionReuseStrategy;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.HttpException;
-import org.apache.hc.core5.http.HttpHost;
-import org.apache.hc.core5.http.HttpRequest;
-import org.apache.hc.core5.http.HttpResponse;
-import org.apache.hc.core5.http.ProtocolException;
import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
import org.apache.hc.core5.http.io.HttpClientConnection;
+import org.apache.hc.core5.http.protocol.DefaultHttpProcessor;
import org.apache.hc.core5.http.protocol.HttpCoreContext;
import org.apache.hc.core5.http.protocol.HttpProcessor;
-import org.apache.hc.core5.http.protocol.ImmutableHttpProcessor;
import org.apache.hc.core5.http.protocol.RequestContent;
import org.apache.hc.core5.http.protocol.RequestTargetHost;
import org.apache.hc.core5.http.protocol.RequestUserAgent;
@@ -77,7 +70,7 @@ import org.apache.logging.log4j.Logger;
*
* @since 4.3
*/
-@Immutable
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
public class MinimalClientExec implements ClientExecChain {
private final Logger log = LogManager.getLogger(getClass());
@@ -97,11 +90,11 @@ public class MinimalClientExec implement
Args.notNull(connManager, "Client connection manager");
Args.notNull(reuseStrategy, "Connection reuse strategy");
Args.notNull(keepAliveStrategy, "Connection keep alive strategy");
- this.httpProcessor = new ImmutableHttpProcessor(
+ this.httpProcessor = new DefaultHttpProcessor(
new RequestContent(),
new RequestTargetHost(),
new RequestClientConnControl(),
- new RequestUserAgent(VersionInfo.getUserAgent(
+ new RequestUserAgent(VersionInfo.getSoftwareInfo(
"Apache-HttpClient", "org.apache.hc.client5", getClass())));
this.requestExecutor = requestExecutor;
this.connManager = connManager;
@@ -109,37 +102,15 @@ public class MinimalClientExec implement
this.keepAliveStrategy = keepAliveStrategy;
}
- static void rewriteRequestURI(
- final HttpRequestWrapper request,
- final HttpRoute route) throws ProtocolException {
- try {
- URI uri = request.getURI();
- if (uri != null) {
- // Make sure the request URI is relative
- if (uri.isAbsolute()) {
- uri = URIUtils.rewriteURI(uri, null, true);
- } else {
- uri = URIUtils.rewriteURI(uri);
- }
- request.setURI(uri);
- }
- } catch (final URISyntaxException ex) {
- throw new ProtocolException("Invalid URI: " + request.getRequestLine().getUri(), ex);
- }
- }
-
@Override
- public CloseableHttpResponse execute(
- final HttpRoute route,
- final HttpRequestWrapper request,
+ public ClassicHttpResponse execute(
+ final RoutedHttpRequest request,
final HttpClientContext context,
final HttpExecutionAware execAware) throws IOException, HttpException {
- Args.notNull(route, "HTTP route");
Args.notNull(request, "HTTP request");
Args.notNull(context, "HTTP context");
- rewriteRequestURI(request, route);
-
+ final HttpRoute route = request.getRoute();
final ConnectionRequest connRequest = connManager.requestConnection(route, null);
if (execAware != null) {
if (execAware.isAborted()) {
@@ -166,14 +137,14 @@ public class MinimalClientExec implement
throw new RequestAbortedException("Request execution failed", cause);
}
- final ConnectionHolder releaseTrigger = new ConnectionHolder(log, connManager, managedConn);
+ final ConnectionHolder connHolder = new ConnectionHolder(log, connManager, managedConn);
try {
if (execAware != null) {
if (execAware.isAborted()) {
- releaseTrigger.close();
+ connHolder.close();
throw new RequestAbortedException("Request aborted");
}
- execAware.setCancellable(releaseTrigger);
+ execAware.setCancellable(connHolder);
}
if (!managedConn.isOpen()) {
@@ -190,52 +161,41 @@ public class MinimalClientExec implement
managedConn.setSocketTimeout(timeout);
}
- HttpHost target = null;
- final HttpRequest original = request.getOriginal();
- if (original instanceof HttpUriRequest) {
- final URI uri = ((HttpUriRequest) original).getURI();
- if (uri.isAbsolute()) {
- target = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
- }
- }
- if (target == null) {
- target = route.getTargetHost();
- }
-
- context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, target);
context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
context.setAttribute(HttpCoreContext.HTTP_CONNECTION, managedConn);
context.setAttribute(HttpClientContext.HTTP_ROUTE, route);
- httpProcessor.process(request, context);
- final HttpResponse response = requestExecutor.execute(request, managedConn, context);
- httpProcessor.process(response, context);
+ httpProcessor.process(request, request.getEntity(), context);
+ final ClassicHttpResponse response = requestExecutor.execute(request, managedConn, context);
+ httpProcessor.process(response, response.getEntity(), context);
// The connection is in or can be brought to a re-usable state.
if (reuseStrategy.keepAlive(request, response, context)) {
// Set the idle duration of this connection
final long duration = keepAliveStrategy.getKeepAliveDuration(response, context);
- releaseTrigger.setValidFor(duration, TimeUnit.MILLISECONDS);
- releaseTrigger.markReusable();
+ connHolder.setValidFor(duration, TimeUnit.MILLISECONDS);
+ connHolder.markReusable();
} else {
- releaseTrigger.markNonReusable();
+ connHolder.markNonReusable();
}
// check for entity, release connection if possible
final HttpEntity entity = response.getEntity();
if (entity == null || !entity.isStreaming()) {
// connection not needed and (assumed to be) in re-usable state
- releaseTrigger.releaseConnection();
- return new HttpResponseProxy(response, null);
+ connHolder.releaseConnection();
+ return new CloseableHttpResponse(response, null);
+ } else {
+ ResponseEntityProxy.enchance(response, connHolder);
+ return new CloseableHttpResponse(response, connHolder);
}
- return new HttpResponseProxy(response, releaseTrigger);
} catch (final ConnectionShutdownException ex) {
final InterruptedIOException ioex = new InterruptedIOException(
"Connection has been shut down");
ioex.initCause(ex);
throw ioex;
} catch (final HttpException | RuntimeException | IOException ex) {
- releaseTrigger.abortConnection();
+ connHolder.abortConnection();
throw ex;
}
}
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MinimalHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MinimalHttpClient.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MinimalHttpClient.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MinimalHttpClient.java Tue Dec 27 19:48:07 2016
@@ -33,20 +33,22 @@ import org.apache.hc.client5.http.HttpRo
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.DefaultConnectionKeepAliveStrategy;
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
-import org.apache.hc.client5.http.methods.CloseableHttpResponse;
import org.apache.hc.client5.http.methods.Configurable;
import org.apache.hc.client5.http.methods.HttpExecutionAware;
-import org.apache.hc.client5.http.methods.HttpRequestWrapper;
+import org.apache.hc.client5.http.methods.RoutedHttpRequest;
import org.apache.hc.client5.http.protocol.ClientProtocolException;
import org.apache.hc.client5.http.protocol.HttpClientContext;
-import org.apache.hc.core5.annotation.ThreadSafe;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHost;
-import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
import org.apache.hc.core5.http.protocol.BasicHttpContext;
import org.apache.hc.core5.http.protocol.HttpContext;
+import org.apache.hc.core5.net.URIAuthority;
import org.apache.hc.core5.util.Args;
/**
@@ -54,7 +56,7 @@ import org.apache.hc.core5.util.Args;
*
* @since 4.3
*/
-@ThreadSafe
+@Contract(threading = ThreadingBehavior.SAFE)
class MinimalHttpClient extends CloseableHttpClient {
private final HttpClientConnectionManager connManager;
@@ -74,7 +76,7 @@ class MinimalHttpClient extends Closeabl
@Override
protected CloseableHttpResponse doExecute(
final HttpHost target,
- final HttpRequest request,
+ final ClassicHttpRequest request,
final HttpContext context) throws IOException {
Args.notNull(target, "Target host");
Args.notNull(request, "HTTP request");
@@ -83,10 +85,14 @@ class MinimalHttpClient extends Closeabl
execAware = (HttpExecutionAware) request;
}
try {
- final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(request, target);
+ if (request.getScheme() == null) {
+ request.setScheme(target.getSchemeName());
+ }
+ if (request.getAuthority() == null) {
+ request.setAuthority(new URIAuthority(target));
+ }
final HttpClientContext localcontext = HttpClientContext.adapt(
- context != null ? context : new BasicHttpContext());
- final HttpRoute route = new HttpRoute(target);
+ context != null ? context : new BasicHttpContext());
RequestConfig config = null;
if (request instanceof Configurable) {
config = ((Configurable) request).getConfig();
@@ -94,7 +100,10 @@ class MinimalHttpClient extends Closeabl
if (config != null) {
localcontext.setRequestConfig(config);
}
- return this.requestExecutor.execute(route, wrapper, localcontext, execAware);
+ final HttpRoute route = new HttpRoute(target);
+ final ClassicHttpResponse response = this.requestExecutor.execute(
+ RoutedHttpRequest.adapt(request, route), localcontext, execAware);
+ return CloseableHttpResponse.adapt(response);
} catch (final HttpException httpException) {
throw new ClientProtocolException(httpException);
}
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/NoopUserTokenHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/NoopUserTokenHandler.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/NoopUserTokenHandler.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/NoopUserTokenHandler.java Tue Dec 27 19:48:07 2016
@@ -28,7 +28,8 @@ package org.apache.hc.client5.http.impl.
import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.protocol.UserTokenHandler;
-import org.apache.hc.core5.annotation.Immutable;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.http.protocol.HttpContext;
/**
@@ -36,7 +37,7 @@ import org.apache.hc.core5.http.protocol
*
* @since 4.3
*/
-@Immutable
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
public class NoopUserTokenHandler implements UserTokenHandler {
public static final NoopUserTokenHandler INSTANCE = new NoopUserTokenHandler();