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:
parent
0603fc9f3c
commit
7477aa3042
|
@ -114,7 +114,7 @@ public final class HttpConnectionManagerParams {
|
||||||
("The maximum must be greater than 0.");
|
("The maximum must be greater than 0.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<?,?> currentValues = (Map) params.getParameter
|
Map<?,?> currentValues = (Map<?,?>) params.getParameter
|
||||||
(ConnManagerPNames.MAX_HOST_CONNECTIONS);
|
(ConnManagerPNames.MAX_HOST_CONNECTIONS);
|
||||||
// param values are meant to be immutable so we'll make a copy
|
// param values are meant to be immutable so we'll make a copy
|
||||||
// to modify
|
// to modify
|
||||||
|
@ -183,7 +183,7 @@ public final class HttpConnectionManagerParams {
|
||||||
// if neither a specific nor a default maximum is configured...
|
// if neither a specific nor a default maximum is configured...
|
||||||
int result = DEFAULT_MAX_HOST_CONNECTIONS;
|
int result = DEFAULT_MAX_HOST_CONNECTIONS;
|
||||||
|
|
||||||
Map<?,?> m = (Map) params.getParameter
|
Map<?,?> m = (Map<?,?>) params.getParameter
|
||||||
(ConnManagerPNames.MAX_HOST_CONNECTIONS);
|
(ConnManagerPNames.MAX_HOST_CONNECTIONS);
|
||||||
if (m != null) {
|
if (m != null) {
|
||||||
Integer max = (Integer) m.get(key);
|
Integer max = (Integer) m.get(key);
|
||||||
|
|
|
@ -33,7 +33,6 @@ package org.apache.http.impl.client;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.http.ConnectionReuseStrategy;
|
import org.apache.http.ConnectionReuseStrategy;
|
||||||
import org.apache.http.HttpException;
|
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.BasicHttpProcessor;
|
||||||
import org.apache.http.protocol.HttpContext;
|
import org.apache.http.protocol.HttpContext;
|
||||||
import org.apache.http.protocol.BasicHttpContext;
|
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.
|
* Convenience base class for HTTP client implementations.
|
||||||
|
@ -75,9 +70,7 @@ import org.apache.http.protocol.HttpResponseInterceptorList;
|
||||||
*
|
*
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractHttpClient
|
public abstract class AbstractHttpClient implements HttpClient {
|
||||||
implements HttpClient, HttpRequestInterceptorList, HttpResponseInterceptorList {
|
|
||||||
|
|
||||||
|
|
||||||
/** The default context. */
|
/** The default context. */
|
||||||
private HttpContext defaultContext;
|
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);
|
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);
|
getHttpProcessor().removeRequestInterceptorByClass(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public synchronized void setInterceptors(final List itcps) {
|
|
||||||
getHttpProcessor().setInterceptors(itcps);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// non-javadoc, see interface HttpClient
|
// non-javadoc, see interface HttpClient
|
||||||
public final HttpResponse execute(HttpUriRequest request)
|
public final HttpResponse execute(HttpUriRequest request)
|
||||||
throws HttpException, IOException, InterruptedException {
|
throws HttpException, IOException, InterruptedException {
|
||||||
|
|
|
@ -55,9 +55,9 @@ import org.apache.http.cookie.CookieIdentityComparator;
|
||||||
*/
|
*/
|
||||||
public class BasicCookieStore implements CookieStore {
|
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
|
// -------------------------------------------------------- Class Variables
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ public class BasicCookieStore implements CookieStore {
|
||||||
*/
|
*/
|
||||||
public BasicCookieStore() {
|
public BasicCookieStore() {
|
||||||
super();
|
super();
|
||||||
this.cookies = new ArrayList();
|
this.cookies = new ArrayList<Cookie>();
|
||||||
this.cookieComparator = new CookieIdentityComparator();
|
this.cookieComparator = new CookieIdentityComparator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,9 +83,8 @@ public class BasicCookieStore implements CookieStore {
|
||||||
public synchronized void addCookie(Cookie cookie) {
|
public synchronized void addCookie(Cookie cookie) {
|
||||||
if (cookie != null) {
|
if (cookie != null) {
|
||||||
// first remove any old cookie that is equivalent
|
// first remove any old cookie that is equivalent
|
||||||
for (Iterator it = cookies.iterator(); it.hasNext();) {
|
for (Iterator<Cookie> it = cookies.iterator(); it.hasNext();) {
|
||||||
Cookie tmp = (Cookie) it.next();
|
if (cookieComparator.compare(cookie, it.next()) == 0) {
|
||||||
if (cookieComparator.compare(cookie, tmp) == 0) {
|
|
||||||
it.remove();
|
it.remove();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -137,9 +136,8 @@ public class BasicCookieStore implements CookieStore {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
boolean removed = false;
|
boolean removed = false;
|
||||||
Iterator it = cookies.iterator();
|
for (Iterator<Cookie> it = cookies.iterator(); it.hasNext();) {
|
||||||
while (it.hasNext()) {
|
if (it.next().isExpired(date)) {
|
||||||
if (((Cookie) (it.next())).isExpired(date)) {
|
|
||||||
it.remove();
|
it.remove();
|
||||||
removed = true;
|
removed = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
package org.apache.http.impl.client;
|
package org.apache.http.impl.client;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.apache.http.auth.AuthScope;
|
import org.apache.http.auth.AuthScope;
|
||||||
import org.apache.http.auth.Credentials;
|
import org.apache.http.auth.Credentials;
|
||||||
|
@ -53,14 +52,14 @@ import org.apache.http.client.CredentialsProvider;
|
||||||
*/
|
*/
|
||||||
public class BasicCredentialsProvider implements CredentialsProvider {
|
public class BasicCredentialsProvider implements CredentialsProvider {
|
||||||
|
|
||||||
private final HashMap credMap;
|
private final HashMap<AuthScope, Credentials> credMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
*/
|
*/
|
||||||
public BasicCredentialsProvider() {
|
public BasicCredentialsProvider() {
|
||||||
super();
|
super();
|
||||||
this.credMap = new HashMap();
|
this.credMap = new HashMap<AuthScope, Credentials>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,7 +72,9 @@ public class BasicCredentialsProvider implements CredentialsProvider {
|
||||||
*
|
*
|
||||||
* @see #getCredentials(AuthScope)
|
* @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) {
|
if (authscope == null) {
|
||||||
throw new IllegalArgumentException("Authentication scope may not be null");
|
throw new IllegalArgumentException("Authentication scope may not be null");
|
||||||
}
|
}
|
||||||
|
@ -88,7 +89,9 @@ public class BasicCredentialsProvider implements CredentialsProvider {
|
||||||
* @return the credentials
|
* @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
|
// see if we get a direct hit
|
||||||
Credentials creds = (Credentials)map.get(authscope);
|
Credentials creds = (Credentials)map.get(authscope);
|
||||||
if (creds == null) {
|
if (creds == null) {
|
||||||
|
@ -96,9 +99,7 @@ public class BasicCredentialsProvider implements CredentialsProvider {
|
||||||
// Do a full scan
|
// Do a full scan
|
||||||
int bestMatchFactor = -1;
|
int bestMatchFactor = -1;
|
||||||
AuthScope bestMatch = null;
|
AuthScope bestMatch = null;
|
||||||
Iterator items = map.keySet().iterator();
|
for (AuthScope current: map.keySet()) {
|
||||||
while (items.hasNext()) {
|
|
||||||
AuthScope current = (AuthScope)items.next();
|
|
||||||
int factor = authscope.match(current);
|
int factor = authscope.match(current);
|
||||||
if (factor > bestMatchFactor) {
|
if (factor > bestMatchFactor) {
|
||||||
bestMatchFactor = factor;
|
bestMatchFactor = factor;
|
||||||
|
|
|
@ -602,7 +602,8 @@ public class DefaultClientRequestDirector
|
||||||
if (this.proxyAuthHandler.isAuthenticationRequested(response, context)) {
|
if (this.proxyAuthHandler.isAuthenticationRequested(response, context)) {
|
||||||
|
|
||||||
LOG.debug("Proxy requested authentication");
|
LOG.debug("Proxy requested authentication");
|
||||||
Map challenges = this.proxyAuthHandler.getChallenges(response, context);
|
Map<String, Header> challenges = this.proxyAuthHandler.getChallenges(
|
||||||
|
response, context);
|
||||||
try {
|
try {
|
||||||
processChallenges(
|
processChallenges(
|
||||||
challenges, this.proxyAuthState, this.proxyAuthHandler,
|
challenges, this.proxyAuthState, this.proxyAuthHandler,
|
||||||
|
@ -819,7 +820,8 @@ public class DefaultClientRequestDirector
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.debug("Target requested authentication");
|
LOG.debug("Target requested authentication");
|
||||||
Map challenges = this.targetAuthHandler.getChallenges(response, context);
|
Map<String, Header> challenges = this.targetAuthHandler.getChallenges(
|
||||||
|
response, context);
|
||||||
try {
|
try {
|
||||||
processChallenges(challenges,
|
processChallenges(challenges,
|
||||||
this.targetAuthState, this.targetAuthHandler,
|
this.targetAuthState, this.targetAuthHandler,
|
||||||
|
@ -846,7 +848,8 @@ public class DefaultClientRequestDirector
|
||||||
if (this.proxyAuthHandler.isAuthenticationRequested(response, context)) {
|
if (this.proxyAuthHandler.isAuthenticationRequested(response, context)) {
|
||||||
|
|
||||||
LOG.debug("Proxy requested authentication");
|
LOG.debug("Proxy requested authentication");
|
||||||
Map challenges = this.proxyAuthHandler.getChallenges(response, context);
|
Map<String, Header> challenges = this.proxyAuthHandler.getChallenges(
|
||||||
|
response, context);
|
||||||
try {
|
try {
|
||||||
processChallenges(challenges,
|
processChallenges(challenges,
|
||||||
this.proxyAuthState, this.proxyAuthHandler,
|
this.proxyAuthState, this.proxyAuthHandler,
|
||||||
|
@ -902,7 +905,7 @@ public class DefaultClientRequestDirector
|
||||||
|
|
||||||
|
|
||||||
private void processChallenges(
|
private void processChallenges(
|
||||||
final Map challenges,
|
final Map<String, Header> challenges,
|
||||||
final AuthState authState,
|
final AuthState authState,
|
||||||
final AuthenticationHandler authHandler,
|
final AuthenticationHandler authHandler,
|
||||||
final HttpResponse response,
|
final HttpResponse response,
|
||||||
|
|
|
@ -161,7 +161,7 @@ public class DefaultHttpClient extends AbstractHttpClient {
|
||||||
|
|
||||||
if (className != null) {
|
if (className != null) {
|
||||||
try {
|
try {
|
||||||
Class clazz = Class.forName(className);
|
Class<?> clazz = Class.forName(className);
|
||||||
ClientConnectionManagerFactory factory =
|
ClientConnectionManagerFactory factory =
|
||||||
(ClientConnectionManagerFactory) clazz.newInstance();
|
(ClientConnectionManagerFactory) clazz.newInstance();
|
||||||
connManager = factory.newInstance(params, registry);
|
connManager = factory.newInstance(params, registry);
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class DefaultProxyAuthenticationHandler extends AbstractAuthenticationHan
|
||||||
return status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED;
|
return status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map getChallenges(
|
public Map<String, Header> getChallenges(
|
||||||
final HttpResponse response,
|
final HttpResponse response,
|
||||||
final HttpContext context) throws MalformedChallengeException {
|
final HttpContext context) throws MalformedChallengeException {
|
||||||
if (response == null) {
|
if (response == null) {
|
||||||
|
|
|
@ -33,8 +33,6 @@ package org.apache.http.impl.client;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
@ -154,10 +152,11 @@ public class DefaultRedirectHandler implements RedirectHandler {
|
||||||
|
|
||||||
if (params.isParameterFalse(ClientPNames.ALLOW_CIRCULAR_REDIRECTS)) {
|
if (params.isParameterFalse(ClientPNames.ALLOW_CIRCULAR_REDIRECTS)) {
|
||||||
|
|
||||||
Set redirectLocations = (Set) context.getAttribute(REDIRECT_LOCATIONS);
|
RedirectLocations redirectLocations = (RedirectLocations) context.getAttribute(
|
||||||
|
REDIRECT_LOCATIONS);
|
||||||
|
|
||||||
if (redirectLocations == null) {
|
if (redirectLocations == null) {
|
||||||
redirectLocations = new HashSet();
|
redirectLocations = new RedirectLocations();
|
||||||
context.setAttribute(REDIRECT_LOCATIONS, redirectLocations);
|
context.setAttribute(REDIRECT_LOCATIONS, redirectLocations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class DefaultTargetAuthenticationHandler extends AbstractAuthenticationHa
|
||||||
return status == HttpStatus.SC_UNAUTHORIZED;
|
return status == HttpStatus.SC_UNAUTHORIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map getChallenges(
|
public Map<String, Header> getChallenges(
|
||||||
final HttpResponse response,
|
final HttpResponse response,
|
||||||
final HttpContext context) throws MalformedChallengeException {
|
final HttpContext context) throws MalformedChallengeException {
|
||||||
if (response == null) {
|
if (response == null) {
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue