HTTPCLIENT-770: code cleanups

Contributed by Paul Lindner <lindner at inuus.com>

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@653041 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2008-05-03 10:39:28 +00:00
parent 257a0ee548
commit aff60e4629
45 changed files with 123 additions and 154 deletions

View File

@ -133,9 +133,9 @@ public class UsernamePasswordCredentials implements Credentials {
*/ */
@Override @Override
public String toString() { public String toString() {
StringBuffer result = new StringBuffer(); StringBuilder result = new StringBuilder();
result.append(this.userName); result.append(this.userName);
result.append(":"); result.append(':');
result.append((this.password == null) ? "null" : this.password); result.append((this.password == null) ? "null" : this.password);
return result.toString(); return result.toString();
} }

View File

@ -45,13 +45,13 @@ import org.apache.http.auth.Credentials;
public class AuthState { public class AuthState {
/** Actual authentication scheme */ /** Actual authentication scheme */
private AuthScheme authScheme = null; private AuthScheme authScheme;
/** Actual authentication scope */ /** Actual authentication scope */
private AuthScope authScope = null; private AuthScope authScope;
/** Credentials selected for authentication */ /** Credentials selected for authentication */
private Credentials credentials = null; private Credentials credentials;
/** /**
* Default constructor. * Default constructor.

View File

@ -48,7 +48,7 @@ import org.apache.http.protocol.HTTP;
abstract class HttpEntityEnclosingRequestBase abstract class HttpEntityEnclosingRequestBase
extends HttpRequestBase implements HttpEntityEnclosingRequest { extends HttpRequestBase implements HttpEntityEnclosingRequest {
private HttpEntity entity = null; private HttpEntity entity;
public HttpEntityEnclosingRequestBase() { public HttpEntityEnclosingRequestBase() {
super(); super();

View File

@ -93,8 +93,8 @@ public class HttpOptions extends HttpRequestBase {
while (it.hasNext()) { while (it.hasNext()) {
Header header = it.nextHeader(); Header header = it.nextHeader();
HeaderElement[] elements = header.getElements(); HeaderElement[] elements = header.getElements();
for (int i = 0; i < elements.length; i++) { for (HeaderElement element : elements) {
methods.add(elements[i].getName()); methods.add(element.getName());
} }
} }
return methods; return methods;

View File

@ -149,8 +149,7 @@ public class RequestAddCookies implements HttpRequestInterceptor {
List<Cookie> cookies = cookieStore.getCookies(); List<Cookie> cookies = cookieStore.getCookies();
// Find cookies matching the given origin // Find cookies matching the given origin
List<Cookie> matchedCookies = new ArrayList<Cookie>(); List<Cookie> matchedCookies = new ArrayList<Cookie>();
for (int i = 0; i < cookies.size(); i++) { for (Cookie cookie : cookies) {
Cookie cookie = cookies.get(i);
if (cookieSpec.match(cookie, cookieOrigin)) { if (cookieSpec.match(cookie, cookieOrigin)) {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("Cookie " + cookie + " match " + cookieOrigin); LOG.debug("Cookie " + cookie + " match " + cookieOrigin);
@ -161,16 +160,15 @@ public class RequestAddCookies implements HttpRequestInterceptor {
// Generate Cookie request headers // Generate Cookie request headers
if (!matchedCookies.isEmpty()) { if (!matchedCookies.isEmpty()) {
List<Header> headers = cookieSpec.formatCookies(matchedCookies); List<Header> headers = cookieSpec.formatCookies(matchedCookies);
for (int i = 0; i < headers.size(); i++) { for (Header header : headers) {
request.addHeader(headers.get(i)); request.addHeader(header);
} }
} }
int ver = cookieSpec.getVersion(); int ver = cookieSpec.getVersion();
if (ver > 0) { if (ver > 0) {
boolean needVersionHeader = false; boolean needVersionHeader = false;
for (int i = 0; i < matchedCookies.size(); i++) { for (Cookie cookie : matchedCookies) {
Cookie cookie = matchedCookies.get(i);
if (ver != cookie.getVersion()) { if (ver != cookie.getVersion()) {
needVersionHeader = true; needVersionHeader = true;
} }

View File

@ -33,7 +33,6 @@ package org.apache.http.client.protocol;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator;
import org.apache.http.Header; import org.apache.http.Header;
import org.apache.http.HttpException; import org.apache.http.HttpException;
@ -66,8 +65,8 @@ public class RequestDefaultHeaders implements HttpRequestInterceptor {
Collection<?> defHeaders = (Collection<?>) request.getParams().getParameter( Collection<?> defHeaders = (Collection<?>) request.getParams().getParameter(
ClientPNames.DEFAULT_HEADERS); ClientPNames.DEFAULT_HEADERS);
if (defHeaders != null) { if (defHeaders != null) {
for (Iterator<?> it = defHeaders.iterator(); it.hasNext(); ) { for (Object defHeader : defHeaders) {
request.addHeader((Header) it.next()); request.addHeader((Header) defHeader);
} }
} }
} }

View File

@ -118,8 +118,7 @@ public class ResponseProcessCookies implements HttpResponseInterceptor {
Header header = iterator.nextHeader(); Header header = iterator.nextHeader();
try { try {
List<Cookie> cookies = cookieSpec.parse(header, cookieOrigin); List<Cookie> cookies = cookieSpec.parse(header, cookieOrigin);
for (int c = 0; c < cookies.size(); c++) { for (Cookie cookie : cookies) {
Cookie cookie = cookies.get(c);
try { try {
cookieSpec.validate(cookie, cookieOrigin); cookieSpec.validate(cookie, cookieOrigin);
cookieStore.addCookie(cookie); cookieStore.addCookie(cookie);

View File

@ -86,22 +86,22 @@ public class URIUtils {
} }
buffer.append(host); buffer.append(host);
if (port > 0) { if (port > 0) {
buffer.append(":"); buffer.append(':');
buffer.append(port); buffer.append(port);
} }
} }
if (path == null || !path.startsWith("/")) { if (path == null || !path.startsWith("/")) {
buffer.append("/"); buffer.append('/');
} }
if (path != null) { if (path != null) {
buffer.append(path); buffer.append(path);
} }
if (query != null) { if (query != null) {
buffer.append("?"); buffer.append('?');
buffer.append(query); buffer.append(query);
} }
if (fragment != null) { if (fragment != null) {
buffer.append("#"); buffer.append('#');
buffer.append(fragment); buffer.append(fragment);
} }
return new URI(buffer.toString()); return new URI(buffer.toString());

View File

@ -39,6 +39,7 @@ import java.net.SocketTimeoutException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Arrays;
import org.apache.http.conn.scheme.PlainSocketFactory; import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.SocketFactory; import org.apache.http.conn.scheme.SocketFactory;
@ -64,7 +65,7 @@ public final class MultihomePlainSocketFactory implements SocketFactory {
* Gets the singleton instance of this class. * Gets the singleton instance of this class.
* @return the one and only plain socket factory * @return the one and only plain socket factory
*/ */
public static final MultihomePlainSocketFactory getSocketFactory() { public static MultihomePlainSocketFactory getSocketFactory() {
return DEFAULT_FACTORY; return DEFAULT_FACTORY;
} }
@ -126,9 +127,7 @@ public final class MultihomePlainSocketFactory implements SocketFactory {
InetAddress[] inetadrs = InetAddress.getAllByName(host); InetAddress[] inetadrs = InetAddress.getAllByName(host);
List<InetAddress> addresses = new ArrayList<InetAddress>(inetadrs.length); List<InetAddress> addresses = new ArrayList<InetAddress>(inetadrs.length);
for (InetAddress inetadr: inetadrs) { addresses.addAll(Arrays.asList(inetadrs));
addresses.add(inetadr);
}
Collections.shuffle(addresses); Collections.shuffle(addresses);
IOException lastEx = null; IOException lastEx = null;

View File

@ -84,7 +84,7 @@ public class HttpRouteParams {
* @return the default proxy set in the argument parameters, or * @return the default proxy set in the argument parameters, or
* <code>null</code> if not set * <code>null</code> if not set
*/ */
public final static HttpHost getDefaultProxy(HttpParams params) { public static HttpHost getDefaultProxy(HttpParams params) {
if (params == null) { if (params == null) {
throw new IllegalArgumentException("Parameters must not be null."); throw new IllegalArgumentException("Parameters must not be null.");
} }
@ -108,7 +108,7 @@ public class HttpRouteParams {
* <code>null</code> by {@link #getDefaultProxy}, * <code>null</code> by {@link #getDefaultProxy},
* to allow for explicit unsetting in hierarchies. * to allow for explicit unsetting in hierarchies.
*/ */
public final static void setDefaultProxy(HttpParams params, public static void setDefaultProxy(HttpParams params,
HttpHost proxy) { HttpHost proxy) {
if (params == null) { if (params == null) {
throw new IllegalArgumentException("Parameters must not be null."); throw new IllegalArgumentException("Parameters must not be null.");
@ -128,7 +128,7 @@ public class HttpRouteParams {
* @return the forced route set in the argument parameters, or * @return the forced route set in the argument parameters, or
* <code>null</code> if not set * <code>null</code> if not set
*/ */
public final static HttpRoute getForcedRoute(HttpParams params) { public static HttpRoute getForcedRoute(HttpParams params) {
if (params == null) { if (params == null) {
throw new IllegalArgumentException("Parameters must not be null."); throw new IllegalArgumentException("Parameters must not be null.");
} }
@ -152,7 +152,7 @@ public class HttpRouteParams {
* <code>null</code> by {@link #getForcedRoute}, * <code>null</code> by {@link #getForcedRoute},
* to allow for explicit unsetting in hierarchies. * to allow for explicit unsetting in hierarchies.
*/ */
public final static void setForcedRoute(HttpParams params, public static void setForcedRoute(HttpParams params,
HttpRoute route) { HttpRoute route) {
if (params == null) { if (params == null) {
throw new IllegalArgumentException("Parameters must not be null."); throw new IllegalArgumentException("Parameters must not be null.");
@ -173,7 +173,7 @@ public class HttpRouteParams {
* @return the local address set in the argument parameters, or * @return the local address set in the argument parameters, or
* <code>null</code> if not set * <code>null</code> if not set
*/ */
public final static InetAddress getLocalAddress(HttpParams params) { public static InetAddress getLocalAddress(HttpParams params) {
if (params == null) { if (params == null) {
throw new IllegalArgumentException("Parameters must not be null."); throw new IllegalArgumentException("Parameters must not be null.");
} }
@ -191,7 +191,7 @@ public class HttpRouteParams {
* @param params the parameters in which to set the value * @param params the parameters in which to set the value
* @param local the value to set, may be <code>null</code> * @param local the value to set, may be <code>null</code>
*/ */
public final static void setLocalAddress(HttpParams params, public static void setLocalAddress(HttpParams params,
InetAddress local) { InetAddress local) {
if (params == null) { if (params == null) {
throw new IllegalArgumentException("Parameters must not be null."); throw new IllegalArgumentException("Parameters must not be null.");

View File

@ -239,8 +239,8 @@ public final class HttpRoute implements RouteInfo, Cloneable {
if ((proxies == null) || (proxies.length < 1)) if ((proxies == null) || (proxies.length < 1))
return null; return null;
for (int i=0; i<proxies.length; i++) { for (HttpHost proxy : proxies) {
if (proxies[i] == null) if (proxy == null)
throw new IllegalArgumentException throw new IllegalArgumentException
("Proxy chain may not contain null elements."); ("Proxy chain may not contain null elements.");
} }
@ -281,7 +281,7 @@ public final class HttpRoute implements RouteInfo, Cloneable {
if (hop >= hopcount) if (hop >= hopcount)
throw new IllegalArgumentException throw new IllegalArgumentException
("Hop index " + hop + ("Hop index " + hop +
" exceeds route length " + hopcount +"."); " exceeds route length " + hopcount);
HttpHost result = null; HttpHost result = null;
if (hop < hopcount-1) if (hop < hopcount-1)
@ -385,8 +385,7 @@ public final class HttpRoute implements RouteInfo, Cloneable {
hc ^= localAddress.hashCode(); hc ^= localAddress.hashCode();
if (this.proxyChain != null) { if (this.proxyChain != null) {
hc ^= proxyChain.length; hc ^= proxyChain.length;
for (int i=0; i<proxyChain.length; i++) for (HttpHost aProxyChain : proxyChain) hc ^= aProxyChain.hashCode();
hc ^= proxyChain[i].hashCode();
} }
if (this.secure) if (this.secure)
@ -422,8 +421,8 @@ public final class HttpRoute implements RouteInfo, Cloneable {
cab.append('s'); cab.append('s');
cab.append("}->"); cab.append("}->");
if (this.proxyChain != null) { if (this.proxyChain != null) {
for (int i=0; i<this.proxyChain.length; i++) { for (HttpHost aProxyChain : this.proxyChain) {
cab.append(this.proxyChain[i]); cab.append(aProxyChain);
cab.append("->"); cab.append("->");
} }
} }

View File

@ -57,7 +57,7 @@ public final class PlainSocketFactory implements SocketFactory {
* Gets the singleton instance of this class. * Gets the singleton instance of this class.
* @return the one and only plain socket factory * @return the one and only plain socket factory
*/ */
public static final PlainSocketFactory getSocketFactory() { public static PlainSocketFactory getSocketFactory() {
return DEFAULT_FACTORY; return DEFAULT_FACTORY;
} }

View File

@ -162,9 +162,9 @@ public abstract class AbstractVerifier implements X509HostnameVerifier {
names.add(cns[0]); names.add(cns[0]);
} }
if(subjectAlts != null) { if(subjectAlts != null) {
for(int i = 0; i < subjectAlts.length; i++) { for (String subjectAlt : subjectAlts) {
if(subjectAlts[i] != null) { if (subjectAlt != null) {
names.add(subjectAlts[i]); names.add(subjectAlt);
} }
} }
} }
@ -303,12 +303,11 @@ public abstract class AbstractVerifier implements X509HostnameVerifier {
cpe.printStackTrace(); cpe.printStackTrace();
} }
if(c != null) { if(c != null) {
Iterator<List<?>> it = c.iterator(); for (List<?> aC : c) {
while(it.hasNext()) { List<?> list = aC;
List<?> list = it.next();
int type = ((Integer) list.get(0)).intValue(); int type = ((Integer) list.get(0)).intValue();
// If type is 2, then we've got a dNSName // If type is 2, then we've got a dNSName
if(type == 2) { if (type == 2) {
String s = (String) list.get(1); String s = (String) list.get(1);
subjectAltList.add(s); subjectAltList.add(s);
} }

View File

@ -53,7 +53,7 @@ public final class CookieOrigin {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Host of origin may not be null"); "Host of origin may not be null");
} }
if (host.trim().equals("")) { if (host.trim().length() == 0) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Host of origin may not be blank"); "Host of origin may not be blank");
} }
@ -66,7 +66,7 @@ public final class CookieOrigin {
} }
this.host = host.toLowerCase(Locale.ENGLISH); this.host = host.toLowerCase(Locale.ENGLISH);
this.port = port; this.port = port;
if (!path.trim().equals("")) { if (path.trim().length() != 0) {
this.path = path; this.path = path;
} else { } else {
this.path = "/"; this.path = "/";
@ -93,15 +93,15 @@ public final class CookieOrigin {
@Override @Override
public String toString() { public String toString() {
StringBuilder buffer = new StringBuilder(); StringBuilder buffer = new StringBuilder();
buffer.append("["); buffer.append('[');
if (this.secure) { if (this.secure) {
buffer.append("(secure)"); buffer.append("(secure)");
} }
buffer.append(this.host); buffer.append(this.host);
buffer.append(":"); buffer.append(':');
buffer.append(Integer.toString(this.port)); buffer.append(Integer.toString(this.port));
buffer.append(this.path); buffer.append(this.path);
buffer.append("]"); buffer.append(']');
return buffer.toString(); return buffer.toString();
} }

View File

@ -58,7 +58,7 @@ public class CookiePathComparator implements Serializable, Comparator<Cookie> {
path = "/"; path = "/";
} }
if (!path.endsWith("/")) { if (!path.endsWith("/")) {
path = path + "/"; path = path + '/';
} }
return path; return path;
} }

View File

@ -120,7 +120,7 @@ public class BasicScheme extends RFC2617Scheme {
* *
* @param credentials The set of credentials to be used for athentication * @param credentials The set of credentials to be used for athentication
* @param request The request being authenticated * @param request The request being authenticated
* @throws InvalidCredentialsException if authentication credentials * @throws org.apache.http.auth.InvalidCredentialsException if authentication credentials
* are not valid or not applicable for this authentication scheme * are not valid or not applicable for this authentication scheme
* @throws AuthenticationException if authorization string cannot * @throws AuthenticationException if authorization string cannot
* be generated due to an authentication failure * be generated due to an authentication failure

View File

@ -198,7 +198,7 @@ public class DigestScheme extends RFC2617Scheme {
* @param credentials A set of credentials to be used for athentication * @param credentials A set of credentials to be used for athentication
* @param request The request being authenticated * @param request The request being authenticated
* *
* @throws InvalidCredentialsException if authentication credentials * @throws org.apache.http.auth.InvalidCredentialsException if authentication credentials
* are not valid or not applicable for this authentication scheme * are not valid or not applicable for this authentication scheme
* @throws AuthenticationException if authorization string cannot * @throws AuthenticationException if authorization string cannot
* be generated due to an authentication failure * be generated due to an authentication failure
@ -242,10 +242,6 @@ public class DigestScheme extends RFC2617Scheme {
/** /**
* Creates an MD5 response digest. * Creates an MD5 response digest.
* *
* @param uname Username
* @param pwd Password
* @param charset The credential charset
*
* @return The created digest as string. This will be the response tag's * @return The created digest as string. This will be the response tag's
* value in the Authentication HTTP header. * value in the Authentication HTTP header.
* @throws AuthenticationException when MD5 is an unsupported algorithm * @throws AuthenticationException when MD5 is an unsupported algorithm
@ -311,7 +307,7 @@ public class DigestScheme extends RFC2617Scheme {
//we do not have access to the entity-body or its hash //we do not have access to the entity-body or its hash
//TODO: add Method ":" digest-uri-value ":" H(entity-body) //TODO: add Method ":" digest-uri-value ":" H(entity-body)
} else { } else {
a2 = method + ":" + uri; a2 = method + ':' + uri;
} }
String md5a2 = encode(md5Helper.digest(EncodingUtils.getAsciiBytes(a2))); String md5a2 = encode(md5Helper.digest(EncodingUtils.getAsciiBytes(a2)));

View File

@ -60,7 +60,7 @@ public abstract class RFC2617Scheme implements AuthScheme {
/** /**
* Authentication parameter map. * Authentication parameter map.
*/ */
private Map<String, String> params = null; private Map<String, String> params;
/** /**
* Flag whether authenticating against a proxy. * Flag whether authenticating against a proxy.
@ -131,8 +131,7 @@ public abstract class RFC2617Scheme implements AuthScheme {
} }
this.params = new HashMap<String, String>(elements.length); this.params = new HashMap<String, String>(elements.length);
for (int i = 0; i < elements.length; i++) { for (HeaderElement element : elements) {
HeaderElement element = elements[i];
this.params.put(element.getName(), element.getValue()); this.params.put(element.getName(), element.getValue());
} }
} }

View File

@ -33,7 +33,6 @@ package org.apache.http.impl.client;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
@ -73,8 +72,7 @@ public abstract class AbstractAuthenticationHandler implements AuthenticationHan
final Header[] headers) throws MalformedChallengeException { final Header[] headers) throws MalformedChallengeException {
Map<String, Header> map = new HashMap<String, Header>(headers.length); Map<String, Header> map = new HashMap<String, Header>(headers.length);
for (int i = 0; i < headers.length; i++) { for (Header header : headers) {
Header header = headers[i];
CharArrayBuffer buffer; CharArrayBuffer buffer;
int pos; int pos;
if (header instanceof FormattedHeader) { if (header instanceof FormattedHeader) {
@ -125,9 +123,9 @@ public abstract class AbstractAuthenticationHandler implements AuthenticationHan
} }
AuthScheme authScheme = null; AuthScheme authScheme = null;
for (Iterator<String> it = authPrefs.iterator(); it.hasNext(); ) { for (String id : authPrefs) {
String id = it.next();
Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH)); Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH));
if (challenge != null) { if (challenge != null) {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug(id + " authentication scheme selected"); LOG.debug(id + " authentication scheme selected");

View File

@ -109,8 +109,8 @@ public class BasicCookieStore implements CookieStore {
*/ */
public synchronized void addCookies(Cookie[] cookies) { public synchronized void addCookies(Cookie[] cookies) {
if (cookies != null) { if (cookies != null) {
for (int i = 0; i < cookies.length; i++) { for (Cookie cooky : cookies) {
this.addCookie(cookies[i]); this.addCookie(cooky);
} }
} }
} }

View File

@ -85,7 +85,7 @@ public class BasicCredentialsProvider implements CredentialsProvider {
* Find matching {@link Credentials credentials} for the given authentication scope. * Find matching {@link Credentials credentials} for the given authentication scope.
* *
* @param map the credentials hash map * @param map the credentials hash map
* @param token the {@link AuthScope authentication scope} * @param authscope the {@link AuthScope authentication scope}
* @return the credentials * @return the credentials
* *
*/ */

View File

@ -761,7 +761,7 @@ public class DefaultClientRequestDirector
StringBuilder buffer = new StringBuilder(host.length() + 6); StringBuilder buffer = new StringBuilder(host.length() + 6);
buffer.append(host); buffer.append(host);
buffer.append(":"); buffer.append(':');
buffer.append(Integer.toString(port)); buffer.append(Integer.toString(port));
String authority = buffer.toString(); String authority = buffer.toString();

View File

@ -54,7 +54,7 @@ import org.apache.http.protocol.HTTP;
class EntityEnclosingRequestWrapper extends RequestWrapper class EntityEnclosingRequestWrapper extends RequestWrapper
implements HttpEntityEnclosingRequest { implements HttpEntityEnclosingRequest {
private HttpEntity entity = null; private HttpEntity entity;
public EntityEnclosingRequestWrapper(final HttpEntityEnclosingRequest request) public EntityEnclosingRequestWrapper(final HttpEntityEnclosingRequest request)
throws ProtocolException { throws ProtocolException {

View File

@ -90,7 +90,7 @@ public abstract class AbstractPoolEntry {
/** /**
* Creates a new pool entry. * Creates a new pool entry.
* *
* @param occ the underlying connection for this entry * @param connOperator the Connection Operator for this entry
* @param route the planned route for the connection, * @param route the planned route for the connection,
* or <code>null</code> * or <code>null</code>
*/ */

View File

@ -223,8 +223,8 @@ public class DefaultClientConnection extends SocketHttpClientConnection
if (HEADERS_LOG.isDebugEnabled()) { if (HEADERS_LOG.isDebugEnabled()) {
HEADERS_LOG.debug("<< " + response.getStatusLine().toString()); HEADERS_LOG.debug("<< " + response.getStatusLine().toString());
Header[] headers = response.getAllHeaders(); Header[] headers = response.getAllHeaders();
for (int i = 0; i < headers.length; i++) { for (Header header : headers) {
HEADERS_LOG.debug("<< " + headers[i].toString()); HEADERS_LOG.debug("<< " + header.toString());
} }
} }
return response; return response;
@ -237,8 +237,8 @@ public class DefaultClientConnection extends SocketHttpClientConnection
if (HEADERS_LOG.isDebugEnabled()) { if (HEADERS_LOG.isDebugEnabled()) {
HEADERS_LOG.debug(">> " + request.getRequestLine().toString()); HEADERS_LOG.debug(">> " + request.getRequestLine().toString());
Header[] headers = request.getAllHeaders(); Header[] headers = request.getAllHeaders();
for (int i = 0; i < headers.length; i++) { for (Header header : headers) {
HEADERS_LOG.debug(">> " + headers[i].toString()); HEADERS_LOG.debug(">> " + header.toString());
} }
} }
} }

View File

@ -361,7 +361,6 @@ public class SingleClientConnManager implements ClientConnectionManager {
/** /**
* Creates a new pool entry. * Creates a new pool entry.
* *
* @param occ the underlying connection for this entry
*/ */
protected PoolEntry() { protected PoolEntry() {
super(SingleClientConnManager.this.connOperator, null); super(SingleClientConnManager.this.connOperator, null);
@ -403,7 +402,7 @@ public class SingleClientConnManager implements ClientConnectionManager {
* Creates a new connection adapter. * Creates a new connection adapter.
* *
* @param entry the pool entry for the connection being wrapped * @param entry the pool entry for the connection being wrapped
* @param plan the planned route for this connection * @param route the planned route for this connection
*/ */
protected ConnAdapter(PoolEntry entry, HttpRoute route) { protected ConnAdapter(PoolEntry entry, HttpRoute route) {
super(SingleClientConnManager.this, entry); super(SingleClientConnManager.this, entry);

View File

@ -52,7 +52,7 @@ public class Wire {
private void wire(String header, InputStream instream) private void wire(String header, InputStream instream)
throws IOException { throws IOException {
StringBuffer buffer = new StringBuffer(); StringBuilder buffer = new StringBuilder();
int ch; int ch;
while ((ch = instream.read()) != -1) { while ((ch = instream.read()) != -1) {
if (ch == 13) { if (ch == 13) {
@ -72,8 +72,8 @@ public class Wire {
} }
} }
if (buffer.length() > 0) { if (buffer.length() > 0) {
buffer.append("\""); buffer.append('\"');
buffer.insert(0, "\""); buffer.insert(0, '\"');
buffer.insert(0, header); buffer.insert(0, header);
log.debug(buffer.toString()); log.debug(buffer.toString());
} }

View File

@ -97,8 +97,6 @@ public abstract class AbstractConnPool implements RefQueueHandler {
/** /**
* Creates a new connection pool. * Creates a new connection pool.
*
* @param mgr the connection manager
*/ */
protected AbstractConnPool() { protected AbstractConnPool() {
issuedConnections = new HashSet<BasicPoolEntryRef>(); issuedConnections = new HashSet<BasicPoolEntryRef>();

View File

@ -251,8 +251,6 @@ public class ConnPoolByRoute extends AbstractConnPool {
* @param timeout the timeout, 0 or negative for no timeout * @param timeout the timeout, 0 or negative for no timeout
* @param tunit the unit for the <code>timeout</code>, * @param tunit the unit for the <code>timeout</code>,
* may be <code>null</code> only if there is no timeout * may be <code>null</code> only if there is no timeout
* @param operator the connection operator, in case
* a connection has to be created
* @param aborter an object which can abort a {@link WaitingThread}. * @param aborter an object which can abort a {@link WaitingThread}.
* *
* @return pool entry holding a connection for the route * @return pool entry holding a connection for the route

View File

@ -62,10 +62,10 @@ public class RouteSpecificPool {
* This list is managed LIFO, to increase idle times and * This list is managed LIFO, to increase idle times and
* allow for closing connections that are not really needed. * allow for closing connections that are not really needed.
*/ */
protected LinkedList<BasicPoolEntry> freeEntries; protected final LinkedList<BasicPoolEntry> freeEntries;
/** The list of threads waiting for this pool. */ /** The list of threads waiting for this pool. */
protected Queue<WaitingThread> waitingThreads; protected final Queue<WaitingThread> waitingThreads;
/** The number of created entries. */ /** The number of created entries. */
protected int numEntries; protected int numEntries;

View File

@ -37,7 +37,7 @@
The implementation of a thread-safe client connection manager. The implementation of a thread-safe client connection manager.
<center> <center>
<image src="doc-files/tsccm-structure.png" alt="Relation Diagram"/> <img src="doc-files/tsccm-structure.png" alt="Relation Diagram"/>
</center> </center>
<p> <p>
@ -48,7 +48,7 @@ maintains a <i>Pool</i> (yellow) of connections and waiting threads.
Both Manager and Pool rely on <i>Operations</i> (cyan) to provide the Both Manager and Pool rely on <i>Operations</i> (cyan) to provide the
actual connections. actual connections.
</p> </p>
</p> <p>
In order to allow connection garbage collection, it is In order to allow connection garbage collection, it is
imperative that hard object references between the areas are imperative that hard object references between the areas are
restricted to the relations indicated by arrows in the diagram: restricted to the relations indicated by arrows in the diagram:

View File

@ -363,7 +363,7 @@ public class BasicClientCookie implements SetCookie, ClientCookie {
private boolean isSecure; private boolean isSecure;
/** The version of the cookie specification I was created from. */ /** The version of the cookie specification I was created from. */
private int cookieVersion = 0; private int cookieVersion;
} }

View File

@ -50,7 +50,7 @@ public class BasicDomainHandler implements CookieAttributeHandler {
if (value == null) { if (value == null) {
throw new MalformedCookieException("Missing value for domain attribute"); throw new MalformedCookieException("Missing value for domain attribute");
} }
if (value.trim().equals("")) { if (value.trim().length() == 0) {
throw new MalformedCookieException("Blank value for domain attribute"); throw new MalformedCookieException("Blank value for domain attribute");
} }
cookie.setDomain(value); cookie.setDomain(value);
@ -74,7 +74,7 @@ public class BasicDomainHandler implements CookieAttributeHandler {
if (domain == null) { if (domain == null) {
throw new MalformedCookieException("Cookie domain may not be null"); throw new MalformedCookieException("Cookie domain may not be null");
} }
if (host.indexOf(".") >= 0) { if (host.contains(".")) {
// Not required to have at least two dots. RFC 2965. // Not required to have at least two dots. RFC 2965.
// A Set-Cookie2 with Domain=ajax.com will be accepted. // A Set-Cookie2 with Domain=ajax.com will be accepted.
@ -114,7 +114,7 @@ public class BasicDomainHandler implements CookieAttributeHandler {
return true; return true;
} }
if (!domain.startsWith(".")) { if (!domain.startsWith(".")) {
domain = "." + domain; domain = '.' + domain;
} }
return host.endsWith(domain) || host.equals(domain.substring(1)); return host.endsWith(domain) || host.equals(domain.substring(1));
} }

View File

@ -47,7 +47,7 @@ public class BasicPathHandler implements CookieAttributeHandler {
if (cookie == null) { if (cookie == null) {
throw new IllegalArgumentException("Cookie may not be null"); throw new IllegalArgumentException("Cookie may not be null");
} }
if (value == null || value.trim().equals("")) { if (value == null || value.trim().length() == 0) {
value = "/"; value = "/";
} }
cookie.setPath(value); cookie.setPath(value);

View File

@ -57,7 +57,7 @@ public class BasicSecureHandler extends AbstractCookieAttributeHandler {
if (origin == null) { if (origin == null) {
throw new IllegalArgumentException("Cookie origin may not be null"); throw new IllegalArgumentException("Cookie origin may not be null");
} }
return cookie.isSecure() ? origin.isSecure() : true; return !cookie.isSecure() || origin.isSecure();
} }
} }

View File

@ -53,9 +53,9 @@ public class BestMatchSpec implements CookieSpec {
private final String[] datepatterns; private final String[] datepatterns;
private final boolean oneHeader; private final boolean oneHeader;
private RFC2965Spec strict = null; private RFC2965Spec strict;
private BrowserCompatSpec compat = null; private BrowserCompatSpec compat;
private NetscapeDraftSpec netscape = null; private NetscapeDraftSpec netscape;
public BestMatchSpec(final String[] datepatterns, boolean oneHeader) { public BestMatchSpec(final String[] datepatterns, boolean oneHeader) {
super(); super();

View File

@ -113,7 +113,7 @@ public class BrowserCompatSpec extends CookieSpecBase {
int i1 = headervalue.toLowerCase(Locale.ENGLISH).indexOf("expires="); int i1 = headervalue.toLowerCase(Locale.ENGLISH).indexOf("expires=");
if (i1 != -1) { if (i1 != -1) {
i1 += "expires=".length(); i1 += "expires=".length();
int i2 = headervalue.indexOf(";", i1); int i2 = headervalue.indexOf(';', i1);
if (i2 == -1) { if (i2 == -1) {
i2 = headervalue.length(); i2 = headervalue.length();
} }

View File

@ -71,12 +71,10 @@ public abstract class CookieSpecBase extends AbstractCookieSpec {
protected List<Cookie> parse(final HeaderElement[] elems, final CookieOrigin origin) protected List<Cookie> parse(final HeaderElement[] elems, final CookieOrigin origin)
throws MalformedCookieException { throws MalformedCookieException {
List<Cookie> cookies = new ArrayList<Cookie>(elems.length); List<Cookie> cookies = new ArrayList<Cookie>(elems.length);
for (int i = 0; i < elems.length; i++) { for (HeaderElement headerelement : elems) {
HeaderElement headerelement = elems[i];
String name = headerelement.getName(); String name = headerelement.getName();
String value = headerelement.getValue(); String value = headerelement.getValue();
if (name == null || name.equals("")) { if (name == null || name.length() == 0) {
throw new MalformedCookieException("Cookie name may not be empty"); throw new MalformedCookieException("Cookie name may not be empty");
} }

View File

@ -152,8 +152,8 @@ public final class DateUtils {
dateValue = dateValue.substring (1, dateValue.length() - 1); dateValue = dateValue.substring (1, dateValue.length() - 1);
} }
for (int i = 0; i < dateFormats.length; i++) { for (String dateFormat : dateFormats) {
SimpleDateFormat dateParser = DateFormatHolder.formatFor(dateFormats[i]); SimpleDateFormat dateParser = DateFormatHolder.formatFor(dateFormat);
dateParser.set2DigitYearStart(startDate); dateParser.set2DigitYearStart(startDate);
try { try {

View File

@ -50,7 +50,7 @@ public class NetscapeDomainHandler extends BasicDomainHandler {
// Perform Netscape Cookie draft specific validation // Perform Netscape Cookie draft specific validation
String host = origin.getHost(); String host = origin.getHost();
String domain = cookie.getDomain(); String domain = cookie.getDomain();
if (host.indexOf(".") >= 0) { if (host.contains(".")) {
int domainParts = new StringTokenizer(domain, ".").countTokens(); int domainParts = new StringTokenizer(domain, ".").countTokens();
if (isSpecialDomain(domain)) { if (isSpecialDomain(domain)) {
@ -78,16 +78,13 @@ public class NetscapeDomainHandler extends BasicDomainHandler {
*/ */
private static boolean isSpecialDomain(final String domain) { private static boolean isSpecialDomain(final String domain) {
final String ucDomain = domain.toUpperCase(Locale.ENGLISH); final String ucDomain = domain.toUpperCase(Locale.ENGLISH);
if (ucDomain.endsWith(".COM") return ucDomain.endsWith(".COM")
|| ucDomain.endsWith(".EDU") || ucDomain.endsWith(".EDU")
|| ucDomain.endsWith(".NET") || ucDomain.endsWith(".NET")
|| ucDomain.endsWith(".GOV") || ucDomain.endsWith(".GOV")
|| ucDomain.endsWith(".MIL") || ucDomain.endsWith(".MIL")
|| ucDomain.endsWith(".ORG") || ucDomain.endsWith(".ORG")
|| ucDomain.endsWith(".INT")) { || ucDomain.endsWith(".INT");
return true;
}
return false;
} }
@Override @Override

View File

@ -52,7 +52,7 @@ public class RFC2109DomainHandler implements CookieAttributeHandler {
if (value == null) { if (value == null) {
throw new MalformedCookieException("Missing value for domain attribute"); throw new MalformedCookieException("Missing value for domain attribute");
} }
if (value.trim().equals("")) { if (value.trim().length() == 0) {
throw new MalformedCookieException("Blank value for domain attribute"); throw new MalformedCookieException("Blank value for domain attribute");
} }
cookie.setDomain(value); cookie.setDomain(value);

View File

@ -146,8 +146,7 @@ public class RFC2109Spec extends CookieSpecBase {
private List<Header> doFormatOneHeader(final List<Cookie> cookies) { private List<Header> doFormatOneHeader(final List<Cookie> cookies) {
int version = Integer.MAX_VALUE; int version = Integer.MAX_VALUE;
// Pick the lowest common denominator // Pick the lowest common denominator
for (int i = 0; i < cookies.size(); i++) { for (Cookie cookie : cookies) {
Cookie cookie = cookies.get(i);
if (cookie.getVersion() < version) { if (cookie.getVersion() < version) {
version = cookie.getVersion(); version = cookie.getVersion();
} }
@ -157,9 +156,9 @@ public class RFC2109Spec extends CookieSpecBase {
buffer.append(": "); buffer.append(": ");
buffer.append("$Version="); buffer.append("$Version=");
buffer.append(Integer.toString(version)); buffer.append(Integer.toString(version));
for (int i = 0; i < cookies.size(); i++) { for (Cookie cooky : cookies) {
buffer.append("; "); buffer.append("; ");
Cookie cookie = cookies.get(i); Cookie cookie = cooky;
formatCookieAsVer(buffer, cookie, version); formatCookieAsVer(buffer, cookie, version);
} }
List<Header> headers = new ArrayList<Header>(1); List<Header> headers = new ArrayList<Header>(1);
@ -169,8 +168,7 @@ public class RFC2109Spec extends CookieSpecBase {
private List<Header> doFormatManyHeaders(final List<Cookie> cookies) { private List<Header> doFormatManyHeaders(final List<Cookie> cookies) {
List<Header> headers = new ArrayList<Header>(cookies.size()); List<Header> headers = new ArrayList<Header>(cookies.size());
for (int i = 0; i < cookies.size(); i++) { for (Cookie cookie : cookies) {
Cookie cookie = cookies.get(i);
int version = cookie.getVersion(); int version = cookie.getVersion();
CharArrayBuffer buffer = new CharArrayBuffer(40); CharArrayBuffer buffer = new CharArrayBuffer(40);
buffer.append("Cookie: "); buffer.append("Cookie: ");

View File

@ -49,7 +49,7 @@ public class RFC2109VersionHandler extends AbstractCookieAttributeHandler {
if (value == null) { if (value == null) {
throw new MalformedCookieException("Missing value for version attribute"); throw new MalformedCookieException("Missing value for version attribute");
} }
if (value.trim().equals("")) { if (value.trim().length() == 0) {
throw new MalformedCookieException("Blank value for version attribute"); throw new MalformedCookieException("Blank value for version attribute");
} }
try { try {

View File

@ -65,7 +65,7 @@ public class RFC2965DomainAttributeHandler implements CookieAttributeHandler {
throw new MalformedCookieException( throw new MalformedCookieException(
"Missing value for domain attribute"); "Missing value for domain attribute");
} }
if (domain.trim().equals("")) { if (domain.trim().length() == 0) {
throw new MalformedCookieException( throw new MalformedCookieException(
"Blank value for domain attribute"); "Blank value for domain attribute");
} }
@ -76,7 +76,7 @@ public class RFC2965DomainAttributeHandler implements CookieAttributeHandler {
// a dot, the user agent supplies a leading dot ..." // a dot, the user agent supplies a leading dot ..."
// That effectively implies that the domain attribute // That effectively implies that the domain attribute
// MAY NOT be an IP address of a host name // MAY NOT be an IP address of a host name
domain = "." + domain; domain = '.' + domain;
} }
cookie.setDomain(domain); cookie.setDomain(domain);
} }
@ -189,10 +189,7 @@ public class RFC2965DomainAttributeHandler implements CookieAttributeHandler {
// effective host name minus domain must not contain any dots // effective host name minus domain must not contain any dots
String effectiveHostWithoutDomain = host.substring( String effectiveHostWithoutDomain = host.substring(
0, host.length() - cookieDomain.length()); 0, host.length() - cookieDomain.length());
if (effectiveHostWithoutDomain.indexOf('.') != -1) { return effectiveHostWithoutDomain.indexOf('.') == -1;
return false;
}
return true;
} }
} }

View File

@ -108,12 +108,10 @@ public class RFC2965Spec extends RFC2109Spec {
HeaderElement[] elems = header.getElements(); HeaderElement[] elems = header.getElements();
List<Cookie> cookies = new ArrayList<Cookie>(elems.length); List<Cookie> cookies = new ArrayList<Cookie>(elems.length);
for (int i = 0; i < elems.length; i++) { for (HeaderElement headerelement : elems) {
HeaderElement headerelement = elems[i];
String name = headerelement.getName(); String name = headerelement.getName();
String value = headerelement.getValue(); String value = headerelement.getValue();
if (name == null || name.equals("")) { if (name == null || name.length() == 0) {
throw new MalformedCookieException("Cookie name may not be empty"); throw new MalformedCookieException("Cookie name may not be empty");
} }
@ -135,7 +133,7 @@ public class RFC2965Spec extends RFC2109Spec {
NameValuePair param = attribs[j]; NameValuePair param = attribs[j];
attribmap.put(param.getName().toLowerCase(Locale.ENGLISH), param); attribmap.put(param.getName().toLowerCase(Locale.ENGLISH), param);
} }
for (Map.Entry<String, NameValuePair> entry: attribmap.entrySet()) { for (Map.Entry<String, NameValuePair> entry : attribmap.entrySet()) {
NameValuePair attrib = entry.getValue(); NameValuePair attrib = entry.getValue();
String s = attrib.getName().toLowerCase(Locale.ENGLISH); String s = attrib.getName().toLowerCase(Locale.ENGLISH);
@ -214,7 +212,7 @@ public class RFC2965Spec extends RFC2109Spec {
* the effective host name is the same as the host name. Note * the effective host name is the same as the host name. Note
* that all effective host names contain at least one dot. * that all effective host names contain at least one dot.
* *
* @param host host name where cookie is received from or being sent to. * @param origin origin where cookie is received from or being sent to.
* @return * @return
*/ */
private static CookieOrigin adjustEffectiveHost(final CookieOrigin origin) { private static CookieOrigin adjustEffectiveHost(final CookieOrigin origin) {