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 2012/08/08 22:35:16 UTC
svn commit: r1370953 [1/5] - in /httpcomponents/httpclient/trunk: ./
fluent-hc/src/main/java/org/apache/http/client/fluent/
httpclient/src/main/java/org/apache/http/client/methods/
httpclient/src/main/java/org/apache/http/client/protocol/ httpclient/sr...
Author: olegk
Date: Wed Aug 8 20:35:13 2012
New Revision: 1370953
URL: http://svn.apache.org/viewvc?rev=1370953&view=rev
Log:
Merged decorator-refactoring branch
Added:
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/HttpExecutionAware.java
- copied, changed from r1369849, httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RoutedRequest.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AbstractBasicHttpClient.java (with props)
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java (with props)
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java (with props)
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/NoopUserTokenHandler.java (with props)
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RequestAbortedException.java
- copied, changed from r1369849, httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RoutedRequest.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RequestDirectorAdaptor.java (with props)
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/BackoffStrategyExec.java (with props)
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/ClientExecChain.java
- copied, changed from r1369849, httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RoutedRequest.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/HttpRequestWrapper.java (with props)
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/HttpResponseWrapper.java (with props)
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/MainClientExec.java (with props)
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/ProtocolExec.java (with props)
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/RedirectExec.java (with props)
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/RetryExec.java (with props)
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/ServiceUnavailableRetryExec.java (with props)
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/IntegrationTestBase.java (with props)
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestAbortHandling.java (contents, props changed)
- copied, changed from r1369849, httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestAbortHandling.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthentication.java (contents, props changed)
- copied, changed from r1369849, httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthentication.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthenticationFallBack.java (contents, props changed)
- copied, changed from r1369849, httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthenticationFallBack.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientReauthentication.java (contents, props changed)
- copied, changed from r1369849, httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestClientReauthentication.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java (contents, props changed)
- copied, changed from r1369849, httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionAutoRelease.java (contents, props changed)
- copied, changed from r1369849, httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestConnectionAutoRelease.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestContentCodings.java (contents, props changed)
- copied, changed from r1369849, httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestContentCodings.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestCookie2Support.java (contents, props changed)
- copied, changed from r1369849, httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestCookie2Support.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestRedirects.java (contents, props changed)
- copied, changed from r1369849, httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRedirects.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestSPNegoScheme.java (contents, props changed)
- copied, changed from r1369849, httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestSPNegoScheme.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestStatefulConnManagement.java (contents, props changed)
- copied, changed from r1369849, httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestStatefulConnManagement.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/tsccm/GetConnThread.java (contents, props changed)
- copied, changed from r1369849, httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/GetConnThread.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/LocalServerTestBase.java (contents, props changed)
- copied, changed from r1369849, httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/BasicServerTestBase.java
Removed:
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestCookie2Support.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRedirects.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestUriEscapes.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestConnectionAutoRelease.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestSPNegoScheme.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthentication.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthenticationFallBack.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestClientReauthentication.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestContentCodings.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestRequestWrapper.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestStatefulConnManagement.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/GetConnThread.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/Helper.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestAbortHandling.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestLocalServer.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/BasicServerTestBase.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/ServerTestBase.java
Modified:
httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/AbortableHttpRequest.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/HttpRequestBase.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/ClientContext.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthenticationBase.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestProxyAuthentication.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestTargetAuthentication.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/ResponseContentEncoding.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/BasicEofSensorWatcher.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/BasicManagedEntity.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/HttpRoutedConnection.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ManagedClientConnection.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AutoRetryHttpClient.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ClientParamsStack.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ContentEncodingHttpClient.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DecompressingHttpClient.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpRequestRetryHandler.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultUserTokenHandler.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/EntityEnclosingRequestWrapper.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpAuthenticator.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ProxyClient.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RequestWrapper.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RoutedRequest.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultHttpClient.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAddCookies.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestClientConnControl.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/utils/TestHttpClientUtils.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/TestConnectionReuse.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDecompressingHttpClient.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestRequestRetryHandler.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/ExecReqThread.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestBasicConnManager.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestIdleConnectionEviction.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestPoolingConnManager.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestPoolingConnManagerNoServer.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/tsccm/TestConnPoolByRoute.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/tsccm/TestSpuriousWakeup.java
httpcomponents/httpclient/trunk/pom.xml
Modified: httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java (original)
+++ httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java Wed Aug 8 20:35:13 2012
@@ -54,14 +54,14 @@ import org.apache.http.conn.ssl.SSLSocke
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.BasicCredentialsProvider;
-import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.protocol.BasicHttpContext;
public class Executor {
final static PoolingClientConnectionManager CONNMGR;
- final static DefaultHttpClient CLIENT;
+ final static HttpClient CLIENT;
static {
SchemeRegistry schemeRegistry = new SchemeRegistry();
@@ -87,7 +87,7 @@ public class Executor {
CONNMGR = new PoolingClientConnectionManager(schemeRegistry);
CONNMGR.setDefaultMaxPerRoute(100);
CONNMGR.setMaxTotal(200);
- CLIENT = new DefaultHttpClient(CONNMGR);
+ CLIENT = new HttpClientBuilder().setConnectionManager(CONNMGR).build();
}
public static Executor newInstance() {
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/AbortableHttpRequest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/AbortableHttpRequest.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/AbortableHttpRequest.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/AbortableHttpRequest.java Wed Aug 8 20:35:13 2012
@@ -39,10 +39,11 @@ import org.apache.http.conn.ManagedClien
* Interface representing an HTTP request that can be aborted by shutting
* down the underlying HTTP connection.
*
- *
- * <!-- empty lines to avoid svn diff problems -->
* @since 4.0
+ *
+ * @deprecated (4.3) use {@link HttpExecutionAware}
*/
+@Deprecated
public interface AbortableHttpRequest {
/**
Copied: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/HttpExecutionAware.java (from r1369849, httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RoutedRequest.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/HttpExecutionAware.java?p2=httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/HttpExecutionAware.java&p1=httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RoutedRequest.java&r1=1369849&r2=1370953&rev=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RoutedRequest.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/HttpExecutionAware.java Wed Aug 8 20:35:13 2012
@@ -25,41 +25,24 @@
*
*/
-package org.apache.http.impl.client;
+package org.apache.http.client.methods;
-import org.apache.http.annotation.NotThreadSafe;
-
-import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.concurrent.Cancellable;
/**
- * A request with the route along which it should be sent.
+ * Interface to be implemented by any object that wishes to be notified of request execution
+ * events.
*
- * @since 4.0
+ * @since 4.3
*/
-@NotThreadSafe // RequestWrapper is @NotThreadSafe
-public class RoutedRequest {
+public interface HttpExecutionAware {
- protected final RequestWrapper request; // @NotThreadSafe
- protected final HttpRoute route; // @Immutable
+ boolean isAborted();
/**
- * Creates a new routed request.
- *
- * @param req the request
- * @param route the route
+ * Sets {@link Cancellable} for the ongoing operation.
*/
- public RoutedRequest(final RequestWrapper req, final HttpRoute route) {
- super();
- this.request = req;
- this.route = route;
- }
-
- public final RequestWrapper getRequest() {
- return request;
- }
-
- public final HttpRoute getRoute() {
- return route;
- }
+ void setCancellable(Cancellable cancellable);
}
+
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/HttpRequestBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/HttpRequestBase.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/HttpRequestBase.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/HttpRequestBase.java Wed Aug 8 20:35:13 2012
@@ -37,6 +37,7 @@ import org.apache.http.annotation.NotThr
import org.apache.http.ProtocolVersion;
import org.apache.http.RequestLine;
import org.apache.http.client.utils.CloneUtils;
+import org.apache.http.concurrent.Cancellable;
import org.apache.http.conn.ClientConnectionRequest;
import org.apache.http.conn.ConnectionReleaseTrigger;
import org.apache.http.message.AbstractHttpMessage;
@@ -51,16 +52,16 @@ import org.apache.http.params.HttpProtoc
*
* @since 4.0
*/
+@SuppressWarnings("deprecation")
@NotThreadSafe
public abstract class HttpRequestBase extends AbstractHttpMessage
- implements HttpUriRequest, AbortableHttpRequest, Cloneable {
+ implements HttpUriRequest, HttpExecutionAware, AbortableHttpRequest, Cloneable {
private Lock abortLock;
private volatile boolean aborted;
private URI uri;
- private ClientConnectionRequest connRequest;
- private ConnectionReleaseTrigger releaseTrigger;
+ private Cancellable cancellable;
public HttpRequestBase() {
super();
@@ -101,43 +102,54 @@ public abstract class HttpRequestBase ex
this.uri = uri;
}
- public void setConnectionRequest(final ClientConnectionRequest connRequest)
- throws IOException {
+ @Deprecated
+ public void setConnectionRequest(final ClientConnectionRequest connRequest) {
if (this.aborted) {
- throw new IOException("Request already aborted");
+ return;
}
this.abortLock.lock();
try {
- this.connRequest = connRequest;
+ this.cancellable = new Cancellable() {
+
+ public boolean cancel() {
+ connRequest.abortRequest();
+ return true;
+ }
+
+ };
} finally {
this.abortLock.unlock();
}
}
- public void setReleaseTrigger(final ConnectionReleaseTrigger releaseTrigger)
- throws IOException {
+ @Deprecated
+ public void setReleaseTrigger(final ConnectionReleaseTrigger releaseTrigger) {
if (this.aborted) {
- throw new IOException("Request already aborted");
+ return;
}
this.abortLock.lock();
try {
- this.releaseTrigger = releaseTrigger;
+ this.cancellable = new Cancellable() {
+
+ public boolean cancel() {
+ try {
+ releaseTrigger.abortConnection();
+ return true;
+ } catch (IOException ex) {
+ return false;
+ }
+ }
+
+ };
} finally {
this.abortLock.unlock();
}
}
- private void cleanup() {
- if (this.connRequest != null) {
- this.connRequest.abortRequest();
- this.connRequest = null;
- }
- if (this.releaseTrigger != null) {
- try {
- this.releaseTrigger.abortConnection();
- } catch (IOException ex) {
- }
- this.releaseTrigger = null;
+ private void cancelExecution() {
+ if (this.cancellable != null) {
+ this.cancellable.cancel();
+ this.cancellable = null;
}
}
@@ -148,7 +160,7 @@ public abstract class HttpRequestBase ex
this.abortLock.lock();
try {
this.aborted = true;
- cleanup();
+ cancelExecution();
} finally {
this.abortLock.unlock();
}
@@ -159,6 +171,39 @@ public abstract class HttpRequestBase ex
}
/**
+ * @since 4.2
+ */
+ public void started() {
+ }
+
+ /**
+ * @since 4.2
+ */
+ public void setCancellable(final Cancellable cancellable) {
+ if (this.aborted) {
+ return;
+ }
+ this.abortLock.lock();
+ try {
+ this.cancellable = cancellable;
+ } finally {
+ this.abortLock.unlock();
+ }
+ }
+
+ /**
+ * @since 4.2
+ */
+ public void completed() {
+ this.abortLock.lock();
+ try {
+ this.cancellable = null;
+ } finally {
+ this.abortLock.unlock();
+ }
+ }
+
+ /**
* Resets internal state of the request making it reusable.
*
* @since 4.2
@@ -166,7 +211,7 @@ public abstract class HttpRequestBase ex
public void reset() {
this.abortLock.lock();
try {
- cleanup();
+ cancelExecution();
this.aborted = false;
} finally {
this.abortLock.unlock();
@@ -188,8 +233,7 @@ public abstract class HttpRequestBase ex
HttpRequestBase clone = (HttpRequestBase) super.clone();
clone.abortLock = new ReentrantLock();
clone.aborted = false;
- clone.releaseTrigger = null;
- clone.connRequest = null;
+ clone.cancellable = null;
clone.headergroup = (HeaderGroup) CloneUtils.clone(this.headergroup);
clone.params = (HttpParams) CloneUtils.clone(this.params);
return clone;
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/ClientContext.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/ClientContext.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/ClientContext.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/ClientContext.java Wed Aug 8 20:35:13 2012
@@ -36,10 +36,19 @@ package org.apache.http.client.protocol;
public interface ClientContext {
/**
+ * Attribute name of a {@link org.apache.http.conn.routing.RouteInfo}
+ * object that represents the actual connection route.
+ *
+ * @since 4.3
+ */
+ public static final String ROUTE = "http.route";
+
+ /**
* Attribute name of a {@link org.apache.http.conn.scheme.Scheme}
* object that represents the actual protocol scheme registry.
*/
public static final String SCHEME_REGISTRY = "http.scheme-registry";
+
/**
* Attribute name of a {@link org.apache.http.cookie.CookieSpecRegistry}
* object that represents the actual cookie specification registry.
@@ -106,4 +115,12 @@ public interface ClientContext {
*/
public static final String USER_TOKEN = "http.user-token";
+ /**
+ * Attribute name of a {@link javax.net.SSLSession} object that represents
+ * the actual SSL session.
+ *
+ * @since 4.3
+ */
+ public static final String SSL_SESSION = "http.ssl-session";
+
}
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java Wed Aug 8 20:35:13 2012
@@ -47,8 +47,9 @@ import org.apache.http.ProtocolException
import org.apache.http.client.CookieStore;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.params.HttpClientParams;
-import org.apache.http.conn.HttpRoutedConnection;
-import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.conn.routing.RouteInfo;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookieSpec;
@@ -111,7 +112,7 @@ public class RequestAddCookies implement
return;
}
- // Obtain the target host (required)
+ // Obtain the target host, possibly virtual (required)
HttpHost targetHost = (HttpHost) context.getAttribute(
ExecutionContext.HTTP_TARGET_HOST);
if (targetHost == null) {
@@ -119,11 +120,10 @@ public class RequestAddCookies implement
return;
}
- // Obtain the client connection (required)
- HttpRoutedConnection conn = (HttpRoutedConnection) context.getAttribute(
- ExecutionContext.HTTP_CONNECTION);
- if (conn == null) {
- this.log.debug("HTTP connection not set in the context");
+ // Obtain the route (required)
+ RouteInfo route = (RouteInfo) context.getAttribute(ClientContext.ROUTE);
+ if (route == null) {
+ this.log.debug("Connection route not set in the context");
return;
}
@@ -147,9 +147,13 @@ public class RequestAddCookies implement
String hostName = targetHost.getHostName();
int port = targetHost.getPort();
if (port < 0) {
- HttpRoute route = conn.getRoute();
if (route.getHopCount() == 1) {
- port = conn.getRemotePort();
+ SchemeRegistry schemeRegistry = (SchemeRegistry) context.getAttribute(
+ ClientContext.SCHEME_REGISTRY);
+ if (schemeRegistry != null) {
+ Scheme scheme = schemeRegistry.getScheme(targetHost);
+ port = scheme.resolvePort(port);
+ }
} else {
// Target port will be selected by the proxy.
// Use conventional ports for known schemes
@@ -158,17 +162,15 @@ public class RequestAddCookies implement
port = 80;
} else if (scheme.equalsIgnoreCase("https")) {
port = 443;
- } else {
- port = 0;
}
}
}
CookieOrigin cookieOrigin = new CookieOrigin(
hostName,
- port,
+ port >= 0 ? port : 0,
requestURI.getPath(),
- conn.isSecure());
+ route.isSecure());
// Get an instance of the selected cookie policy
CookieSpec cookieSpec = registry.getCookieSpec(policy, request.getParams());
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthenticationBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthenticationBase.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthenticationBase.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthenticationBase.java Wed Aug 8 20:35:13 2012
@@ -44,6 +44,7 @@ import org.apache.http.auth.ContextAware
import org.apache.http.auth.Credentials;
import org.apache.http.protocol.HttpContext;
+@Deprecated
abstract class RequestAuthenticationBase implements HttpRequestInterceptor {
final Log log = LogFactory.getLog(getClass());
@@ -112,7 +113,6 @@ abstract class RequestAuthenticationBase
}
}
- @SuppressWarnings("deprecation")
private Header authenticate(
final AuthScheme authScheme,
final Credentials creds,
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java Wed Aug 8 20:35:13 2012
@@ -36,9 +36,7 @@ import org.apache.http.annotation.Immuta
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
-import org.apache.http.conn.HttpRoutedConnection;
-import org.apache.http.conn.routing.HttpRoute;
-import org.apache.http.protocol.ExecutionContext;
+import org.apache.http.conn.routing.RouteInfo;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
@@ -73,15 +71,12 @@ public class RequestClientConnControl im
}
// Obtain the client connection (required)
- HttpRoutedConnection conn = (HttpRoutedConnection) context.getAttribute(
- ExecutionContext.HTTP_CONNECTION);
- if (conn == null) {
- this.log.debug("HTTP connection not set in the context");
+ RouteInfo route = (RouteInfo) context.getAttribute(ClientContext.ROUTE);
+ if (route == null) {
+ this.log.debug("Connection route not set in the context");
return;
}
- HttpRoute route = conn.getRoute();
-
if (route.getHopCount() == 1 || route.isTunnelled()) {
if (!request.containsHeader(HTTP.CONN_DIRECTIVE)) {
request.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestProxyAuthentication.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestProxyAuthentication.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestProxyAuthentication.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestProxyAuthentication.java Wed Aug 8 20:35:13 2012
@@ -36,6 +36,7 @@ import org.apache.http.auth.AUTH;
import org.apache.http.auth.AuthState;
import org.apache.http.conn.HttpRoutedConnection;
import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.impl.client.HttpAuthenticator;
import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpContext;
@@ -44,7 +45,10 @@ import org.apache.http.protocol.HttpCont
* based on the actual state of the HTTP authentication context.
*
* @since 4.0
+ *
+ * @deprecated (4.3) use {@link HttpAuthenticator}.
*/
+@Deprecated
@Immutable
public class RequestProxyAuthentication extends RequestAuthenticationBase {
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestTargetAuthentication.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestTargetAuthentication.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestTargetAuthentication.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestTargetAuthentication.java Wed Aug 8 20:35:13 2012
@@ -34,6 +34,7 @@ import org.apache.http.HttpRequest;
import org.apache.http.annotation.Immutable;
import org.apache.http.auth.AUTH;
import org.apache.http.auth.AuthState;
+import org.apache.http.impl.client.HttpAuthenticator;
import org.apache.http.protocol.HttpContext;
/**
@@ -41,7 +42,10 @@ import org.apache.http.protocol.HttpCont
* based on the actual state of the HTTP authentication context.
*
* @since 4.0
+ *
+ * @deprecated (4.3) use {@link HttpAuthenticator}.
*/
+@Deprecated
@Immutable
public class RequestTargetAuthentication extends RequestAuthenticationBase {
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/ResponseContentEncoding.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/ResponseContentEncoding.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/ResponseContentEncoding.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/ResponseContentEncoding.java Wed Aug 8 20:35:13 2012
@@ -78,16 +78,17 @@ public class ResponseContentEncoding imp
Header ceheader = entity.getContentEncoding();
if (ceheader != null) {
HeaderElement[] codecs = ceheader.getElements();
+ boolean uncompressed = false;
for (HeaderElement codec : codecs) {
String codecname = codec.getName().toLowerCase(Locale.US);
if ("gzip".equals(codecname) || "x-gzip".equals(codecname)) {
response.setEntity(new GzipDecompressingEntity(response.getEntity()));
- if (context != null) context.setAttribute(UNCOMPRESSED, true);
- return;
+ uncompressed = true;
+ break;
} else if ("deflate".equals(codecname)) {
response.setEntity(new DeflateDecompressingEntity(response.getEntity()));
- if (context != null) context.setAttribute(UNCOMPRESSED, true);
- return;
+ uncompressed = true;
+ break;
} else if ("identity".equals(codecname)) {
/* Don't need to transform the content - no-op */
@@ -96,6 +97,11 @@ public class ResponseContentEncoding imp
throw new HttpException("Unsupported Content-Coding: " + codec.getName());
}
}
+ if (uncompressed) {
+ response.removeHeaders("Content-Length");
+ response.removeHeaders("Content-Encoding");
+ response.removeHeaders("Content-MD5");
+ }
}
}
}
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/BasicEofSensorWatcher.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/BasicEofSensorWatcher.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/BasicEofSensorWatcher.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/BasicEofSensorWatcher.java Wed Aug 8 20:35:13 2012
@@ -37,7 +37,10 @@ import org.apache.http.annotation.NotThr
* is released on close or EOF.
*
* @since 4.0
+ *
+ * @deprecated (4.3) do not use.
*/
+@Deprecated
@NotThreadSafe
public class BasicEofSensorWatcher implements EofSensorWatcher {
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/BasicManagedEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/BasicManagedEntity.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/BasicManagedEntity.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/BasicManagedEntity.java Wed Aug 8 20:35:13 2012
@@ -45,7 +45,10 @@ import org.apache.http.util.EntityUtils;
* the unmanaged entity in the response with a managed one.
*
* @since 4.0
+ *
+ * @deprecated (4.3) do not use.
*/
+@Deprecated
@NotThreadSafe
public class BasicManagedEntity extends HttpEntityWrapper
implements ConnectionReleaseTrigger, EofSensorWatcher {
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/HttpRoutedConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/HttpRoutedConnection.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/HttpRoutedConnection.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/HttpRoutedConnection.java Wed Aug 8 20:35:13 2012
@@ -36,7 +36,10 @@ import org.apache.http.conn.routing.Http
* Interface to access routing information of a client side connection.
*
* @since 4.1
+ *
+ * @deprecated (4.3) no longer used
*/
+@Deprecated
public interface HttpRoutedConnection extends HttpInetConnection {
/**
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ManagedClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ManagedClientConnection.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ManagedClientConnection.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ManagedClientConnection.java Wed Aug 8 20:35:13 2012
@@ -45,6 +45,7 @@ import org.apache.http.conn.routing.Http
*
* @since 4.0
*/
+@SuppressWarnings("deprecation")
public interface ManagedClientConnection extends
HttpClientConnection, HttpRoutedConnection, ConnectionReleaseTrigger {
Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AbstractBasicHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AbstractBasicHttpClient.java?rev=1370953&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AbstractBasicHttpClient.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AbstractBasicHttpClient.java Wed Aug 8 20:35:13 2012
@@ -0,0 +1,149 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.client;
+
+import java.io.IOException;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.net.URI;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.annotation.ThreadSafe;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.ResponseHandler;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.client.utils.URIUtils;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.EntityUtils;
+
+/**
+ * @since 4.3
+ */
+@ThreadSafe
+public abstract class AbstractBasicHttpClient implements HttpClient {
+
+ private final Log log = LogFactory.getLog(getClass());
+
+ public HttpResponse execute(
+ final HttpUriRequest request,
+ final HttpContext context) throws IOException, ClientProtocolException {
+ if (request == null) {
+ throw new IllegalArgumentException("Request must not be null.");
+ }
+ return execute(determineTarget(request), request, context);
+ }
+
+ private static HttpHost determineTarget(HttpUriRequest 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;
+
+ URI requestURI = request.getURI();
+ if (requestURI.isAbsolute()) {
+ target = URIUtils.extractHost(requestURI);
+ if (target == null) {
+ throw new ClientProtocolException("URI does not specify a valid host name: "
+ + requestURI);
+ }
+ }
+ return target;
+ }
+
+ public HttpResponse execute(
+ final HttpUriRequest request) throws IOException, ClientProtocolException {
+ return execute(request, (HttpContext) null);
+ }
+
+ public HttpResponse execute(
+ final HttpHost target,
+ final HttpRequest request) throws IOException, ClientProtocolException {
+ return execute(target, request, (HttpContext) null);
+ }
+
+ public <T> T execute(final HttpUriRequest request,
+ final ResponseHandler<? extends T> responseHandler) throws IOException,
+ ClientProtocolException {
+ return execute(request, responseHandler, null);
+ }
+
+ public <T> T execute(final HttpUriRequest request,
+ final ResponseHandler<? extends T> responseHandler, final HttpContext context)
+ throws IOException, ClientProtocolException {
+ HttpHost target = determineTarget(request);
+ return execute(target, request, responseHandler, context);
+ }
+
+ public <T> T execute(final HttpHost target, final HttpRequest request,
+ final ResponseHandler<? extends T> responseHandler) throws IOException,
+ ClientProtocolException {
+ return execute(target, request, responseHandler, null);
+ }
+
+ public <T> T execute(final HttpHost target, final HttpRequest request,
+ final ResponseHandler<? extends T> responseHandler, final HttpContext context)
+ throws IOException, ClientProtocolException {
+ if (responseHandler == null) {
+ throw new IllegalArgumentException("Response handler must not be null.");
+ }
+
+ HttpResponse response = execute(target, request, context);
+
+ T result;
+ try {
+ result = responseHandler.handleResponse(response);
+ } catch (Exception t) {
+ HttpEntity entity = response.getEntity();
+ try {
+ EntityUtils.consume(entity);
+ } catch (Exception t2) {
+ // Log this exception. The original exception is more
+ // important and will be thrown to the caller.
+ this.log.warn("Error consuming content after an exception.", t2);
+ }
+ if (t instanceof RuntimeException) {
+ throw (RuntimeException) t;
+ }
+ if (t instanceof IOException) {
+ throw (IOException) t;
+ }
+ throw new UndeclaredThrowableException(t);
+ }
+
+ // Handling the response was successful. Ensure that the content has
+ // been fully consumed.
+ HttpEntity entity = response.getEntity();
+ EntityUtils.consume(entity);
+ return result;
+ }
+
+}
Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AbstractBasicHttpClient.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AbstractBasicHttpClient.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AbstractBasicHttpClient.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java Wed Aug 8 20:35:13 2012
@@ -29,12 +29,10 @@ package org.apache.http.impl.client;
import java.io.IOException;
import java.lang.reflect.UndeclaredThrowableException;
-import java.net.URI;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.ConnectionReuseStrategy;
-import org.apache.http.HttpEntity;
import org.apache.http.HttpException;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
@@ -56,14 +54,11 @@ import org.apache.http.client.HttpReques
import org.apache.http.client.RedirectHandler;
import org.apache.http.client.RedirectStrategy;
import org.apache.http.client.RequestDirector;
-import org.apache.http.client.ResponseHandler;
import org.apache.http.client.UserTokenHandler;
-import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.params.AuthPolicy;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.client.params.CookiePolicy;
import org.apache.http.client.protocol.ClientContext;
-import org.apache.http.client.utils.URIUtils;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.ClientConnectionManagerFactory;
import org.apache.http.conn.ConnectionKeepAliveStrategy;
@@ -94,7 +89,6 @@ import org.apache.http.protocol.HttpCont
import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.HttpRequestExecutor;
import org.apache.http.protocol.ImmutableHttpProcessor;
-import org.apache.http.util.EntityUtils;
/**
* Base class for {@link HttpClient} implementations. This class acts as
@@ -179,10 +173,12 @@ import org.apache.http.util.EntityUtils;
* shut down by calling {@link ClientConnectionManager#shutdown()}!
*
* @since 4.0
+ *
+ * @deprecated (4.3) use {@link HttpClientBuilder}.
*/
-@SuppressWarnings("deprecation")
@ThreadSafe
-public abstract class AbstractHttpClient implements HttpClient {
+@Deprecated
+public abstract class AbstractHttpClient extends AbstractBasicHttpClient {
private final Log log = LogFactory.getLog(getClass());
@@ -270,6 +266,7 @@ public abstract class AbstractHttpClient
protected AbstractHttpClient(
final ClientConnectionManager conman,
final HttpParams params) {
+ super();
defaultParams = params;
connManager = conman;
} // constructor
@@ -778,55 +775,6 @@ public abstract class AbstractHttpClient
protocolProcessor = null;
}
- public final HttpResponse execute(HttpUriRequest request)
- throws IOException, ClientProtocolException {
-
- return execute(request, (HttpContext) null);
- }
-
- /**
- * Maps to {@link HttpClient#execute(HttpHost,HttpRequest,HttpContext)
- * execute(target, request, context)}.
- * The target is determined from the URI of the request.
- *
- * @param request the request to execute
- * @param context the request-specific execution context,
- * or <code>null</code> to use a default context
- */
- public final HttpResponse execute(HttpUriRequest request,
- HttpContext context)
- throws IOException, ClientProtocolException {
-
- if (request == null) {
- throw new IllegalArgumentException
- ("Request must not be null.");
- }
-
- return execute(determineTarget(request), request, context);
- }
-
- private static HttpHost determineTarget(HttpUriRequest 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;
-
- URI requestURI = request.getURI();
- if (requestURI.isAbsolute()) {
- target = URIUtils.extractHost(requestURI);
- if (target == null) {
- throw new ClientProtocolException(
- "URI does not specify a valid host name: " + requestURI);
- }
- }
- return target;
- }
-
- public final HttpResponse execute(HttpHost target, HttpRequest request)
- throws IOException, ClientProtocolException {
-
- return execute(target, request, (HttpContext) null);
- }
-
public final HttpResponse execute(HttpHost target, HttpRequest request,
HttpContext context)
throws IOException, ClientProtocolException {
@@ -992,8 +940,7 @@ public abstract class AbstractHttpClient
final AuthenticationStrategy proxyAuthStrategy,
final UserTokenHandler userTokenHandler,
final HttpParams params) {
- return new DefaultRequestDirector(
- log,
+ return new RequestDirectorAdaptor(
requestExec,
conman,
reustrat,
@@ -1028,69 +975,4 @@ public abstract class AbstractHttpClient
(null, getParams(), req.getParams(), null);
}
- public <T> T execute(
- final HttpUriRequest request,
- final ResponseHandler<? extends T> responseHandler)
- throws IOException, ClientProtocolException {
- return execute(request, responseHandler, null);
- }
-
- public <T> T execute(
- final HttpUriRequest request,
- final ResponseHandler<? extends T> responseHandler,
- final HttpContext context)
- throws IOException, ClientProtocolException {
- HttpHost target = determineTarget(request);
- return execute(target, request, responseHandler, context);
- }
-
- public <T> T execute(
- final HttpHost target,
- final HttpRequest request,
- final ResponseHandler<? extends T> responseHandler)
- throws IOException, ClientProtocolException {
- return execute(target, request, responseHandler, null);
- }
-
- public <T> T execute(
- final HttpHost target,
- final HttpRequest request,
- final ResponseHandler<? extends T> responseHandler,
- final HttpContext context)
- throws IOException, ClientProtocolException {
- if (responseHandler == null) {
- throw new IllegalArgumentException
- ("Response handler must not be null.");
- }
-
- HttpResponse response = execute(target, request, context);
-
- T result;
- try {
- result = responseHandler.handleResponse(response);
- } catch (Exception t) {
- HttpEntity entity = response.getEntity();
- try {
- EntityUtils.consume(entity);
- } catch (Exception t2) {
- // Log this exception. The original exception is more
- // important and will be thrown to the caller.
- this.log.warn("Error consuming content after an exception.", t2);
- }
- if (t instanceof RuntimeException) {
- throw (RuntimeException) t;
- }
- if (t instanceof IOException) {
- throw (IOException) t;
- }
- throw new UndeclaredThrowableException(t);
- }
-
- // Handling the response was successful. Ensure that the content has
- // been fully consumed.
- HttpEntity entity = response.getEntity();
- EntityUtils.consume(entity);
- return result;
- }
-
}
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AutoRetryHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AutoRetryHttpClient.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AutoRetryHttpClient.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AutoRetryHttpClient.java Wed Aug 8 20:35:13 2012
@@ -51,6 +51,8 @@ import org.apache.http.util.EntityUtils;
* a non-2xx response using the {@link ServiceUnavailableRetryStrategy} interface.
*
* @since 4.2
+ *
+ * @deprecated (4.3) use {@link HttpClientBuilder}.
*/
@ThreadSafe
public class AutoRetryHttpClient implements HttpClient {
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ClientParamsStack.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ClientParamsStack.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ClientParamsStack.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ClientParamsStack.java Wed Aug 8 20:35:13 2012
@@ -29,6 +29,7 @@ package org.apache.http.impl.client;
import org.apache.http.annotation.NotThreadSafe;
+import org.apache.http.params.DefaultedHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.AbstractHttpParams;
@@ -64,11 +65,12 @@ import org.apache.http.params.AbstractHt
* an empty params collection, since it avoids searching the empty collection
* when looking up parameters.
*
- *
- *
* @since 4.0
+ *
+ * @deprecated (4.3) use {@link DefaultedHttpParams}
*/
@NotThreadSafe
+@Deprecated
public class ClientParamsStack extends AbstractHttpParams {
/** The application parameter collection, or <code>null</code>. */
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ContentEncodingHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ContentEncodingHttpClient.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ContentEncodingHttpClient.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ContentEncodingHttpClient.java Wed Aug 8 20:35:13 2012
@@ -47,6 +47,8 @@ import org.apache.http.protocol.BasicHtt
* responses in compressed or uncompressed form.
*
* @since 4.1
+ *
+ * @deprecated (4.2) use {@link HttpClientBuilder}
*/
@Deprecated
@ThreadSafe // since DefaultHttpClient is
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DecompressingHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DecompressingHttpClient.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DecompressingHttpClient.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DecompressingHttpClient.java Wed Aug 8 20:35:13 2012
@@ -70,7 +70,10 @@ import org.apache.http.util.EntityUtils;
* in either order and still have cacheable responses be cached.</p>
*
* @since 4.2
+ *
+ * @deprecated (4.3) use {@link HttpClientBuilder}
*/
+@Deprecated
public class DecompressingHttpClient implements HttpClient {
private final HttpClient backend;
@@ -153,11 +156,6 @@ public class DecompressingHttpClient imp
acceptEncodingInterceptor.process(wrapped, context);
HttpResponse response = backend.execute(target, wrapped, context);
contentEncodingInterceptor.process(response, context);
- if (Boolean.TRUE.equals(context.getAttribute(ResponseContentEncoding.UNCOMPRESSED))) {
- response.removeHeaders("Content-Length");
- response.removeHeaders("Content-Encoding");
- response.removeHeaders("Content-MD5");
- }
return response;
} catch (HttpException e) {
throw new ClientProtocolException(e);
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java Wed Aug 8 20:35:13 2012
@@ -111,8 +111,11 @@ import org.apache.http.util.VersionInfo;
* </ul>
*
* @since 4.0
+ *
+ * @deprecated (4.3) use {@link HttpClientBuilder}.
*/
@ThreadSafe
+@Deprecated
public class DefaultHttpClient extends AbstractHttpClient {
/**
@@ -219,8 +222,6 @@ public class DefaultHttpClient extends A
httpproc.addInterceptor(new ResponseProcessCookies());
// HTTP authentication interceptors
httpproc.addInterceptor(new RequestAuthCache());
- httpproc.addInterceptor(new RequestTargetAuthentication());
- httpproc.addInterceptor(new RequestProxyAuthentication());
return httpproc;
}
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpRequestRetryHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpRequestRetryHandler.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpRequestRetryHandler.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpRequestRetryHandler.java Wed Aug 8 20:35:13 2012
@@ -39,14 +39,13 @@ import org.apache.http.annotation.Immuta
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpRequest;
import org.apache.http.client.HttpRequestRetryHandler;
+import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.ExecutionContext;
-import org.apache.http.client.methods.HttpUriRequest;
/**
* The default {@link HttpRequestRetryHandler} used by request executors.
*
- *
* @since 4.0
*/
@Immutable
@@ -157,6 +156,8 @@ public class DefaultHttpRequestRetryHand
/**
* @since 4.2
+ *
+ * @deprecated (4.3)
*/
protected boolean requestIsAborted(final HttpRequest request) {
HttpRequest req = request;
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java Wed Aug 8 20:35:13 2012
@@ -126,8 +126,10 @@ import org.apache.http.util.EntityUtils;
* </ul>
*
* @since 4.0
+ *
+ * @deprecated (4.3)
*/
-@SuppressWarnings("deprecation")
+@Deprecated
@NotThreadSafe // e.g. managedConn
public class DefaultRequestDirector implements RequestDirector {
@@ -504,11 +506,9 @@ public class DefaultRequestDirector impl
target = route.getTargetHost();
}
- HttpHost proxy = route.getProxyHost();
-
// Populate the execution context
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
- context.setAttribute(ExecutionContext.HTTP_PROXY_HOST, proxy);
+ context.setAttribute(ClientContext.ROUTE, route);
context.setAttribute(ExecutionContext.HTTP_CONNECTION, managedConn);
// Run request protocol interceptors
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultUserTokenHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultUserTokenHandler.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultUserTokenHandler.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultUserTokenHandler.java Wed Aug 8 20:35:13 2012
@@ -31,14 +31,11 @@ import java.security.Principal;
import javax.net.ssl.SSLSession;
import org.apache.http.annotation.Immutable;
-
import org.apache.http.auth.AuthScheme;
import org.apache.http.auth.AuthState;
import org.apache.http.auth.Credentials;
import org.apache.http.client.UserTokenHandler;
import org.apache.http.client.protocol.ClientContext;
-import org.apache.http.conn.HttpRoutedConnection;
-import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpContext;
/**
@@ -74,13 +71,9 @@ public class DefaultUserTokenHandler imp
}
if (userPrincipal == null) {
- HttpRoutedConnection conn = (HttpRoutedConnection) context.getAttribute(
- ExecutionContext.HTTP_CONNECTION);
- if (conn.isOpen()) {
- SSLSession sslsession = conn.getSSLSession();
- if (sslsession != null) {
- userPrincipal = sslsession.getLocalPrincipal();
- }
+ SSLSession sslsession = (SSLSession) context.getAttribute(ClientContext.SSL_SESSION);
+ if (sslsession != null) {
+ userPrincipal = sslsession.getLocalPrincipal();
}
}
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/EntityEnclosingRequestWrapper.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/EntityEnclosingRequestWrapper.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/EntityEnclosingRequestWrapper.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/EntityEnclosingRequestWrapper.java Wed Aug 8 20:35:13 2012
@@ -33,6 +33,7 @@ import java.io.OutputStream;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.entity.HttpEntityWrapper;
+import org.apache.http.impl.client.exec.HttpRequestWrapper;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
@@ -48,9 +49,11 @@ import org.apache.http.protocol.HTTP;
* This class is also capable of resetting the request headers to
* the state of the original request.
*
- *
* @since 4.0
+ *
+ * @deprecated (4.3) use {@link HttpRequestWrapper}.
*/
+@Deprecated
@NotThreadSafe // e.g. [gs]etEntity()
public class EntityEnclosingRequestWrapper extends RequestWrapper
implements HttpEntityEnclosingRequest {
@@ -89,7 +92,6 @@ public class EntityEnclosingRequestWrapp
super(entity);
}
- @SuppressWarnings("deprecation")
@Override
public void consumeContent() throws IOException {
consumed = true;
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpAuthenticator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpAuthenticator.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpAuthenticator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpAuthenticator.java Wed Aug 8 20:35:13 2012
@@ -27,6 +27,7 @@
package org.apache.http.impl.client;
+import java.io.IOException;
import java.util.Locale;
import java.util.Map;
import java.util.Queue;
@@ -34,12 +35,17 @@ import java.util.Queue;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.Header;
+import org.apache.http.HttpException;
import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthProtocolState;
import org.apache.http.auth.AuthOption;
import org.apache.http.auth.AuthScheme;
import org.apache.http.auth.AuthState;
+import org.apache.http.auth.AuthenticationException;
+import org.apache.http.auth.ContextAwareAuthScheme;
+import org.apache.http.auth.Credentials;
import org.apache.http.auth.MalformedChallengeException;
import org.apache.http.client.AuthenticationStrategy;
import org.apache.http.protocol.HttpContext;
@@ -81,7 +87,24 @@ public class HttpAuthenticator {
}
}
- public boolean authenticate(
+ /**
+ * @deprecated (4.3) use {@link #handleAuthChallenge(
+ * HttpHost, HttpResponse, AuthenticationStrategy, AuthState, HttpContext)}.
+ */
+ @Deprecated
+ public boolean authenticate (
+ final HttpHost host,
+ final HttpResponse response,
+ final AuthenticationStrategy authStrategy,
+ final AuthState authState,
+ final HttpContext context) {
+ return handleAuthChallenge(host, response, authStrategy, authState, context);
+ }
+
+ /**
+ * @since 4.3
+ */
+ public boolean handleAuthChallenge(
final HttpHost host,
final HttpResponse response,
final AuthenticationStrategy authStrategy,
@@ -156,4 +179,80 @@ public class HttpAuthenticator {
}
}
+ /**
+ * @since 4.3
+ */
+ public void generateAuthResponse(
+ final HttpRequest request,
+ final AuthState authState,
+ final HttpContext context) throws HttpException, IOException {
+ AuthScheme authScheme = authState.getAuthScheme();
+ Credentials creds = authState.getCredentials();
+ switch (authState.getState()) {
+ case FAILURE:
+ return;
+ case SUCCESS:
+ ensureAuthScheme(authScheme);
+ if (authScheme.isConnectionBased()) {
+ return;
+ }
+ break;
+ case CHALLENGED:
+ Queue<AuthOption> authOptions = authState.getAuthOptions();
+ if (authOptions != null) {
+ while (!authOptions.isEmpty()) {
+ AuthOption authOption = authOptions.remove();
+ authScheme = authOption.getAuthScheme();
+ creds = authOption.getCredentials();
+ authState.update(authScheme, creds);
+ if (this.log.isDebugEnabled()) {
+ this.log.debug("Generating response to an authentication challenge using "
+ + authScheme.getSchemeName() + " scheme");
+ }
+ try {
+ Header header = doAuth(authScheme, creds, request, context);
+ request.addHeader(header);
+ break;
+ } catch (AuthenticationException ex) {
+ if (this.log.isWarnEnabled()) {
+ this.log.warn(authScheme + " authentication error: " + ex.getMessage());
+ }
+ }
+ }
+ return;
+ } else {
+ ensureAuthScheme(authScheme);
+ }
+ }
+ if (authScheme != null) {
+ try {
+ Header header = doAuth(authScheme, creds, request, context);
+ request.addHeader(header);
+ } catch (AuthenticationException ex) {
+ if (this.log.isErrorEnabled()) {
+ this.log.error(authScheme + " authentication error: " + ex.getMessage());
+ }
+ }
+ }
+ }
+
+ private void ensureAuthScheme(final AuthScheme authScheme) {
+ if (authScheme == null) {
+ throw new IllegalStateException("Auth scheme is not set");
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ private Header doAuth(
+ final AuthScheme authScheme,
+ final Credentials creds,
+ final HttpRequest request,
+ final HttpContext context) throws AuthenticationException {
+ if (authScheme instanceof ContextAwareAuthScheme) {
+ return ((ContextAwareAuthScheme) authScheme).authenticate(creds, request, context);
+ } else {
+ return authScheme.authenticate(creds, request);
+ }
+ }
+
}