From 7477aa3042a561a5be690e40d62f7f080b0bd3a1 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Wed, 12 Dec 2007 14:03:21 +0000 Subject: [PATCH] Generics in o.a.h.impl.client git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@603615 13f79535-47bb-0310-9956-ffa450edef68 --- .../params/HttpConnectionManagerParams.java | 4 +- .../http/impl/client/AbstractHttpClient.java | 19 +----- .../http/impl/client/BasicCookieStore.java | 16 +++-- .../impl/client/BasicCredentialsProvider.java | 17 +++--- .../client/DefaultClientRequestDirector.java | 11 ++-- .../http/impl/client/DefaultHttpClient.java | 2 +- .../DefaultProxyAuthenticationHandler.java | 2 +- .../impl/client/DefaultRedirectHandler.java | 7 +-- .../DefaultTargetAuthenticationHandler.java | 2 +- .../http/impl/client/RedirectLocations.java | 59 +++++++++++++++++++ 10 files changed, 93 insertions(+), 46 deletions(-) create mode 100644 module-client/src/main/java/org/apache/http/impl/client/RedirectLocations.java diff --git a/module-client/src/main/java/org/apache/http/conn/params/HttpConnectionManagerParams.java b/module-client/src/main/java/org/apache/http/conn/params/HttpConnectionManagerParams.java index c664b651c..27a4974b8 100644 --- a/module-client/src/main/java/org/apache/http/conn/params/HttpConnectionManagerParams.java +++ b/module-client/src/main/java/org/apache/http/conn/params/HttpConnectionManagerParams.java @@ -114,7 +114,7 @@ public final class HttpConnectionManagerParams { ("The maximum must be greater than 0."); } - Map currentValues = (Map) params.getParameter + Map currentValues = (Map) params.getParameter (ConnManagerPNames.MAX_HOST_CONNECTIONS); // param values are meant to be immutable so we'll make a copy // to modify @@ -183,7 +183,7 @@ public final class HttpConnectionManagerParams { // if neither a specific nor a default maximum is configured... int result = DEFAULT_MAX_HOST_CONNECTIONS; - Map m = (Map) params.getParameter + Map m = (Map) params.getParameter (ConnManagerPNames.MAX_HOST_CONNECTIONS); if (m != null) { Integer max = (Integer) m.get(key); diff --git a/module-client/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java b/module-client/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java index df0ffcd76..5f03137a4 100644 --- a/module-client/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java +++ b/module-client/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java @@ -33,7 +33,6 @@ package org.apache.http.impl.client; import java.io.IOException; import java.net.URI; -import java.util.List; import org.apache.http.ConnectionReuseStrategy; import org.apache.http.HttpException; @@ -59,10 +58,6 @@ import org.apache.http.params.HttpParams; import org.apache.http.protocol.BasicHttpProcessor; import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.BasicHttpContext; -import org.apache.http.protocol.HttpRequestInterceptorList; -import org.apache.http.protocol.HttpResponseInterceptorList; - - /** * Convenience base class for HTTP client implementations. @@ -75,9 +70,7 @@ import org.apache.http.protocol.HttpResponseInterceptorList; * * @since 4.0 */ -public abstract class AbstractHttpClient - implements HttpClient, HttpRequestInterceptorList, HttpResponseInterceptorList { - +public abstract class AbstractHttpClient implements HttpClient { /** The default context. */ private HttpContext defaultContext; @@ -387,7 +380,7 @@ public abstract class AbstractHttpClient } - public void removeResponseInterceptorByClass(Class clazz) { + public void removeResponseInterceptorByClass(Class clazz) { getHttpProcessor().removeResponseInterceptorByClass(clazz); } @@ -417,17 +410,11 @@ public abstract class AbstractHttpClient } - public void removeRequestInterceptorByClass(Class clazz) { + public void removeRequestInterceptorByClass(Class clazz) { getHttpProcessor().removeRequestInterceptorByClass(clazz); } - public synchronized void setInterceptors(final List itcps) { - getHttpProcessor().setInterceptors(itcps); - } - - - // non-javadoc, see interface HttpClient public final HttpResponse execute(HttpUriRequest request) throws HttpException, IOException, InterruptedException { diff --git a/module-client/src/main/java/org/apache/http/impl/client/BasicCookieStore.java b/module-client/src/main/java/org/apache/http/impl/client/BasicCookieStore.java index b140a9768..535333b9a 100644 --- a/module-client/src/main/java/org/apache/http/impl/client/BasicCookieStore.java +++ b/module-client/src/main/java/org/apache/http/impl/client/BasicCookieStore.java @@ -55,9 +55,9 @@ import org.apache.http.cookie.CookieIdentityComparator; */ public class BasicCookieStore implements CookieStore { - private final ArrayList cookies; + private final ArrayList cookies; - private final Comparator cookieComparator; + private final Comparator cookieComparator; // -------------------------------------------------------- Class Variables @@ -66,7 +66,7 @@ public class BasicCookieStore implements CookieStore { */ public BasicCookieStore() { super(); - this.cookies = new ArrayList(); + this.cookies = new ArrayList(); this.cookieComparator = new CookieIdentityComparator(); } @@ -83,9 +83,8 @@ public class BasicCookieStore implements CookieStore { public synchronized void addCookie(Cookie cookie) { if (cookie != null) { // first remove any old cookie that is equivalent - for (Iterator it = cookies.iterator(); it.hasNext();) { - Cookie tmp = (Cookie) it.next(); - if (cookieComparator.compare(cookie, tmp) == 0) { + for (Iterator it = cookies.iterator(); it.hasNext();) { + if (cookieComparator.compare(cookie, it.next()) == 0) { it.remove(); break; } @@ -137,9 +136,8 @@ public class BasicCookieStore implements CookieStore { return false; } boolean removed = false; - Iterator it = cookies.iterator(); - while (it.hasNext()) { - if (((Cookie) (it.next())).isExpired(date)) { + for (Iterator it = cookies.iterator(); it.hasNext();) { + if (it.next().isExpired(date)) { it.remove(); removed = true; } diff --git a/module-client/src/main/java/org/apache/http/impl/client/BasicCredentialsProvider.java b/module-client/src/main/java/org/apache/http/impl/client/BasicCredentialsProvider.java index 9c531d5dd..1e877adb5 100644 --- a/module-client/src/main/java/org/apache/http/impl/client/BasicCredentialsProvider.java +++ b/module-client/src/main/java/org/apache/http/impl/client/BasicCredentialsProvider.java @@ -31,7 +31,6 @@ package org.apache.http.impl.client; import java.util.HashMap; -import java.util.Iterator; import org.apache.http.auth.AuthScope; import org.apache.http.auth.Credentials; @@ -53,14 +52,14 @@ import org.apache.http.client.CredentialsProvider; */ public class BasicCredentialsProvider implements CredentialsProvider { - private final HashMap credMap; + private final HashMap credMap; /** * Default constructor. */ public BasicCredentialsProvider() { super(); - this.credMap = new HashMap(); + this.credMap = new HashMap(); } /** @@ -73,7 +72,9 @@ public class BasicCredentialsProvider implements CredentialsProvider { * * @see #getCredentials(AuthScope) */ - public synchronized void setCredentials(final AuthScope authscope, final Credentials credentials) { + public synchronized void setCredentials( + final AuthScope authscope, + final Credentials credentials) { if (authscope == null) { throw new IllegalArgumentException("Authentication scope may not be null"); } @@ -88,7 +89,9 @@ public class BasicCredentialsProvider implements CredentialsProvider { * @return the credentials * */ - private static Credentials matchCredentials(final HashMap map, final AuthScope authscope) { + private static Credentials matchCredentials( + final HashMap map, + final AuthScope authscope) { // see if we get a direct hit Credentials creds = (Credentials)map.get(authscope); if (creds == null) { @@ -96,9 +99,7 @@ public class BasicCredentialsProvider implements CredentialsProvider { // Do a full scan int bestMatchFactor = -1; AuthScope bestMatch = null; - Iterator items = map.keySet().iterator(); - while (items.hasNext()) { - AuthScope current = (AuthScope)items.next(); + for (AuthScope current: map.keySet()) { int factor = authscope.match(current); if (factor > bestMatchFactor) { bestMatchFactor = factor; diff --git a/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java b/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java index e19252af9..d9660e2d6 100644 --- a/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java +++ b/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java @@ -602,7 +602,8 @@ public class DefaultClientRequestDirector if (this.proxyAuthHandler.isAuthenticationRequested(response, context)) { LOG.debug("Proxy requested authentication"); - Map challenges = this.proxyAuthHandler.getChallenges(response, context); + Map challenges = this.proxyAuthHandler.getChallenges( + response, context); try { processChallenges( challenges, this.proxyAuthState, this.proxyAuthHandler, @@ -819,7 +820,8 @@ public class DefaultClientRequestDirector } LOG.debug("Target requested authentication"); - Map challenges = this.targetAuthHandler.getChallenges(response, context); + Map challenges = this.targetAuthHandler.getChallenges( + response, context); try { processChallenges(challenges, this.targetAuthState, this.targetAuthHandler, @@ -846,7 +848,8 @@ public class DefaultClientRequestDirector if (this.proxyAuthHandler.isAuthenticationRequested(response, context)) { LOG.debug("Proxy requested authentication"); - Map challenges = this.proxyAuthHandler.getChallenges(response, context); + Map challenges = this.proxyAuthHandler.getChallenges( + response, context); try { processChallenges(challenges, this.proxyAuthState, this.proxyAuthHandler, @@ -902,7 +905,7 @@ public class DefaultClientRequestDirector private void processChallenges( - final Map challenges, + final Map challenges, final AuthState authState, final AuthenticationHandler authHandler, final HttpResponse response, diff --git a/module-client/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java b/module-client/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java index eb1423e8f..cb38797d3 100644 --- a/module-client/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java +++ b/module-client/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java @@ -161,7 +161,7 @@ public class DefaultHttpClient extends AbstractHttpClient { if (className != null) { try { - Class clazz = Class.forName(className); + Class clazz = Class.forName(className); ClientConnectionManagerFactory factory = (ClientConnectionManagerFactory) clazz.newInstance(); connManager = factory.newInstance(params, registry); diff --git a/module-client/src/main/java/org/apache/http/impl/client/DefaultProxyAuthenticationHandler.java b/module-client/src/main/java/org/apache/http/impl/client/DefaultProxyAuthenticationHandler.java index bf01c649c..9a7cb99f2 100644 --- a/module-client/src/main/java/org/apache/http/impl/client/DefaultProxyAuthenticationHandler.java +++ b/module-client/src/main/java/org/apache/http/impl/client/DefaultProxyAuthenticationHandler.java @@ -59,7 +59,7 @@ public class DefaultProxyAuthenticationHandler extends AbstractAuthenticationHan return status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED; } - public Map getChallenges( + public Map getChallenges( final HttpResponse response, final HttpContext context) throws MalformedChallengeException { if (response == null) { diff --git a/module-client/src/main/java/org/apache/http/impl/client/DefaultRedirectHandler.java b/module-client/src/main/java/org/apache/http/impl/client/DefaultRedirectHandler.java index a7f51d1ae..95797501d 100644 --- a/module-client/src/main/java/org/apache/http/impl/client/DefaultRedirectHandler.java +++ b/module-client/src/main/java/org/apache/http/impl/client/DefaultRedirectHandler.java @@ -33,8 +33,6 @@ package org.apache.http.impl.client; import java.net.URI; import java.net.URISyntaxException; -import java.util.HashSet; -import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -154,10 +152,11 @@ public class DefaultRedirectHandler implements RedirectHandler { if (params.isParameterFalse(ClientPNames.ALLOW_CIRCULAR_REDIRECTS)) { - Set redirectLocations = (Set) context.getAttribute(REDIRECT_LOCATIONS); + RedirectLocations redirectLocations = (RedirectLocations) context.getAttribute( + REDIRECT_LOCATIONS); if (redirectLocations == null) { - redirectLocations = new HashSet(); + redirectLocations = new RedirectLocations(); context.setAttribute(REDIRECT_LOCATIONS, redirectLocations); } diff --git a/module-client/src/main/java/org/apache/http/impl/client/DefaultTargetAuthenticationHandler.java b/module-client/src/main/java/org/apache/http/impl/client/DefaultTargetAuthenticationHandler.java index 2fb7ac987..4a8fc6b2c 100644 --- a/module-client/src/main/java/org/apache/http/impl/client/DefaultTargetAuthenticationHandler.java +++ b/module-client/src/main/java/org/apache/http/impl/client/DefaultTargetAuthenticationHandler.java @@ -59,7 +59,7 @@ public class DefaultTargetAuthenticationHandler extends AbstractAuthenticationHa return status == HttpStatus.SC_UNAUTHORIZED; } - public Map getChallenges( + public Map getChallenges( final HttpResponse response, final HttpContext context) throws MalformedChallengeException { if (response == null) { diff --git a/module-client/src/main/java/org/apache/http/impl/client/RedirectLocations.java b/module-client/src/main/java/org/apache/http/impl/client/RedirectLocations.java new file mode 100644 index 000000000..9008d5d9a --- /dev/null +++ b/module-client/src/main/java/org/apache/http/impl/client/RedirectLocations.java @@ -0,0 +1,59 @@ +/* + * $HeadURL$ + * $Revision$ + * $Date$ + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.http.impl.client; + +import java.net.URI; +import java.util.HashSet; +import java.util.Set; + +public class RedirectLocations { + + private final Set uris; + + public RedirectLocations() { + super(); + this.uris = new HashSet(); + } + + public boolean contains(final URI uri) { + return this.uris.contains(uri); + } + + public void add(final URI uri) { + this.uris.add(uri); + } + + public boolean remove(final URI uri) { + return this.uris.remove(uri); + } + +}