Code cleanups

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1483265 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2013-05-16 09:12:42 +00:00
parent 3c4e5f3dfd
commit ff1acb48a8
8 changed files with 23 additions and 17 deletions

View File

@ -45,7 +45,7 @@ import org.apache.http.client.CookieStore;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.socket.ConnectionSocketFactory;
@ -207,9 +207,9 @@ public class Executor {
*/
public Response execute(
final Request request) throws ClientProtocolException, IOException {
this.localContext.setAttribute(ClientContext.CREDS_PROVIDER, this.credentialsProvider);
this.localContext.setAttribute(ClientContext.AUTH_CACHE, this.authCache);
this.localContext.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
this.localContext.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credentialsProvider);
this.localContext.setAttribute(HttpClientContext.AUTH_CACHE, this.authCache);
this.localContext.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
final HttpRequestBase httprequest = request.getHttpRequest();
httprequest.reset();
return new Response(this.httpclient.execute(httprequest, this.localContext));

View File

@ -119,6 +119,7 @@ public class CachingHttpClientBuilder extends HttpClientBuilder {
return null;
}
@SuppressWarnings("resource")
private SchedulingStrategy createSchedulingStrategy(final CacheConfig config) {
return schedulingStrategy != null ? schedulingStrategy : new ImmediateSchedulingStrategy(config);
}

View File

@ -551,13 +551,14 @@ public class SSLSocketFactory implements LayeredConnectionSocketFactory, SchemeL
final HttpContext context) throws IOException, ConnectTimeoutException {
Args.notNull(host, "HTTP host");
Args.notNull(remoteAddress, "Remote address");
Socket sock = socket != null ? socket : createSocket(context);
final Socket sock = socket != null ? socket : createSocket(context);
if (localAddress != null) {
sock.bind(localAddress);
}
try {
sock.connect(remoteAddress, connectTimeout);
} catch (final SocketTimeoutException ex) {
closeSocket(sock);
throw new ConnectTimeoutException(host, remoteAddress);
}
// Setup SSL layering if necessary
@ -565,10 +566,17 @@ public class SSLSocketFactory implements LayeredConnectionSocketFactory, SchemeL
final SSLSocket sslsock = (SSLSocket) sock;
sslsock.startHandshake();
verifyHostname(sslsock, host.getHostName());
} else {
sock = createLayeredSocket(sock, host.getHostName(), remoteAddress.getPort(), context);
}
return sock;
} else {
return createLayeredSocket(sock, host.getHostName(), remoteAddress.getPort(), context);
}
}
private void closeSocket(final Socket sock) {
try {
sock.close();
} catch (final IOException ignore) {
}
}
public Socket createLayeredSocket(

View File

@ -456,6 +456,7 @@ public class HttpClientBuilder {
}
}
}
@SuppressWarnings("resource")
final PoolingHttpClientConnectionManager poolingmgr = new PoolingHttpClientConnectionManager(
RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainSocketFactory.getSocketFactory())

View File

@ -78,12 +78,10 @@ public class BrowserCompatSpec extends CookieSpecBase {
};
private final String[] datepatterns;
private final BrowserCompatSpecFactory.SecurityLevel securityLevel;
/** Default constructor */
public BrowserCompatSpec(final String[] datepatterns, final BrowserCompatSpecFactory.SecurityLevel securityLevel) {
super();
this.securityLevel = securityLevel;
if (datepatterns != null) {
this.datepatterns = datepatterns.clone();
} else {

View File

@ -194,7 +194,7 @@ public class MainClientExec implements ClientExecChain {
try {
if (execAware != null) {
if (execAware.isAborted()) {
connHolder.abortConnection();
connHolder.close();
throw new RequestAbortedException("Request aborted");
} else {
execAware.setCancellable(connHolder);

View File

@ -141,7 +141,7 @@ public class MinimalClientExec implements ClientExecChain {
try {
if (execAware != null) {
if (execAware.isAborted()) {
releaseTrigger.abortConnection();
releaseTrigger.close();
throw new RequestAbortedException("Request aborted");
} else {
execAware.setCancellable(releaseTrigger);

View File

@ -45,13 +45,11 @@ import org.apache.http.client.methods.HttpExecutionAware;
import org.apache.http.client.methods.HttpRequestWrapper;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.client.utils.URIUtils;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpProcessor;
import org.apache.http.util.Args;
@ -168,9 +166,9 @@ public class ProtocolExec implements ClientExecChain {
}
// Run request protocol interceptors
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
context.setAttribute(ClientContext.ROUTE, route);
context.setAttribute(ExecutionContext.HTTP_REQUEST, request);
context.setAttribute(HttpClientContext.HTTP_TARGET_HOST, target);
context.setAttribute(HttpClientContext.HTTP_ROUTE, route);
context.setAttribute(HttpClientContext.HTTP_REQUEST, request);
this.httpProcessor.process(request, context);
@ -178,7 +176,7 @@ public class ProtocolExec implements ClientExecChain {
context, execAware);
try {
// Run response protocol interceptors
context.setAttribute(ExecutionContext.HTTP_RESPONSE, response);
context.setAttribute(HttpClientContext.HTTP_RESPONSE, response);
this.httpProcessor.process(response, context);
return response;
} catch (final RuntimeException ex) {