adapted to HTTPCORE-100
git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@558119 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d4862a917b
commit
fd53851031
|
@ -31,10 +31,12 @@
|
||||||
|
|
||||||
package org.apache.http.client.protocol;
|
package org.apache.http.client.protocol;
|
||||||
|
|
||||||
import org.apache.http.protocol.HttpContext;
|
|
||||||
import org.apache.http.protocol.HttpExecutionContext;
|
|
||||||
|
|
||||||
public class HttpClientContext extends HttpExecutionContext {
|
/**
|
||||||
|
* {@link org.apache.http.protocol.HttpContext Context}
|
||||||
|
* attribute names for client.
|
||||||
|
*/
|
||||||
|
public interface ClientContext {
|
||||||
|
|
||||||
public static final String COOKIESPEC_REGISTRY = "http.cookiespec-registry";
|
public static final String COOKIESPEC_REGISTRY = "http.cookiespec-registry";
|
||||||
public static final String AUTHSCHEME_REGISTRY = "http.authscheme-registry";
|
public static final String AUTHSCHEME_REGISTRY = "http.authscheme-registry";
|
||||||
|
@ -43,9 +45,4 @@ public class HttpClientContext extends HttpExecutionContext {
|
||||||
public static final String COOKIE_ORIGIN = "http.cookie-origin";
|
public static final String COOKIE_ORIGIN = "http.cookie-origin";
|
||||||
public static final String TARGET_AUTH_STATE = "http.auth.target-scope";
|
public static final String TARGET_AUTH_STATE = "http.auth.target-scope";
|
||||||
public static final String PROXY_AUTH_STATE = "http.auth.proxy-scope";
|
public static final String PROXY_AUTH_STATE = "http.auth.proxy-scope";
|
||||||
|
|
||||||
public HttpClientContext(final HttpContext parentContext) {
|
|
||||||
super(parentContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -54,7 +54,7 @@ import org.apache.http.cookie.CookieOrigin;
|
||||||
import org.apache.http.cookie.CookieSpec;
|
import org.apache.http.cookie.CookieSpec;
|
||||||
import org.apache.http.cookie.CookieSpecRegistry;
|
import org.apache.http.cookie.CookieSpecRegistry;
|
||||||
import org.apache.http.protocol.HttpContext;
|
import org.apache.http.protocol.HttpContext;
|
||||||
import org.apache.http.protocol.HttpExecutionContext;
|
import org.apache.http.protocol.ExecutionContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request interceptor that matches cookies available in the current
|
* Request interceptor that matches cookies available in the current
|
||||||
|
@ -86,7 +86,7 @@ public class RequestAddCookies implements HttpRequestInterceptor {
|
||||||
|
|
||||||
// Obtain HTTP state
|
// Obtain HTTP state
|
||||||
HttpState state = (HttpState) context.getAttribute(
|
HttpState state = (HttpState) context.getAttribute(
|
||||||
HttpClientContext.HTTP_STATE);
|
ClientContext.HTTP_STATE);
|
||||||
if (state == null) {
|
if (state == null) {
|
||||||
LOG.info("HTTP state not available in HTTP context");
|
LOG.info("HTTP state not available in HTTP context");
|
||||||
return;
|
return;
|
||||||
|
@ -94,7 +94,7 @@ public class RequestAddCookies implements HttpRequestInterceptor {
|
||||||
|
|
||||||
// Obtain the registry of cookie specs
|
// Obtain the registry of cookie specs
|
||||||
CookieSpecRegistry registry= (CookieSpecRegistry) context.getAttribute(
|
CookieSpecRegistry registry= (CookieSpecRegistry) context.getAttribute(
|
||||||
HttpClientContext.COOKIESPEC_REGISTRY);
|
ClientContext.COOKIESPEC_REGISTRY);
|
||||||
if (registry == null) {
|
if (registry == null) {
|
||||||
LOG.info("CookieSpec registry not available in HTTP context");
|
LOG.info("CookieSpec registry not available in HTTP context");
|
||||||
return;
|
return;
|
||||||
|
@ -102,14 +102,14 @@ public class RequestAddCookies implements HttpRequestInterceptor {
|
||||||
|
|
||||||
// Obtain the target host (required)
|
// Obtain the target host (required)
|
||||||
HttpHost targetHost = (HttpHost) context.getAttribute(
|
HttpHost targetHost = (HttpHost) context.getAttribute(
|
||||||
HttpExecutionContext.HTTP_TARGET_HOST);
|
ExecutionContext.HTTP_TARGET_HOST);
|
||||||
if (targetHost == null) {
|
if (targetHost == null) {
|
||||||
throw new IllegalStateException("Target host not specified in HTTP context");
|
throw new IllegalStateException("Target host not specified in HTTP context");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtain the client connection (required)
|
// Obtain the client connection (required)
|
||||||
ManagedClientConnection conn = (ManagedClientConnection) context.getAttribute(
|
ManagedClientConnection conn = (ManagedClientConnection) context.getAttribute(
|
||||||
HttpExecutionContext.HTTP_CONNECTION);
|
ExecutionContext.HTTP_CONNECTION);
|
||||||
if (conn == null) {
|
if (conn == null) {
|
||||||
throw new IllegalStateException("Client connection not specified in HTTP context");
|
throw new IllegalStateException("Client connection not specified in HTTP context");
|
||||||
}
|
}
|
||||||
|
@ -169,8 +169,8 @@ public class RequestAddCookies implements HttpRequestInterceptor {
|
||||||
|
|
||||||
// Stick the CookieSpec and CookieOrigin instances to the HTTP context
|
// Stick the CookieSpec and CookieOrigin instances to the HTTP context
|
||||||
// so they could be obtained by the response interceptor
|
// so they could be obtained by the response interceptor
|
||||||
context.setAttribute(HttpClientContext.COOKIE_SPEC, cookieSpec);
|
context.setAttribute(ClientContext.COOKIE_SPEC, cookieSpec);
|
||||||
context.setAttribute(HttpClientContext.COOKIE_ORIGIN, cookieOrigin);
|
context.setAttribute(ClientContext.COOKIE_ORIGIN, cookieOrigin);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class RequestProxyAuthentication implements HttpRequestInterceptor {
|
||||||
|
|
||||||
// Obtain authentication state
|
// Obtain authentication state
|
||||||
AuthState authState = (AuthState) context.getAttribute(
|
AuthState authState = (AuthState) context.getAttribute(
|
||||||
HttpClientContext.PROXY_AUTH_STATE);
|
ClientContext.PROXY_AUTH_STATE);
|
||||||
if (authState == null) {
|
if (authState == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class RequestTargetAuthentication implements HttpRequestInterceptor {
|
||||||
|
|
||||||
// Obtain authentication state
|
// Obtain authentication state
|
||||||
AuthState authState = (AuthState) context.getAttribute(
|
AuthState authState = (AuthState) context.getAttribute(
|
||||||
HttpClientContext.TARGET_AUTH_STATE);
|
ClientContext.TARGET_AUTH_STATE);
|
||||||
if (authState == null) {
|
if (authState == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,21 +76,21 @@ public class ResponseProcessCookies implements HttpResponseInterceptor {
|
||||||
|
|
||||||
// Obtain HTTP state
|
// Obtain HTTP state
|
||||||
HttpState state = (HttpState) context.getAttribute(
|
HttpState state = (HttpState) context.getAttribute(
|
||||||
HttpClientContext.HTTP_STATE);
|
ClientContext.HTTP_STATE);
|
||||||
if (state == null) {
|
if (state == null) {
|
||||||
LOG.info("HTTP state not available in HTTP context");
|
LOG.info("HTTP state not available in HTTP context");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Obtain actual CookieSpec instance
|
// Obtain actual CookieSpec instance
|
||||||
CookieSpec cookieSpec = (CookieSpec) context.getAttribute(
|
CookieSpec cookieSpec = (CookieSpec) context.getAttribute(
|
||||||
HttpClientContext.COOKIE_SPEC);
|
ClientContext.COOKIE_SPEC);
|
||||||
if (cookieSpec == null) {
|
if (cookieSpec == null) {
|
||||||
LOG.info("CookieSpec not available in HTTP context");
|
LOG.info("CookieSpec not available in HTTP context");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Obtain actual CookieOrigin instance
|
// Obtain actual CookieOrigin instance
|
||||||
CookieOrigin cookieOrigin = (CookieOrigin) context.getAttribute(
|
CookieOrigin cookieOrigin = (CookieOrigin) context.getAttribute(
|
||||||
HttpClientContext.COOKIE_ORIGIN);
|
ClientContext.COOKIE_ORIGIN);
|
||||||
if (cookieOrigin == null) {
|
if (cookieOrigin == null) {
|
||||||
LOG.info("CookieOrigin not available in HTTP context");
|
LOG.info("CookieOrigin not available in HTTP context");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -51,12 +51,12 @@ import org.apache.http.client.HttpState;
|
||||||
import org.apache.http.client.RedirectHandler;
|
import org.apache.http.client.RedirectHandler;
|
||||||
import org.apache.http.client.RoutedRequest;
|
import org.apache.http.client.RoutedRequest;
|
||||||
import org.apache.http.client.methods.HttpUriRequest;
|
import org.apache.http.client.methods.HttpUriRequest;
|
||||||
import org.apache.http.client.protocol.HttpClientContext;
|
|
||||||
import org.apache.http.conn.ClientConnectionManager;
|
import org.apache.http.conn.ClientConnectionManager;
|
||||||
import org.apache.http.cookie.CookieSpecRegistry;
|
import org.apache.http.cookie.CookieSpecRegistry;
|
||||||
import org.apache.http.params.HttpParams;
|
import org.apache.http.params.HttpParams;
|
||||||
import org.apache.http.protocol.BasicHttpProcessor;
|
import org.apache.http.protocol.BasicHttpProcessor;
|
||||||
import org.apache.http.protocol.HttpContext;
|
import org.apache.http.protocol.HttpContext;
|
||||||
|
import org.apache.http.protocol.BasicHttpContext;
|
||||||
import org.apache.http.protocol.HttpRequestInterceptorList;
|
import org.apache.http.protocol.HttpRequestInterceptorList;
|
||||||
import org.apache.http.protocol.HttpResponseInterceptorList;
|
import org.apache.http.protocol.HttpResponseInterceptorList;
|
||||||
|
|
||||||
|
@ -418,7 +418,7 @@ public abstract class AbstractHttpClient
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (context == null) {
|
if (context == null) {
|
||||||
context = new HttpClientContext(getDefaultContext());
|
context = new BasicHttpContext(getDefaultContext());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,7 +456,7 @@ public abstract class AbstractHttpClient
|
||||||
// all shared objects that are potentially threading unsafe.
|
// all shared objects that are potentially threading unsafe.
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (context == null) {
|
if (context == null) {
|
||||||
context = new HttpClientContext(getDefaultContext());
|
context = new BasicHttpContext(getDefaultContext());
|
||||||
}
|
}
|
||||||
// Create a director for this request
|
// Create a director for this request
|
||||||
director = new DefaultClientRequestDirector(
|
director = new DefaultClientRequestDirector(
|
||||||
|
|
|
@ -50,7 +50,7 @@ import org.apache.http.auth.AuthenticationException;
|
||||||
import org.apache.http.auth.MalformedChallengeException;
|
import org.apache.http.auth.MalformedChallengeException;
|
||||||
import org.apache.http.client.AuthenticationHandler;
|
import org.apache.http.client.AuthenticationHandler;
|
||||||
import org.apache.http.client.params.HttpClientParams;
|
import org.apache.http.client.params.HttpClientParams;
|
||||||
import org.apache.http.client.protocol.HttpClientContext;
|
import org.apache.http.client.protocol.ClientContext;
|
||||||
import org.apache.http.message.BufferedHeader;
|
import org.apache.http.message.BufferedHeader;
|
||||||
import org.apache.http.params.HttpParams;
|
import org.apache.http.params.HttpParams;
|
||||||
import org.apache.http.protocol.HTTP;
|
import org.apache.http.protocol.HTTP;
|
||||||
|
@ -153,7 +153,7 @@ public class DefaultAuthenticationHandler implements AuthenticationHandler {
|
||||||
final HttpContext context) throws AuthenticationException {
|
final HttpContext context) throws AuthenticationException {
|
||||||
|
|
||||||
AuthSchemeRegistry registry = (AuthSchemeRegistry) context.getAttribute(
|
AuthSchemeRegistry registry = (AuthSchemeRegistry) context.getAttribute(
|
||||||
HttpClientContext.AUTHSCHEME_REGISTRY);
|
ClientContext.AUTHSCHEME_REGISTRY);
|
||||||
if (registry == null) {
|
if (registry == null) {
|
||||||
throw new IllegalStateException("AuthScheme registry not set in HTTP context");
|
throw new IllegalStateException("AuthScheme registry not set in HTTP context");
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ import org.apache.http.client.RoutedRequest;
|
||||||
import org.apache.http.client.methods.AbortableHttpRequest;
|
import org.apache.http.client.methods.AbortableHttpRequest;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.client.params.HttpClientParams;
|
import org.apache.http.client.params.HttpClientParams;
|
||||||
import org.apache.http.client.protocol.HttpClientContext;
|
import org.apache.http.client.protocol.ClientContext;
|
||||||
import org.apache.http.conn.BasicManagedEntity;
|
import org.apache.http.conn.BasicManagedEntity;
|
||||||
import org.apache.http.conn.ClientConnectionManager;
|
import org.apache.http.conn.ClientConnectionManager;
|
||||||
import org.apache.http.conn.ConnectionPoolTimeoutException;
|
import org.apache.http.conn.ConnectionPoolTimeoutException;
|
||||||
|
@ -83,7 +83,7 @@ import org.apache.http.params.HttpParamsLinker;
|
||||||
import org.apache.http.params.HttpProtocolParams;
|
import org.apache.http.params.HttpProtocolParams;
|
||||||
import org.apache.http.protocol.HTTP;
|
import org.apache.http.protocol.HTTP;
|
||||||
import org.apache.http.protocol.HttpContext;
|
import org.apache.http.protocol.HttpContext;
|
||||||
import org.apache.http.protocol.HttpExecutionContext;
|
import org.apache.http.protocol.ExecutionContext;
|
||||||
import org.apache.http.protocol.HttpProcessor;
|
import org.apache.http.protocol.HttpProcessor;
|
||||||
import org.apache.http.protocol.HttpRequestExecutor;
|
import org.apache.http.protocol.HttpRequestExecutor;
|
||||||
import org.apache.http.util.CharArrayBuffer;
|
import org.apache.http.util.CharArrayBuffer;
|
||||||
|
@ -323,15 +323,15 @@ public class DefaultClientRequestDirector
|
||||||
HttpHost proxy = route.getProxyHost();
|
HttpHost proxy = route.getProxyHost();
|
||||||
|
|
||||||
// Populate the execution context
|
// Populate the execution context
|
||||||
context.setAttribute(HttpExecutionContext.HTTP_TARGET_HOST,
|
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST,
|
||||||
target);
|
target);
|
||||||
context.setAttribute(HttpExecutionContext.HTTP_PROXY_HOST,
|
context.setAttribute(ExecutionContext.HTTP_PROXY_HOST,
|
||||||
proxy);
|
proxy);
|
||||||
context.setAttribute(HttpExecutionContext.HTTP_CONNECTION,
|
context.setAttribute(ExecutionContext.HTTP_CONNECTION,
|
||||||
managedConn);
|
managedConn);
|
||||||
context.setAttribute(HttpClientContext.TARGET_AUTH_STATE,
|
context.setAttribute(ClientContext.TARGET_AUTH_STATE,
|
||||||
targetAuthState);
|
targetAuthState);
|
||||||
context.setAttribute(HttpClientContext.PROXY_AUTH_STATE,
|
context.setAttribute(ClientContext.PROXY_AUTH_STATE,
|
||||||
proxyAuthState);
|
proxyAuthState);
|
||||||
requestExec.preProcess(request, httpProcessor, context);
|
requestExec.preProcess(request, httpProcessor, context);
|
||||||
|
|
||||||
|
@ -339,7 +339,7 @@ public class DefaultClientRequestDirector
|
||||||
((AbortableHttpRequest) orig).setReleaseTrigger(managedConn);
|
((AbortableHttpRequest) orig).setReleaseTrigger(managedConn);
|
||||||
}
|
}
|
||||||
|
|
||||||
context.setAttribute(HttpExecutionContext.HTTP_REQUEST,
|
context.setAttribute(ExecutionContext.HTTP_REQUEST,
|
||||||
request);
|
request);
|
||||||
|
|
||||||
execCount++;
|
execCount++;
|
||||||
|
@ -580,7 +580,8 @@ public class DefaultClientRequestDirector
|
||||||
response.getStatusLine());
|
response.getStatusLine());
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpState state = (HttpState) context.getAttribute(HttpClientContext.HTTP_STATE);
|
HttpState state = (HttpState)
|
||||||
|
context.getAttribute(ClientContext.HTTP_STATE);
|
||||||
|
|
||||||
if (state != null && HttpClientParams.isAuthenticating(params)) {
|
if (state != null && HttpClientParams.isAuthenticating(params)) {
|
||||||
if (this.authHandler.isProxyAuthenticationRequested(response, context)) {
|
if (this.authHandler.isProxyAuthenticationRequested(response, context)) {
|
||||||
|
@ -757,13 +758,15 @@ public class DefaultClientRequestDirector
|
||||||
return new RoutedRequest.Impl(redirect, newRoute);
|
return new RoutedRequest.Impl(redirect, newRoute);
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpState state = (HttpState) context.getAttribute(HttpClientContext.HTTP_STATE);
|
HttpState state = (HttpState)
|
||||||
|
context.getAttribute(ClientContext.HTTP_STATE);
|
||||||
|
|
||||||
if (state != null && HttpClientParams.isAuthenticating(params)) {
|
if (state != null && HttpClientParams.isAuthenticating(params)) {
|
||||||
|
|
||||||
if (this.authHandler.isTargetAuthenticationRequested(response, context)) {
|
if (this.authHandler.isTargetAuthenticationRequested(response, context)) {
|
||||||
|
|
||||||
target = (HttpHost) context.getAttribute(HttpExecutionContext.HTTP_TARGET_HOST);
|
target = (HttpHost)
|
||||||
|
context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
target = route.getTargetHost();
|
target = route.getTargetHost();
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ import org.apache.http.client.VersionInfo;
|
||||||
import org.apache.http.client.params.AuthPolicy;
|
import org.apache.http.client.params.AuthPolicy;
|
||||||
import org.apache.http.client.params.CookiePolicy;
|
import org.apache.http.client.params.CookiePolicy;
|
||||||
import org.apache.http.client.params.HttpClientParams;
|
import org.apache.http.client.params.HttpClientParams;
|
||||||
import org.apache.http.client.protocol.HttpClientContext;
|
import org.apache.http.client.protocol.ClientContext;
|
||||||
import org.apache.http.client.protocol.RequestAddCookies;
|
import org.apache.http.client.protocol.RequestAddCookies;
|
||||||
import org.apache.http.client.protocol.RequestProxyAuthentication;
|
import org.apache.http.client.protocol.RequestProxyAuthentication;
|
||||||
import org.apache.http.client.protocol.RequestTargetAuthentication;
|
import org.apache.http.client.protocol.RequestTargetAuthentication;
|
||||||
|
@ -77,7 +77,7 @@ import org.apache.http.protocol.RequestContent;
|
||||||
import org.apache.http.protocol.RequestExpectContinue;
|
import org.apache.http.protocol.RequestExpectContinue;
|
||||||
import org.apache.http.protocol.RequestTargetHost;
|
import org.apache.http.protocol.RequestTargetHost;
|
||||||
import org.apache.http.protocol.RequestUserAgent;
|
import org.apache.http.protocol.RequestUserAgent;
|
||||||
import org.apache.http.protocol.SyncHttpExecutionContext;
|
import org.apache.http.protocol.SyncBasicHttpContext;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ public class DefaultHttpClient extends AbstractHttpClient {
|
||||||
|
|
||||||
|
|
||||||
protected HttpContext createHttpContext() {
|
protected HttpContext createHttpContext() {
|
||||||
return new SyncHttpExecutionContext(null);
|
return new SyncBasicHttpContext(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -245,13 +245,13 @@ public class DefaultHttpClient extends AbstractHttpClient {
|
||||||
|
|
||||||
protected void populateContext(final HttpContext context) {
|
protected void populateContext(final HttpContext context) {
|
||||||
context.setAttribute(
|
context.setAttribute(
|
||||||
HttpClientContext.AUTHSCHEME_REGISTRY,
|
ClientContext.AUTHSCHEME_REGISTRY,
|
||||||
getAuthSchemes());
|
getAuthSchemes());
|
||||||
context.setAttribute(
|
context.setAttribute(
|
||||||
HttpClientContext.COOKIESPEC_REGISTRY,
|
ClientContext.COOKIESPEC_REGISTRY,
|
||||||
getCookieSpecs());
|
getCookieSpecs());
|
||||||
context.setAttribute(
|
context.setAttribute(
|
||||||
HttpClientContext.HTTP_STATE,
|
ClientContext.HTTP_STATE,
|
||||||
getState());
|
getState());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ import javax.net.ssl.SSLHandshakeException;
|
||||||
import org.apache.http.NoHttpResponseException;
|
import org.apache.http.NoHttpResponseException;
|
||||||
import org.apache.http.client.HttpRequestRetryHandler;
|
import org.apache.http.client.HttpRequestRetryHandler;
|
||||||
import org.apache.http.protocol.HttpContext;
|
import org.apache.http.protocol.HttpContext;
|
||||||
import org.apache.http.protocol.HttpExecutionContext;
|
import org.apache.http.protocol.ExecutionContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default {@link HttpRequestRetryHandler} used by request executors.
|
* The default {@link HttpRequestRetryHandler} used by request executors.
|
||||||
|
@ -105,7 +105,8 @@ public class DefaultHttpRequestRetryHandler implements HttpRequestRetryHandler {
|
||||||
// SSL handshake exception
|
// SSL handshake exception
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Boolean b = (Boolean) context.getAttribute(HttpExecutionContext.HTTP_REQ_SENT);
|
Boolean b = (Boolean)
|
||||||
|
context.getAttribute(ExecutionContext.HTTP_REQ_SENT);
|
||||||
boolean sent = (b != null && b.booleanValue());
|
boolean sent = (b != null && b.booleanValue());
|
||||||
if (!sent || this.requestSentRetryEnabled) {
|
if (!sent || this.requestSentRetryEnabled) {
|
||||||
// Retry if the request has not been sent fully or
|
// Retry if the request has not been sent fully or
|
||||||
|
|
|
@ -48,7 +48,7 @@ import org.apache.http.client.RedirectHandler;
|
||||||
import org.apache.http.client.params.HttpClientParams;
|
import org.apache.http.client.params.HttpClientParams;
|
||||||
import org.apache.http.params.HttpParams;
|
import org.apache.http.params.HttpParams;
|
||||||
import org.apache.http.protocol.HttpContext;
|
import org.apache.http.protocol.HttpContext;
|
||||||
import org.apache.http.protocol.HttpExecutionContext;
|
import org.apache.http.protocol.ExecutionContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default implementation of a redirect handler.
|
* Default implementation of a redirect handler.
|
||||||
|
@ -124,7 +124,7 @@ public class DefaultRedirectHandler implements RedirectHandler {
|
||||||
}
|
}
|
||||||
// Adjust location URI
|
// Adjust location URI
|
||||||
HttpHost target = (HttpHost) context.getAttribute(
|
HttpHost target = (HttpHost) context.getAttribute(
|
||||||
HttpExecutionContext.HTTP_TARGET_HOST);
|
ExecutionContext.HTTP_TARGET_HOST);
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
throw new IllegalStateException("Target host not available " +
|
throw new IllegalStateException("Target host not available " +
|
||||||
"in the HTTP context");
|
"in the HTTP context");
|
||||||
|
|
|
@ -36,7 +36,7 @@ import org.apache.http.conn.ClientConnectionManager;
|
||||||
import org.apache.http.conn.HttpRoute;
|
import org.apache.http.conn.HttpRoute;
|
||||||
import org.apache.http.params.HttpParams;
|
import org.apache.http.params.HttpParams;
|
||||||
import org.apache.http.protocol.HttpContext;
|
import org.apache.http.protocol.HttpContext;
|
||||||
import org.apache.http.protocol.HttpExecutionContext;
|
import org.apache.http.protocol.ExecutionContext;
|
||||||
import org.apache.http.protocol.HttpProcessor;
|
import org.apache.http.protocol.HttpProcessor;
|
||||||
import org.apache.http.protocol.HttpRequestExecutor;
|
import org.apache.http.protocol.HttpRequestExecutor;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
|
@ -96,12 +96,12 @@ public class ExecReqThread extends GetConnThread {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
request_spec.context.setAttribute
|
request_spec.context.setAttribute
|
||||||
(HttpExecutionContext.HTTP_CONNECTION, connection);
|
(ExecutionContext.HTTP_CONNECTION, connection);
|
||||||
|
|
||||||
doOpenConnection();
|
doOpenConnection();
|
||||||
|
|
||||||
HttpRequest request = (HttpRequest) request_spec.context.
|
HttpRequest request = (HttpRequest) request_spec.context.
|
||||||
getAttribute(HttpExecutionContext.HTTP_REQUEST);
|
getAttribute(ExecutionContext.HTTP_REQUEST);
|
||||||
request_spec.executor.preProcess
|
request_spec.executor.preProcess
|
||||||
(request, request_spec.processor, request_spec.context);
|
(request, request_spec.processor, request_spec.context);
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.params.HttpParams;
|
import org.apache.http.params.HttpParams;
|
||||||
import org.apache.http.params.HttpParamsLinker;
|
import org.apache.http.params.HttpParamsLinker;
|
||||||
import org.apache.http.protocol.HttpContext;
|
import org.apache.http.protocol.HttpContext;
|
||||||
import org.apache.http.protocol.HttpExecutionContext;
|
import org.apache.http.protocol.ExecutionContext;
|
||||||
import org.apache.http.protocol.HttpProcessor;
|
import org.apache.http.protocol.HttpProcessor;
|
||||||
import org.apache.http.protocol.HttpRequestExecutor;
|
import org.apache.http.protocol.HttpRequestExecutor;
|
||||||
|
|
||||||
|
@ -65,9 +65,9 @@ public final class Helper {
|
||||||
HttpContext ctxt)
|
HttpContext ctxt)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
ctxt.setAttribute(HttpExecutionContext.HTTP_CONNECTION, conn);
|
ctxt.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
|
||||||
ctxt.setAttribute(HttpExecutionContext.HTTP_TARGET_HOST, target);
|
ctxt.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
|
||||||
ctxt.setAttribute(HttpExecutionContext.HTTP_REQUEST, req);
|
ctxt.setAttribute(ExecutionContext.HTTP_REQUEST, req);
|
||||||
|
|
||||||
HttpParamsLinker.link(req, params);
|
HttpParamsLinker.link(req, params);
|
||||||
exec.preProcess(req, proc, ctxt);
|
exec.preProcess(req, proc, ctxt);
|
||||||
|
|
|
@ -43,7 +43,7 @@ import org.apache.http.entity.StringEntity;
|
||||||
import org.apache.http.localserver.LocalTestServer;
|
import org.apache.http.localserver.LocalTestServer;
|
||||||
import org.apache.http.localserver.ServerTestBase;
|
import org.apache.http.localserver.ServerTestBase;
|
||||||
import org.apache.http.params.HttpParamsLinker;
|
import org.apache.http.params.HttpParamsLinker;
|
||||||
import org.apache.http.protocol.HttpExecutionContext;
|
import org.apache.http.protocol.ExecutionContext;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,11 +81,11 @@ public class TestLocalServer extends ServerTestBase {
|
||||||
HttpClientConnection conn = connectTo(target);
|
HttpClientConnection conn = connectTo(target);
|
||||||
|
|
||||||
httpContext.setAttribute(
|
httpContext.setAttribute(
|
||||||
HttpExecutionContext.HTTP_CONNECTION, conn);
|
ExecutionContext.HTTP_CONNECTION, conn);
|
||||||
httpContext.setAttribute(
|
httpContext.setAttribute(
|
||||||
HttpExecutionContext.HTTP_TARGET_HOST, target);
|
ExecutionContext.HTTP_TARGET_HOST, target);
|
||||||
httpContext.setAttribute(
|
httpContext.setAttribute(
|
||||||
HttpExecutionContext.HTTP_REQUEST, request);
|
ExecutionContext.HTTP_REQUEST, request);
|
||||||
|
|
||||||
HttpParamsLinker.link(request, defaultParams);
|
HttpParamsLinker.link(request, defaultParams);
|
||||||
httpExecutor.preProcess
|
httpExecutor.preProcess
|
||||||
|
@ -124,11 +124,11 @@ public class TestLocalServer extends ServerTestBase {
|
||||||
HttpClientConnection conn = connectTo(target);
|
HttpClientConnection conn = connectTo(target);
|
||||||
|
|
||||||
httpContext.setAttribute(
|
httpContext.setAttribute(
|
||||||
HttpExecutionContext.HTTP_CONNECTION, conn);
|
ExecutionContext.HTTP_CONNECTION, conn);
|
||||||
httpContext.setAttribute(
|
httpContext.setAttribute(
|
||||||
HttpExecutionContext.HTTP_TARGET_HOST, target);
|
ExecutionContext.HTTP_TARGET_HOST, target);
|
||||||
httpContext.setAttribute(
|
httpContext.setAttribute(
|
||||||
HttpExecutionContext.HTTP_REQUEST, request);
|
ExecutionContext.HTTP_REQUEST, request);
|
||||||
|
|
||||||
HttpParamsLinker.link(request, defaultParams);
|
HttpParamsLinker.link(request, defaultParams);
|
||||||
httpExecutor.preProcess
|
httpExecutor.preProcess
|
||||||
|
|
|
@ -49,7 +49,8 @@ import org.apache.http.conn.params.HttpConnectionManagerParams;
|
||||||
import org.apache.http.localserver.ServerTestBase;
|
import org.apache.http.localserver.ServerTestBase;
|
||||||
import org.apache.http.message.BasicHttpRequest;
|
import org.apache.http.message.BasicHttpRequest;
|
||||||
import org.apache.http.params.HttpParams;
|
import org.apache.http.params.HttpParams;
|
||||||
import org.apache.http.protocol.HttpExecutionContext;
|
import org.apache.http.protocol.BasicHttpContext;
|
||||||
|
import org.apache.http.protocol.ExecutionContext;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
|
|
||||||
|
|
||||||
|
@ -138,13 +139,13 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
||||||
ExecReqThread.RequestSpec ertrs = new ExecReqThread.RequestSpec();
|
ExecReqThread.RequestSpec ertrs = new ExecReqThread.RequestSpec();
|
||||||
ertrs.executor = httpExecutor;
|
ertrs.executor = httpExecutor;
|
||||||
ertrs.processor = httpProcessor;
|
ertrs.processor = httpProcessor;
|
||||||
ertrs.context = new HttpExecutionContext(null);
|
ertrs.context = new BasicHttpContext(null);
|
||||||
ertrs.params = defaultParams;
|
ertrs.params = defaultParams;
|
||||||
|
|
||||||
ertrs.context.setAttribute
|
ertrs.context.setAttribute
|
||||||
(HttpExecutionContext.HTTP_TARGET_HOST, target);
|
(ExecutionContext.HTTP_TARGET_HOST, target);
|
||||||
ertrs.context.setAttribute
|
ertrs.context.setAttribute
|
||||||
(HttpExecutionContext.HTTP_REQUEST, request);
|
(ExecutionContext.HTTP_REQUEST, request);
|
||||||
|
|
||||||
threads[i] = new ExecReqThread(mgr, route, 5000L, ertrs);
|
threads[i] = new ExecReqThread(mgr, route, 5000L, ertrs);
|
||||||
}
|
}
|
||||||
|
@ -223,7 +224,7 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
||||||
|
|
||||||
// repeat the communication, no need to prepare the request again
|
// repeat the communication, no need to prepare the request again
|
||||||
conn.open(route, httpContext, defaultParams);
|
conn.open(route, httpContext, defaultParams);
|
||||||
httpContext.setAttribute(HttpExecutionContext.HTTP_CONNECTION, conn);
|
httpContext.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
|
||||||
response = httpExecutor.execute(request, conn, httpContext);
|
response = httpExecutor.execute(request, conn, httpContext);
|
||||||
httpExecutor.postProcess(response, httpProcessor, httpContext);
|
httpExecutor.postProcess(response, httpProcessor, httpContext);
|
||||||
|
|
||||||
|
@ -243,7 +244,7 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
||||||
assertTrue("connection should have been open", conn.isOpen());
|
assertTrue("connection should have been open", conn.isOpen());
|
||||||
|
|
||||||
// repeat the communication, no need to prepare the request again
|
// repeat the communication, no need to prepare the request again
|
||||||
httpContext.setAttribute(HttpExecutionContext.HTTP_CONNECTION, conn);
|
httpContext.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
|
||||||
response = httpExecutor.execute(request, conn, httpContext);
|
response = httpExecutor.execute(request, conn, httpContext);
|
||||||
httpExecutor.postProcess(response, httpProcessor, httpContext);
|
httpExecutor.postProcess(response, httpProcessor, httpContext);
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ import org.apache.http.params.HttpParams;
|
||||||
import org.apache.http.params.HttpProtocolParams;
|
import org.apache.http.params.HttpProtocolParams;
|
||||||
import org.apache.http.protocol.BasicHttpProcessor;
|
import org.apache.http.protocol.BasicHttpProcessor;
|
||||||
import org.apache.http.protocol.HttpContext;
|
import org.apache.http.protocol.HttpContext;
|
||||||
import org.apache.http.protocol.HttpExecutionContext;
|
import org.apache.http.protocol.BasicHttpContext;
|
||||||
import org.apache.http.protocol.HttpRequestHandler;
|
import org.apache.http.protocol.HttpRequestHandler;
|
||||||
import org.apache.http.protocol.HttpRequestHandlerRegistry;
|
import org.apache.http.protocol.HttpRequestHandlerRegistry;
|
||||||
import org.apache.http.protocol.HttpService;
|
import org.apache.http.protocol.HttpService;
|
||||||
|
@ -365,7 +365,7 @@ public class LocalTestServer {
|
||||||
|
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
HttpContext context = new HttpExecutionContext(null);
|
HttpContext context = new BasicHttpContext(null);
|
||||||
try {
|
try {
|
||||||
while ((servicedSocket != null) &&
|
while ((servicedSocket != null) &&
|
||||||
this.conn.isOpen() && !Thread.interrupted()) {
|
this.conn.isOpen() && !Thread.interrupted()) {
|
||||||
|
|
|
@ -45,7 +45,7 @@ import org.apache.http.params.BasicHttpParams;
|
||||||
import org.apache.http.params.HttpParams;
|
import org.apache.http.params.HttpParams;
|
||||||
import org.apache.http.params.HttpProtocolParams;
|
import org.apache.http.params.HttpProtocolParams;
|
||||||
import org.apache.http.protocol.BasicHttpProcessor;
|
import org.apache.http.protocol.BasicHttpProcessor;
|
||||||
import org.apache.http.protocol.HttpExecutionContext;
|
import org.apache.http.protocol.BasicHttpContext;
|
||||||
import org.apache.http.protocol.HttpRequestExecutor;
|
import org.apache.http.protocol.HttpRequestExecutor;
|
||||||
import org.apache.http.protocol.RequestConnControl;
|
import org.apache.http.protocol.RequestConnControl;
|
||||||
import org.apache.http.protocol.RequestContent;
|
import org.apache.http.protocol.RequestContent;
|
||||||
|
@ -74,7 +74,7 @@ public abstract class ServerTestBase extends TestCase {
|
||||||
protected BasicHttpProcessor httpProcessor;
|
protected BasicHttpProcessor httpProcessor;
|
||||||
|
|
||||||
/** The default context for the client side. */
|
/** The default context for the client side. */
|
||||||
protected HttpExecutionContext httpContext;
|
protected BasicHttpContext httpContext;
|
||||||
|
|
||||||
/** The request executor for the client side. */
|
/** The request executor for the client side. */
|
||||||
protected HttpRequestExecutor httpExecutor;
|
protected HttpRequestExecutor httpExecutor;
|
||||||
|
@ -135,7 +135,7 @@ public abstract class ServerTestBase extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// the context is created each time, it may get modified by test cases
|
// the context is created each time, it may get modified by test cases
|
||||||
httpContext = new HttpExecutionContext(null);
|
httpContext = new BasicHttpContext(null);
|
||||||
|
|
||||||
if (httpExecutor == null) {
|
if (httpExecutor == null) {
|
||||||
httpExecutor = new HttpRequestExecutor();
|
httpExecutor = new HttpRequestExecutor();
|
||||||
|
|
Loading…
Reference in New Issue