Use Asserts to verify object state; use Args to verify method arguments

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1423516 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2012-12-18 16:22:58 +00:00
parent b284816743
commit d72e9b3ae7
145 changed files with 738 additions and 1720 deletions

View File

@ -31,12 +31,14 @@ import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.ProtocolVersion;
import org.apache.http.StatusLine;
import org.apache.http.annotation.Immutable;
import org.apache.http.message.HeaderGroup;
import org.apache.http.util.Args;
/**
* Structure used to store an {@link HttpResponse} in a cache. Some entries
@ -85,18 +87,10 @@ public class HttpCacheEntry implements Serializable {
final Resource resource,
final Map<String,String> variantMap) {
super();
if (requestDate == null) {
throw new IllegalArgumentException("Request date may not be null");
}
if (responseDate == null) {
throw new IllegalArgumentException("Response date may not be null");
}
if (statusLine == null) {
throw new IllegalArgumentException("Status line may not be null");
}
if (responseHeaders == null) {
throw new IllegalArgumentException("Response headers may not be null");
}
Args.notNull(requestDate, "Request date");
Args.notNull(responseDate, "Response date");
Args.notNull(statusLine, "Status line");
Args.notNull(responseHeaders, "Response headers");
this.requestDate = requestDate;
this.responseDate = responseDate;
this.statusLine = statusLine;

View File

@ -36,6 +36,7 @@ import org.apache.http.HttpEntity;
import org.apache.http.annotation.Immutable;
import org.apache.http.client.cache.HttpCacheEntry;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.Args;
@Immutable
class CacheEntity implements HttpEntity, Serializable {
@ -74,9 +75,7 @@ class CacheEntity implements HttpEntity, Serializable {
}
public void writeTo(final OutputStream outstream) throws IOException {
if (outstream == null) {
throw new IllegalArgumentException("Output stream may not be null");
}
Args.notNull(outstream, "Output stream");
InputStream instream = this.cacheEntry.getResource().getInputStream();
try {
IOUtils.copy(instream, outstream);

View File

@ -66,6 +66,7 @@ import org.apache.http.message.BasicHttpResponse;
import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
import org.apache.http.util.EntityUtils;
import org.apache.http.util.VersionInfo;
@ -119,12 +120,8 @@ public class CachingExec implements ClientExecChain {
HttpCache cache,
CacheConfig config) {
super();
if (backend == null) {
throw new IllegalArgumentException("HTTP backend may not be null");
}
if (cache == null) {
throw new IllegalArgumentException("HttpCache may not be null");
}
Args.notNull(backend, "HTTP backend");
Args.notNull(cache, "HttpCache");
this.cacheConfig = config != null ? config : CacheConfig.DEFAULT;
this.backend = backend;
this.responseCache = cache;

View File

@ -77,6 +77,7 @@ import org.apache.http.params.HttpParams;
import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
import org.apache.http.util.EntityUtils;
import org.apache.http.util.VersionInfo;
@ -165,15 +166,9 @@ public class CachingHttpClient implements HttpClient {
HttpCache cache,
CacheConfig config) {
super();
if (client == null) {
throw new IllegalArgumentException("HttpClient may not be null");
}
if (cache == null) {
throw new IllegalArgumentException("HttpCache may not be null");
}
if (config == null) {
throw new IllegalArgumentException("CacheConfig may not be null");
}
Args.notNull(client, "HttpClient");
Args.notNull(cache, "HttpCache");
Args.notNull(config, "CacheConfig");
this.maxObjectSizeBytes = config.getMaxObjectSize();
this.sharedCache = config.isSharedCache();
this.backend = client;

View File

@ -35,6 +35,7 @@ import java.io.SequenceInputStream;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.client.cache.Resource;
import org.apache.http.entity.AbstractHttpEntity;
import org.apache.http.util.Args;
@NotThreadSafe
class CombinedEntity extends AbstractHttpEntity {
@ -66,9 +67,7 @@ class CombinedEntity extends AbstractHttpEntity {
}
public void writeTo(final OutputStream outstream) throws IOException {
if (outstream == null) {
throw new IllegalArgumentException("Output stream may not be null");
}
Args.notNull(outstream, "Output stream");
InputStream instream = getContent();
try {
int l;

View File

@ -37,6 +37,7 @@ import org.apache.http.client.cache.HttpCacheEntry;
import org.apache.http.client.cache.HttpCacheStorage;
import org.apache.http.client.cache.HttpCacheUpdateCallback;
import org.apache.http.client.cache.Resource;
import org.apache.http.util.Args;
/**
* {@link HttpCacheStorage} implementation capable of deallocating resources associated with
@ -84,12 +85,8 @@ public class ManagedHttpCacheStorage implements HttpCacheStorage {
}
public void putEntry(final String url, final HttpCacheEntry entry) throws IOException {
if (url == null) {
throw new IllegalArgumentException("URL may not be null");
}
if (entry == null) {
throw new IllegalArgumentException("Cache entry may not be null");
}
Args.notNull(url, "URL");
Args.notNull(entry, "Cache entry");
ensureValidState();
synchronized (this) {
this.entries.put(url, entry);
@ -98,9 +95,7 @@ public class ManagedHttpCacheStorage implements HttpCacheStorage {
}
public HttpCacheEntry getEntry(final String url) throws IOException {
if (url == null) {
throw new IllegalArgumentException("URL may not be null");
}
Args.notNull(url, "URL");
ensureValidState();
synchronized (this) {
return this.entries.get(url);
@ -108,9 +103,7 @@ public class ManagedHttpCacheStorage implements HttpCacheStorage {
}
public void removeEntry(String url) throws IOException {
if (url == null) {
throw new IllegalArgumentException("URL may not be null");
}
Args.notNull(url, "URL");
ensureValidState();
synchronized (this) {
// Cannot deallocate the associated resources immediately as the
@ -122,12 +115,8 @@ public class ManagedHttpCacheStorage implements HttpCacheStorage {
public void updateEntry(
final String url,
final HttpCacheUpdateCallback callback) throws IOException {
if (url == null) {
throw new IllegalArgumentException("URL may not be null");
}
if (callback == null) {
throw new IllegalArgumentException("Callback may not be null");
}
Args.notNull(url, "URL");
Args.notNull(callback, "Callback");
ensureValidState();
synchronized (this) {
HttpCacheEntry existing = this.entries.get(url);

View File

@ -27,6 +27,7 @@
package org.apache.http.auth;
import org.apache.http.annotation.Immutable;
import org.apache.http.util.Args;
/**
* @since 4.2
@ -39,12 +40,8 @@ public final class AuthOption {
public AuthOption(final AuthScheme authScheme, final Credentials creds) {
super();
if (authScheme == null) {
throw new IllegalArgumentException("Auth scheme may not be null");
}
if (creds == null) {
throw new IllegalArgumentException("User credentials may not be null");
}
Args.notNull(authScheme, "Auth scheme");
Args.notNull(creds, "User credentials");
this.authScheme = authScheme;
this.creds = creds;
}

View File

@ -36,10 +36,10 @@ import org.apache.http.HttpRequest;
import org.apache.http.annotation.ThreadSafe;
import org.apache.http.config.Lookup;
import org.apache.http.config.Registry;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
/**
* Authentication scheme registry that can be used to obtain the corresponding
@ -78,12 +78,8 @@ public final class AuthSchemeRegistry implements Lookup<AuthSchemeProvider> {
public void register(
final String name,
final AuthSchemeFactory factory) {
if (name == null) {
throw new IllegalArgumentException("Name may not be null");
}
if (factory == null) {
throw new IllegalArgumentException("Authentication scheme factory may not be null");
}
Args.notNull(name, "Name");
Args.notNull(factory, "Authentication scheme factory");
registeredSchemes.put(name.toLowerCase(Locale.ENGLISH), factory);
}
@ -94,9 +90,7 @@ public final class AuthSchemeRegistry implements Lookup<AuthSchemeProvider> {
* @param name the identifier of the class to unregister
*/
public void unregister(final String name) {
if (name == null) {
throw new IllegalArgumentException("Name may not be null");
}
Args.notNull(name, "Name");
registeredSchemes.remove(name.toLowerCase(Locale.ENGLISH));
}
@ -114,9 +108,7 @@ public final class AuthSchemeRegistry implements Lookup<AuthSchemeProvider> {
public AuthScheme getAuthScheme(final String name, final HttpParams params)
throws IllegalStateException {
if (name == null) {
throw new IllegalArgumentException("Name may not be null");
}
Args.notNull(name, "Name");
AuthSchemeFactory factory = registeredSchemes.get(name.toLowerCase(Locale.ENGLISH));
if (factory != null) {
return factory.newInstance(params);

View File

@ -30,7 +30,7 @@ import java.util.Locale;
import org.apache.http.HttpHost;
import org.apache.http.annotation.Immutable;
import org.apache.http.util.Args;
import org.apache.http.util.LangUtils;
/**
@ -162,9 +162,7 @@ public class AuthScope {
*/
public AuthScope(final AuthScope authscope) {
super();
if (authscope == null) {
throw new IllegalArgumentException("Scope may not be null");
}
Args.notNull(authscope, "Scope");
this.host = authscope.getHost();
this.port = authscope.getPort();
this.realm = authscope.getRealm();

View File

@ -29,6 +29,7 @@ package org.apache.http.auth;
import java.util.Queue;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.util.Args;
/**
* This class provides detailed information about the state of the authentication process.
@ -108,12 +109,8 @@ public class AuthState {
* @since 4.2
*/
public void update(final AuthScheme authScheme, final Credentials credentials) {
if (authScheme == null) {
throw new IllegalArgumentException("Auth scheme may not be null or empty");
}
if (credentials == null) {
throw new IllegalArgumentException("Credentials may not be null or empty");
}
Args.notNull(authScheme, "Auth scheme");
Args.notNull(credentials, "Credentials");
this.authScheme = authScheme;
this.credentials = credentials;
this.authOptions = null;
@ -146,9 +143,7 @@ public class AuthState {
* @since 4.2
*/
public void update(final Queue<AuthOption> authOptions) {
if (authOptions == null || authOptions.isEmpty()) {
throw new IllegalArgumentException("Queue of auth options may not be null or empty");
}
Args.notEmpty(authOptions, "Queue of auth options");
this.authOptions = authOptions;
this.authScheme = null;
this.credentials = null;

View File

@ -30,7 +30,7 @@ import java.io.Serializable;
import java.security.Principal;
import org.apache.http.annotation.Immutable;
import org.apache.http.util.Args;
import org.apache.http.util.LangUtils;
/**
@ -47,9 +47,7 @@ public final class BasicUserPrincipal implements Principal, Serializable {
public BasicUserPrincipal(final String username) {
super();
if (username == null) {
throw new IllegalArgumentException("User name may not be null");
}
Args.notNull(username, "User name");
this.username = username;
}

View File

@ -31,7 +31,7 @@ import java.security.Principal;
import java.util.Locale;
import org.apache.http.annotation.Immutable;
import org.apache.http.util.Args;
import org.apache.http.util.LangUtils;
/**
@ -62,9 +62,7 @@ public class NTCredentials implements Credentials, Serializable {
*/
public NTCredentials(String usernamePassword) {
super();
if (usernamePassword == null) {
throw new IllegalArgumentException("Username:password string may not be null");
}
Args.notNull(usernamePassword, "Username:password string");
String username;
int atColon = usernamePassword.indexOf(':');
if (atColon >= 0) {
@ -102,9 +100,7 @@ public class NTCredentials implements Credentials, Serializable {
final String workstation,
final String domain) {
super();
if (userName == null) {
throw new IllegalArgumentException("User name may not be null");
}
Args.notNull(userName, "User name");
this.principal = new NTUserPrincipal(domain, userName);
this.password = password;
if (workstation != null) {

View File

@ -31,7 +31,7 @@ import java.security.Principal;
import java.util.Locale;
import org.apache.http.annotation.Immutable;
import org.apache.http.util.Args;
import org.apache.http.util.LangUtils;
/**
@ -52,9 +52,7 @@ public class NTUserPrincipal implements Principal, Serializable {
final String domain,
final String username) {
super();
if (username == null) {
throw new IllegalArgumentException("User name may not be null");
}
Args.notNull(username, "User name");
this.username = username;
if (domain != null) {
this.domain = domain.toUpperCase(Locale.ENGLISH);

View File

@ -30,7 +30,7 @@ import java.io.Serializable;
import java.security.Principal;
import org.apache.http.annotation.Immutable;
import org.apache.http.util.Args;
import org.apache.http.util.LangUtils;
/**
@ -55,9 +55,7 @@ public class UsernamePasswordCredentials implements Credentials, Serializable {
*/
public UsernamePasswordCredentials(String usernamePassword) {
super();
if (usernamePassword == null) {
throw new IllegalArgumentException("Username:password string may not be null");
}
Args.notNull(usernamePassword, "Username:password string");
int atColon = usernamePassword.indexOf(':');
if (atColon >= 0) {
this.principal = new BasicUserPrincipal(usernamePassword.substring(0, atColon));
@ -77,9 +75,7 @@ public class UsernamePasswordCredentials implements Credentials, Serializable {
*/
public UsernamePasswordCredentials(String userName, String password) {
super();
if (userName == null) {
throw new IllegalArgumentException("Username may not be null");
}
Args.notNull(userName, "Username");
this.principal = new BasicUserPrincipal(userName);
this.password = password;
}

View File

@ -30,9 +30,9 @@ package org.apache.http.auth.params;
import org.apache.http.annotation.Immutable;
import org.apache.http.auth.AuthSchemeProvider;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.Args;
/**
* An adaptor for manipulating HTTP authentication parameters
@ -59,9 +59,7 @@ public final class AuthParams {
* @return The charset
*/
public static String getCredentialCharset(final HttpParams params) {
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
Args.notNull(params, "HTTP parameters");
String charset = (String) params.getParameter
(AuthPNames.CREDENTIAL_CHARSET);
if (charset == null) {
@ -78,9 +76,7 @@ public final class AuthParams {
* @param charset The charset
*/
public static void setCredentialCharset(final HttpParams params, final String charset) {
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
Args.notNull(params, "HTTP parameters");
params.setParameter(AuthPNames.CREDENTIAL_CHARSET, charset);
}

View File

@ -31,6 +31,7 @@ import java.io.OutputStream;
import org.apache.http.HttpEntity;
import org.apache.http.entity.HttpEntityWrapper;
import org.apache.http.util.Args;
import org.apache.http.util.EntityUtils;
/**
@ -88,9 +89,7 @@ abstract class DecompressingEntity extends HttpEntityWrapper {
*/
@Override
public void writeTo(OutputStream outstream) throws IOException {
if (outstream == null) {
throw new IllegalArgumentException("Output stream may not be null");
}
Args.notNull(outstream, "Output stream");
InputStream instream = getContent();
try {
byte[] buffer = new byte[BUFFER_SIZE];

View File

@ -28,7 +28,6 @@
package org.apache.http.client.entity;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.Arrays;
@ -196,13 +195,7 @@ public class EntityBuilder {
e = new UrlEncodedFormEntity(this.parameters,
this.contentType != null ? this.contentType.getCharset() : null);
} else if (this.serializable != null) {
// TODO: replace with constructor from 4.3
try {
e = new SerializableEntity(this.serializable, false);
} catch (IOException never) {
throw new IllegalStateException(
"I/O error creating SerializableEntity without buffering");
}
e = new SerializableEntity(this.serializable);
e.setContentType(ContentType.DEFAULT_BINARY.toString());
} else if (this.file != null) {
e = new FileEntity(this.file, getContentOrDefault(ContentType.DEFAULT_BINARY));

View File

@ -37,6 +37,7 @@ import org.apache.http.HttpEntity;
import org.apache.http.entity.HttpEntityWrapper;
import org.apache.http.message.BasicHeader;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.Args;
/**
* Wrapping entity that compresses content when {@link #writeTo writing}.
@ -75,9 +76,7 @@ public class GzipCompressingEntity extends HttpEntityWrapper {
@Override
public void writeTo(final OutputStream outstream) throws IOException {
if (outstream == null) {
throw new IllegalArgumentException("Output stream may not be null");
}
Args.notNull(outstream, "Output stream");
GZIPOutputStream gzip = new GZIPOutputStream(outstream);
try {
wrappedEntity.writeTo(gzip);

View File

@ -31,12 +31,12 @@ import java.net.URI;
import java.util.HashSet;
import java.util.Set;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.Header;
import org.apache.http.HeaderElement;
import org.apache.http.HeaderIterator;
import org.apache.http.HttpResponse;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.util.Args;
/**
* HTTP OPTIONS method.
@ -83,9 +83,7 @@ public class HttpOptions extends HttpRequestBase {
}
public Set<String> getAllowedMethods(final HttpResponse response) {
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
Args.notNull(response, "HTTP response");
HeaderIterator it = response.headerIterator("Allow");
Set<String> methods = new HashSet<String>();

View File

@ -28,9 +28,9 @@ package org.apache.http.client.params;
import org.apache.http.annotation.Immutable;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.Args;
/**
* An adaptor for manipulating HTTP client parameters in {@link HttpParams}.
@ -48,41 +48,31 @@ public class HttpClientParams {
}
public static boolean isRedirecting(final HttpParams params) {
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
Args.notNull(params, "HTTP parameters");
return params.getBooleanParameter
(ClientPNames.HANDLE_REDIRECTS, true);
}
public static void setRedirecting(final HttpParams params, boolean value) {
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
Args.notNull(params, "HTTP parameters");
params.setBooleanParameter
(ClientPNames.HANDLE_REDIRECTS, value);
}
public static boolean isAuthenticating(final HttpParams params) {
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
Args.notNull(params, "HTTP parameters");
return params.getBooleanParameter
(ClientPNames.HANDLE_AUTHENTICATION, true);
}
public static void setAuthenticating(final HttpParams params, boolean value) {
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
Args.notNull(params, "HTTP parameters");
params.setBooleanParameter
(ClientPNames.HANDLE_AUTHENTICATION, value);
}
public static String getCookiePolicy(final HttpParams params) {
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
Args.notNull(params, "HTTP parameters");
String cookiePolicy = (String)
params.getParameter(ClientPNames.COOKIE_POLICY);
if (cookiePolicy == null) {
@ -92,9 +82,7 @@ public class HttpClientParams {
}
public static void setCookiePolicy(final HttpParams params, final String cookiePolicy) {
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
Args.notNull(params, "HTTP parameters");
params.setParameter(ClientPNames.COOKIE_POLICY, cookiePolicy);
}
@ -104,9 +92,7 @@ public class HttpClientParams {
* @since 4.2
*/
public static void setConnectionManagerTimeout(final HttpParams params, long timeout) {
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
Args.notNull(params, "HTTP parameters");
params.setLongParameter(ClientPNames.CONN_MANAGER_TIMEOUT, timeout);
}
@ -120,9 +106,7 @@ public class HttpClientParams {
* @return the timeout value
*/
public static long getConnectionManagerTimeout(final HttpParams params) {
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
Args.notNull(params, "HTTP parameters");
Long timeout = (Long) params.getParameter(ClientPNames.CONN_MANAGER_TIMEOUT);
if (timeout != null) {
return timeout.longValue();

View File

@ -34,6 +34,7 @@ import org.apache.http.client.CookieStore;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.cookie.CookieSpecRegistry;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
/**
* Configuration facade for {@link HttpContext} instances.
@ -49,8 +50,7 @@ public class ClientContextConfigurer implements ClientContext {
private final HttpContext context;
public ClientContextConfigurer (final HttpContext context) {
if (context == null)
throw new IllegalArgumentException("HTTP context may not be null");
Args.notNull(context, "HTTP context");
this.context = context;
}

View File

@ -54,6 +54,7 @@ import org.apache.http.cookie.CookieSpec;
import org.apache.http.cookie.CookieSpecProvider;
import org.apache.http.cookie.SetCookie2;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
/**
* Request interceptor that matches cookies available in the current
@ -73,12 +74,8 @@ public class RequestAddCookies implements HttpRequestInterceptor {
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
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(request, "HTTP request");
Args.notNull(context, "HTTP context");
String method = request.getRequestLine().getMethod();
if (method.equalsIgnoreCase("CONNECT")) {

View File

@ -45,6 +45,7 @@ import org.apache.http.client.AuthCache;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.conn.routing.RouteInfo;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
/**
* Request interceptor that can preemptively authenticate against known hosts,
@ -64,12 +65,8 @@ public class RequestAuthCache implements HttpRequestInterceptor {
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
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(request, "HTTP request");
Args.notNull(context, "HTTP context");
HttpClientContext clientContext = HttpClientContext.adapt(context);

View File

@ -43,6 +43,7 @@ import org.apache.http.auth.AuthenticationException;
import org.apache.http.auth.ContextAwareAuthScheme;
import org.apache.http.auth.Credentials;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Asserts;
@Deprecated
abstract class RequestAuthenticationBase implements HttpRequestInterceptor {
@ -108,9 +109,7 @@ abstract class RequestAuthenticationBase implements HttpRequestInterceptor {
}
private void ensureAuthScheme(final AuthScheme authScheme) {
if (authScheme == null) {
throw new IllegalStateException("Auth scheme is not set");
}
Asserts.notNull(authScheme, "Auth scheme");
}
private Header authenticate(
@ -118,9 +117,7 @@ abstract class RequestAuthenticationBase implements HttpRequestInterceptor {
final Credentials creds,
final HttpRequest request,
final HttpContext context) throws AuthenticationException {
if (authScheme == null) {
throw new IllegalStateException("Auth state object is null");
}
Asserts.notNull(authScheme, "Auth scheme");
if (authScheme instanceof ContextAwareAuthScheme) {
return ((ContextAwareAuthScheme) authScheme).authenticate(creds, request, context);
} else {

View File

@ -31,14 +31,14 @@ import java.io.IOException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.annotation.Immutable;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.annotation.Immutable;
import org.apache.http.conn.routing.RouteInfo;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
/**
* This protocol interceptor is responsible for adding <code>Connection</code>
@ -60,9 +60,7 @@ public class RequestClientConnControl implements HttpRequestInterceptor {
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
}
Args.notNull(request, "HTTP request");
String method = request.getRequestLine().getMethod();
if (method.equalsIgnoreCase("CONNECT")) {

View File

@ -30,14 +30,14 @@ package org.apache.http.client.protocol;
import java.io.IOException;
import java.util.Collection;
import org.apache.http.annotation.Immutable;
import org.apache.http.Header;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.annotation.Immutable;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
/**
* Request interceptor that adds default request headers.
@ -64,9 +64,7 @@ public class RequestDefaultHeaders implements HttpRequestInterceptor {
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
}
Args.notNull(request, "HTTP request");
String method = request.getRequestLine().getMethod();
if (method.equalsIgnoreCase("CONNECT")) {

View File

@ -39,6 +39,7 @@ import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.impl.client.HttpAuthenticator;
import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
/**
* Generates authentication header for the proxy host, if required,
@ -58,12 +59,8 @@ public class RequestProxyAuthentication extends RequestAuthenticationBase {
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
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(request, "HTTP request");
Args.notNull(context, "HTTP context");
if (request.containsHeader(AUTH.PROXY_AUTH_RESP)) {
return;

View File

@ -36,6 +36,7 @@ import org.apache.http.auth.AUTH;
import org.apache.http.auth.AuthState;
import org.apache.http.impl.client.HttpAuthenticator;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
/**
* Generates authentication header for the target host, if required,
@ -55,12 +56,8 @@ public class RequestTargetAuthentication extends RequestAuthenticationBase {
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
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(request, "HTTP request");
Args.notNull(context, "HTTP context");
String method = request.getRequestLine().getMethod();
if (method.equalsIgnoreCase("CONNECT")) {

View File

@ -46,6 +46,7 @@ import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
/**
* Response interceptor that adds successfully completed {@link AuthScheme}s
@ -69,12 +70,8 @@ public class ResponseAuthCache implements HttpResponseInterceptor {
public void process(final HttpResponse response, final HttpContext context)
throws HttpException, IOException {
if (response == null) {
throw new IllegalArgumentException("HTTP request may not be null");
}
if (context == null) {
throw new IllegalArgumentException("HTTP context may not be null");
}
Args.notNull(response, "HTTP request");
Args.notNull(context, "HTTP context");
AuthCache authCache = (AuthCache) context.getAttribute(ClientContext.AUTH_CACHE);
HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);

View File

@ -30,8 +30,6 @@ package org.apache.http.client.protocol;
import java.io.IOException;
import java.util.List;
import org.apache.http.annotation.Immutable;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.Header;
@ -39,6 +37,7 @@ import org.apache.http.HeaderIterator;
import org.apache.http.HttpException;
import org.apache.http.HttpResponse;
import org.apache.http.HttpResponseInterceptor;
import org.apache.http.annotation.Immutable;
import org.apache.http.client.CookieStore;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieOrigin;
@ -46,6 +45,7 @@ import org.apache.http.cookie.CookieSpec;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SM;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
/**
* Response interceptor that populates the current {@link CookieStore} with data
@ -64,12 +64,8 @@ public class ResponseProcessCookies implements HttpResponseInterceptor {
public void process(final HttpResponse response, final HttpContext context)
throws HttpException, IOException {
if (response == null) {
throw new IllegalArgumentException("HTTP request may not be null");
}
if (context == null) {
throw new IllegalArgumentException("HTTP context may not be null");
}
Args.notNull(response, "HTTP request");
Args.notNull(context, "HTTP context");
HttpClientContext clientContext = HttpClientContext.adapt(context);

View File

@ -30,9 +30,9 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.util.Stack;
import org.apache.http.annotation.Immutable;
import org.apache.http.HttpHost;
import org.apache.http.annotation.Immutable;
import org.apache.http.util.Args;
/**
* A collection of utilities for {@link URI URIs}, to workaround
@ -128,9 +128,7 @@ public class URIUtils {
final URI uri,
final HttpHost target,
boolean dropFragment) throws URISyntaxException {
if (uri == null) {
throw new IllegalArgumentException("URI may not be null");
}
Args.notNull(uri, "URI");
URIBuilder uribuilder = new URIBuilder(uri);
if (target != null) {
uribuilder.setScheme(target.getSchemeName());
@ -169,9 +167,7 @@ public class URIUtils {
* If the resulting URI is invalid.
*/
public static URI rewriteURI(final URI uri) throws URISyntaxException {
if (uri == null) {
throw new IllegalArgumentException("URI may not be null");
}
Args.notNull(uri, "URI");
if (uri.getFragment() != null || uri.getUserInfo() != null) {
return new URIBuilder(uri).setFragment(null).setUserInfo(null).build();
} else {
@ -200,12 +196,8 @@ public class URIUtils {
* @return the resulting URI
*/
public static URI resolve(final URI baseURI, URI reference){
if (baseURI == null) {
throw new IllegalArgumentException("Base URI may nor be null");
}
if (reference == null) {
throw new IllegalArgumentException("Reference URI may nor be null");
}
Args.notNull(baseURI, "Base URI");
Args.notNull(reference, "Reference URI");
String s = reference.toString();
if (s.startsWith("?")) {
return resolveReferenceStartingWithQueryString(baseURI, reference);

View File

@ -31,6 +31,7 @@ import java.io.InputStream;
import java.io.IOException;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.util.Args;
/**
* Basic implementation of {@link EofSensorWatcher}. The underlying connection
@ -58,10 +59,7 @@ public class BasicEofSensorWatcher implements EofSensorWatcher {
*/
public BasicEofSensorWatcher(ManagedClientConnection conn,
boolean reuse) {
if (conn == null)
throw new IllegalArgumentException
("Connection may not be null.");
Args.notNull(conn, "Connection");
managedConn = conn;
attemptReuse = reuse;
}

View File

@ -36,6 +36,7 @@ import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.HttpEntity;
import org.apache.http.entity.HttpEntityWrapper;
import org.apache.http.util.Args;
import org.apache.http.util.EntityUtils;
/**
@ -73,11 +74,7 @@ public class BasicManagedEntity extends HttpEntityWrapper
ManagedClientConnection conn,
boolean reuse) {
super(entity);
if (conn == null)
throw new IllegalArgumentException
("Connection may not be null.");
Args.notNull(conn, "Connection");
this.managedConn = conn;
this.attemptReuse = reuse;
}

View File

@ -26,10 +26,11 @@
package org.apache.http.conn;
import java.io.InputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.util.Args;
/**
* A stream wrapper that triggers actions on {@link #close close()} and EOF.
@ -80,9 +81,7 @@ public class EofSensorInputStream extends InputStream implements ConnectionRelea
*/
public EofSensorInputStream(final InputStream in,
final EofSensorWatcher watcher) {
if (in == null) {
throw new IllegalArgumentException("Wrapped stream may not be null");
}
Args.notNull(in, "Wrapped stream");
wrappedStream = in;
selfClosed = false;
eofWatcher = watcher;

View File

@ -30,6 +30,7 @@ import java.net.InetAddress;
import java.net.InetSocketAddress;
import org.apache.http.HttpHost;
import org.apache.http.util.Args;
/**
* Extended {@link InetSocketAddress} implementation that also provides access to the original
@ -48,9 +49,7 @@ public class HttpInetSocketAddress extends InetSocketAddress {
public HttpInetSocketAddress(final HttpHost httphost, final InetAddress addr, int port) {
super(addr, port);
if (httphost == null) {
throw new IllegalArgumentException("HTTP host may not be null");
}
Args.notNull(httphost, "HTTP host");
this.httphost = httphost;
}

View File

@ -43,6 +43,8 @@ import org.apache.http.conn.scheme.SchemeSocketFactory;
import org.apache.http.conn.scheme.SocketFactory;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.Args;
import org.apache.http.util.Asserts;
/**
* Socket factory that implements a simple multi-home fail-over on connect failure,
@ -106,13 +108,8 @@ public final class MultihomePlainSocketFactory implements SocketFactory {
InetAddress localAddress, int localPort,
HttpParams params)
throws IOException {
if (host == null) {
throw new IllegalArgumentException("Target host may not be null.");
}
if (params == null) {
throw new IllegalArgumentException("Parameters may not be null.");
}
Args.notNull(host, "Target host");
Args.notNull(params, "HTTP parameters");
if (sock == null)
sock = createSocket();
@ -170,22 +167,10 @@ public final class MultihomePlainSocketFactory implements SocketFactory {
public final boolean isSecure(Socket sock)
throws IllegalArgumentException {
if (sock == null) {
throw new IllegalArgumentException("Socket may not be null.");
}
// This class check assumes that createSocket() calls the constructor
// directly. If it was using javax.net.SocketFactory, we couldn't make
// an assumption about the socket class here.
if (sock.getClass() != Socket.class) {
throw new IllegalArgumentException
("Socket not created by this factory.");
}
Args.notNull(sock, "Socket");
// This check is performed last since it calls a method implemented
// by the argument object. getClass() is final in java.lang.Object.
if (sock.isClosed()) {
throw new IllegalArgumentException("Socket is closed.");
}
Asserts.check(!sock.isClosed(), "Socket is closed");
return false;
} // isSecure

View File

@ -27,10 +27,10 @@
package org.apache.http.conn.params;
import org.apache.http.annotation.Immutable;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.Args;
/**
* An adaptor for manipulating HTTP connection management
@ -60,9 +60,7 @@ public final class ConnManagerParams implements ConnManagerPNames {
*/
@Deprecated
public static long getTimeout(final HttpParams params) {
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
Args.notNull(params, "HTTP parameters");
return params.getLongParameter(TIMEOUT, 0);
}
@ -77,9 +75,7 @@ public final class ConnManagerParams implements ConnManagerPNames {
*/
@Deprecated
public static void setTimeout(final HttpParams params, long timeout) {
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
Args.notNull(params, "HTTP parameters");
params.setLongParameter(TIMEOUT, timeout);
}
@ -101,10 +97,7 @@ public final class ConnManagerParams implements ConnManagerPNames {
*/
public static void setMaxConnectionsPerRoute(final HttpParams params,
final ConnPerRoute connPerRoute) {
if (params == null) {
throw new IllegalArgumentException
("HTTP parameters must not be null.");
}
Args.notNull(params, "HTTP parameters");
params.setParameter(MAX_CONNECTIONS_PER_ROUTE, connPerRoute);
}
@ -116,10 +109,7 @@ public final class ConnManagerParams implements ConnManagerPNames {
* @return lookup interface for maximum number of connections allowed per route.
*/
public static ConnPerRoute getMaxConnectionsPerRoute(final HttpParams params) {
if (params == null) {
throw new IllegalArgumentException
("HTTP parameters must not be null.");
}
Args.notNull(params, "HTTP parameters");
ConnPerRoute connPerRoute = (ConnPerRoute) params.getParameter(MAX_CONNECTIONS_PER_ROUTE);
if (connPerRoute == null) {
connPerRoute = DEFAULT_CONN_PER_ROUTE;
@ -136,10 +126,7 @@ public final class ConnManagerParams implements ConnManagerPNames {
public static void setMaxTotalConnections(
final HttpParams params,
int maxTotalConnections) {
if (params == null) {
throw new IllegalArgumentException
("HTTP parameters must not be null.");
}
Args.notNull(params, "HTTP parameters");
params.setIntParameter(MAX_TOTAL_CONNECTIONS, maxTotalConnections);
}
@ -152,10 +139,7 @@ public final class ConnManagerParams implements ConnManagerPNames {
*/
public static int getMaxTotalConnections(
final HttpParams params) {
if (params == null) {
throw new IllegalArgumentException
("HTTP parameters must not be null.");
}
Args.notNull(params, "HTTP parameters");
return params.getIntParameter(MAX_TOTAL_CONNECTIONS, DEFAULT_MAX_TOTAL_CONNECTIONS);
}

View File

@ -33,6 +33,7 @@ import org.apache.http.annotation.ThreadSafe;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.pool.ConnPoolControl;
import org.apache.http.util.Args;
/**
* This class maintains a map of HTTP routes to maximum number of connections allowed
@ -77,30 +78,18 @@ public final class ConnPerRouteBean implements ConnPerRoute {
}
public void setDefaultMaxPerRoute(int max) {
if (max < 1) {
throw new IllegalArgumentException
("The maximum must be greater than 0.");
}
Args.positive(max, "Defautl max per route");
this.defaultMax = max;
}
public void setMaxForRoute(final HttpRoute route, int max) {
if (route == null) {
throw new IllegalArgumentException
("HTTP route may not be null.");
}
if (max < 1) {
throw new IllegalArgumentException
("The maximum must be greater than 0.");
}
Args.notNull(route, "HTTP route");
Args.positive(max, "Max per route");
this.maxPerHostMap.put(route, Integer.valueOf(max));
}
public int getMaxForRoute(final HttpRoute route) {
if (route == null) {
throw new IllegalArgumentException
("HTTP route may not be null.");
}
Args.notNull(route, "HTTP route");
Integer max = this.maxPerHostMap.get(route);
if (max != null) {
return max.intValue();

View File

@ -28,12 +28,12 @@ package org.apache.http.conn.params;
import java.net.InetAddress;
import org.apache.http.annotation.Immutable;
import org.apache.http.HttpHost;
import org.apache.http.params.HttpParams;
import org.apache.http.annotation.Immutable;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.params.HttpParams;
import org.apache.http.util.Args;
/**
* An adaptor for manipulating HTTP routing parameters
@ -78,9 +78,7 @@ public class ConnRouteParams implements ConnRoutePNames {
* <code>null</code> if not set
*/
public static HttpHost getDefaultProxy(HttpParams params) {
if (params == null) {
throw new IllegalArgumentException("Parameters must not be null.");
}
Args.notNull(params, "Parameters");
HttpHost proxy = (HttpHost)
params.getParameter(DEFAULT_PROXY);
if ((proxy != null) && NO_HOST.equals(proxy)) {
@ -102,9 +100,7 @@ public class ConnRouteParams implements ConnRoutePNames {
*/
public static void setDefaultProxy(HttpParams params,
HttpHost proxy) {
if (params == null) {
throw new IllegalArgumentException("Parameters must not be null.");
}
Args.notNull(params, "Parameters");
params.setParameter(DEFAULT_PROXY, proxy);
}
@ -120,9 +116,7 @@ public class ConnRouteParams implements ConnRoutePNames {
* <code>null</code> if not set
*/
public static HttpRoute getForcedRoute(HttpParams params) {
if (params == null) {
throw new IllegalArgumentException("Parameters must not be null.");
}
Args.notNull(params, "Parameters");
HttpRoute route = (HttpRoute)
params.getParameter(FORCED_ROUTE);
if ((route != null) && NO_ROUTE.equals(route)) {
@ -144,9 +138,7 @@ public class ConnRouteParams implements ConnRoutePNames {
*/
public static void setForcedRoute(HttpParams params,
HttpRoute route) {
if (params == null) {
throw new IllegalArgumentException("Parameters must not be null.");
}
Args.notNull(params, "Parameters");
params.setParameter(FORCED_ROUTE, route);
}
@ -163,9 +155,7 @@ public class ConnRouteParams implements ConnRoutePNames {
* <code>null</code> if not set
*/
public static InetAddress getLocalAddress(HttpParams params) {
if (params == null) {
throw new IllegalArgumentException("Parameters must not be null.");
}
Args.notNull(params, "Parameters");
InetAddress local = (InetAddress)
params.getParameter(LOCAL_ADDRESS);
// no explicit unsetting
@ -181,9 +171,7 @@ public class ConnRouteParams implements ConnRoutePNames {
*/
public static void setLocalAddress(HttpParams params,
InetAddress local) {
if (params == null) {
throw new IllegalArgumentException("Parameters must not be null.");
}
Args.notNull(params, "Parameters");
params.setParameter(LOCAL_ADDRESS, local);
}

View File

@ -28,6 +28,7 @@
package org.apache.http.conn.routing;
import org.apache.http.annotation.Immutable;
import org.apache.http.util.Args;
/**
* Basic implementation of an {@link HttpRouteDirector HttpRouteDirector}.
@ -50,10 +51,7 @@ public class BasicRouteDirector implements HttpRouteDirector {
* 0 is for success, a negative value for failure.
*/
public int nextStep(RouteInfo plan, RouteInfo fact) {
if (plan == null) {
throw new IllegalArgumentException
("Planned route may not be null.");
}
Args.notNull(plan, "Planned route");
int step = UNREACHABLE;

View File

@ -30,6 +30,7 @@ package org.apache.http.conn.routing;
import java.net.InetAddress;
import org.apache.http.annotation.Immutable;
import org.apache.http.util.Args;
import org.apache.http.util.LangUtils;
import org.apache.http.HttpHost;
@ -92,19 +93,14 @@ public final class HttpRoute implements RouteInfo, Cloneable {
HttpHost target, HttpHost[] proxies,
boolean secure,
TunnelType tunnelled, LayerType layered) {
if (target == null) {
throw new IllegalArgumentException
("Target host may not be null.");
Args.notNull(target, "Target host");
Args.notNull(proxies, "Array of proxy hosts");
for (HttpHost proxy: proxies) {
Args.notNull(proxy, "Proxy host");
}
if (proxies == null) {
throw new IllegalArgumentException
("Proxies may not be null.");
if (tunnelled == TunnelType.TUNNELLED) {
Args.check(proxies.length > 0, "Proxy required if tunnelled");
}
if ((tunnelled == TunnelType.TUNNELLED) && (proxies.length == 0)) {
throw new IllegalArgumentException
("Proxy required if tunnelled.");
}
// tunnelled is already checked above, that is in line with the default
if (tunnelled == null)
tunnelled = TunnelType.PLAIN;
@ -205,10 +201,7 @@ public final class HttpRoute implements RouteInfo, Cloneable {
this(local, target, toChain(proxy), secure,
secure ? TunnelType.TUNNELLED : TunnelType.PLAIN,
secure ? LayerType.LAYERED : LayerType.PLAIN);
if (proxy == null) {
throw new IllegalArgumentException
("Proxy host may not be null.");
}
Args.notNull(proxy, "Proxy host");
}
@ -238,13 +231,6 @@ public final class HttpRoute implements RouteInfo, Cloneable {
private static HttpHost[] toChain(HttpHost[] proxies) {
if ((proxies == null) || (proxies.length < 1))
return EMPTY_HTTP_HOST_ARRAY;
for (HttpHost proxy : proxies) {
if (proxy == null)
throw new IllegalArgumentException
("Proxy chain may not contain null elements.");
}
// copy the proxy chain, the traditional way
HttpHost[] result = new HttpHost[proxies.length];
System.arraycopy(proxies, 0, result, 0, proxies.length);
@ -272,14 +258,9 @@ public final class HttpRoute implements RouteInfo, Cloneable {
public final HttpHost getHopTarget(int hop) {
if (hop < 0)
throw new IllegalArgumentException
("Hop index must not be negative: " + hop);
Args.notNegative(hop, "Hop index");
final int hopcount = getHopCount();
if (hop >= hopcount)
throw new IllegalArgumentException
("Hop index " + hop +
" exceeds route length " + hopcount);
Args.check(hop < hopcount, "Hop index exceeds tracked route length");
HttpHost result = null;
if (hop < hopcount-1)

View File

@ -30,6 +30,8 @@ package org.apache.http.conn.routing;
import java.net.InetAddress;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.util.Args;
import org.apache.http.util.Asserts;
import org.apache.http.util.LangUtils;
import org.apache.http.HttpHost;
@ -78,9 +80,7 @@ public final class RouteTracker implements RouteInfo, Cloneable {
* <code>null</code> for the default
*/
public RouteTracker(HttpHost target, InetAddress local) {
if (target == null) {
throw new IllegalArgumentException("Target host may not be null.");
}
Args.notNull(target, "Target host");
this.targetHost = target;
this.localAddress = local;
this.tunnelled = TunnelType.PLAIN;
@ -116,9 +116,7 @@ public final class RouteTracker implements RouteInfo, Cloneable {
* <code>false</code> otherwise
*/
public final void connectTarget(boolean secure) {
if (this.connected) {
throw new IllegalStateException("Already connected.");
}
Asserts.check(!this.connected, "Already connected");
this.connected = true;
this.secure = secure;
}
@ -131,12 +129,8 @@ public final class RouteTracker implements RouteInfo, Cloneable {
* <code>false</code> otherwise
*/
public final void connectProxy(HttpHost proxy, boolean secure) {
if (proxy == null) {
throw new IllegalArgumentException("Proxy host may not be null.");
}
if (this.connected) {
throw new IllegalStateException("Already connected.");
}
Args.notNull(proxy, "Proxy host");
Asserts.check(!this.connected, "Already connected");
this.connected = true;
this.proxyChain = new HttpHost[]{ proxy };
this.secure = secure;
@ -149,12 +143,8 @@ public final class RouteTracker implements RouteInfo, Cloneable {
* <code>false</code> otherwise
*/
public final void tunnelTarget(boolean secure) {
if (!this.connected) {
throw new IllegalStateException("No tunnel unless connected.");
}
if (this.proxyChain == null) {
throw new IllegalStateException("No tunnel without proxy.");
}
Asserts.check(this.connected, "No tunnel unless connected");
Asserts.notNull(this.proxyChain, "No tunnel without proxy");
this.tunnelled = TunnelType.TUNNELLED;
this.secure = secure;
}
@ -169,16 +159,9 @@ public final class RouteTracker implements RouteInfo, Cloneable {
* <code>false</code> otherwise
*/
public final void tunnelProxy(HttpHost proxy, boolean secure) {
if (proxy == null) {
throw new IllegalArgumentException("Proxy host may not be null.");
}
if (!this.connected) {
throw new IllegalStateException("No tunnel unless connected.");
}
if (this.proxyChain == null) {
throw new IllegalStateException("No proxy tunnel without proxy.");
}
Args.notNull(proxy, "Proxy host");
Asserts.check(this.connected, "No tunnel unless connected");
Asserts.notNull(this.proxyChain, "No tunnel without proxy");
// prepare an extended proxy chain
HttpHost[] proxies = new HttpHost[this.proxyChain.length+1];
System.arraycopy(this.proxyChain, 0,
@ -198,10 +181,7 @@ public final class RouteTracker implements RouteInfo, Cloneable {
public final void layerProtocol(boolean secure) {
// it is possible to layer a protocol over a direct connection,
// although this case is probably not considered elsewhere
if (!this.connected) {
throw new IllegalStateException
("No layered protocol unless connected.");
}
Asserts.check(this.connected, "No layered protocol unless connected");
this.layered = LayerType.LAYERED;
this.secure = secure;
}
@ -226,16 +206,9 @@ public final class RouteTracker implements RouteInfo, Cloneable {
}
public final HttpHost getHopTarget(int hop) {
if (hop < 0)
throw new IllegalArgumentException
("Hop index must not be negative: " + hop);
Args.notNegative(hop, "Hop index");
final int hopcount = getHopCount();
if (hop >= hopcount) {
throw new IllegalArgumentException
("Hop index " + hop +
" exceeds tracked route length " + hopcount +".");
}
Args.check(hop < hopcount, "Hop index exceeds tracked route length");
HttpHost result = null;
if (hop < hopcount-1)
result = this.proxyChain[hop];

View File

@ -35,11 +35,11 @@ import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import org.apache.http.annotation.Immutable;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.conn.DnsResolver;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.Args;
/**
* The default class for creating plain (unencrypted) sockets.
@ -100,12 +100,8 @@ public class PlainSocketFactory implements SocketFactory, SchemeSocketFactory {
final InetSocketAddress remoteAddress,
final InetSocketAddress localAddress,
final HttpParams params) throws IOException, ConnectTimeoutException {
if (remoteAddress == null) {
throw new IllegalArgumentException("Remote address may not be null");
}
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
Args.notNull(remoteAddress, "Remote address");
Args.notNull(params, "HTTP parameters");
Socket sock = socket;
if (sock == null) {
sock = createSocket();
@ -134,15 +130,8 @@ public class PlainSocketFactory implements SocketFactory, SchemeSocketFactory {
* @param sock the connected socket
*
* @return <code>false</code>
*
* @throws IllegalArgumentException if the argument is invalid
*/
public final boolean isSecure(Socket sock)
throws IllegalArgumentException {
if (sock == null) {
throw new IllegalArgumentException("Socket may not be null.");
}
public final boolean isSecure(Socket sock) {
return false;
}

View File

@ -31,7 +31,7 @@ import java.util.Locale;
import org.apache.http.annotation.Immutable;
import org.apache.http.config.Registry;
import org.apache.http.conn.SchemePortResolver;
import org.apache.http.util.Args;
import org.apache.http.util.LangUtils;
/**
@ -89,15 +89,9 @@ public final class Scheme {
* @since 4.1
*/
public Scheme(final String name, final int port, final SchemeSocketFactory factory) {
if (name == null) {
throw new IllegalArgumentException("Scheme name may not be null");
}
if ((port <= 0) || (port > 0xffff)) {
throw new IllegalArgumentException("Port is invalid: " + port);
}
if (factory == null) {
throw new IllegalArgumentException("Socket factory may not be null");
}
Args.notNull(name, "Scheme name");
Args.check(port > 0 && port <= 0xffff, "Port is invalid");
Args.notNull(factory, "Socket factory");
this.name = name.toLowerCase(Locale.ENGLISH);
this.defaultPort = port;
if (factory instanceof SchemeLayeredSocketFactory) {
@ -130,18 +124,9 @@ public final class Scheme {
final SocketFactory factory,
final int port) {
if (name == null) {
throw new IllegalArgumentException
("Scheme name may not be null");
}
if (factory == null) {
throw new IllegalArgumentException
("Socket factory may not be null");
}
if ((port <= 0) || (port > 0xffff)) {
throw new IllegalArgumentException
("Port is invalid: " + port);
}
Args.notNull(name, "Scheme name");
Args.notNull(factory, "Socket factory");
Args.check(port > 0 && port <= 0xffff, "Port is invalid");
this.name = name.toLowerCase(Locale.ENGLISH);
if (factory instanceof LayeredSocketFactory) {

View File

@ -31,10 +31,10 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.http.HttpHost;
import org.apache.http.annotation.ThreadSafe;
import org.apache.http.config.Registry;
import org.apache.http.HttpHost;
import org.apache.http.util.Args;
/**
* A set of supported protocol {@link Scheme}s.
@ -90,9 +90,7 @@ public final class SchemeRegistry {
* if a scheme with the respective name is not registered
*/
public final Scheme getScheme(HttpHost host) {
if (host == null) {
throw new IllegalArgumentException("Host must not be null.");
}
Args.notNull(host, "Host");
return getScheme(host.getSchemeName());
}
@ -105,9 +103,7 @@ public final class SchemeRegistry {
* <code>null</code> if there is none by this name
*/
public final Scheme get(String name) {
if (name == null)
throw new IllegalArgumentException("Name must not be null.");
Args.notNull(name, "Scheme name");
// leave it to the caller to use the correct name - all lowercase
//name = name.toLowerCase();
Scheme found = registeredSchemes.get(name);
@ -125,9 +121,7 @@ public final class SchemeRegistry {
* <code>null</code> if none was registered
*/
public final Scheme register(Scheme sch) {
if (sch == null)
throw new IllegalArgumentException("Scheme must not be null.");
Args.notNull(sch, "Scheme");
Scheme old = registeredSchemes.put(sch.getName(), sch);
return old;
}
@ -141,9 +135,7 @@ public final class SchemeRegistry {
* <code>null</code> if there was none
*/
public final Scheme unregister(String name) {
if (name == null)
throw new IllegalArgumentException("Name must not be null.");
Args.notNull(name, "Scheme name");
// leave it to the caller to use the correct name - all lowercase
//name = name.toLowerCase();
Scheme gone = registeredSchemes.remove(name);

View File

@ -27,29 +27,6 @@
package org.apache.http.conn.ssl;
import org.apache.http.HttpHost;
import org.apache.http.annotation.ThreadSafe;
import org.apache.http.config.SocketConfig;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.conn.HttpInetSocketAddress;
import org.apache.http.conn.scheme.HostNameResolver;
import org.apache.http.conn.scheme.LayeredSchemeSocketFactory;
import org.apache.http.conn.scheme.LayeredSocketFactory;
import org.apache.http.conn.scheme.SchemeLayeredSocketFactory;
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 javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@ -67,6 +44,30 @@ import java.security.SecureRandom;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import org.apache.http.HttpHost;
import org.apache.http.annotation.ThreadSafe;
import org.apache.http.config.SocketConfig;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.conn.HttpInetSocketAddress;
import org.apache.http.conn.scheme.HostNameResolver;
import org.apache.http.conn.scheme.LayeredSchemeSocketFactory;
import org.apache.http.conn.scheme.LayeredSocketFactory;
import org.apache.http.conn.scheme.SchemeLayeredSocketFactory;
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;
/**
* Layered socket factory for TLS/SSL connections.
* <p>
@ -477,9 +478,7 @@ public class SSLSocketFactory implements LayeredConnectionSocketFactory, SchemeL
public SSLSocketFactory(
final SSLContext sslContext, final X509HostnameVerifier hostnameVerifier) {
super();
if (sslContext == null) {
throw new IllegalArgumentException("SSL context may not be null");
}
Args.notNull(sslContext, "SSL context");
this.socketfactory = sslContext.getSocketFactory();
this.hostnameVerifier = hostnameVerifier;
this.nameResolver = null;
@ -491,9 +490,7 @@ public class SSLSocketFactory implements LayeredConnectionSocketFactory, SchemeL
public SSLSocketFactory(
final javax.net.ssl.SSLSocketFactory socketfactory,
final X509HostnameVerifier hostnameVerifier) {
if (socketfactory == null) {
throw new IllegalArgumentException("SSL socket factory may not be null");
}
Args.notNull(socketfactory, "SSL socket factory");
this.socketfactory = socketfactory;
this.hostnameVerifier = hostnameVerifier;
this.nameResolver = null;
@ -531,12 +528,8 @@ public class SSLSocketFactory implements LayeredConnectionSocketFactory, SchemeL
final InetSocketAddress remoteAddress,
final InetSocketAddress localAddress,
final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
if (remoteAddress == null) {
throw new IllegalArgumentException("Remote address may not be null");
}
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
Args.notNull(remoteAddress, "Remote address");
Args.notNull(params, "HTTP parameters");
HttpHost host;
if (remoteAddress instanceof HttpInetSocketAddress) {
host = ((HttpInetSocketAddress) remoteAddress).getHttpHost();
@ -565,17 +558,9 @@ public class SSLSocketFactory implements LayeredConnectionSocketFactory, SchemeL
*/
@Deprecated
public boolean isSecure(final Socket sock) throws IllegalArgumentException {
if (sock == null) {
throw new IllegalArgumentException("Socket may not be null");
}
// This instanceof check is in line with createSocket() above.
if (!(sock instanceof SSLSocket)) {
throw new IllegalArgumentException("Socket not created by this factory");
}
// This check is performed last since it calls the argument object.
if (sock.isClosed()) {
throw new IllegalArgumentException("Socket is closed");
}
Args.notNull(sock, "Socket");
Asserts.check(sock instanceof SSLSocket, "Socket not created by this factory");
Asserts.check(!sock.isClosed(), "Socket is closed");
return true;
}
@ -610,9 +595,7 @@ public class SSLSocketFactory implements LayeredConnectionSocketFactory, SchemeL
*/
@Deprecated
public void setHostnameVerifier(X509HostnameVerifier hostnameVerifier) {
if ( hostnameVerifier == null ) {
throw new IllegalArgumentException("Hostname verifier may not be null");
}
Args.notNull(hostnameVerifier, "Hostname verifier");
this.hostnameVerifier = hostnameVerifier;
}
@ -695,12 +678,8 @@ public class SSLSocketFactory implements LayeredConnectionSocketFactory, SchemeL
final InetSocketAddress remoteAddress,
final InetSocketAddress localAddress,
final HttpContext context) throws IOException, ConnectTimeoutException {
if (host == null) {
throw new IllegalArgumentException("HTTP host may not be null");
}
if (remoteAddress == null) {
throw new IllegalArgumentException("Remote address may not be null");
}
Args.notNull(host, "HTTP host");
Args.notNull(remoteAddress, "Remote address");
Socket sock = socket != null ? socket : createSocket(context);
if (localAddress != null) {
sock.bind(localAddress);

View File

@ -29,6 +29,7 @@ package org.apache.http.cookie;
import java.util.Locale;
import org.apache.http.annotation.Immutable;
import org.apache.http.util.Args;
/**
* CookieOrigin class encapsulates details of an origin server that
@ -46,21 +47,9 @@ public final class CookieOrigin {
public CookieOrigin(final String host, int port, final String path, boolean secure) {
super();
if (host == null) {
throw new IllegalArgumentException(
"Host of origin may not be null");
}
if (host.trim().length() == 0) {
throw new IllegalArgumentException(
"Host of origin may not be blank");
}
if (port < 0) {
throw new IllegalArgumentException("Invalid port: " + port);
}
if (path == null) {
throw new IllegalArgumentException(
"Path of origin may not be null.");
}
Args.notBlank(host, "Host");
Args.notNegative(port, "Port");
Args.notNull(path, "Path");
this.host = host.toLowerCase(Locale.ENGLISH);
this.port = port;
if (path.trim().length() != 0) {

View File

@ -40,6 +40,7 @@ import org.apache.http.config.Registry;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
/**
* Cookie specification registry that can be used to obtain the corresponding
@ -73,12 +74,8 @@ public final class CookieSpecRegistry implements Lookup<CookieSpecProvider> {
* @see #getCookieSpec(String)
*/
public void register(final String name, final CookieSpecFactory factory) {
if (name == null) {
throw new IllegalArgumentException("Name may not be null");
}
if (factory == null) {
throw new IllegalArgumentException("Cookie spec factory may not be null");
}
Args.notNull(name, "Name");
Args.notNull(factory, "Cookie spec factory");
registeredSpecs.put(name.toLowerCase(Locale.ENGLISH), factory);
}
@ -88,9 +85,7 @@ public final class CookieSpecRegistry implements Lookup<CookieSpecProvider> {
* @param id the identifier of the {@link CookieSpec cookie specification} to unregister
*/
public void unregister(final String id) {
if (id == null) {
throw new IllegalArgumentException("Id may not be null");
}
Args.notNull(id, "Id");
registeredSpecs.remove(id.toLowerCase(Locale.ENGLISH));
}
@ -108,9 +103,7 @@ public final class CookieSpecRegistry implements Lookup<CookieSpecProvider> {
public CookieSpec getCookieSpec(final String name, final HttpParams params)
throws IllegalStateException {
if (name == null) {
throw new IllegalArgumentException("Name may not be null");
}
Args.notNull(name, "Name");
CookieSpecFactory factory = registeredSpecs.get(name.toLowerCase(Locale.ENGLISH));
if (factory != null) {
return factory.newInstance(params);

View File

@ -28,11 +28,10 @@ package org.apache.http.impl.auth;
import java.util.Locale;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.FormattedHeader;
import org.apache.http.Header;
import org.apache.http.HttpRequest;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.auth.AUTH;
import org.apache.http.auth.AuthenticationException;
import org.apache.http.auth.ChallengeState;
@ -41,6 +40,7 @@ import org.apache.http.auth.Credentials;
import org.apache.http.auth.MalformedChallengeException;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
import org.apache.http.util.CharArrayBuffer;
/**
@ -86,9 +86,7 @@ public abstract class AuthSchemeBase implements ContextAwareAuthScheme {
* is malformed
*/
public void processChallenge(final Header header) throws MalformedChallengeException {
if (header == null) {
throw new IllegalArgumentException("Header may not be null");
}
Args.notNull(header, "Header");
String authheader = header.getName();
if (authheader.equalsIgnoreCase(AUTH.WWW_AUTH)) {
this.challengeState = ChallengeState.TARGET;

View File

@ -28,22 +28,22 @@ package org.apache.http.impl.auth;
import java.nio.charset.Charset;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.commons.codec.binary.Base64;
import org.apache.http.Consts;
import org.apache.http.Header;
import org.apache.http.HttpRequest;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.auth.AUTH;
import org.apache.http.auth.AuthenticationException;
import org.apache.http.auth.ChallengeState;
import org.apache.http.auth.ContextAwareAuthScheme;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.AUTH;
import org.apache.http.auth.InvalidCredentialsException;
import org.apache.http.auth.MalformedChallengeException;
import org.apache.http.message.BufferedHeader;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
import org.apache.http.util.CharArrayBuffer;
import org.apache.http.util.EncodingUtils;
@ -153,12 +153,8 @@ public class BasicScheme extends RFC2617Scheme {
final HttpRequest request,
final HttpContext context) throws AuthenticationException {
if (credentials == null) {
throw new IllegalArgumentException("Credentials may not be null");
}
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
}
Args.notNull(credentials, "Credentials");
Args.notNull(request, "HTTP request");
StringBuilder tmp = new StringBuilder();
tmp.append(credentials.getUserPrincipal().getName());
tmp.append(":");
@ -195,12 +191,8 @@ public class BasicScheme extends RFC2617Scheme {
final Credentials credentials,
final String charset,
boolean proxy) {
if (credentials == null) {
throw new IllegalArgumentException("Credentials may not be null");
}
if (charset == null) {
throw new IllegalArgumentException("charset may not be null");
}
Args.notNull(credentials, "Credentials");
Args.notNull(charset, "charset");
StringBuilder tmp = new StringBuilder();
tmp.append(credentials.getUserPrincipal().getName());

View File

@ -38,24 +38,24 @@ import java.util.Locale;
import java.util.Set;
import java.util.StringTokenizer;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.Consts;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpRequest;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.auth.AUTH;
import org.apache.http.auth.AuthenticationException;
import org.apache.http.auth.ChallengeState;
import org.apache.http.auth.ContextAwareAuthScheme;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.AUTH;
import org.apache.http.auth.MalformedChallengeException;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.message.BasicHeaderValueFormatter;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.message.BufferedHeader;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
import org.apache.http.util.CharArrayBuffer;
import org.apache.http.util.EncodingUtils;
@ -206,12 +206,8 @@ public class DigestScheme extends RFC2617Scheme {
final HttpRequest request,
final HttpContext context) throws AuthenticationException {
if (credentials == null) {
throw new IllegalArgumentException("Credentials may not be null");
}
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
}
Args.notNull(credentials, "Credentials");
Args.notNull(request, "HTTP request");
if (getParameter("realm") == null) {
throw new AuthenticationException("missing realm in challenge");
}

View File

@ -40,6 +40,7 @@ import org.apache.http.client.protocol.ClientContext;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.message.BasicHeader;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
import org.apache.http.util.CharArrayBuffer;
import org.ietf.jgss.GSSContext;
import org.ietf.jgss.GSSException;
@ -122,9 +123,7 @@ public abstract class GGSSchemeBase extends AuthSchemeBase {
final Credentials credentials,
final HttpRequest request,
final HttpContext context) throws AuthenticationException {
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
}
Args.notNull(request, "HTTP request");
switch (state) {
case UNINITIATED:
throw new AuthenticationException(getSchemeName() + " authentication has not been initiated");

View File

@ -30,6 +30,7 @@ import org.apache.http.HttpRequest;
import org.apache.http.auth.AuthenticationException;
import org.apache.http.auth.Credentials;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
import org.ietf.jgss.GSSException;
import org.ietf.jgss.Oid;
@ -86,9 +87,7 @@ public class KerberosScheme extends GGSSchemeBase {
* @return <code>null</code>
*/
public String getParameter(String name) {
if (name == null) {
throw new IllegalArgumentException("Parameter name may not be null");
}
Args.notNull(name, "Parameter name");
return null;
}

View File

@ -26,18 +26,17 @@
package org.apache.http.impl.auth;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.Header;
import org.apache.http.HttpRequest;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.auth.AUTH;
import org.apache.http.auth.AuthenticationException;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.InvalidCredentialsException;
import org.apache.http.auth.MalformedChallengeException;
import org.apache.http.auth.NTCredentials;
import org.apache.http.impl.auth.AuthSchemeBase;
import org.apache.http.message.BufferedHeader;
import org.apache.http.util.Args;
import org.apache.http.util.CharArrayBuffer;
/**
@ -65,9 +64,7 @@ public class NTLMScheme extends AuthSchemeBase {
public NTLMScheme(final NTLMEngine engine) {
super();
if (engine == null) {
throw new IllegalArgumentException("NTLM engine may not be null");
}
Args.notNull(engine, "NTLM engine");
this.engine = engine;
this.state = State.UNINITIATED;
this.challenge = null;

View File

@ -34,6 +34,7 @@ import org.apache.http.HttpRequest;
import org.apache.http.auth.AuthenticationException;
import org.apache.http.auth.Credentials;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
import org.ietf.jgss.GSSException;
import org.ietf.jgss.Oid;
@ -175,9 +176,7 @@ public class NegotiateScheme extends GGSSchemeBase {
* @return the parameter with the given name
*/
public String getParameter(String name) {
if (name == null) {
throw new IllegalArgumentException("Parameter name may not be null");
}
Args.notNull(name, "Parameter name");
return null;
}

View File

@ -30,6 +30,7 @@ import org.apache.http.HttpRequest;
import org.apache.http.auth.AuthenticationException;
import org.apache.http.auth.Credentials;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
import org.ietf.jgss.GSSException;
import org.ietf.jgss.Oid;
@ -87,9 +88,7 @@ public class SPNegoScheme extends GGSSchemeBase {
* @return <code>null</code>
*/
public String getParameter(String name) {
if (name == null) {
throw new IllegalArgumentException("Parameter name may not be null");
}
Args.notNull(name, "Parameter name");
return null;
}

View File

@ -31,6 +31,7 @@ import java.util.Map;
import org.apache.http.client.BackoffManager;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.pool.ConnPoolControl;
import org.apache.http.util.Args;
/**
* <p>The <code>AIMDBackoffManager</code> applies an additive increase,
@ -126,9 +127,7 @@ public class AIMDBackoffManager implements BackoffManager {
* @param d must be between 0.0 and 1.0, exclusive.
*/
public void setBackoffFactor(double d) {
if (d <= 0.0 || d >= 1.0) {
throw new IllegalArgumentException("backoffFactor must be 0.0 < f < 1.0");
}
Args.check(d > 0.0 && d < 1.0, "Backoff factor must be 0.0 < f < 1.0");
backoffFactor = d;
}
@ -140,9 +139,7 @@ public class AIMDBackoffManager implements BackoffManager {
* @param l must be positive
*/
public void setCooldownMillis(long l) {
if (coolDown <= 0) {
throw new IllegalArgumentException("cooldownMillis must be positive");
}
Args.positive(coolDown, "Cool down");
coolDown = l;
}
@ -152,9 +149,7 @@ public class AIMDBackoffManager implements BackoffManager {
* @param cap must be >= 1
*/
public void setPerHostConnectionCap(int cap) {
if (cap < 1) {
throw new IllegalArgumentException("perHostConnectionCap must be >= 1");
}
Args.positive(cap, "Per host connection cap");
this.cap = cap;
}

View File

@ -51,6 +51,7 @@ import org.apache.http.client.params.AuthPolicy;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Asserts;
import org.apache.http.util.CharArrayBuffer;
/**
@ -142,10 +143,7 @@ public abstract class AbstractAuthenticationHandler implements AuthenticationHan
AuthSchemeRegistry registry = (AuthSchemeRegistry) context.getAttribute(
ClientContext.AUTHSCHEME_REGISTRY);
if (registry == null) {
throw new IllegalStateException("AuthScheme registry not set in HTTP context");
}
Asserts.notNull(registry, "AuthScheme registry");
Collection<String> authPrefs = getAuthPreferences(response, context);
if (authPrefs == null) {
authPrefs = DEFAULT_SCHEME_PRIORITY;

View File

@ -89,6 +89,7 @@ import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.HttpRequestExecutor;
import org.apache.http.protocol.ImmutableHttpProcessor;
import org.apache.http.util.Args;
/**
* Base class for {@link HttpClient} implementations. This class acts as
@ -780,10 +781,7 @@ public abstract class AbstractHttpClient extends CloseableHttpClient {
HttpContext context)
throws IOException, ClientProtocolException {
if (request == null) {
throw new IllegalArgumentException
("Request must not be null.");
}
Args.notNull(request, "HTTP request");
// a null target may be acceptable, this depends on the route planner
// a null context is acceptable, default context created below

View File

@ -51,6 +51,7 @@ import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.params.AuthPolicy;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
/**
* @deprecated (4.2) do not use
@ -87,18 +88,10 @@ class AuthenticationStrategyAdaptor implements AuthenticationStrategy {
final HttpHost authhost,
final HttpResponse response,
final HttpContext context) throws MalformedChallengeException {
if (challenges == null) {
throw new IllegalArgumentException("Map of auth challenges may not be null");
}
if (authhost == null) {
throw new IllegalArgumentException("Host may not be null");
}
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
if (context == null) {
throw new IllegalArgumentException("HTTP context may not be null");
}
Args.notNull(challenges, "Map of auth challenges");
Args.notNull(authhost, "Host");
Args.notNull(response, "HTTP response");
Args.notNull(context, "HTTP context");
Queue<AuthOption> options = new LinkedList<AuthOption>();
CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(

View File

@ -59,6 +59,7 @@ import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.config.Lookup;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
import org.apache.http.util.CharArrayBuffer;
@Immutable
@ -88,9 +89,7 @@ abstract class AuthenticationStrategyImpl implements AuthenticationStrategy {
final HttpHost authhost,
final HttpResponse response,
final HttpContext context) {
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
Args.notNull(response, "HTTP response");
int status = response.getStatusLine().getStatusCode();
return status == this.challengeCode;
}
@ -99,9 +98,7 @@ abstract class AuthenticationStrategyImpl implements AuthenticationStrategy {
final HttpHost authhost,
final HttpResponse response,
final HttpContext context) throws MalformedChallengeException {
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
Args.notNull(response, "HTTP response");
Header[] headers = response.getHeaders(this.headerName);
Map<String, Header> map = new HashMap<String, Header>(headers.length);
for (Header header : headers) {
@ -140,18 +137,10 @@ abstract class AuthenticationStrategyImpl implements AuthenticationStrategy {
final HttpHost authhost,
final HttpResponse response,
final HttpContext context) throws MalformedChallengeException {
if (challenges == null) {
throw new IllegalArgumentException("Map of auth challenges may not be null");
}
if (authhost == null) {
throw new IllegalArgumentException("Host may not be null");
}
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
if (context == null) {
throw new IllegalArgumentException("HTTP context may not be null");
}
Args.notNull(challenges, "Map of auth challenges");
Args.notNull(authhost, "Host");
Args.notNull(response, "HTTP response");
Args.notNull(context, "HTTP context");
HttpClientContext clientContext = HttpClientContext.adapt(context);
Queue<AuthOption> options = new LinkedList<AuthOption>();
@ -210,15 +199,9 @@ abstract class AuthenticationStrategyImpl implements AuthenticationStrategy {
public void authSucceeded(
final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) {
if (authhost == null) {
throw new IllegalArgumentException("Host may not be null");
}
if (authScheme == null) {
throw new IllegalArgumentException("Auth scheme may not be null");
}
if (context == null) {
throw new IllegalArgumentException("HTTP context may not be null");
}
Args.notNull(authhost, "Host");
Args.notNull(authScheme, "Auth scheme");
Args.notNull(context, "HTTP context");
HttpClientContext clientContext = HttpClientContext.adapt(context);
@ -247,12 +230,8 @@ abstract class AuthenticationStrategyImpl implements AuthenticationStrategy {
public void authFailed(
final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) {
if (authhost == null) {
throw new IllegalArgumentException("Host may not be null");
}
if (context == null) {
throw new IllegalArgumentException("HTTP context may not be null");
}
Args.notNull(authhost, "Host");
Args.notNull(context, "HTTP context");
HttpClientContext clientContext = HttpClientContext.adapt(context);

View File

@ -44,6 +44,7 @@ import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
import org.apache.http.util.EntityUtils;
/**
@ -67,13 +68,8 @@ public class AutoRetryHttpClient implements HttpClient {
public AutoRetryHttpClient(
final HttpClient client, final ServiceUnavailableRetryStrategy retryStrategy) {
super();
if (client == null) {
throw new IllegalArgumentException("HttpClient may not be null");
}
if (retryStrategy == null) {
throw new IllegalArgumentException(
"ServiceUnavailableRetryStrategy may not be null");
}
Args.notNull(client, "HttpClient");
Args.notNull(retryStrategy, "ServiceUnavailableRetryStrategy");
this.backend = client;
this.retryStrategy = retryStrategy;
}

View File

@ -34,6 +34,7 @@ import org.apache.http.auth.AuthScheme;
import org.apache.http.client.AuthCache;
import org.apache.http.conn.SchemePortResolver;
import org.apache.http.impl.conn.DefaultSchemePortResolver;
import org.apache.http.util.Args;
/**
* Default implementation of {@link AuthCache}.
@ -74,23 +75,17 @@ public class BasicAuthCache implements AuthCache {
}
public void put(final HttpHost host, final AuthScheme authScheme) {
if (host == null) {
throw new IllegalArgumentException("HTTP host may not be null");
}
Args.notNull(host, "HTTP host");
this.map.put(getKey(host), authScheme);
}
public AuthScheme get(final HttpHost host) {
if (host == null) {
throw new IllegalArgumentException("HTTP host may not be null");
}
Args.notNull(host, "HTTP host");
return this.map.get(getKey(host));
}
public void remove(final HttpHost host) {
if (host == null) {
throw new IllegalArgumentException("HTTP host may not be null");
}
Args.notNull(host, "HTTP host");
this.map.remove(getKey(host));
}

View File

@ -30,10 +30,10 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.http.annotation.ThreadSafe;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.util.Args;
/**
* Default implementation of {@link CredentialsProvider}.
@ -56,9 +56,7 @@ public class BasicCredentialsProvider implements CredentialsProvider {
public void setCredentials(
final AuthScope authscope,
final Credentials credentials) {
if (authscope == null) {
throw new IllegalArgumentException("Authentication scope may not be null");
}
Args.notNull(authscope, "Authentication scope");
credMap.put(authscope, credentials);
}
@ -95,9 +93,7 @@ public class BasicCredentialsProvider implements CredentialsProvider {
}
public Credentials getCredentials(final AuthScope authscope) {
if (authscope == null) {
throw new IllegalArgumentException("Authentication scope may not be null");
}
Args.notNull(authscope, "Authentication scope");
return matchCredentials(this.credMap, authscope);
}

View File

@ -32,6 +32,7 @@ import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.params.DefaultedHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.AbstractHttpParams;
import org.apache.http.util.Args;
/**
* Represents a stack of parameter collections.
@ -190,10 +191,7 @@ public class ClientParamsStack extends AbstractHttpParams {
* <code>null</code> if it is not set anywhere in this stack
*/
public Object getParameter(String name) {
if (name == null) {
throw new IllegalArgumentException
("Parameter name must not be null.");
}
Args.notNull(name, "Parameter name");
Object result = null;

View File

@ -46,6 +46,7 @@ import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.utils.URIUtils;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
import org.apache.http.util.EntityUtils;
/**
@ -71,9 +72,7 @@ public abstract class CloseableHttpClient implements HttpClient, Closeable {
public CloseableHttpResponse execute(
final HttpUriRequest request,
final HttpContext context) throws IOException, ClientProtocolException {
if (request == null) {
throw new IllegalArgumentException("Request must not be null.");
}
Args.notNull(request, "HTTP request");
return doExecute(determineTarget(request), request, context);
}
@ -126,9 +125,7 @@ public abstract class CloseableHttpClient implements HttpClient, Closeable {
public <T> T execute(final HttpHost target, final HttpRequest request,
final ResponseHandler<? extends T> responseHandler, final HttpContext context)
throws IOException, ClientProtocolException {
if (responseHandler == null) {
throw new IllegalArgumentException("Response handler must not be null.");
}
Args.notNull(responseHandler, "Response handler");
HttpResponse response = execute(target, request, context);

View File

@ -26,15 +26,15 @@
*/
package org.apache.http.impl.client;
import org.apache.http.annotation.Immutable;
import org.apache.http.HeaderElement;
import org.apache.http.HeaderElementIterator;
import org.apache.http.HttpResponse;
import org.apache.http.annotation.Immutable;
import org.apache.http.conn.ConnectionKeepAliveStrategy;
import org.apache.http.message.BasicHeaderElementIterator;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
/**
* Default implementation of a strategy deciding duration
@ -51,9 +51,7 @@ public class DefaultConnectionKeepAliveStrategy implements ConnectionKeepAliveSt
public static final DefaultConnectionKeepAliveStrategy INSTANCE = new DefaultConnectionKeepAliveStrategy();
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
Args.notNull(response, "HTTP response");
HeaderElementIterator it = new BasicHeaderElementIterator(
response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {

View File

@ -34,14 +34,14 @@ import java.net.UnknownHostException;
import javax.net.ssl.SSLException;
import org.apache.http.annotation.Immutable;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpRequest;
import org.apache.http.annotation.Immutable;
import org.apache.http.client.HttpRequestRetryHandler;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
/**
* The default {@link HttpRequestRetryHandler} used by request executors.
@ -82,12 +82,8 @@ public class DefaultHttpRequestRetryHandler implements HttpRequestRetryHandler {
final IOException exception,
int executionCount,
final HttpContext context) {
if (exception == null) {
throw new IllegalArgumentException("Exception parameter may not be null");
}
if (context == null) {
throw new IllegalArgumentException("HTTP context may not be null");
}
Args.notNull(exception, "Exception parameter");
Args.notNull(context, "HTTP context");
if (executionCount > this.retryCount) {
// Do not retry if over max retry count
return false;

View File

@ -30,16 +30,16 @@ package org.apache.http.impl.client;
import java.util.List;
import java.util.Map;
import org.apache.http.annotation.Immutable;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.annotation.Immutable;
import org.apache.http.auth.AUTH;
import org.apache.http.auth.MalformedChallengeException;
import org.apache.http.auth.params.AuthPNames;
import org.apache.http.client.AuthenticationHandler;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
/**
* Default {@link AuthenticationHandler} implementation for proxy host
@ -60,9 +60,7 @@ public class DefaultProxyAuthenticationHandler extends AbstractAuthenticationHan
public boolean isAuthenticationRequested(
final HttpResponse response,
final HttpContext context) {
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
Args.notNull(response, "HTTP response");
int status = response.getStatusLine().getStatusCode();
return status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED;
}
@ -70,9 +68,7 @@ public class DefaultProxyAuthenticationHandler extends AbstractAuthenticationHan
public Map<String, Header> getChallenges(
final HttpResponse response,
final HttpContext context) throws MalformedChallengeException {
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
Args.notNull(response, "HTTP response");
Header[] headers = response.getHeaders(AUTH.PROXY_AUTH);
return parseChallenges(headers);
}

View File

@ -30,8 +30,6 @@ package org.apache.http.impl.client;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.http.annotation.Immutable;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.Header;
@ -40,6 +38,7 @@ import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.ProtocolException;
import org.apache.http.annotation.Immutable;
import org.apache.http.client.CircularRedirectException;
import org.apache.http.client.RedirectHandler;
import org.apache.http.client.methods.HttpGet;
@ -47,8 +46,10 @@ import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.client.utils.URIUtils;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
import org.apache.http.util.Asserts;
/**
* Default implementation of {@link RedirectHandler}.
@ -72,9 +73,7 @@ public class DefaultRedirectHandler implements RedirectHandler {
public boolean isRedirectRequested(
final HttpResponse response,
final HttpContext context) {
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
Args.notNull(response, "HTTP response");
int statusCode = response.getStatusLine().getStatusCode();
switch (statusCode) {
@ -96,9 +95,7 @@ public class DefaultRedirectHandler implements RedirectHandler {
public URI getLocationURI(
final HttpResponse response,
final HttpContext context) throws ProtocolException {
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
Args.notNull(response, "HTTP response");
//get the location header to find out where to redirect to
Header locationHeader = response.getFirstHeader("location");
if (locationHeader == null) {
@ -130,10 +127,7 @@ public class DefaultRedirectHandler implements RedirectHandler {
// Adjust location URI
HttpHost target = (HttpHost) context.getAttribute(
ExecutionContext.HTTP_TARGET_HOST);
if (target == null) {
throw new IllegalStateException("Target host not available " +
"in the HTTP context");
}
Asserts.notNull(target, "Target host");
HttpRequest request = (HttpRequest) context.getAttribute(
ExecutionContext.HTTP_REQUEST);

View File

@ -50,6 +50,8 @@ import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.client.utils.URIUtils;
import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
import org.apache.http.util.Asserts;
/**
* Default implementation of {@link RedirectStrategy}. This strategy honors the restrictions
@ -90,12 +92,8 @@ public class DefaultRedirectStrategy implements RedirectStrategy {
final HttpRequest request,
final HttpResponse response,
final HttpContext context) throws ProtocolException {
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
}
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
Args.notNull(request, "HTTP request");
Args.notNull(response, "HTTP response");
int statusCode = response.getStatusLine().getStatusCode();
String method = request.getRequestLine().getMethod();
@ -117,15 +115,9 @@ public class DefaultRedirectStrategy implements RedirectStrategy {
final HttpRequest request,
final HttpResponse response,
final HttpContext context) throws ProtocolException {
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
}
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
if (context == null) {
throw new IllegalArgumentException("HTTP context may not be null");
}
Args.notNull(request, "HTTP request");
Args.notNull(response, "HTTP response");
Args.notNull(context, "HTTP context");
HttpClientContext clientContext = HttpClientContext.adapt(context);
@ -158,10 +150,7 @@ public class DefaultRedirectStrategy implements RedirectStrategy {
}
// Adjust location URI
HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
if (target == null) {
throw new IllegalStateException("Target host not available " +
"in the HTTP context");
}
Asserts.notNull(target, "Target host");
URI requestURI = new URI(request.getRequestLine().getUri());
URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, target, true);
uri = URIUtils.resolve(absoluteRequestURI, uri);

View File

@ -85,6 +85,8 @@ import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.HttpRequestExecutor;
import org.apache.http.util.Args;
import org.apache.http.util.Asserts;
import org.apache.http.util.EntityUtils;
/**
@ -266,58 +268,19 @@ public class DefaultRequestDirector implements RequestDirector {
final UserTokenHandler userTokenHandler,
final HttpParams params) {
if (log == null) {
throw new IllegalArgumentException
("Log may not be null.");
}
if (requestExec == null) {
throw new IllegalArgumentException
("Request executor may not be null.");
}
if (conman == null) {
throw new IllegalArgumentException
("Client connection manager may not be null.");
}
if (reustrat == null) {
throw new IllegalArgumentException
("Connection reuse strategy may not be null.");
}
if (kastrat == null) {
throw new IllegalArgumentException
("Connection keep alive strategy may not be null.");
}
if (rouplan == null) {
throw new IllegalArgumentException
("Route planner may not be null.");
}
if (httpProcessor == null) {
throw new IllegalArgumentException
("HTTP protocol processor may not be null.");
}
if (retryHandler == null) {
throw new IllegalArgumentException
("HTTP request retry handler may not be null.");
}
if (redirectStrategy == null) {
throw new IllegalArgumentException
("Redirect 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.");
}
if (params == null) {
throw new IllegalArgumentException
("HTTP parameters may not be null");
}
Args.notNull(log, "Log");
Args.notNull(requestExec, "Request executor");
Args.notNull(conman, "Client connection manager");
Args.notNull(reustrat, "Connection reuse strategy");
Args.notNull(kastrat, "Connection keep alive strategy");
Args.notNull(rouplan, "Route planner");
Args.notNull(httpProcessor, "HTTP protocol processor");
Args.notNull(retryHandler, "HTTP request retry handler");
Args.notNull(redirectStrategy, "Redirect strategy");
Args.notNull(targetAuthStrategy, "Target authentication strategy");
Args.notNull(proxyAuthStrategy, "Proxy authentication strategy");
Args.notNull(userTokenHandler, "User token handler");
Args.notNull(params, "HTTP parameters");
this.log = log;
this.authenticator = new HttpAuthenticator(log);
this.requestExec = requestExec;
@ -780,11 +743,7 @@ public class DefaultRequestDirector implements RequestDirector {
target = (HttpHost) request.getParams().getParameter(
ClientPNames.DEFAULT_HOST);
}
if (target == null) {
throw new IllegalStateException
("Target host must not be null, or set in parameters.");
}
Asserts.notNull(target, "Target host");
return this.routePlanner.determineRoute(target, request, context);
}

View File

@ -32,6 +32,7 @@ import org.apache.http.HttpStatus;
import org.apache.http.annotation.Immutable;
import org.apache.http.client.ServiceUnavailableRetryStrategy;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
/**
* Default implementation of the {@link ServiceUnavailableRetryStrategy} interface.
@ -57,12 +58,8 @@ public class DefaultServiceUnavailableRetryStrategy implements ServiceUnavailabl
public DefaultServiceUnavailableRetryStrategy(int maxRetries, int retryInterval) {
super();
if (maxRetries < 1) {
throw new IllegalArgumentException("MaxRetries must be greater than 1");
}
if (retryInterval < 1) {
throw new IllegalArgumentException("Retry interval must be greater than 1");
}
Args.positive(maxRetries, "Max retries");
Args.positive(retryInterval, "Retry interval");
this.maxRetries = maxRetries;
this.retryInterval = retryInterval;
}

View File

@ -30,16 +30,16 @@ package org.apache.http.impl.client;
import java.util.List;
import java.util.Map;
import org.apache.http.annotation.Immutable;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.annotation.Immutable;
import org.apache.http.auth.AUTH;
import org.apache.http.auth.MalformedChallengeException;
import org.apache.http.auth.params.AuthPNames;
import org.apache.http.client.AuthenticationHandler;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
/**
* Default {@link AuthenticationHandler} implementation for target host
@ -60,9 +60,7 @@ public class DefaultTargetAuthenticationHandler extends AbstractAuthenticationHa
public boolean isAuthenticationRequested(
final HttpResponse response,
final HttpContext context) {
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
Args.notNull(response, "HTTP response");
int status = response.getStatusLine().getStatusCode();
return status == HttpStatus.SC_UNAUTHORIZED;
}
@ -70,9 +68,7 @@ public class DefaultTargetAuthenticationHandler extends AbstractAuthenticationHa
public Map<String, Header> getChallenges(
final HttpResponse response,
final HttpContext context) throws MalformedChallengeException {
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
Args.notNull(response, "HTTP response");
Header[] headers = response.getHeaders(AUTH.WWW_AUTH);
return parseChallenges(headers);
}

View File

@ -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")

View File

@ -62,6 +62,8 @@ import org.apache.http.params.BasicHttpParams;
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 CloseableHttpClient {
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 CloseableHttpClient {
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 CloseableHttpClient {
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;

View File

@ -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 AbstractHttpMessage implements HttpUriReques
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 AbstractHttpMessage implements HttpUriReques
}
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;
}

View File

@ -39,6 +39,7 @@ import org.apache.http.client.methods.HttpExecutionAware;
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 implements ClientExecChain {
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 implements ClientExecChain {
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);

View File

@ -74,6 +74,7 @@ import org.apache.http.protocol.HttpProcessor;
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 ClientExecChain {
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 ClientExecChain {
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) {

View File

@ -51,6 +51,7 @@ 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;
/**
* @since 4.3
@ -67,12 +68,8 @@ public class ProtocolExec implements ClientExecChain {
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 ClientExecChain {
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();

View File

@ -50,6 +50,7 @@ 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.conn.routing.HttpRoutePlanner;
import org.apache.http.util.Args;
import org.apache.http.util.EntityUtils;
/**
@ -69,15 +70,9 @@ public class RedirectExec implements ClientExecChain {
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 ClientExecChain {
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;

View File

@ -41,6 +41,7 @@ import org.apache.http.client.methods.HttpExecutionAware;
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 ClientExecChain {
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 ClientExecChain {
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 {

View File

@ -40,6 +40,7 @@ import org.apache.http.client.methods.HttpExecutionAware;
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 implements ClientExecChain {
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;
}

View File

@ -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

View File

@ -43,6 +43,8 @@ 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.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 BasicClientConnectionManager implements ClientConnectionManager {
* @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 BasicClientConnectionManager implements ClientConnectionManager {
}
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 BasicClientConnectionManager implements ClientConnectionManager {
}
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 BasicClientConnectionManager implements ClientConnectionManager {
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 BasicClientConnectionManager implements ClientConnectionManager {
}
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);

View File

@ -55,6 +55,8 @@ import org.apache.http.conn.socket.ConnectionSocketFactory;
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 BasicHttpClientConnectionManager implements HttpClientConnectionMan
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 BasicHttpClientConnectionManager implements HttpClientConnectionMan
}
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 BasicHttpClientConnectionManager implements HttpClientConnectionMan
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 BasicHttpClientConnectionManager implements HttpClientConnectionMan
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 BasicHttpClientConnectionManager implements HttpClientConnectionMan
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 BasicHttpClientConnectionManager implements HttpClientConnectionMan
}
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;
}

View File

@ -50,6 +50,7 @@ import org.apache.http.params.BasicHttpParams;
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 extends SocketHttpClientConnection
}
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 extends SocketHttpClientConnection
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;

View File

@ -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 DefaultClientConnectionOperator implements ClientConnectionOperator
* @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 DefaultClientConnectionOperator implements ClientConnectionOperator
* 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 DefaultClientConnectionOperator implements ClientConnectionOperator
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 DefaultClientConnectionOperator implements ClientConnectionOperator
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 {

View File

@ -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.HttpResponseFactory;
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.BasicLineParser;
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 extends AbstractMessageParser<HttpRespons
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);
}

View File

@ -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 implements HttpRoutePlanner {
* @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 implements HttpRoutePlanner {
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 implements HttpRoutePlanner {
// 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());

View File

@ -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.HttpResponseFactory;
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 extends AbstractMessageParser<HttpMessage> {
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);

View File

@ -40,6 +40,7 @@ import org.apache.http.conn.params.ConnRouteParams;
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 implements HttpRoutePlanner {
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());

View File

@ -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 implements SchemePortResolver {
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;

View File

@ -50,6 +50,8 @@ import org.apache.http.conn.socket.ConnectionSocketFactory;
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 {

View File

@ -35,6 +35,7 @@ import java.util.concurrent.ConcurrentHashMap;
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 implements DnsResolver {
* 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);
}

View File

@ -50,6 +50,8 @@ 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;
/**
* @since 4.2
@ -71,15 +73,9 @@ class ManagedClientConnectionImpl implements ManagedClientConnection {
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 implements ManagedClientConnection {
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 implements ManagedClientConnection {
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 implements ManagedClientConnection {
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 implements ManagedClientConnection {
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 implements ManagedClientConnection {
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 implements ManagedClientConnection {
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();
}

View File

@ -35,19 +35,19 @@ import java.util.concurrent.TimeoutException;
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 PoolingClientConnectionManager implements ClientConnectionManager,
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 PoolingClientConnectionManager implements ClientConnectionManager,
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 PoolingClientConnectionManager implements ClientConnectionManager,
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 PoolingClientConnectionManager implements ClientConnectionManager,
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) {

View File

@ -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 PoolingHttpClientConnectionManager implements HttpClientConnectionM
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 PoolingHttpClientConnectionManager implements HttpClientConnectionM
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 PoolingHttpClientConnectionManager implements HttpClientConnectionM
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 PoolingHttpClientConnectionManager implements HttpClientConnectionM
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 PoolingHttpClientConnectionManager implements HttpClientConnectionM
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);

View File

@ -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 implements HttpRoutePlanner {
*/
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 implements HttpRoutePlanner {
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 implements HttpRoutePlanner {
// 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 implements HttpRoutePlanner {
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;

View File

@ -43,6 +43,8 @@ import org.apache.http.conn.routing.HttpRoute;
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 implements ClientConnectionManager {
* @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 implements ClientConnectionManager {
* @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 implements ClientConnectionManager {
* 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 implements ClientConnectionManager {
}
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 implements ClientConnectionManager {
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 implements ClientConnectionManager {
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 implements ClientConnectionManager {
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()) {

Some files were not shown because too many files have changed in this diff Show More