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
This commit is contained in:
Oleg Kalnichevski 2007-12-12 14:03:21 +00:00
parent 0603fc9f3c
commit 7477aa3042
10 changed files with 93 additions and 46 deletions

View File

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

View File

@ -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<HttpResponseInterceptor> clazz) {
getHttpProcessor().removeResponseInterceptorByClass(clazz);
}
@ -417,17 +410,11 @@ public abstract class AbstractHttpClient
}
public void removeRequestInterceptorByClass(Class clazz) {
public void removeRequestInterceptorByClass(Class<HttpRequestInterceptor> 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 {

View File

@ -55,9 +55,9 @@ import org.apache.http.cookie.CookieIdentityComparator;
*/
public class BasicCookieStore implements CookieStore {
private final ArrayList cookies;
private final ArrayList<Cookie> cookies;
private final Comparator cookieComparator;
private final Comparator<Cookie> cookieComparator;
// -------------------------------------------------------- Class Variables
@ -66,7 +66,7 @@ public class BasicCookieStore implements CookieStore {
*/
public BasicCookieStore() {
super();
this.cookies = new ArrayList();
this.cookies = new ArrayList<Cookie>();
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<Cookie> 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<Cookie> it = cookies.iterator(); it.hasNext();) {
if (it.next().isExpired(date)) {
it.remove();
removed = true;
}

View File

@ -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<AuthScope, Credentials> credMap;
/**
* Default constructor.
*/
public BasicCredentialsProvider() {
super();
this.credMap = new HashMap();
this.credMap = new HashMap<AuthScope, Credentials>();
}
/**
@ -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<AuthScope, Credentials> 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;

View File

@ -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<String, Header> 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<String, Header> 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<String, Header> 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<String, Header> challenges,
final AuthState authState,
final AuthenticationHandler authHandler,
final HttpResponse response,

View File

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

View File

@ -59,7 +59,7 @@ public class DefaultProxyAuthenticationHandler extends AbstractAuthenticationHan
return status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED;
}
public Map getChallenges(
public Map<String, Header> getChallenges(
final HttpResponse response,
final HttpContext context) throws MalformedChallengeException {
if (response == null) {

View File

@ -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);
}

View File

@ -59,7 +59,7 @@ public class DefaultTargetAuthenticationHandler extends AbstractAuthenticationHa
return status == HttpStatus.SC_UNAUTHORIZED;
}
public Map getChallenges(
public Map<String, Header> getChallenges(
final HttpResponse response,
final HttpContext context) throws MalformedChallengeException {
if (response == null) {

View File

@ -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
* <http://www.apache.org/>.
*
*/
package org.apache.http.impl.client;
import java.net.URI;
import java.util.HashSet;
import java.util.Set;
public class RedirectLocations {
private final Set<URI> uris;
public RedirectLocations() {
super();
this.uris = new HashSet<URI>();
}
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);
}
}