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/12/18 17:23:14 UTC
svn commit: r1423516 [3/4] - in /httpcomponents/httpclient/trunk:
httpclient-cache/src/main/java/org/apache/http/client/cache/
httpclient-cache/src/main/java/org/apache/http/impl/client/cache/
httpclient/src/main/java/org/apache/http/auth/ httpclient/s...
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=1423516&r1=1423515&r2=1423516&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 Tue Dec 18 16:22:58 2012
@@ -49,6 +49,7 @@ import org.apache.http.auth.Credentials;
import org.apache.http.auth.MalformedChallengeException;
import org.apache.http.client.AuthenticationStrategy;
import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.Asserts;
public class HttpAuthenticator {
@@ -239,9 +240,7 @@ public class HttpAuthenticator {
}
private void ensureAuthScheme(final AuthScheme authScheme) {
- if (authScheme == null) {
- throw new IllegalStateException("Auth scheme is not set");
- }
+ Asserts.notNull(authScheme, "Auth scheme");
}
@SuppressWarnings("deprecation")
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java Tue Dec 18 16:22:58 2012
@@ -62,6 +62,8 @@ import org.apache.http.params.BasicHttpP
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
/**
* @since 4.3
@@ -90,15 +92,9 @@ class InternalHttpClient extends Closeab
final CredentialsProvider credentialsProvider,
final RequestConfig defaultConfig) {
super();
- if (execChain == null) {
- throw new IllegalArgumentException("HTTP client exec chain may not be null");
- }
- if (connManager == null) {
- throw new IllegalArgumentException("HTTP connection manager may not be null");
- }
- if (routePlanner == null) {
- throw new IllegalArgumentException("HTTP route planner may not be null");
- }
+ Args.notNull(execChain, "HTTP client exec chain");
+ Args.notNull(connManager, "HTTP connection manager");
+ Args.notNull(routePlanner, "HTTP route planner");
this.execChain = execChain;
this.connManager = connManager;
this.routePlanner = routePlanner;
@@ -118,9 +114,7 @@ class InternalHttpClient extends Closeab
if (host == null) {
host = (HttpHost) request.getParams().getParameter(ClientPNames.DEFAULT_HOST);
}
- if (host == null) {
- throw new IllegalStateException("Target host may not be null");
- }
+ Asserts.notNull(host, "Target host");
return this.routePlanner.determineRoute(host, request, context);
}
@@ -153,9 +147,7 @@ class InternalHttpClient extends Closeab
final HttpHost target,
final HttpRequest request,
final HttpContext context) throws IOException, ClientProtocolException {
- if (request == null) {
- throw new IllegalArgumentException("Request must not be null.");
- }
+ Args.notNull(request, "Request");
HttpExecutionAware execListner = null;
if (request instanceof HttpExecutionAware) {
execListner = (HttpExecutionAware) request;
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RequestWrapper.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RequestWrapper.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RequestWrapper.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RequestWrapper.java Tue Dec 18 16:22:58 2012
@@ -30,16 +30,16 @@ package org.apache.http.impl.client;
import java.net.URI;
import java.net.URISyntaxException;
-import org.apache.http.annotation.NotThreadSafe;
-
import org.apache.http.HttpRequest;
import org.apache.http.ProtocolException;
import org.apache.http.ProtocolVersion;
import org.apache.http.RequestLine;
+import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.message.AbstractHttpMessage;
import org.apache.http.message.BasicRequestLine;
import org.apache.http.params.HttpProtocolParams;
+import org.apache.http.util.Args;
/**
* A wrapper class for {@link HttpRequest}s that can be used to change
@@ -66,9 +66,7 @@ public class RequestWrapper extends Abst
public RequestWrapper(final HttpRequest request) throws ProtocolException {
super();
- if (request == null) {
- throw new IllegalArgumentException("HTTP request may not be null");
- }
+ Args.notNull(request, "HTTP request");
this.original = request;
setParams(request.getParams());
setHeaders(request.getAllHeaders());
@@ -102,9 +100,7 @@ public class RequestWrapper extends Abst
}
public void setMethod(final String method) {
- if (method == null) {
- throw new IllegalArgumentException("Method name may not be null");
- }
+ Args.notNull(method, "Method name");
this.method = method;
}
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/BackoffStrategyExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/BackoffStrategyExec.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/BackoffStrategyExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/BackoffStrategyExec.java Tue Dec 18 16:22:58 2012
@@ -39,6 +39,7 @@ import org.apache.http.client.methods.Ht
import org.apache.http.client.methods.HttpRequestWrapper;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.util.Args;
/**
* @since 4.3
@@ -55,15 +56,9 @@ public class BackoffStrategyExec impleme
final ConnectionBackoffStrategy connectionBackoffStrategy,
final BackoffManager backoffManager) {
super();
- if (requestExecutor == null) {
- throw new IllegalArgumentException("HTTP client request executor may not be null");
- }
- if (connectionBackoffStrategy == null) {
- throw new IllegalArgumentException("Connection backoff strategy may not be null");
- }
- if (backoffManager == null) {
- throw new IllegalArgumentException("Backoff manager may not be null");
- }
+ Args.notNull(requestExecutor, "HTTP client request executor");
+ Args.notNull(connectionBackoffStrategy, "Connection backoff strategy");
+ Args.notNull(backoffManager, "Backoff manager");
this.requestExecutor = requestExecutor;
this.connectionBackoffStrategy = connectionBackoffStrategy;
this.backoffManager = backoffManager;
@@ -74,15 +69,9 @@ public class BackoffStrategyExec impleme
final HttpRequestWrapper request,
final HttpClientContext context,
final HttpExecutionAware execAware) throws IOException, HttpException {
- if (route == null) {
- throw new IllegalArgumentException("HTTP route may not be null");
- }
- if (request == null) {
- throw new IllegalArgumentException("HTTP request may not be null");
- }
- if (context == null) {
- throw new IllegalArgumentException("HTTP context may not be null");
- }
+ Args.notNull(route, "HTTP route");
+ Args.notNull(request, "HTTP request");
+ Args.notNull(context, "HTTP context");
CloseableHttpResponse out = null;
try {
out = this.requestExecutor.execute(route, request, context, execAware);
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/MainClientExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/MainClientExec.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/MainClientExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/MainClientExec.java Tue Dec 18 16:22:58 2012
@@ -74,6 +74,7 @@ import org.apache.http.protocol.HttpProc
import org.apache.http.protocol.HttpRequestExecutor;
import org.apache.http.protocol.ImmutableHttpProcessor;
import org.apache.http.protocol.RequestUserAgent;
+import org.apache.http.util.Args;
import org.apache.http.util.EntityUtils;
/**
@@ -104,27 +105,13 @@ public class MainClientExec implements C
final AuthenticationStrategy targetAuthStrategy,
final AuthenticationStrategy proxyAuthStrategy,
final UserTokenHandler userTokenHandler) {
- if (requestExecutor == null) {
- throw new IllegalArgumentException("HTTP request executor may not be null");
- }
- if (connManager == null) {
- throw new IllegalArgumentException("Client connection manager may not be null");
- }
- if (reuseStrategy == null) {
- throw new IllegalArgumentException("Connection reuse strategy may not be null");
- }
- if (keepAliveStrategy == null) {
- throw new IllegalArgumentException("Connection keep alive strategy may not be null");
- }
- if (targetAuthStrategy == null) {
- throw new IllegalArgumentException("Target authentication strategy may not be null");
- }
- if (proxyAuthStrategy == null) {
- throw new IllegalArgumentException("Proxy authentication strategy may not be null");
- }
- if (userTokenHandler == null) {
- throw new IllegalArgumentException("User token handler may not be null");
- }
+ Args.notNull(requestExecutor, "HTTP request executor");
+ Args.notNull(connManager, "Client connection manager");
+ Args.notNull(reuseStrategy, "Connection reuse strategy");
+ Args.notNull(keepAliveStrategy, "Connection keep alive strategy");
+ Args.notNull(targetAuthStrategy, "Target authentication strategy");
+ Args.notNull(proxyAuthStrategy, "Proxy authentication strategy");
+ Args.notNull(userTokenHandler, "User token handler");
this.authenticator = new HttpAuthenticator();
this.proxyHttpProcessor = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
new RequestClientConnControl(),
@@ -145,15 +132,9 @@ public class MainClientExec implements C
final HttpRequestWrapper request,
final HttpClientContext context,
final HttpExecutionAware execAware) throws IOException, HttpException {
- if (route == null) {
- throw new IllegalArgumentException("HTTP route may not be null");
- }
- if (request == null) {
- throw new IllegalArgumentException("HTTP request may not be null");
- }
- if (context == null) {
- throw new IllegalArgumentException("HTTP context may not be null");
- }
+ Args.notNull(route, "HTTP route");
+ Args.notNull(request, "HTTP request");
+ Args.notNull(context, "HTTP context");
AuthState targetAuthState = context.getTargetAuthState();
if (targetAuthState == null) {
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/ProtocolExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/ProtocolExec.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/ProtocolExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/ProtocolExec.java Tue Dec 18 16:22:58 2012
@@ -51,6 +51,7 @@ import org.apache.http.impl.auth.BasicSc
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpProcessor;
+import org.apache.http.util.Args;
/**
* @since 4.3
@@ -67,12 +68,8 @@ public class ProtocolExec implements Cli
public ProtocolExec(
final ClientExecChain requestExecutor,
final HttpProcessor httpProcessor) {
- if (requestExecutor == null) {
- throw new IllegalArgumentException("HTTP client request executor may not be null");
- }
- if (httpProcessor == null) {
- throw new IllegalArgumentException("HTTP protocol processor may not be null");
- }
+ Args.notNull(requestExecutor, "HTTP client request executor");
+ Args.notNull(httpProcessor, "HTTP protocol processor");
this.requestExecutor = requestExecutor;
this.httpProcessor = httpProcessor;
}
@@ -112,15 +109,9 @@ public class ProtocolExec implements Cli
final HttpRequestWrapper request,
final HttpClientContext context,
final HttpExecutionAware execAware) throws IOException, HttpException {
- if (route == null) {
- throw new IllegalArgumentException("HTTP route may not be null");
- }
- if (request == null) {
- throw new IllegalArgumentException("HTTP request may not be null");
- }
- if (context == null) {
- throw new IllegalArgumentException("HTTP context may not be null");
- }
+ Args.notNull(route, "HTTP route");
+ Args.notNull(request, "HTTP request");
+ Args.notNull(context, "HTTP context");
HttpHost target = route.getTargetHost();
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/RedirectExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/RedirectExec.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/RedirectExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/RedirectExec.java Tue Dec 18 16:22:58 2012
@@ -50,6 +50,7 @@ import org.apache.http.client.protocol.H
import org.apache.http.client.utils.URIUtils;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.conn.routing.HttpRoutePlanner;
+import org.apache.http.util.Args;
import org.apache.http.util.EntityUtils;
/**
@@ -69,15 +70,9 @@ public class RedirectExec implements Cli
final HttpRoutePlanner routePlanner,
final RedirectStrategy redirectStrategy) {
super();
- if (requestExecutor == null) {
- throw new IllegalArgumentException("HTTP client request executor may not be null");
- }
- if (routePlanner == null) {
- throw new IllegalArgumentException("HTTP route planner may not be null");
- }
- if (redirectStrategy == null) {
- throw new IllegalArgumentException("HTTP redirect strategy may not be null");
- }
+ Args.notNull(requestExecutor, "HTTP client request executor");
+ Args.notNull(routePlanner, "HTTP route planner");
+ Args.notNull(redirectStrategy, "HTTP redirect strategy");
this.requestExecutor = requestExecutor;
this.routePlanner = routePlanner;
this.redirectStrategy = redirectStrategy;
@@ -88,15 +83,9 @@ public class RedirectExec implements Cli
final HttpRequestWrapper request,
final HttpClientContext context,
final HttpExecutionAware execAware) throws IOException, HttpException {
- if (route == null) {
- throw new IllegalArgumentException("HTTP route may not be null");
- }
- if (request == null) {
- throw new IllegalArgumentException("HTTP request may not be null");
- }
- if (context == null) {
- throw new IllegalArgumentException("HTTP context may not be null");
- }
+ Args.notNull(route, "HTTP route");
+ Args.notNull(request, "HTTP request");
+ Args.notNull(context, "HTTP context");
RequestConfig config = context.getRequestConfig();
int maxRedirects = config.getMaxRedirects() > 0 ? config.getMaxRedirects() : 50;
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/RetryExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/RetryExec.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/RetryExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/RetryExec.java Tue Dec 18 16:22:58 2012
@@ -41,6 +41,7 @@ import org.apache.http.client.methods.Ht
import org.apache.http.client.methods.HttpRequestWrapper;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.util.Args;
/**
* @since 4.3
@@ -56,12 +57,8 @@ public class RetryExec implements Client
public RetryExec(
final ClientExecChain requestExecutor,
final HttpRequestRetryHandler retryHandler) {
- if (requestExecutor == null) {
- throw new IllegalArgumentException("HTTP request executor may not be null");
- }
- if (retryHandler == null) {
- throw new IllegalArgumentException("HTTP request retry handler may not be null");
- }
+ Args.notNull(requestExecutor, "HTTP request executor");
+ Args.notNull(retryHandler, "HTTP request retry handler");
this.requestExecutor = requestExecutor;
this.retryHandler = retryHandler;
}
@@ -71,15 +68,9 @@ public class RetryExec implements Client
final HttpRequestWrapper request,
final HttpClientContext context,
final HttpExecutionAware execAware) throws IOException, HttpException {
- if (route == null) {
- throw new IllegalArgumentException("HTTP route may not be null");
- }
- if (request == null) {
- throw new IllegalArgumentException("HTTP request may not be null");
- }
- if (context == null) {
- throw new IllegalArgumentException("HTTP context may not be null");
- }
+ Args.notNull(route, "HTTP route");
+ Args.notNull(request, "HTTP request");
+ Args.notNull(context, "HTTP context");
Header[] origheaders = request.getAllHeaders();
for (int execCount = 1;; execCount++) {
try {
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/ServiceUnavailableRetryExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/ServiceUnavailableRetryExec.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/ServiceUnavailableRetryExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/ServiceUnavailableRetryExec.java Tue Dec 18 16:22:58 2012
@@ -40,6 +40,7 @@ import org.apache.http.client.methods.Ht
import org.apache.http.client.methods.HttpRequestWrapper;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.util.Args;
/**
* {@link ClientExecChain} implementation that can automatically retry the request in case of
@@ -59,13 +60,8 @@ public class ServiceUnavailableRetryExec
final ClientExecChain requestExecutor,
final ServiceUnavailableRetryStrategy retryStrategy) {
super();
- if (requestExecutor == null) {
- throw new IllegalArgumentException("HTTP request executor may not be null");
- }
- if (retryStrategy == null) {
- throw new IllegalArgumentException(
- "ServiceUnavailableRetryStrategy may not be null");
- }
+ Args.notNull(requestExecutor, "HTTP request executor");
+ Args.notNull(retryStrategy, "Retry strategy");
this.requestExecutor = requestExecutor;
this.retryStrategy = retryStrategy;
}
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/AbstractPoolEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/AbstractPoolEntry.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/AbstractPoolEntry.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/AbstractPoolEntry.java Tue Dec 18 16:22:58 2012
@@ -30,12 +30,14 @@ import java.io.IOException;
import java.io.InterruptedIOException;
import org.apache.http.HttpHost;
-import org.apache.http.params.HttpParams;
-import org.apache.http.protocol.HttpContext;
-import org.apache.http.conn.routing.HttpRoute;
-import org.apache.http.conn.routing.RouteTracker;
import org.apache.http.conn.ClientConnectionOperator;
import org.apache.http.conn.OperatedClientConnection;
+import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.conn.routing.RouteTracker;
+import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
/**
* A pool entry for use by connection manager implementations.
@@ -87,9 +89,7 @@ public abstract class AbstractPoolEntry
protected AbstractPoolEntry(ClientConnectionOperator connOperator,
HttpRoute route) {
super();
- if (connOperator == null) {
- throw new IllegalArgumentException("Connection operator may not be null");
- }
+ Args.notNull(connOperator, "Connection operator");
this.connOperator = connOperator;
this.connection = connOperator.createConnection();
this.route = route;
@@ -127,18 +127,10 @@ public abstract class AbstractPoolEntry
HttpContext context, HttpParams params)
throws IOException {
- if (route == null) {
- throw new IllegalArgumentException
- ("Route must not be null.");
- }
- if (params == null) {
- throw new IllegalArgumentException
- ("Parameters must not be null.");
- }
- if ((this.tracker != null) && this.tracker.isConnected()) {
- throw new IllegalStateException("Connection already open.");
- }
-
+ Args.notNull(route, "Route");
+ Args.notNull(params, "HTTP parameters");
+ Asserts.notNull(this.tracker, "Route tracker");
+ Asserts.check(!this.tracker.isConnected(), "Connection already open");
// - collect the arguments
// - call the operator
// - update the tracking data
@@ -184,18 +176,10 @@ public abstract class AbstractPoolEntry
public void tunnelTarget(boolean secure, HttpParams params)
throws IOException {
- if (params == null) {
- throw new IllegalArgumentException
- ("Parameters must not be null.");
- }
-
- if ((this.tracker == null) || !this.tracker.isConnected()) {
- throw new IllegalStateException("Connection not open.");
- }
- if (this.tracker.isTunnelled()) {
- throw new IllegalStateException
- ("Connection is already tunnelled.");
- }
+ Args.notNull(params, "HTTP parameters");
+ Asserts.notNull(this.tracker, "Route tracker");
+ Asserts.check(this.tracker.isConnected(), "Connection not open");
+ Asserts.check(!this.tracker.isTunnelled(), "Connection is already tunnelled");
this.connection.update(null, tracker.getTargetHost(),
secure, params);
@@ -220,19 +204,11 @@ public abstract class AbstractPoolEntry
public void tunnelProxy(HttpHost next, boolean secure, HttpParams params)
throws IOException {
- if (next == null) {
- throw new IllegalArgumentException
- ("Next proxy must not be null.");
- }
- if (params == null) {
- throw new IllegalArgumentException
- ("Parameters must not be null.");
- }
+ Args.notNull(next, "Next proxy");
+ Args.notNull(params, "Parameters");
- //@@@ check for proxy in planned route?
- if ((this.tracker == null) || !this.tracker.isConnected()) {
- throw new IllegalStateException("Connection not open.");
- }
+ Asserts.notNull(this.tracker, "Route tracker");
+ Asserts.check(this.tracker.isConnected(), "Connection not open");
this.connection.update(null, next, secure, params);
this.tracker.tunnelProxy(next, secure);
@@ -250,24 +226,11 @@ public abstract class AbstractPoolEntry
throws IOException {
//@@@ is context allowed to be null? depends on operator?
- if (params == null) {
- throw new IllegalArgumentException
- ("Parameters must not be null.");
- }
-
- if ((this.tracker == null) || !this.tracker.isConnected()) {
- throw new IllegalStateException("Connection not open.");
- }
- if (!this.tracker.isTunnelled()) {
- //@@@ allow this?
- throw new IllegalStateException
- ("Protocol layering without a tunnel not supported.");
- }
- if (this.tracker.isLayered()) {
- throw new IllegalStateException
- ("Multiple protocol layering not supported.");
- }
-
+ Args.notNull(params, "HTTP parameters");
+ Asserts.notNull(this.tracker, "Route tracker");
+ Asserts.check(this.tracker.isConnected(), "Connection not open");
+ Asserts.check(this.tracker.isTunnelled(), "Protocol layering without a tunnel not supported");
+ Asserts.check(!this.tracker.isLayered(), "Multiple protocol layering not supported");
// - collect the arguments
// - call the operator
// - update the tracking data
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/BasicClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/BasicClientConnectionManager.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/BasicClientConnectionManager.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/BasicClientConnectionManager.java Tue Dec 18 16:22:58 2012
@@ -43,6 +43,8 @@ import org.apache.http.conn.ManagedClien
import org.apache.http.conn.OperatedClientConnection;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
/**
* A connection manager for a single connection. This connection manager maintains only one active
@@ -99,9 +101,7 @@ public class BasicClientConnectionManage
* @param schreg the scheme registry
*/
public BasicClientConnectionManager(final SchemeRegistry schreg) {
- if (schreg == null) {
- throw new IllegalArgumentException("Scheme registry may not be null");
- }
+ Args.notNull(schreg, "Scheme registry");
this.schemeRegistry = schreg;
this.connOperator = createConnectionOperator(schreg);
}
@@ -147,23 +147,17 @@ public class BasicClientConnectionManage
}
private void assertNotShutdown() {
- if (this.shutdown) {
- throw new IllegalStateException("Connection manager has been shut down");
- }
+ Asserts.check(!this.shutdown, "Connection manager has been shut down");
}
ManagedClientConnection getConnection(final HttpRoute route, final Object state) {
- if (route == null) {
- throw new IllegalArgumentException("Route may not be null.");
- }
+ Args.notNull(route, "Route");
synchronized (this) {
assertNotShutdown();
if (this.log.isDebugEnabled()) {
this.log.debug("Get connection for route " + route);
}
- if (this.conn != null) {
- throw new IllegalStateException(MISUSE_MESSAGE);
- }
+ Asserts.check(this.conn == null, MISUSE_MESSAGE);
if (this.poolEntry != null && !this.poolEntry.getPlannedRoute().equals(route)) {
this.poolEntry.close();
this.poolEntry = null;
@@ -194,10 +188,8 @@ public class BasicClientConnectionManage
}
public void releaseConnection(final ManagedClientConnection conn, long keepalive, TimeUnit tunit) {
- if (!(conn instanceof ManagedClientConnectionImpl)) {
- throw new IllegalArgumentException("Connection class mismatch, " +
- "connection not obtained from this manager");
- }
+ Args.check(conn instanceof ManagedClientConnectionImpl, "Connection class mismatch, " +
+ "connection not obtained from this manager");
ManagedClientConnectionImpl managedConn = (ManagedClientConnectionImpl) conn;
synchronized (managedConn) {
if (this.log.isDebugEnabled()) {
@@ -207,9 +199,7 @@ public class BasicClientConnectionManage
return; // already released
}
ClientConnectionManager manager = managedConn.getManager();
- if (manager != null && manager != this) {
- throw new IllegalStateException("Connection not obtained from this manager");
- }
+ Asserts.check(manager == this, "Connection not obtained from this manager");
synchronized (this) {
if (this.shutdown) {
shutdownConnection(managedConn);
@@ -252,9 +242,7 @@ public class BasicClientConnectionManage
}
public void closeIdleConnections(long idletime, TimeUnit tunit) {
- if (tunit == null) {
- throw new IllegalArgumentException("Time unit must not be null.");
- }
+ Args.notNull(tunit, "Time unit");
synchronized (this) {
assertNotShutdown();
long time = tunit.toMillis(idletime);
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/BasicHttpClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/BasicHttpClientConnectionManager.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/BasicHttpClientConnectionManager.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/BasicHttpClientConnectionManager.java Tue Dec 18 16:22:58 2012
@@ -55,6 +55,8 @@ import org.apache.http.conn.socket.Conne
import org.apache.http.conn.socket.PlainSocketFactory;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
import org.apache.http.util.LangUtils;
/**
@@ -180,9 +182,7 @@ public class BasicHttpClientConnectionMa
public final ConnectionRequest requestConnection(
final HttpRoute route,
final Object state) {
- if (route == null) {
- throw new IllegalArgumentException("Route may not be null");
- }
+ Args.notNull(route, "Route");
return new ConnectionRequest() {
public boolean cancel() {
@@ -236,15 +236,11 @@ public class BasicHttpClientConnectionMa
}
synchronized HttpClientConnection getConnection(final HttpRoute route, final Object state) {
- if (this.shutdown) {
- throw new IllegalStateException("Connection manager has been shut down");
- }
+ Asserts.check(!this.shutdown, "Connection manager has been shut down");
if (this.log.isDebugEnabled()) {
this.log.debug("Get connection for route " + route);
}
- if (this.leased) {
- throw new IllegalStateException("Connection is still allocated");
- }
+ Asserts.check(!this.leased, "Connection is still allocated");
if (!LangUtils.equals(this.route, route) || !LangUtils.equals(this.state, state)) {
closeConnection();
}
@@ -262,12 +258,8 @@ public class BasicHttpClientConnectionMa
final HttpClientConnection conn,
final Object state,
long keepalive, final TimeUnit tunit) {
- if (conn == null) {
- throw new IllegalArgumentException("Connection may not be null");
- }
- if (conn != this.conn) {
- throw new IllegalArgumentException("Connection not obtained from this manager");
- }
+ Args.notNull(conn, "Connection");
+ Asserts.check(conn == this.conn, "Connection not obtained from this manager");
if (this.log.isDebugEnabled()) {
this.log.debug("Releasing connection " + conn);
}
@@ -310,15 +302,9 @@ public class BasicHttpClientConnectionMa
final InetAddress local,
final int connectTimeout,
final HttpContext context) throws IOException {
- if (conn == null) {
- throw new IllegalArgumentException("Connection may not be null");
- }
- if (host == null) {
- throw new IllegalArgumentException("HTTP host may not be null");
- }
- if (conn != this.conn) {
- throw new IllegalArgumentException("Connection not obtained from this manager");
- }
+ Args.notNull(conn, "Connection");
+ Args.notNull(host, "HTTP host");
+ Asserts.check(conn == this.conn, "Connection not obtained from this manager");
InetSocketAddress localAddress = local != null ? new InetSocketAddress(local, 0) : null;
this.connectionOperator.connect(this.conn, host, localAddress,
connectTimeout, this.socketConfig, context);
@@ -328,15 +314,9 @@ public class BasicHttpClientConnectionMa
final HttpClientConnection conn,
final HttpHost host,
final HttpContext context) throws IOException {
- if (conn == null) {
- throw new IllegalArgumentException("Connection may not be null");
- }
- if (host == null) {
- throw new IllegalArgumentException("HTTP host may not be null");
- }
- if (conn != this.conn) {
- throw new IllegalArgumentException("Connection not obtained from this manager");
- }
+ Args.notNull(conn, "Connection");
+ Args.notNull(host, "HTTP host");
+ Asserts.check(conn == this.conn, "Connection not obtained from this manager");
this.connectionOperator.upgrade(this.conn, host, context);
}
@@ -350,9 +330,7 @@ public class BasicHttpClientConnectionMa
}
public synchronized void closeIdleConnections(long idletime, TimeUnit tunit) {
- if (tunit == null) {
- throw new IllegalArgumentException("Time unit must not be null.");
- }
+ Args.notNull(tunit, "Time unit");
if (this.shutdown) {
return;
}
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnection.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnection.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnection.java Tue Dec 18 16:22:58 2012
@@ -50,6 +50,7 @@ import org.apache.http.params.BasicHttpP
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.Args;
import org.apache.http.impl.SocketHttpClientConnection;
import org.apache.http.io.HttpMessageParser;
import org.apache.http.io.SessionInputBuffer;
@@ -129,11 +130,8 @@ public class DefaultClientConnection ext
}
public void openCompleted(boolean secure, HttpParams params) throws IOException {
+ Args.notNull(params, "Parameters");
assertNotOpen();
- if (params == null) {
- throw new IllegalArgumentException
- ("Parameters must not be null.");
- }
this.connSecure = secure;
bind(this.socket, params);
}
@@ -240,14 +238,8 @@ public class DefaultClientConnection ext
throws IOException {
assertOpen();
- if (target == null) {
- throw new IllegalArgumentException
- ("Target host must not be null.");
- }
- if (params == null) {
- throw new IllegalArgumentException
- ("Parameters must not be null.");
- }
+ Args.notNull(target, "Target host");
+ Args.notNull(params, "Parameters");
if (sock != null) {
this.socket = sock;
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java Tue Dec 18 16:22:58 2012
@@ -29,32 +29,32 @@ package org.apache.http.impl.conn;
import java.io.IOException;
import java.net.ConnectException;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
-import java.net.InetAddress;
import java.net.UnknownHostException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.http.annotation.ThreadSafe;
-
import org.apache.http.HttpHost;
-import org.apache.http.params.HttpParams;
-import org.apache.http.params.HttpConnectionParams;
-import org.apache.http.protocol.HttpContext;
-
+import org.apache.http.annotation.ThreadSafe;
import org.apache.http.client.protocol.ClientContext;
+import org.apache.http.conn.ClientConnectionOperator;
import org.apache.http.conn.ConnectTimeoutException;
+import org.apache.http.conn.DnsResolver;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.conn.HttpInetSocketAddress;
import org.apache.http.conn.OperatedClientConnection;
-import org.apache.http.conn.ClientConnectionOperator;
-import org.apache.http.conn.scheme.SchemeLayeredSocketFactory;
import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeLayeredSocketFactory;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.scheme.SchemeSocketFactory;
-
-import org.apache.http.conn.DnsResolver;
+import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
/**
* Default implementation of a {@link ClientConnectionOperator}. It uses a {@link SchemeRegistry}
@@ -107,9 +107,7 @@ public class DefaultClientConnectionOper
* @since 4.2
*/
public DefaultClientConnectionOperator(final SchemeRegistry schemes) {
- if (schemes == null) {
- throw new IllegalArgumentException("Scheme registry amy not be null");
- }
+ Args.notNull(schemes, "Scheme registry");
this.schemeRegistry = schemes;
this.dnsResolver = new SystemDefaultDnsResolver();
}
@@ -124,14 +122,9 @@ public class DefaultClientConnectionOper
* the custom DNS lookup mechanism
*/
public DefaultClientConnectionOperator(final SchemeRegistry schemes,final DnsResolver dnsResolver) {
- if (schemes == null) {
- throw new IllegalArgumentException(
- "Scheme registry may not be null");
- }
+ Args.notNull(schemes, "Scheme registry");
- if(dnsResolver == null){
- throw new IllegalArgumentException("DNS resolver may not be null");
- }
+ Args.notNull(dnsResolver, "DNS resolver");
this.schemeRegistry = schemes;
this.dnsResolver = dnsResolver;
@@ -156,18 +149,10 @@ public class DefaultClientConnectionOper
final InetAddress local,
final HttpContext context,
final HttpParams params) throws IOException {
- if (conn == null) {
- throw new IllegalArgumentException("Connection may not be null");
- }
- if (target == null) {
- throw new IllegalArgumentException("Target host may not be null");
- }
- if (params == null) {
- throw new IllegalArgumentException("Parameters may not be null");
- }
- if (conn.isOpen()) {
- throw new IllegalStateException("Connection must not be open");
- }
+ Args.notNull(conn, "Connection");
+ Args.notNull(target, "Target host");
+ Args.notNull(params, "HTTP parameters");
+ Asserts.check(!conn.isOpen(), "Connection must not be open");
SchemeRegistry registry = getSchemeRegistry(context);
Scheme schm = registry.getScheme(target.getSchemeName());
@@ -220,27 +205,15 @@ public class DefaultClientConnectionOper
final HttpHost target,
final HttpContext context,
final HttpParams params) throws IOException {
- if (conn == null) {
- throw new IllegalArgumentException("Connection may not be null");
- }
- if (target == null) {
- throw new IllegalArgumentException("Target host may not be null");
- }
- if (params == null) {
- throw new IllegalArgumentException("Parameters may not be null");
- }
- if (!conn.isOpen()) {
- throw new IllegalStateException("Connection must be open");
- }
+ Args.notNull(conn, "Connection");
+ Args.notNull(target, "Target host");
+ Args.notNull(params, "Parameters");
+ Asserts.check(conn.isOpen(), "Connection must be open");
SchemeRegistry registry = getSchemeRegistry(context);
Scheme schm = registry.getScheme(target.getSchemeName());
- if (!(schm.getSchemeSocketFactory() instanceof SchemeLayeredSocketFactory)) {
- throw new IllegalArgumentException
- ("Target scheme (" + schm.getName() +
- ") must have layered socket factory.");
- }
-
+ Asserts.check(schm.getSchemeSocketFactory() instanceof LayeredConnectionSocketFactory,
+ "Socket factory must implement SchemeLayeredSocketFactory");
SchemeLayeredSocketFactory lsf = (SchemeLayeredSocketFactory) schm.getSchemeSocketFactory();
Socket sock;
try {
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpResponseParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpResponseParser.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpResponseParser.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpResponseParser.java Tue Dec 18 16:22:58 2012
@@ -29,9 +29,6 @@ package org.apache.http.impl.conn;
import java.io.IOException;
-import org.apache.http.annotation.ThreadSafe;
-import org.apache.http.config.MessageConstraints;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpException;
@@ -40,6 +37,8 @@ import org.apache.http.HttpResponseFacto
import org.apache.http.NoHttpResponseException;
import org.apache.http.ProtocolException;
import org.apache.http.StatusLine;
+import org.apache.http.annotation.ThreadSafe;
+import org.apache.http.config.MessageConstraints;
import org.apache.http.impl.DefaultHttpResponseFactory;
import org.apache.http.impl.io.AbstractMessageParser;
import org.apache.http.io.SessionInputBuffer;
@@ -47,6 +46,7 @@ import org.apache.http.message.BasicLine
import org.apache.http.message.LineParser;
import org.apache.http.message.ParserCursor;
import org.apache.http.params.HttpParams;
+import org.apache.http.util.Args;
import org.apache.http.util.CharArrayBuffer;
/**
@@ -75,10 +75,7 @@ public class DefaultHttpResponseParser e
final HttpResponseFactory responseFactory,
final HttpParams params) {
super(buffer, parser, params);
- if (responseFactory == null) {
- throw new IllegalArgumentException
- ("Response factory may not be null");
- }
+ Args.notNull(responseFactory, "Response factory");
this.responseFactory = responseFactory;
this.lineBuf = new CharArrayBuffer(128);
}
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpRoutePlanner.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpRoutePlanner.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpRoutePlanner.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpRoutePlanner.java Tue Dec 18 16:22:58 2012
@@ -36,6 +36,8 @@ import org.apache.http.HttpException;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.conn.routing.HttpRoutePlanner;
@@ -75,10 +77,7 @@ public class DefaultHttpRoutePlanner imp
* @param schreg the scheme registry
*/
public DefaultHttpRoutePlanner(SchemeRegistry schreg) {
- if (schreg == null) {
- throw new IllegalArgumentException
- ("SchemeRegistry must not be null.");
- }
+ Args.notNull(schreg, "Scheme registry");
schemeRegistry = schreg;
}
@@ -87,10 +86,7 @@ public class DefaultHttpRoutePlanner imp
HttpContext context)
throws HttpException {
- if (request == null) {
- throw new IllegalStateException
- ("Request must not be null.");
- }
+ Args.notNull(request, "HTTP request");
// If we have a forced route, we can do without a target.
HttpRoute route =
@@ -101,10 +97,7 @@ public class DefaultHttpRoutePlanner imp
// If we get here, there is no forced route.
// So we need a target to compute a route.
- if (target == null) {
- throw new IllegalStateException
- ("Target host must not be null.");
- }
+ Asserts.notNull(target, "Target host");
final InetAddress local =
ConnRouteParams.getLocalAddress(request.getParams());
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultResponseParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultResponseParser.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultResponseParser.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultResponseParser.java Tue Dec 18 16:22:58 2012
@@ -29,8 +29,6 @@ package org.apache.http.impl.conn;
import java.io.IOException;
-import org.apache.http.annotation.ThreadSafe;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpException;
@@ -39,11 +37,13 @@ import org.apache.http.HttpResponseFacto
import org.apache.http.NoHttpResponseException;
import org.apache.http.ProtocolException;
import org.apache.http.StatusLine;
+import org.apache.http.annotation.ThreadSafe;
import org.apache.http.impl.io.AbstractMessageParser;
import org.apache.http.io.SessionInputBuffer;
import org.apache.http.message.LineParser;
import org.apache.http.message.ParserCursor;
import org.apache.http.params.HttpParams;
+import org.apache.http.util.Args;
import org.apache.http.util.CharArrayBuffer;
/**
@@ -77,10 +77,7 @@ public class DefaultResponseParser exten
final HttpResponseFactory responseFactory,
final HttpParams params) {
super(buffer, parser, params);
- if (responseFactory == null) {
- throw new IllegalArgumentException
- ("Response factory may not be null");
- }
+ Args.notNull(responseFactory, "Response factory");
this.responseFactory = responseFactory;
this.lineBuf = new CharArrayBuffer(128);
this.maxGarbageLines = getMaxGarbageLines(params);
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultRoutePlanner.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultRoutePlanner.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultRoutePlanner.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultRoutePlanner.java Tue Dec 18 16:22:58 2012
@@ -40,6 +40,7 @@ import org.apache.http.conn.params.ConnR
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.conn.routing.HttpRoutePlanner;
import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.Args;
/**
* Default implementation of an {@link HttpRoutePlanner}. This implementation
@@ -65,12 +66,8 @@ public class DefaultRoutePlanner impleme
final HttpHost host,
final HttpRequest request,
final HttpContext context) throws HttpException {
- if (host == null) {
- throw new IllegalArgumentException("Target host may not be null");
- }
- if (request == null) {
- throw new IllegalArgumentException("Request may not be null");
- }
+ Args.notNull(host, "Target host");
+ Args.notNull(request, "Request");
// If we have a forced route, we can do without a target.
HttpRoute route = ConnRouteParams.getForcedRoute(request.getParams());
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultSchemePortResolver.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultSchemePortResolver.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultSchemePortResolver.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultSchemePortResolver.java Tue Dec 18 16:22:58 2012
@@ -28,6 +28,7 @@ package org.apache.http.impl.conn;
import org.apache.http.HttpHost;
import org.apache.http.conn.SchemePortResolver;
+import org.apache.http.util.Args;
/**
* Default {@link SchemePortResolver}.
@@ -39,9 +40,7 @@ public class DefaultSchemePortResolver i
public static final DefaultSchemePortResolver INSTANCE = new DefaultSchemePortResolver();
public int resolve(final HttpHost host) {
- if (host == null) {
- throw new IllegalArgumentException("HTTP host may not be null");
- }
+ Args.notNull(host, "HTTP host");
int port = host.getPort();
if (port > 0) {
return port;
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionOperator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionOperator.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionOperator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionOperator.java Tue Dec 18 16:22:58 2012
@@ -50,6 +50,8 @@ import org.apache.http.conn.socket.Conne
import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
import org.apache.http.conn.socket.PlainSocketFactory;
import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
@Immutable
class HttpClientConnectionOperator {
@@ -65,9 +67,7 @@ class HttpClientConnectionOperator {
final SchemePortResolver schemePortResolver,
final DnsResolver dnsResolver) {
super();
- if (socketFactoryRegistry == null) {
- throw new IllegalArgumentException("Socket factory registry may nor be null");
- }
+ Args.notNull(socketFactoryRegistry, "Socket factory registry");
this.socketFactoryRegistry = socketFactoryRegistry;
this.schemePortResolver = schemePortResolver != null ? schemePortResolver :
DefaultSchemePortResolver.INSTANCE;
@@ -149,10 +149,8 @@ class HttpClientConnectionOperator {
if (sf == null) {
sf = PlainSocketFactory.INSTANCE;
}
- if (!(sf instanceof LayeredConnectionSocketFactory)) {
- throw new IllegalArgumentException
- ("Target scheme (" + host.getSchemeName() + ") must have layered socket factory");
- }
+ Asserts.check(sf instanceof LayeredConnectionSocketFactory,
+ "Socket factory must implement LayeredConnectionSocketFactory");
LayeredConnectionSocketFactory lsf = (LayeredConnectionSocketFactory) sf;
Socket sock = conn.getSocket();
try {
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/InMemoryDnsResolver.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/InMemoryDnsResolver.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/InMemoryDnsResolver.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/InMemoryDnsResolver.java Tue Dec 18 16:22:58 2012
@@ -35,6 +35,7 @@ import java.util.concurrent.ConcurrentHa
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.conn.DnsResolver;
+import org.apache.http.util.Args;
/**
* In-memory DNS resolver implementation.
@@ -71,12 +72,8 @@ public class InMemoryDnsResolver impleme
* host name.
*/
public void add(final String host, final InetAddress... ips) {
- if (host == null) {
- throw new IllegalArgumentException("Host name may not be null");
- }
- if (ips == null) {
- throw new IllegalArgumentException("Array of IP addresses may not be null");
- }
+ Args.notNull(host, "Host name");
+ Args.notNull(ips, "Array of IP addresses");
dnsMap.put(host, ips);
}
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ManagedClientConnectionImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ManagedClientConnectionImpl.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ManagedClientConnectionImpl.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ManagedClientConnectionImpl.java Tue Dec 18 16:22:58 2012
@@ -50,6 +50,8 @@ import org.apache.http.conn.routing.Http
import org.apache.http.conn.routing.RouteTracker;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
/**
* @since 4.2
@@ -71,15 +73,9 @@ class ManagedClientConnectionImpl implem
final ClientConnectionOperator operator,
final HttpPoolEntry entry) {
super();
- if (manager == null) {
- throw new IllegalArgumentException("Connection manager may not be null");
- }
- if (operator == null) {
- throw new IllegalArgumentException("Connection operator may not be null");
- }
- if (entry == null) {
- throw new IllegalArgumentException("HTTP pool entry may not be null");
- }
+ Args.notNull(manager, "Connection manager");
+ Args.notNull(operator, "Connection operator");
+ Args.notNull(entry, "HTTP pool entry");
this.manager = manager;
this.operator = operator;
this.poolEntry = entry;
@@ -287,21 +283,16 @@ class ManagedClientConnectionImpl implem
final HttpRoute route,
final HttpContext context,
final HttpParams params) throws IOException {
- if (route == null) {
- throw new IllegalArgumentException("Route may not be null");
- }
- if (params == null) {
- throw new IllegalArgumentException("HTTP parameters may not be null");
- }
+ Args.notNull(route, "Route");
+ Args.notNull(params, "HTTP parameters");
OperatedClientConnection conn;
synchronized (this) {
if (this.poolEntry == null) {
throw new ConnectionShutdownException();
}
RouteTracker tracker = this.poolEntry.getTracker();
- if (tracker.isConnected()) {
- throw new IllegalStateException("Connection already open");
- }
+ Asserts.notNull(tracker, "Route tracker");
+ Asserts.check(!tracker.isConnected(), "Connection already open");
conn = this.poolEntry.getConnection();
}
@@ -327,9 +318,7 @@ class ManagedClientConnectionImpl implem
public void tunnelTarget(
boolean secure, final HttpParams params) throws IOException {
- if (params == null) {
- throw new IllegalArgumentException("HTTP parameters may not be null");
- }
+ Args.notNull(params, "HTTP parameters");
HttpHost target;
OperatedClientConnection conn;
synchronized (this) {
@@ -337,12 +326,9 @@ class ManagedClientConnectionImpl implem
throw new ConnectionShutdownException();
}
RouteTracker tracker = this.poolEntry.getTracker();
- if (!tracker.isConnected()) {
- throw new IllegalStateException("Connection not open");
- }
- if (tracker.isTunnelled()) {
- throw new IllegalStateException("Connection is already tunnelled");
- }
+ Asserts.notNull(tracker, "Route tracker");
+ Asserts.check(tracker.isConnected(), "Connection not open");
+ Asserts.check(!tracker.isTunnelled(), "Connection is already tunnelled");
target = tracker.getTargetHost();
conn = this.poolEntry.getConnection();
}
@@ -360,21 +346,16 @@ class ManagedClientConnectionImpl implem
public void tunnelProxy(
final HttpHost next, boolean secure, final HttpParams params) throws IOException {
- if (next == null) {
- throw new IllegalArgumentException("Next proxy amy not be null");
- }
- if (params == null) {
- throw new IllegalArgumentException("HTTP parameters may not be null");
- }
+ Args.notNull(next, "Next proxy");
+ Args.notNull(params, "HTTP parameters");
OperatedClientConnection conn;
synchronized (this) {
if (this.poolEntry == null) {
throw new ConnectionShutdownException();
}
RouteTracker tracker = this.poolEntry.getTracker();
- if (!tracker.isConnected()) {
- throw new IllegalStateException("Connection not open");
- }
+ Asserts.notNull(tracker, "Route tracker");
+ Asserts.check(tracker.isConnected(), "Connection not open");
conn = this.poolEntry.getConnection();
}
@@ -391,9 +372,7 @@ class ManagedClientConnectionImpl implem
public void layerProtocol(
final HttpContext context, final HttpParams params) throws IOException {
- if (params == null) {
- throw new IllegalArgumentException("HTTP parameters may not be null");
- }
+ Args.notNull(params, "HTTP parameters");
HttpHost target;
OperatedClientConnection conn;
synchronized (this) {
@@ -401,15 +380,10 @@ class ManagedClientConnectionImpl implem
throw new ConnectionShutdownException();
}
RouteTracker tracker = this.poolEntry.getTracker();
- if (!tracker.isConnected()) {
- throw new IllegalStateException("Connection not open");
- }
- if (!tracker.isTunnelled()) {
- throw new IllegalStateException("Protocol layering without a tunnel not supported");
- }
- if (tracker.isLayered()) {
- throw new IllegalStateException("Multiple protocol layering not supported");
- }
+ Asserts.notNull(tracker, "Route tracker");
+ Asserts.check(tracker.isConnected(), "Connection not open");
+ Asserts.check(tracker.isTunnelled(), "Protocol layering without a tunnel not supported");
+ Asserts.check(!tracker.isLayered(), "Multiple protocol layering not supported");
target = tracker.getTargetHost();
conn = this.poolEntry.getConnection();
}
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingClientConnectionManager.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingClientConnectionManager.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingClientConnectionManager.java Tue Dec 18 16:22:58 2012
@@ -35,19 +35,19 @@ import java.util.concurrent.TimeoutExcep
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.annotation.ThreadSafe;
-import org.apache.http.conn.routing.HttpRoute;
-import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.ClientConnectionOperator;
import org.apache.http.conn.ClientConnectionRequest;
import org.apache.http.conn.ConnectionPoolTimeoutException;
+import org.apache.http.conn.DnsResolver;
import org.apache.http.conn.ManagedClientConnection;
import org.apache.http.conn.OperatedClientConnection;
+import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.pool.ConnPoolControl;
import org.apache.http.pool.PoolStats;
-import org.apache.http.impl.conn.DefaultClientConnectionOperator;
-import org.apache.http.impl.conn.SchemeRegistryFactory;
-import org.apache.http.conn.DnsResolver;
+import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
/**
* Manages a pool of {@link OperatedClientConnection client connections} and
@@ -106,12 +106,8 @@ public class PoolingClientConnectionMana
final long timeToLive, final TimeUnit tunit,
final DnsResolver dnsResolver) {
super();
- if (schemeRegistry == null) {
- throw new IllegalArgumentException("Scheme registry may not be null");
- }
- if (dnsResolver == null) {
- throw new IllegalArgumentException("DNS resolver may not be null");
- }
+ Args.notNull(schemeRegistry, "Scheme registry");
+ Args.notNull(dnsResolver, "DNS resolver");
this.schemeRegistry = schemeRegistry;
this.dnsResolver = dnsResolver;
this.operator = createConnectionOperator(schemeRegistry);
@@ -182,9 +178,7 @@ public class PoolingClientConnectionMana
public ClientConnectionRequest requestConnection(
final HttpRoute route,
final Object state) {
- if (route == null) {
- throw new IllegalArgumentException("HTTP route may not be null");
- }
+ Args.notNull(route, "HTTP route");
if (this.log.isDebugEnabled()) {
this.log.debug("Connection request: " + format(route, state) + formatStats(route));
}
@@ -216,9 +210,7 @@ public class PoolingClientConnectionMana
if (entry == null || future.isCancelled()) {
throw new InterruptedException();
}
- if (entry.getConnection() == null) {
- throw new IllegalStateException("Pool entry with no connection");
- }
+ Asserts.check(entry.getConnection() != null, "Pool entry with no connection");
if (this.log.isDebugEnabled()) {
this.log.debug("Connection leased: " + format(entry) + formatStats(entry.getRoute()));
}
@@ -239,16 +231,10 @@ public class PoolingClientConnectionMana
public void releaseConnection(
final ManagedClientConnection conn, final long keepalive, final TimeUnit tunit) {
- if (!(conn instanceof ManagedClientConnectionImpl)) {
- throw new IllegalArgumentException
- ("Connection class mismatch, " +
- "connection not obtained from this manager.");
- }
+ Args.check(conn instanceof ManagedClientConnectionImpl, "Connection class mismatch, " +
+ "connection not obtained from this manager");
ManagedClientConnectionImpl managedConn = (ManagedClientConnectionImpl) conn;
- if (managedConn.getManager() != this) {
- throw new IllegalStateException("Connection not obtained from this manager.");
- }
-
+ Asserts.check(managedConn.getManager() == this, "Connection not obtained from this manager");
synchronized (managedConn) {
HttpPoolEntry entry = managedConn.detach();
if (entry == null) {
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java Tue Dec 18 16:22:58 2012
@@ -61,6 +61,8 @@ import org.apache.http.pool.ConnFactory;
import org.apache.http.pool.ConnPoolControl;
import org.apache.http.pool.PoolStats;
import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
/**
* <tt>ClientConnectionPoolManager</tt> maintains a pool of
@@ -192,9 +194,7 @@ public class PoolingHttpClientConnection
public ConnectionRequest requestConnection(
final HttpRoute route,
final Object state) {
- if (route == null) {
- throw new IllegalArgumentException("HTTP route may not be null");
- }
+ Args.notNull(route, "HTTP route");
if (this.log.isDebugEnabled()) {
this.log.debug("Connection request: " + format(route, state) + formatStats(route));
}
@@ -225,9 +225,7 @@ public class PoolingHttpClientConnection
if (entry == null || future.isCancelled()) {
throw new InterruptedException();
}
- if (entry.getConnection() == null) {
- throw new IllegalStateException("Pool entry with no connection");
- }
+ Asserts.check(entry.getConnection() != null, "Pool entry with no connection");
if (this.log.isDebugEnabled()) {
this.log.debug("Connection leased: " + format(entry) + formatStats(entry.getRoute()));
}
@@ -249,9 +247,7 @@ public class PoolingHttpClientConnection
final HttpClientConnection managedConn,
final Object state,
final long keepalive, final TimeUnit tunit) {
- if (managedConn == null) {
- throw new IllegalArgumentException("Managed connection may not be null");
- }
+ Args.notNull(managedConn, "Managed connection");
synchronized (managedConn) {
CPoolEntry entry = CPoolProxy.detach(managedConn);
if (entry == null) {
@@ -287,9 +283,7 @@ public class PoolingHttpClientConnection
final InetAddress local,
final int connectTimeout,
final HttpContext context) throws IOException {
- if (managedConn == null) {
- throw new IllegalArgumentException("Connection may not be null");
- }
+ Args.notNull(managedConn, "Connection");
SocketClientConnection conn;
synchronized (managedConn) {
CPoolEntry entry = CPoolProxy.getPoolEntry(managedConn);
@@ -311,9 +305,7 @@ public class PoolingHttpClientConnection
final HttpClientConnection managedConn,
final HttpHost host,
final HttpContext context) throws IOException {
- if (managedConn == null) {
- throw new IllegalArgumentException("Connection may not be null");
- }
+ Args.notNull(managedConn, "Connection");
SocketClientConnection conn;
synchronized (managedConn) {
CPoolEntry entry = CPoolProxy.getPoolEntry(managedConn);
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ProxySelectorRoutePlanner.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ProxySelectorRoutePlanner.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ProxySelectorRoutePlanner.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ProxySelectorRoutePlanner.java Tue Dec 18 16:22:58 2012
@@ -41,6 +41,8 @@ import org.apache.http.HttpException;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.conn.routing.HttpRoutePlanner;
@@ -90,11 +92,7 @@ public class ProxySelectorRoutePlanner i
*/
public ProxySelectorRoutePlanner(SchemeRegistry schreg,
ProxySelector prosel) {
-
- if (schreg == null) {
- throw new IllegalArgumentException
- ("SchemeRegistry must not be null.");
- }
+ Args.notNull(schreg, "SchemeRegistry");
schemeRegistry = schreg;
proxySelector = prosel;
}
@@ -123,10 +121,7 @@ public class ProxySelectorRoutePlanner i
HttpContext context)
throws HttpException {
- if (request == null) {
- throw new IllegalStateException
- ("Request must not be null.");
- }
+ Args.notNull(request, "HTTP request");
// If we have a forced route, we can do without a target.
HttpRoute route =
@@ -137,10 +132,7 @@ public class ProxySelectorRoutePlanner i
// If we get here, there is no forced route.
// So we need a target to compute a route.
- if (target == null) {
- throw new IllegalStateException
- ("Target host must not be null.");
- }
+ Asserts.notNull(target, "Target host");
final InetAddress local =
ConnRouteParams.getLocalAddress(request.getParams());
@@ -250,11 +242,7 @@ public class ProxySelectorRoutePlanner i
HttpHost target,
HttpRequest request,
HttpContext context) {
-
- if ((proxies == null) || proxies.isEmpty()) {
- throw new IllegalArgumentException
- ("Proxy list must not be empty.");
- }
+ Args.notEmpty(proxies, "List of proxies");
Proxy result = null;
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java Tue Dec 18 16:22:58 2012
@@ -43,6 +43,8 @@ import org.apache.http.conn.routing.Http
import org.apache.http.conn.routing.RouteTracker;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.params.HttpParams;
+import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
/**
* A connection manager for a single connection. This connection manager
@@ -118,10 +120,7 @@ public class SingleClientConnManager imp
* @param schreg the scheme registry
*/
public SingleClientConnManager(final SchemeRegistry schreg) {
- if (schreg == null) {
- throw new IllegalArgumentException
- ("Scheme registry must not be null.");
- }
+ Args.notNull(schreg, "Scheme registry");
this.schemeRegistry = schreg;
this.connOperator = createConnectionOperator(schreg);
this.uniquePoolEntry = new PoolEntry();
@@ -174,8 +173,7 @@ public class SingleClientConnManager imp
* @throws IllegalStateException if this manager is shut down
*/
protected final void assertStillUp() throws IllegalStateException {
- if (this.isShutDown)
- throw new IllegalStateException("Manager is shut down.");
+ Asserts.check(!this.isShutDown, "Manager is shut down");
}
public final ClientConnectionRequest requestConnection(
@@ -206,9 +204,7 @@ public class SingleClientConnManager imp
* along the given route
*/
public ManagedClientConnection getConnection(HttpRoute route, Object state) {
- if (route == null) {
- throw new IllegalArgumentException("Route may not be null.");
- }
+ Args.notNull(route, "Route");
assertStillUp();
if (log.isDebugEnabled()) {
@@ -216,8 +212,8 @@ public class SingleClientConnManager imp
}
synchronized (this) {
- if (managedConn != null)
- throw new IllegalStateException(MISUSE_MESSAGE);
+
+ Asserts.check(managedConn == null, MISUSE_MESSAGE);
// check re-usability of the connection
boolean recreate = false;
@@ -260,14 +256,10 @@ public class SingleClientConnManager imp
public void releaseConnection(
ManagedClientConnection conn,
long validDuration, TimeUnit timeUnit) {
+ Args.check(conn instanceof ConnAdapter, "Connection class mismatch, " +
+ "connection not obtained from this manager");
assertStillUp();
- if (!(conn instanceof ConnAdapter)) {
- throw new IllegalArgumentException
- ("Connection class mismatch, " +
- "connection not obtained from this manager.");
- }
-
if (log.isDebugEnabled()) {
log.debug("Releasing connection " + conn);
}
@@ -277,10 +269,7 @@ public class SingleClientConnManager imp
if (sca.poolEntry == null)
return; // already released
ClientConnectionManager manager = sca.getManager();
- if (manager != null && manager != this) {
- throw new IllegalArgumentException
- ("Connection not obtained from this manager.");
- }
+ Asserts.check(manager == this, "Connection not obtained from this manager");
try {
// make sure that the response has been read completely
if (sca.isOpen() && (this.alwaysShutDown ||
@@ -325,9 +314,7 @@ public class SingleClientConnManager imp
assertStillUp();
// idletime can be 0 or negative, no problem there
- if (tunit == null) {
- throw new IllegalArgumentException("Time unit must not be null.");
- }
+ Args.notNull(tunit, "Time unit");
synchronized (this) {
if ((managedConn == null) && uniquePoolEntry.connection.isOpen()) {
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/Wire.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/Wire.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/Wire.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/Wire.java Tue Dec 18 16:22:58 2012
@@ -26,13 +26,13 @@
package org.apache.http.impl.conn;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.ByteArrayInputStream;
-
-import org.apache.http.annotation.Immutable;
import org.apache.commons.logging.Log;
+import org.apache.http.annotation.Immutable;
+import org.apache.http.util.Args;
/**
* Logs data to the wire LOG.
@@ -94,49 +94,37 @@ public class Wire {
public void output(InputStream outstream)
throws IOException {
- if (outstream == null) {
- throw new IllegalArgumentException("Output may not be null");
- }
+ Args.notNull(outstream, "Output");
wire(">> ", outstream);
}
public void input(InputStream instream)
throws IOException {
- if (instream == null) {
- throw new IllegalArgumentException("Input may not be null");
- }
+ Args.notNull(instream, "Input");
wire("<< ", instream);
}
public void output(byte[] b, int off, int len)
throws IOException {
- if (b == null) {
- throw new IllegalArgumentException("Output may not be null");
- }
+ Args.notNull(b, "Output");
wire(">> ", new ByteArrayInputStream(b, off, len));
}
public void input(byte[] b, int off, int len)
throws IOException {
- if (b == null) {
- throw new IllegalArgumentException("Input may not be null");
- }
+ Args.notNull(b, "Input");
wire("<< ", new ByteArrayInputStream(b, off, len));
}
public void output(byte[] b)
throws IOException {
- if (b == null) {
- throw new IllegalArgumentException("Output may not be null");
- }
+ Args.notNull(b, "Output");
wire(">> ", new ByteArrayInputStream(b));
}
public void input(byte[] b)
throws IOException {
- if (b == null) {
- throw new IllegalArgumentException("Input may not be null");
- }
+ Args.notNull(b, "Input");
wire("<< ", new ByteArrayInputStream(b));
}
@@ -156,9 +144,7 @@ public class Wire {
@Deprecated
public void output(final String s)
throws IOException {
- if (s == null) {
- throw new IllegalArgumentException("Output may not be null");
- }
+ Args.notNull(s, "Output");
output(s.getBytes());
}
@@ -168,9 +154,7 @@ public class Wire {
@Deprecated
public void input(final String s)
throws IOException {
- if (s == null) {
- throw new IllegalArgumentException("Input may not be null");
- }
+ Args.notNull(s, "Input");
input(s.getBytes());
}
}
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java Tue Dec 18 16:22:58 2012
@@ -29,21 +29,21 @@ package org.apache.http.impl.conn.tsccm;
import java.io.IOException;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
-import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
-import org.apache.http.annotation.GuardedBy;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.http.annotation.GuardedBy;
import org.apache.http.conn.ConnectionPoolTimeoutException;
import org.apache.http.conn.OperatedClientConnection;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.impl.conn.IdleConnectionHandler;
+import org.apache.http.util.Args;
/**
* An abstract connection pool.
@@ -160,9 +160,7 @@ public abstract class AbstractConnPool {
public void closeIdleConnections(long idletime, TimeUnit tunit) {
// idletime can be 0 or negative, no problem there
- if (tunit == null) {
- throw new IllegalArgumentException("Time unit must not be null.");
- }
+ Args.notNull(tunit, "Time unit");
poolLock.lock();
try {
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntry.java?rev=1423516&r1=1423515&r2=1423516&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntry.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntry.java Tue Dec 18 16:22:58 2012
@@ -29,10 +29,11 @@ package org.apache.http.impl.conn.tsccm;
import java.lang.ref.ReferenceQueue;
import java.util.concurrent.TimeUnit;
-import org.apache.http.conn.OperatedClientConnection;
import org.apache.http.conn.ClientConnectionOperator;
+import org.apache.http.conn.OperatedClientConnection;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.impl.conn.AbstractPoolEntry;
+import org.apache.http.util.Args;
/**
* Basic implementation of a connection pool entry.
@@ -54,9 +55,7 @@ public class BasicPoolEntry extends Abst
HttpRoute route,
ReferenceQueue<Object> queue) {
super(op, route);
- if (route == null) {
- throw new IllegalArgumentException("HTTP route may not be null");
- }
+ Args.notNull(route, "HTTP route");
this.created = System.currentTimeMillis();
this.validUntil = Long.MAX_VALUE;
this.expiry = this.validUntil;
@@ -86,9 +85,7 @@ public class BasicPoolEntry extends Abst
public BasicPoolEntry(ClientConnectionOperator op,
HttpRoute route, long connTTL, TimeUnit timeunit) {
super(op, route);
- if (route == null) {
- throw new IllegalArgumentException("HTTP route may not be null");
- }
+ Args.notNull(route, "HTTP route");
this.created = System.currentTimeMillis();
if (connTTL > 0) {
this.validUntil = this.created + timeunit.toMillis(connTTL);