Deprecated HttpParams and related classes in favor of new configuration API
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1414680 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1179458a52
commit
73dc5eebfd
|
@ -31,9 +31,9 @@ import org.apache.http.Header;
|
|||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.conn.params.ConnRoutePNames;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
@ -46,13 +46,14 @@ import org.apache.http.util.EntityUtils;
|
|||
public class ClientExecuteProxy {
|
||||
|
||||
public static void main(String[] args)throws Exception {
|
||||
HttpHost proxy = new HttpHost("127.0.0.1", 8080, "http");
|
||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
||||
try {
|
||||
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
|
||||
|
||||
HttpHost target = new HttpHost("issues.apache.org", 443, "https");
|
||||
HttpHost proxy = new HttpHost("127.0.0.1", 8080, "http");
|
||||
|
||||
RequestConfig config = RequestConfig.custom().setDefaultProxy(proxy).build();
|
||||
HttpGet request = new HttpGet("/");
|
||||
request.setConfig(config);
|
||||
|
||||
System.out.println("executing request to " + target + " via " + proxy);
|
||||
CloseableHttpResponse response = httpclient.execute(target, request);
|
||||
|
|
|
@ -33,14 +33,12 @@ import org.apache.http.client.AuthCache;
|
|||
import org.apache.http.client.CredentialsProvider;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.protocol.ClientContext;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.impl.auth.BasicScheme;
|
||||
import org.apache.http.impl.client.BasicAuthCache;
|
||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.protocol.BasicHttpContext;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,14 +33,12 @@ import org.apache.http.client.AuthCache;
|
|||
import org.apache.http.client.CredentialsProvider;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.protocol.ClientContext;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.impl.auth.DigestScheme;
|
||||
import org.apache.http.impl.client.BasicAuthCache;
|
||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.protocol.BasicHttpContext;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,9 +30,9 @@ import org.apache.http.HttpHost;
|
|||
import org.apache.http.auth.AuthScope;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
import org.apache.http.client.CredentialsProvider;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.conn.params.ConnRoutePNames;
|
||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
|
@ -55,9 +55,9 @@ public class ClientProxyAuthentication {
|
|||
HttpHost targetHost = new HttpHost("www.verisign.com", 443, "https");
|
||||
HttpHost proxy = new HttpHost("localhost", 8080);
|
||||
|
||||
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
|
||||
|
||||
RequestConfig config = RequestConfig.custom().setDefaultProxy(proxy).build();
|
||||
HttpGet httpget = new HttpGet("/");
|
||||
httpget.setConfig(config);
|
||||
|
||||
System.out.println("executing request: " + httpget.getRequestLine());
|
||||
System.out.println("via proxy: " + proxy);
|
||||
|
|
|
@ -28,12 +28,18 @@
|
|||
package org.apache.http.auth.params;
|
||||
|
||||
import org.apache.http.auth.AuthScheme;
|
||||
import org.apache.http.auth.AuthSchemeProvider;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
|
||||
/**
|
||||
* Parameter names for HTTP authentication classes.
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
*
|
||||
* @deprecated (4.3) use {@link RequestConfig} and constructor parameters of
|
||||
* {@link AuthSchemeProvider}s.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface AuthPNames {
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
|
||||
package org.apache.http.auth.params;
|
||||
|
||||
import org.apache.http.auth.AuthSchemeProvider;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.params.HttpAbstractParamBean;
|
||||
import org.apache.http.params.HttpParams;
|
||||
|
||||
|
@ -36,7 +38,11 @@ import org.apache.http.params.HttpParams;
|
|||
* using Java Beans conventions.
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated (4.3) use {@link RequestConfig} and constructor parameters of
|
||||
* {@link AuthSchemeProvider}s.
|
||||
*/
|
||||
@Deprecated
|
||||
public class AuthParamBean extends HttpAbstractParamBean {
|
||||
|
||||
public AuthParamBean (final HttpParams params) {
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
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;
|
||||
|
@ -38,9 +40,11 @@ import org.apache.http.protocol.HTTP;
|
|||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @see AuthPNames
|
||||
* @deprecated (4.3) use {@link RequestConfig} and constructor parameters of
|
||||
* {@link AuthSchemeProvider}s.
|
||||
*/
|
||||
@Immutable
|
||||
@Deprecated
|
||||
public final class AuthParams {
|
||||
|
||||
private AuthParams() {
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* 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.client.config;
|
||||
|
||||
import org.apache.http.annotation.Immutable;
|
||||
|
||||
/**
|
||||
* Standard authentication schemes supported by HttpClient.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
@Immutable
|
||||
public final class AuthSchemes {
|
||||
|
||||
/**
|
||||
* Basic authentication scheme as defined in RFC2617 (considered inherently
|
||||
* insecure, but most widely supported)
|
||||
*/
|
||||
public static final String BASIC = "Basic";
|
||||
|
||||
/**
|
||||
* Digest authentication scheme as defined in RFC2617.
|
||||
*/
|
||||
public static final String DIGEST = "Digest";
|
||||
|
||||
/**
|
||||
* The NTLM scheme is a proprietary Microsoft Windows Authentication
|
||||
* protocol (considered to be the most secure among currently supported
|
||||
* authentication schemes).
|
||||
*/
|
||||
public static final String NTLM = "NTLM";
|
||||
|
||||
/**
|
||||
* SPNEGO Authentication scheme.
|
||||
*/
|
||||
public static final String SPNEGO = "negotiate";
|
||||
|
||||
/**
|
||||
* Kerberos Authentication scheme.
|
||||
*/
|
||||
public static final String KERBEROS = "Kerberos";
|
||||
|
||||
private AuthSchemes() {
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* 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.client.config;
|
||||
|
||||
import org.apache.http.annotation.Immutable;
|
||||
|
||||
/**
|
||||
* Standard cookie specifications supported by HttpClient.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
@Immutable
|
||||
public final class CookieSpecs {
|
||||
|
||||
/**
|
||||
* The policy that provides high degree of compatibility
|
||||
* with common cookie management of popular HTTP agents.
|
||||
*/
|
||||
public static final String BROWSER_COMPATIBILITY = "compatibility";
|
||||
|
||||
/**
|
||||
* The Netscape cookie draft compliant policy.
|
||||
*/
|
||||
public static final String NETSCAPE = "netscape";
|
||||
|
||||
/**
|
||||
* The RFC 2109 compliant policy.
|
||||
*/
|
||||
public static final String RFC_2109 = "rfc2109";
|
||||
|
||||
/**
|
||||
* The RFC 2965 compliant policy.
|
||||
*/
|
||||
public static final String RFC_2965 = "rfc2965";
|
||||
|
||||
/**
|
||||
* The default 'best match' policy.
|
||||
*/
|
||||
public static final String BEST_MATCH = "best-match";
|
||||
|
||||
/**
|
||||
* The policy that ignores cookies.
|
||||
*/
|
||||
public static final String IGNORE_COOKIES = "ignoreCookies";
|
||||
|
||||
private CookieSpecs() {
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,306 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* 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.client.config;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
|
||||
public class RequestConfig implements Cloneable {
|
||||
|
||||
public static final RequestConfig DEFAULT = new Builder().build();
|
||||
|
||||
private final boolean expectContinueEnabled;
|
||||
private final HttpHost defaultProxy;
|
||||
private final InetAddress localAddress;
|
||||
private final boolean staleConnectionCheckEnabled;
|
||||
private final String cookieSpec;
|
||||
private final boolean redirectsEnabled;
|
||||
private final boolean relativeRedirectsAllowed;
|
||||
private final boolean circularRedirectsAllowed;
|
||||
private final int maxRedirects;
|
||||
private final boolean authenticationEnabled;
|
||||
private final Collection<String> targetPreferredAuthSchemes;
|
||||
private final Collection<String> proxyPreferredAuthSchemes;
|
||||
private final int connectionRequestTimeout;
|
||||
private final int connectTimeout;
|
||||
private final int socketTimeout;
|
||||
|
||||
RequestConfig(
|
||||
final boolean expectContinueEnabled,
|
||||
final HttpHost defaultProxy,
|
||||
final InetAddress localAddress,
|
||||
final boolean staleConnectionCheckEnabled,
|
||||
final String cookieSpec,
|
||||
final boolean redirectsEnabled,
|
||||
final boolean relativeRedirectsAllowed,
|
||||
final boolean circularRedirectsAllowed,
|
||||
final int maxRedirects,
|
||||
final boolean authenticationEnabled,
|
||||
final Collection<String> targetPreferredAuthSchemes,
|
||||
final Collection<String> proxyPreferredAuthSchemes,
|
||||
final int connectionRequestTimeout,
|
||||
final int connectTimeout,
|
||||
final int socketTimeout) {
|
||||
super();
|
||||
this.expectContinueEnabled = expectContinueEnabled;
|
||||
this.defaultProxy = defaultProxy;
|
||||
this.localAddress = localAddress;
|
||||
this.staleConnectionCheckEnabled = staleConnectionCheckEnabled;
|
||||
this.cookieSpec = cookieSpec;
|
||||
this.redirectsEnabled = redirectsEnabled;
|
||||
this.relativeRedirectsAllowed = relativeRedirectsAllowed;
|
||||
this.circularRedirectsAllowed = circularRedirectsAllowed;
|
||||
this.maxRedirects = maxRedirects;
|
||||
this.authenticationEnabled = authenticationEnabled;
|
||||
this.targetPreferredAuthSchemes = targetPreferredAuthSchemes;
|
||||
this.proxyPreferredAuthSchemes = proxyPreferredAuthSchemes;
|
||||
this.connectionRequestTimeout = connectionRequestTimeout;
|
||||
this.connectTimeout = connectTimeout;
|
||||
this.socketTimeout = socketTimeout;
|
||||
}
|
||||
|
||||
public boolean isExpectContinueEnabled() {
|
||||
return expectContinueEnabled;
|
||||
}
|
||||
|
||||
public HttpHost getDefaultProxy() {
|
||||
return defaultProxy;
|
||||
}
|
||||
|
||||
public InetAddress getLocalAddress() {
|
||||
return localAddress;
|
||||
}
|
||||
|
||||
public boolean isStaleConnectionCheckEnabled() {
|
||||
return staleConnectionCheckEnabled;
|
||||
}
|
||||
|
||||
public String getCookieSpec() {
|
||||
return cookieSpec;
|
||||
}
|
||||
|
||||
public boolean isRedirectsEnabled() {
|
||||
return redirectsEnabled;
|
||||
}
|
||||
|
||||
public boolean isRelativeRedirectsAllowed() {
|
||||
return relativeRedirectsAllowed;
|
||||
}
|
||||
|
||||
public boolean isCircularRedirectsAllowed() {
|
||||
return circularRedirectsAllowed;
|
||||
}
|
||||
|
||||
public int getMaxRedirects() {
|
||||
return maxRedirects;
|
||||
}
|
||||
|
||||
public boolean isAuthenticationEnabled() {
|
||||
return authenticationEnabled;
|
||||
}
|
||||
|
||||
public Collection<String> getTargetPreferredAuthSchemes() {
|
||||
return targetPreferredAuthSchemes;
|
||||
}
|
||||
|
||||
public Collection<String> getProxyPreferredAuthSchemes() {
|
||||
return proxyPreferredAuthSchemes;
|
||||
}
|
||||
|
||||
public int getConnectionRequestTimeout() {
|
||||
return connectionRequestTimeout;
|
||||
}
|
||||
|
||||
public int getConnectTimeout() {
|
||||
return connectTimeout;
|
||||
}
|
||||
|
||||
public int getSocketTimeout() {
|
||||
return socketTimeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RequestConfig clone() throws CloneNotSupportedException {
|
||||
return (RequestConfig) super.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(", expectContinueEnabled=").append(expectContinueEnabled);
|
||||
builder.append(", defaultProxy=").append(defaultProxy);
|
||||
builder.append(", localAddress=").append(localAddress);
|
||||
builder.append(", staleConnectionCheckEnabled=").append(staleConnectionCheckEnabled);
|
||||
builder.append(", cookieSpec=").append(cookieSpec);
|
||||
builder.append(", redirectsEnabled=").append(redirectsEnabled);
|
||||
builder.append(", relativeRedirectsAllowed=").append(relativeRedirectsAllowed);
|
||||
builder.append(", maxRedirects=").append(maxRedirects);
|
||||
builder.append(", circularRedirectsAllowed=").append(circularRedirectsAllowed);
|
||||
builder.append(", authenticationEnabled=").append(authenticationEnabled);
|
||||
builder.append(", targetPreferredAuthSchemes=").append(targetPreferredAuthSchemes);
|
||||
builder.append(", proxyPreferredAuthSchemes=").append(proxyPreferredAuthSchemes);
|
||||
builder.append(", connectionRequestTimeout=").append(connectionRequestTimeout);
|
||||
builder.append(", connectTimeout=").append(connectTimeout);
|
||||
builder.append(", socketTimeout=").append(socketTimeout);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static RequestConfig.Builder custom() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private boolean expectContinueEnabled;
|
||||
private HttpHost defaultProxy;
|
||||
private InetAddress localAddress;
|
||||
private boolean staleConnectionCheckEnabled;
|
||||
private String cookieSpec;
|
||||
private boolean redirectsEnabled;
|
||||
private boolean relativeRedirectsAllowed;
|
||||
private boolean circularRedirectsAllowed;
|
||||
private int maxRedirects;
|
||||
private boolean authenticationEnabled;
|
||||
private Collection<String> targetPreferredAuthSchemes;
|
||||
private Collection<String> proxyPreferredAuthSchemes;
|
||||
private int connectionRequestTimeout;
|
||||
private int connectTimeout;
|
||||
private int socketTimeout;
|
||||
|
||||
Builder() {
|
||||
super();
|
||||
this.staleConnectionCheckEnabled = true;
|
||||
this.redirectsEnabled = true;
|
||||
this.maxRedirects = 50;
|
||||
this.relativeRedirectsAllowed = true;
|
||||
this.authenticationEnabled = true;
|
||||
this.connectionRequestTimeout = -1;
|
||||
this.connectTimeout = -1;
|
||||
this.socketTimeout = -1;
|
||||
}
|
||||
|
||||
public Builder setExpectContinueEnabled(boolean expectContinueEnabled) {
|
||||
this.expectContinueEnabled = expectContinueEnabled;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setDefaultProxy(final HttpHost defaultProxy) {
|
||||
this.defaultProxy = defaultProxy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setLocalAddress(final InetAddress localAddress) {
|
||||
this.localAddress = localAddress;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setStaleConnectionCheckEnabled(boolean staleConnectionCheckEnabled) {
|
||||
this.staleConnectionCheckEnabled = staleConnectionCheckEnabled;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setCookieSpec(final String cookieSpec) {
|
||||
this.cookieSpec = cookieSpec;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setRedirectsEnabled(boolean redirectsEnabled) {
|
||||
this.redirectsEnabled = redirectsEnabled;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setRelativeRedirectsAllowed(boolean relativeRedirectsAllowed) {
|
||||
this.relativeRedirectsAllowed = relativeRedirectsAllowed;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setCircularRedirectsAllowed(boolean circularRedirectsAllowed) {
|
||||
this.circularRedirectsAllowed = circularRedirectsAllowed;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setMaxRedirects(final int maxRedirects) {
|
||||
this.maxRedirects = maxRedirects;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setAuthenticationEnabled(boolean authenticationEnabled) {
|
||||
this.authenticationEnabled = authenticationEnabled;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setTargetPreferredAuthSchemes(final Collection<String> targetPreferredAuthSchemes) {
|
||||
this.targetPreferredAuthSchemes = targetPreferredAuthSchemes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setProxyPreferredAuthSchemes(final Collection<String> proxyPreferredAuthSchemes) {
|
||||
this.proxyPreferredAuthSchemes = proxyPreferredAuthSchemes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setConnectionRequestTimeout(final int connectionRequestTimeout) {
|
||||
this.connectionRequestTimeout = connectionRequestTimeout;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setConnectTimeout(int connectTimeout) {
|
||||
this.connectTimeout = connectTimeout;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setSocketTimeout(final int socketTimeout) {
|
||||
this.socketTimeout = socketTimeout;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RequestConfig build() {
|
||||
return new RequestConfig(
|
||||
expectContinueEnabled,
|
||||
defaultProxy,
|
||||
localAddress,
|
||||
staleConnectionCheckEnabled,
|
||||
cookieSpec,
|
||||
redirectsEnabled,
|
||||
relativeRedirectsAllowed,
|
||||
circularRedirectsAllowed,
|
||||
maxRedirects,
|
||||
authenticationEnabled,
|
||||
targetPreferredAuthSchemes,
|
||||
proxyPreferredAuthSchemes,
|
||||
connectionRequestTimeout,
|
||||
connectTimeout,
|
||||
socketTimeout);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* 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.client.methods;
|
||||
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
|
||||
/**
|
||||
* Configuration interface for HTTP requests.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
public interface Configurable {
|
||||
|
||||
RequestConfig getConfig();
|
||||
|
||||
}
|
|
@ -36,6 +36,7 @@ import org.apache.http.annotation.NotThreadSafe;
|
|||
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.http.RequestLine;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.utils.CloneUtils;
|
||||
import org.apache.http.concurrent.Cancellable;
|
||||
import org.apache.http.conn.ClientConnectionRequest;
|
||||
|
@ -45,15 +46,14 @@ import org.apache.http.message.BasicRequestLine;
|
|||
import org.apache.http.params.HttpProtocolParams;
|
||||
|
||||
/**
|
||||
* Basic implementation of an HTTP request that can be modified. Methods of the
|
||||
* {@link AbortableHttpRequest} interface implemented by this class are thread safe.
|
||||
* Base implementation of {@link HttpUriRequest}.
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@NotThreadSafe
|
||||
public abstract class HttpRequestBase extends AbstractHttpMessage
|
||||
implements HttpUriRequest, HttpExecutionAware, AbortableHttpRequest, Cloneable {
|
||||
implements HttpUriRequest, Configurable, HttpExecutionAware, AbortableHttpRequest, Cloneable {
|
||||
|
||||
private Lock abortLock;
|
||||
private volatile boolean aborted;
|
||||
|
@ -61,6 +61,7 @@ public abstract class HttpRequestBase extends AbstractHttpMessage
|
|||
private ProtocolVersion version;
|
||||
private URI uri;
|
||||
private Cancellable cancellable;
|
||||
private RequestConfig config;
|
||||
|
||||
public HttpRequestBase() {
|
||||
super();
|
||||
|
@ -108,6 +109,14 @@ public abstract class HttpRequestBase extends AbstractHttpMessage
|
|||
this.uri = uri;
|
||||
}
|
||||
|
||||
public RequestConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public void setConfig(final RequestConfig config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setConnectionRequest(final ClientConnectionRequest connRequest) {
|
||||
if (this.aborted) {
|
||||
|
|
|
@ -36,8 +36,6 @@ import org.apache.http.HttpRequest;
|
|||
* convenience methods to access request properties such as request URI
|
||||
* and method type.
|
||||
*
|
||||
*
|
||||
* <!-- empty lines to avoid svn diff problems -->
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface HttpUriRequest extends HttpRequest {
|
||||
|
|
|
@ -36,10 +36,10 @@ import org.apache.http.HttpEntityEnclosingRequest;
|
|||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.utils.CloneUtils;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.HeaderGroup;
|
||||
import org.apache.http.params.HttpParams;
|
||||
|
||||
/**
|
||||
* @since 4.3
|
||||
|
@ -52,7 +52,7 @@ public class RequestBuilder {
|
|||
private URI uri;
|
||||
private HeaderGroup headergroup;
|
||||
private HttpEntity entity;
|
||||
private HttpParams params;
|
||||
private RequestConfig config;
|
||||
|
||||
RequestBuilder(final String method) {
|
||||
super();
|
||||
|
@ -124,7 +124,11 @@ public class RequestBuilder {
|
|||
} else {
|
||||
entity = null;
|
||||
}
|
||||
params = request.getParams();
|
||||
if (request instanceof Configurable) {
|
||||
this.config = ((Configurable) request).getConfig();
|
||||
} else {
|
||||
this.config = null;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -234,12 +238,12 @@ public class RequestBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
public HttpParams getParams() {
|
||||
return params;
|
||||
public RequestConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public RequestBuilder setParams(final HttpParams params) {
|
||||
this.params = params;
|
||||
public RequestBuilder setConfig(final RequestConfig config) {
|
||||
this.config = config;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -264,9 +268,7 @@ public class RequestBuilder {
|
|||
if (this.headergroup != null) {
|
||||
result.setHeaders(this.headergroup.getAllHeaders());
|
||||
}
|
||||
if (this.params != null) {
|
||||
result.setParams(this.params);
|
||||
}
|
||||
result.setConfig(this.config);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ package org.apache.http.client.params;
|
|||
import org.apache.http.params.CoreConnectionPNames;
|
||||
import org.apache.http.params.CoreProtocolPNames;
|
||||
import org.apache.http.auth.params.AuthPNames;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.cookie.params.CookieSpecPNames;
|
||||
import org.apache.http.conn.params.ConnManagerPNames;
|
||||
import org.apache.http.conn.params.ConnConnectionPNames;
|
||||
|
@ -46,8 +47,10 @@ import org.apache.http.conn.params.ConnRoutePNames;
|
|||
* in which the respective constants are actually defined.
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated (4.3) use {@link RequestConfig}
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Deprecated
|
||||
public interface AllClientPNames extends
|
||||
CoreConnectionPNames, CoreProtocolPNames,
|
||||
ClientPNames, AuthPNames, CookieSpecPNames,
|
||||
|
|
|
@ -28,12 +28,16 @@
|
|||
package org.apache.http.client.params;
|
||||
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.http.client.config.AuthSchemes;
|
||||
|
||||
/**
|
||||
* Standard authentication schemes supported by HttpClient.
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated (4.3) use {@link AuthSchemes}
|
||||
*/
|
||||
@Deprecated
|
||||
@Immutable
|
||||
public final class AuthPolicy {
|
||||
|
||||
|
|
|
@ -26,17 +26,18 @@
|
|||
|
||||
package org.apache.http.client.params;
|
||||
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
|
||||
/**
|
||||
* Parameter names for HTTP client parameters.
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated (4.3) use {@link RequestConfig}
|
||||
*/
|
||||
@Deprecated
|
||||
public interface ClientPNames {
|
||||
|
||||
/**
|
||||
* @deprecated (4.2) do not use
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String CONNECTION_MANAGER_FACTORY_CLASS_NAME = "http.connection-manager.factory-class-name";
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,6 +30,7 @@ package org.apache.http.client.params;
|
|||
import java.util.Collection;
|
||||
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpHost;
|
||||
|
@ -42,7 +43,10 @@ import org.apache.http.params.HttpParams;
|
|||
* Java Beans conventions.
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated (4.3) use {@link RequestConfig}
|
||||
*/
|
||||
@Deprecated
|
||||
@NotThreadSafe
|
||||
public class ClientParamBean extends HttpAbstractParamBean {
|
||||
|
||||
|
|
|
@ -28,12 +28,16 @@
|
|||
package org.apache.http.client.params;
|
||||
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.http.client.config.CookieSpecs;
|
||||
|
||||
/**
|
||||
* Standard cookie specifications supported by HttpClient.
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated (4.3) use {@link CookieSpecs}
|
||||
*/
|
||||
@Deprecated
|
||||
@Immutable
|
||||
public final class CookiePolicy {
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
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;
|
||||
|
@ -35,7 +36,10 @@ import org.apache.http.params.HttpParams;
|
|||
* An adaptor for manipulating HTTP client parameters in {@link HttpParams}.
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated (4.3) use {@link RequestConfig}
|
||||
*/
|
||||
@Deprecated
|
||||
@Immutable
|
||||
public class HttpClientParams {
|
||||
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* 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.client.params;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.http.auth.params.AuthPNames;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.conn.params.ConnRouteParams;
|
||||
import org.apache.http.params.HttpConnectionParams;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.params.HttpProtocolParams;
|
||||
|
||||
/**
|
||||
* @deprecated (4.3) provided for compatibility with {@link HttpParams}. Do not use.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
@Deprecated
|
||||
public final class HttpParamConfig {
|
||||
|
||||
private HttpParamConfig() {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static RequestConfig getRequestConfig(final HttpParams params) {
|
||||
return RequestConfig.custom()
|
||||
.setAuthenticationEnabled(HttpClientParams.isAuthenticating(params))
|
||||
.setCircularRedirectsAllowed(params.isParameterFalse(ClientPNames.REJECT_RELATIVE_REDIRECT))
|
||||
.setConnectionRequestTimeout((int) HttpClientParams.getConnectionManagerTimeout(params))
|
||||
.setConnectTimeout(HttpConnectionParams.getConnectionTimeout(params))
|
||||
.setCookieSpec(HttpClientParams.getCookiePolicy(params))
|
||||
.setDefaultProxy(ConnRouteParams.getDefaultProxy(params))
|
||||
.setExpectContinueEnabled(HttpProtocolParams.useExpectContinue(params))
|
||||
.setLocalAddress(ConnRouteParams.getLocalAddress(params))
|
||||
.setMaxRedirects(params.getIntParameter(ClientPNames.MAX_REDIRECTS, 50))
|
||||
.setProxyPreferredAuthSchemes((Collection<String>) params.getParameter(
|
||||
AuthPNames.PROXY_AUTH_PREF))
|
||||
.setTargetPreferredAuthSchemes((Collection<String>) params.getParameter(
|
||||
AuthPNames.TARGET_AUTH_PREF))
|
||||
.setRedirectsEnabled(HttpClientParams.isRedirecting(params))
|
||||
.setRelativeRedirectsAllowed(params.isParameterTrue(ClientPNames.ALLOW_CIRCULAR_REDIRECTS))
|
||||
.setSocketTimeout(HttpConnectionParams.getSoTimeout(params))
|
||||
.setStaleConnectionCheckEnabled(HttpConnectionParams.isStaleCheckingEnabled(params))
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
|
@ -125,7 +125,17 @@ public interface ClientContext {
|
|||
/**
|
||||
* Attribute name of a {@link org.apache.http.config.Lookup} object that represents
|
||||
* the actual {@link ConnectionSocketFactory} registry.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
public static final String SOCKET_FACTORY_REGISTRY = "http.socket-factory-registry";
|
||||
|
||||
/**
|
||||
* Attribute name of a {@link org.apache.http.client.config.RequestConfig} object that
|
||||
* represents the actual request configuration.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
public static final String REQUEST_CONFIG = "http.request-config";
|
||||
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.apache.http.auth.AuthState;
|
|||
import org.apache.http.client.AuthCache;
|
||||
import org.apache.http.client.CookieStore;
|
||||
import org.apache.http.client.CredentialsProvider;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.config.Lookup;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.conn.routing.RouteInfo;
|
||||
|
@ -158,4 +159,13 @@ public class HttpClientContext extends HttpCoreContext implements ClientContext
|
|||
setAttribute(USER_TOKEN, obj);
|
||||
}
|
||||
|
||||
public RequestConfig getRequestConfig() {
|
||||
RequestConfig config = getAttribute(REQUEST_CONFIG, RequestConfig.class);
|
||||
return config != null ? config : RequestConfig.DEFAULT;
|
||||
}
|
||||
|
||||
public void setRequestConfig(final RequestConfig config) {
|
||||
setAttribute(REQUEST_CONFIG, config);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -43,8 +43,9 @@ import org.apache.http.HttpRequest;
|
|||
import org.apache.http.HttpRequestInterceptor;
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.http.client.CookieStore;
|
||||
import org.apache.http.client.config.CookieSpecs;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.client.params.HttpClientParams;
|
||||
import org.apache.http.config.Lookup;
|
||||
import org.apache.http.conn.routing.RouteInfo;
|
||||
import org.apache.http.cookie.Cookie;
|
||||
|
@ -58,14 +59,6 @@ import org.apache.http.protocol.HttpContext;
|
|||
* Request interceptor that matches cookies available in the current
|
||||
* {@link CookieStore} to the request being executed and generates
|
||||
* corresponding <code>Cookie</code> request headers.
|
||||
* <p>
|
||||
* The following parameters can be used to customize the behavior of this
|
||||
* class:
|
||||
* <ul>
|
||||
* <li>{@link org.apache.http.cookie.params.CookieSpecPNames#DATE_PATTERNS}</li>
|
||||
* <li>{@link org.apache.http.cookie.params.CookieSpecPNames#SINGLE_COOKIE_HEADER}</li>
|
||||
* <li>{@link org.apache.http.client.params.ClientPNames#COOKIE_POLICY}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
|
@ -122,7 +115,11 @@ public class RequestAddCookies implements HttpRequestInterceptor {
|
|||
return;
|
||||
}
|
||||
|
||||
String policy = HttpClientParams.getCookiePolicy(request.getParams());
|
||||
RequestConfig config = clientContext.getRequestConfig();
|
||||
String policy = config.getCookieSpec();
|
||||
if (policy == null) {
|
||||
policy = CookieSpecs.BEST_MATCH;
|
||||
}
|
||||
if (this.log.isDebugEnabled()) {
|
||||
this.log.debug("CookieSpec selected: " + policy);
|
||||
}
|
||||
|
|
|
@ -44,11 +44,22 @@ import org.apache.http.protocol.HttpContext;
|
|||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Immutable
|
||||
public class RequestDefaultHeaders implements HttpRequestInterceptor {
|
||||
|
||||
public RequestDefaultHeaders() {
|
||||
private final Collection<? extends Header> defaultHeaders;
|
||||
|
||||
/**
|
||||
* @since 4.3
|
||||
*/
|
||||
public RequestDefaultHeaders(final Collection<? extends Header> defaultHeaders) {
|
||||
super();
|
||||
this.defaultHeaders = defaultHeaders;
|
||||
}
|
||||
|
||||
public RequestDefaultHeaders() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public void process(final HttpRequest request, final HttpContext context)
|
||||
|
@ -64,8 +75,11 @@ public class RequestDefaultHeaders implements HttpRequestInterceptor {
|
|||
|
||||
// Add default headers
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<Header> defHeaders = (Collection<Header>) request.getParams().getParameter(
|
||||
ClientPNames.DEFAULT_HEADERS);
|
||||
Collection<? extends Header> defHeaders = (Collection<? extends Header>)
|
||||
request.getParams().getParameter(ClientPNames.DEFAULT_HEADERS);
|
||||
if (defHeaders == null) {
|
||||
defHeaders = this.defaultHeaders;
|
||||
}
|
||||
|
||||
if (defHeaders != null) {
|
||||
for (Header defHeader : defHeaders) {
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* 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.client.protocol;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpEntityEnclosingRequest;
|
||||
import org.apache.http.HttpException;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpRequestInterceptor;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.protocol.HTTP;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.apache.http.util.Args;
|
||||
|
||||
/**
|
||||
* RequestExpectContinue is responsible for enabling the 'expect-continue'
|
||||
* handshake by adding <code>Expect</code> header.
|
||||
* <p/>
|
||||
* This interceptor takes into account {@link RequestConfig#isExpectContinueEnabled()}
|
||||
* setting.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
@Immutable
|
||||
public class RequestExpectContinue implements HttpRequestInterceptor {
|
||||
|
||||
public RequestExpectContinue() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void process(final HttpRequest request, final HttpContext context)
|
||||
throws HttpException, IOException {
|
||||
Args.notNull(request, "HTTP request");
|
||||
|
||||
if (!request.containsHeader(HTTP.EXPECT_DIRECTIVE)) {
|
||||
if (request instanceof HttpEntityEnclosingRequest) {
|
||||
ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
|
||||
HttpEntity entity = ((HttpEntityEnclosingRequest)request).getEntity();
|
||||
// Do not send the expect header if request body is known to be empty
|
||||
if (entity != null
|
||||
&& entity.getContentLength() != 0 && !ver.lessEquals(HttpVersion.HTTP_1_0)) {
|
||||
HttpClientContext clientContext = HttpClientContext.adapt(context);
|
||||
RequestConfig config = clientContext.getRequestConfig();
|
||||
if (config.isExpectContinueEnabled()) {
|
||||
request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -79,7 +79,9 @@ public interface HttpClientConnectionManager {
|
|||
HttpClientConnection conn, Object newState, long validDuration, TimeUnit timeUnit);
|
||||
|
||||
void connect(
|
||||
HttpClientConnection conn, HttpHost host, InetAddress localAddress,
|
||||
HttpClientConnection conn,
|
||||
HttpHost host, InetAddress localAddress,
|
||||
int connectTimeout,
|
||||
HttpContext context) throws IOException;
|
||||
|
||||
void upgrade(
|
||||
|
|
|
@ -32,6 +32,8 @@ import org.apache.http.impl.conn.DefaultHttpResponseParser;
|
|||
* Parameter names for HTTP client connections.
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated (4.1) use custom {@link DefaultHttpResponseParser} implementation.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface ConnConnectionPNames {
|
||||
|
@ -53,7 +55,7 @@ public interface ConnConnectionPNames {
|
|||
* Use {@link java.lang.Integer#MAX_VALUE} for unlimited number.
|
||||
* </p>
|
||||
*
|
||||
* @deprecated Use custom {@link DefaultHttpResponseParser} implementation
|
||||
* @deprecated (4.1) Use custom {@link DefaultHttpResponseParser} implementation
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String MAX_STATUS_LINE_GARBAGE = "http.connection.max-status-line-garbage";
|
||||
|
|
|
@ -31,7 +31,7 @@ package org.apache.http.conn.params;
|
|||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated (4.1.2) use configuration methods of the specific connection manager implementation.
|
||||
* @deprecated (4.1) use configuration methods of the specific connection manager implementation.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface ConnManagerPNames {
|
||||
|
|
|
@ -39,7 +39,7 @@ import org.apache.http.params.HttpParams;
|
|||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated (4.1.2) use configuration methods of the specific connection manager implementation.
|
||||
* @deprecated (4.1) use configuration methods of the specific connection manager implementation.
|
||||
*/
|
||||
@NotThreadSafe
|
||||
@Deprecated
|
||||
|
|
|
@ -40,7 +40,7 @@ import org.apache.http.params.HttpParams;
|
|||
*
|
||||
* @see ConnManagerPNames
|
||||
*
|
||||
* @deprecated (4.1.2) use configuration methods of the specific connection manager implementation.
|
||||
* @deprecated (4.1) use configuration methods of the specific connection manager implementation.
|
||||
*/
|
||||
@Deprecated
|
||||
@Immutable
|
||||
|
|
|
@ -26,11 +26,16 @@
|
|||
|
||||
package org.apache.http.conn.params;
|
||||
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
|
||||
/**
|
||||
* Parameter names for connection routing.
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated (4.3) use {@link RequestConfig}.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface ConnRoutePNames {
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,6 +32,7 @@ import java.net.InetAddress;
|
|||
import org.apache.http.annotation.NotThreadSafe;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.params.HttpAbstractParamBean;
|
||||
import org.apache.http.params.HttpParams;
|
||||
|
@ -42,7 +43,10 @@ import org.apache.http.params.HttpParams;
|
|||
* using Java Beans conventions.
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated (4.3) use {@link RequestConfig}.
|
||||
*/
|
||||
@Deprecated
|
||||
@NotThreadSafe
|
||||
public class ConnRouteParamBean extends HttpAbstractParamBean {
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.apache.http.annotation.Immutable;
|
|||
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
|
||||
/**
|
||||
|
@ -39,7 +40,10 @@ import org.apache.http.conn.routing.HttpRoute;
|
|||
* in {@link HttpParams}.
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated (4.3) use {@link RequestConfig}.
|
||||
*/
|
||||
@Deprecated
|
||||
@Immutable
|
||||
public class ConnRouteParams implements ConnRoutePNames {
|
||||
|
||||
|
|
|
@ -27,11 +27,16 @@
|
|||
|
||||
package org.apache.http.cookie.params;
|
||||
|
||||
import org.apache.http.cookie.CookieSpecProvider;
|
||||
|
||||
/**
|
||||
* Parameter names for HTTP cookie management classes.
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated (4.3) use constructor parameters of {@link CookieSpecProvider}s.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface CookieSpecPNames {
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,6 +30,7 @@ package org.apache.http.cookie.params;
|
|||
import java.util.Collection;
|
||||
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
import org.apache.http.cookie.CookieSpecProvider;
|
||||
|
||||
import org.apache.http.params.HttpAbstractParamBean;
|
||||
import org.apache.http.params.HttpParams;
|
||||
|
@ -40,7 +41,10 @@ import org.apache.http.params.HttpParams;
|
|||
* conventions.
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated (4.3) use constructor parameters of {@link CookieSpecProvider}s.
|
||||
*/
|
||||
@Deprecated
|
||||
@NotThreadSafe
|
||||
public class CookieSpecParamBean extends HttpAbstractParamBean {
|
||||
|
||||
|
|
|
@ -63,6 +63,8 @@ public abstract class AuthSchemeBase implements ContextAwareAuthScheme {
|
|||
* state.
|
||||
*
|
||||
* @since 4.2
|
||||
*
|
||||
* @deprecated (4.3) do not use.
|
||||
*/
|
||||
public AuthSchemeBase(final ChallengeState challengeState) {
|
||||
super();
|
||||
|
@ -70,7 +72,7 @@ public abstract class AuthSchemeBase implements ContextAwareAuthScheme {
|
|||
}
|
||||
|
||||
public AuthSchemeBase() {
|
||||
this(null);
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,9 +26,12 @@
|
|||
|
||||
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.auth.AuthenticationException;
|
||||
|
@ -38,7 +41,6 @@ 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.auth.params.AuthParams;
|
||||
import org.apache.http.message.BufferedHeader;
|
||||
import org.apache.http.protocol.BasicHttpContext;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
|
@ -47,12 +49,6 @@ import org.apache.http.util.EncodingUtils;
|
|||
|
||||
/**
|
||||
* Basic authentication scheme as defined in RFC 2617.
|
||||
* <p>
|
||||
* The following parameters can be used to customize the behavior of this
|
||||
* class:
|
||||
* <ul>
|
||||
* <li>{@link org.apache.http.auth.params.AuthPNames#CREDENTIAL_CHARSET}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
|
@ -62,19 +58,29 @@ public class BasicScheme extends RFC2617Scheme {
|
|||
/** Whether the basic authentication process is complete */
|
||||
private boolean complete;
|
||||
|
||||
/**
|
||||
* @since 4.3
|
||||
*/
|
||||
public BasicScheme(final Charset credentialsCharset) {
|
||||
super(credentialsCharset);
|
||||
this.complete = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>BasicScheme</tt> with the given challenge
|
||||
* state.
|
||||
*
|
||||
* @since 4.2
|
||||
*
|
||||
* @deprecated (4.3) do not use.
|
||||
*/
|
||||
@Deprecated
|
||||
public BasicScheme(final ChallengeState challengeState) {
|
||||
super(challengeState);
|
||||
this.complete = false;
|
||||
}
|
||||
|
||||
public BasicScheme() {
|
||||
this(null);
|
||||
this(Consts.ASCII);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -153,9 +159,24 @@ public class BasicScheme extends RFC2617Scheme {
|
|||
if (request == null) {
|
||||
throw new IllegalArgumentException("HTTP request may not be null");
|
||||
}
|
||||
StringBuilder tmp = new StringBuilder();
|
||||
tmp.append(credentials.getUserPrincipal().getName());
|
||||
tmp.append(":");
|
||||
tmp.append((credentials.getPassword() == null) ? "null" : credentials.getPassword());
|
||||
|
||||
String charset = AuthParams.getCredentialCharset(request.getParams());
|
||||
return authenticate(credentials, charset, isProxy());
|
||||
byte[] base64password = Base64.encodeBase64(
|
||||
EncodingUtils.getBytes(tmp.toString(), getCredentialsCharset(request)));
|
||||
|
||||
CharArrayBuffer buffer = new CharArrayBuffer(32);
|
||||
if (isProxy()) {
|
||||
buffer.append(AUTH.PROXY_AUTH_RESP);
|
||||
} else {
|
||||
buffer.append(AUTH.WWW_AUTH_RESP);
|
||||
}
|
||||
buffer.append(": Basic ");
|
||||
buffer.append(base64password, 0, base64password.length);
|
||||
|
||||
return new BufferedHeader(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -166,7 +187,10 @@ public class BasicScheme extends RFC2617Scheme {
|
|||
* @param charset The charset to use for encoding the credentials
|
||||
*
|
||||
* @return a basic authorization header
|
||||
*
|
||||
* @deprecated (4.3) use {@link #authenticate(Credentials, HttpRequest, HttpContext)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public static Header authenticate(
|
||||
final Credentials credentials,
|
||||
final String charset,
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
|
||||
package org.apache.http.impl.auth;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.apache.http.annotation.Immutable;
|
||||
|
||||
import org.apache.http.auth.AuthScheme;
|
||||
|
@ -45,12 +47,26 @@ import org.apache.http.protocol.HttpContext;
|
|||
@SuppressWarnings("deprecation")
|
||||
public class BasicSchemeFactory implements AuthSchemeFactory, AuthSchemeProvider {
|
||||
|
||||
private final Charset charset;
|
||||
|
||||
/**
|
||||
* @since 4.3
|
||||
*/
|
||||
public BasicSchemeFactory(final Charset charset) {
|
||||
super();
|
||||
this.charset = charset;
|
||||
}
|
||||
|
||||
public BasicSchemeFactory() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public AuthScheme newInstance(final HttpParams params) {
|
||||
return new BasicScheme();
|
||||
}
|
||||
|
||||
public AuthScheme create(final HttpContext context) {
|
||||
return new BasicScheme();
|
||||
return new BasicScheme(this.charset);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
package org.apache.http.impl.auth;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
|
@ -39,6 +40,7 @@ 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;
|
||||
|
@ -49,7 +51,6 @@ 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.auth.params.AuthParams;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.message.BasicHeaderValueFormatter;
|
||||
import org.apache.http.message.BufferedHeader;
|
||||
|
@ -64,22 +65,10 @@ import org.apache.http.util.EncodingUtils;
|
|||
* Currently only qop=auth or no qop is supported. qop=auth-int
|
||||
* is unsupported. If auth and auth-int are provided, auth is
|
||||
* used.
|
||||
* <p>
|
||||
* Credential charset is configured via the
|
||||
* {@link org.apache.http.auth.params.AuthPNames#CREDENTIAL_CHARSET}
|
||||
* parameter of the HTTP request.
|
||||
* <p>
|
||||
* <p/>
|
||||
* Since the digest username is included as clear text in the generated
|
||||
* Authentication header, the charset of the username must be compatible
|
||||
* with the
|
||||
* {@link org.apache.http.params.CoreProtocolPNames#HTTP_ELEMENT_CHARSET
|
||||
* http element charset}.
|
||||
* <p>
|
||||
* The following parameters can be used to customize the behavior of this
|
||||
* class:
|
||||
* <ul>
|
||||
* <li>{@link org.apache.http.auth.params.AuthPNames#CREDENTIAL_CHARSET}</li>
|
||||
* </ul>
|
||||
* with the HTTP element charset used by the connection.
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
|
@ -111,19 +100,29 @@ public class DigestScheme extends RFC2617Scheme {
|
|||
private String a1;
|
||||
private String a2;
|
||||
|
||||
/**
|
||||
* @since 4.3
|
||||
*/
|
||||
public DigestScheme(final Charset credentialsCharset) {
|
||||
super(credentialsCharset);
|
||||
this.complete = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>DigestScheme</tt> with the given challenge
|
||||
* state.
|
||||
*
|
||||
* @since 4.2
|
||||
*
|
||||
* @deprecated (4.3) do not use.
|
||||
*/
|
||||
@Deprecated
|
||||
public DigestScheme(final ChallengeState challengeState) {
|
||||
super(challengeState);
|
||||
this.complete = false;
|
||||
}
|
||||
|
||||
public DigestScheme() {
|
||||
this(null);
|
||||
this(Consts.ASCII);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -224,8 +223,7 @@ public class DigestScheme extends RFC2617Scheme {
|
|||
getParameters().put("uri", request.getRequestLine().getUri());
|
||||
String charset = getParameter("charset");
|
||||
if (charset == null) {
|
||||
charset = AuthParams.getCredentialCharset(request.getParams());
|
||||
getParameters().put("charset", charset);
|
||||
getParameters().put("charset", getCredentialsCharset(request));
|
||||
}
|
||||
return createDigestHeader(credentials, request);
|
||||
}
|
||||
|
@ -430,7 +428,7 @@ public class DigestScheme extends RFC2617Scheme {
|
|||
buffer.append(", ");
|
||||
}
|
||||
boolean noQuotes = "nc".equals(param.getName()) || "qop".equals(param.getName());
|
||||
BasicHeaderValueFormatter.DEFAULT.formatNameValuePair(buffer, param, !noQuotes);
|
||||
BasicHeaderValueFormatter.INSTANCE.formatNameValuePair(buffer, param, !noQuotes);
|
||||
}
|
||||
return new BufferedHeader(buffer);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
|
||||
package org.apache.http.impl.auth;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.apache.http.annotation.Immutable;
|
||||
|
||||
import org.apache.http.auth.AuthScheme;
|
||||
|
@ -45,12 +47,26 @@ import org.apache.http.protocol.HttpContext;
|
|||
@SuppressWarnings("deprecation")
|
||||
public class DigestSchemeFactory implements AuthSchemeFactory, AuthSchemeProvider {
|
||||
|
||||
private final Charset charset;
|
||||
|
||||
/**
|
||||
* @since 4.3
|
||||
*/
|
||||
public DigestSchemeFactory(final Charset charset) {
|
||||
super();
|
||||
this.charset = charset;
|
||||
}
|
||||
|
||||
public DigestSchemeFactory() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public AuthScheme newInstance(final HttpParams params) {
|
||||
return new DigestScheme();
|
||||
}
|
||||
|
||||
public AuthScheme create(final HttpContext context) {
|
||||
return new DigestScheme();
|
||||
return new DigestScheme(this.charset);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,8 +36,9 @@ import org.apache.http.auth.ContextAwareAuthScheme;
|
|||
import org.apache.http.auth.Credentials;
|
||||
import org.apache.http.auth.InvalidCredentialsException;
|
||||
import org.apache.http.auth.MalformedChallengeException;
|
||||
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.ExecutionContext;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.apache.http.util.CharArrayBuffer;
|
||||
import org.ietf.jgss.GSSContext;
|
||||
|
@ -131,16 +132,18 @@ public abstract class GGSSchemeBase extends AuthSchemeBase {
|
|||
throw new AuthenticationException(getSchemeName() + " authentication has failed");
|
||||
case CHALLENGE_RECEIVED:
|
||||
try {
|
||||
String key = null;
|
||||
if (isProxy()) {
|
||||
key = ExecutionContext.HTTP_PROXY_HOST;
|
||||
} else {
|
||||
key = ExecutionContext.HTTP_TARGET_HOST;
|
||||
HttpRoute route = (HttpRoute) context.getAttribute(ClientContext.ROUTE);
|
||||
if (route == null) {
|
||||
throw new AuthenticationException("Connection route is not available");
|
||||
}
|
||||
HttpHost host = (HttpHost) context.getAttribute(key);
|
||||
if (host == null) {
|
||||
throw new AuthenticationException("Authentication host is not set " +
|
||||
"in the execution context");
|
||||
HttpHost host;
|
||||
if (isProxy()) {
|
||||
host = route.getProxyHost();
|
||||
if (host == null) {
|
||||
host = route.getTargetHost();
|
||||
}
|
||||
} else {
|
||||
host = route.getTargetHost();
|
||||
}
|
||||
String authServer;
|
||||
if (!this.stripPort && host.getPort() > 0) {
|
||||
|
|
|
@ -26,15 +26,19 @@
|
|||
|
||||
package org.apache.http.impl.auth;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
|
||||
import org.apache.http.Consts;
|
||||
import org.apache.http.HeaderElement;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.auth.ChallengeState;
|
||||
import org.apache.http.auth.MalformedChallengeException;
|
||||
import org.apache.http.auth.params.AuthPNames;
|
||||
import org.apache.http.message.BasicHeaderValueParser;
|
||||
import org.apache.http.message.HeaderValueParser;
|
||||
import org.apache.http.message.ParserCursor;
|
||||
|
@ -47,27 +51,55 @@ import org.apache.http.util.CharArrayBuffer;
|
|||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@NotThreadSafe // AuthSchemeBase, params
|
||||
public abstract class RFC2617Scheme extends AuthSchemeBase {
|
||||
|
||||
/**
|
||||
* Authentication parameter map.
|
||||
*/
|
||||
private final Map<String, String> params;
|
||||
private final Charset credentialsCharset;
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>RFC2617Scheme</tt> with the given challenge
|
||||
* state.
|
||||
*
|
||||
* @since 4.2
|
||||
*
|
||||
* @deprecated (4.3) do not use.
|
||||
*/
|
||||
@Deprecated
|
||||
public RFC2617Scheme(final ChallengeState challengeState) {
|
||||
super(challengeState);
|
||||
this.params = new HashMap<String, String>();
|
||||
this.credentialsCharset = Consts.ASCII;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.3
|
||||
*/
|
||||
public RFC2617Scheme(final Charset credentialsCharset) {
|
||||
super();
|
||||
this.params = new HashMap<String, String>();
|
||||
this.credentialsCharset = credentialsCharset != null ? credentialsCharset : Consts.ASCII;
|
||||
}
|
||||
|
||||
public RFC2617Scheme() {
|
||||
this(null);
|
||||
this(Consts.ASCII);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @since 4.3
|
||||
*/
|
||||
public Charset getCredentialsCharset() {
|
||||
return credentialsCharset;
|
||||
}
|
||||
|
||||
String getCredentialsCharset(final HttpRequest request) {
|
||||
String charset = (String) request.getParams().getParameter(AuthPNames.CREDENTIAL_CHARSET);
|
||||
if (charset == null) {
|
||||
charset = getCredentialsCharset().name();
|
||||
}
|
||||
return charset;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
package org.apache.http.impl.client;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
|
@ -52,7 +53,8 @@ import org.apache.http.auth.MalformedChallengeException;
|
|||
import org.apache.http.client.AuthCache;
|
||||
import org.apache.http.client.AuthenticationStrategy;
|
||||
import org.apache.http.client.CredentialsProvider;
|
||||
import org.apache.http.client.params.AuthPolicy;
|
||||
import org.apache.http.client.config.AuthSchemes;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.config.Lookup;
|
||||
import org.apache.http.protocol.HTTP;
|
||||
|
@ -60,28 +62,26 @@ import org.apache.http.protocol.HttpContext;
|
|||
import org.apache.http.util.CharArrayBuffer;
|
||||
|
||||
@Immutable
|
||||
class AuthenticationStrategyImpl implements AuthenticationStrategy {
|
||||
abstract class AuthenticationStrategyImpl implements AuthenticationStrategy {
|
||||
|
||||
private final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
private static final List<String> DEFAULT_SCHEME_PRIORITY =
|
||||
Collections.unmodifiableList(Arrays.asList(new String[] {
|
||||
AuthPolicy.SPNEGO,
|
||||
AuthPolicy.KERBEROS,
|
||||
AuthPolicy.NTLM,
|
||||
AuthPolicy.DIGEST,
|
||||
AuthPolicy.BASIC
|
||||
AuthSchemes.SPNEGO,
|
||||
AuthSchemes.KERBEROS,
|
||||
AuthSchemes.NTLM,
|
||||
AuthSchemes.DIGEST,
|
||||
AuthSchemes.BASIC
|
||||
}));
|
||||
|
||||
private final int challengeCode;
|
||||
private final String headerName;
|
||||
private final String prefParamName;
|
||||
|
||||
AuthenticationStrategyImpl(int challengeCode, final String headerName, final String prefParamName) {
|
||||
AuthenticationStrategyImpl(int challengeCode, final String headerName) {
|
||||
super();
|
||||
this.challengeCode = challengeCode;
|
||||
this.headerName = headerName;
|
||||
this.prefParamName = prefParamName;
|
||||
}
|
||||
|
||||
public boolean isAuthenticationRequested(
|
||||
|
@ -133,6 +133,8 @@ class AuthenticationStrategyImpl implements AuthenticationStrategy {
|
|||
return map;
|
||||
}
|
||||
|
||||
abstract Collection<String> getPreferredAuthSchemes(RequestConfig config);
|
||||
|
||||
public Queue<AuthOption> select(
|
||||
final Map<String, Header> challenges,
|
||||
final HttpHost authhost,
|
||||
|
@ -163,9 +165,8 @@ class AuthenticationStrategyImpl implements AuthenticationStrategy {
|
|||
this.log.debug("Credentials provider not set in the context");
|
||||
return options;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> authPrefs = (List<String>) response.getParams().getParameter(this.prefParamName);
|
||||
RequestConfig config = clientContext.getRequestConfig();
|
||||
Collection<String> authPrefs = getPreferredAuthSchemes(config);
|
||||
if (authPrefs == null) {
|
||||
authPrefs = DEFAULT_SCHEME_PRIORITY;
|
||||
}
|
||||
|
@ -240,8 +241,8 @@ class AuthenticationStrategyImpl implements AuthenticationStrategy {
|
|||
return false;
|
||||
}
|
||||
String schemeName = authScheme.getSchemeName();
|
||||
return schemeName.equalsIgnoreCase(AuthPolicy.BASIC) ||
|
||||
schemeName.equalsIgnoreCase(AuthPolicy.DIGEST);
|
||||
return schemeName.equalsIgnoreCase(AuthSchemes.BASIC) ||
|
||||
schemeName.equalsIgnoreCase(AuthSchemes.DIGEST);
|
||||
}
|
||||
|
||||
public void authFailed(
|
||||
|
|
|
@ -41,13 +41,13 @@ import org.apache.http.ProtocolException;
|
|||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.http.client.CircularRedirectException;
|
||||
import org.apache.http.client.RedirectStrategy;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpHead;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.client.methods.RequestBuilder;
|
||||
import org.apache.http.client.params.ClientPNames;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.client.utils.URIUtils;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.protocol.ExecutionContext;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
|
||||
|
@ -126,6 +126,9 @@ public class DefaultRedirectStrategy implements RedirectStrategy {
|
|||
if (context == null) {
|
||||
throw new IllegalArgumentException("HTTP context may not be null");
|
||||
}
|
||||
|
||||
HttpClientContext clientContext = HttpClientContext.adapt(context);
|
||||
|
||||
//get the location header to find out where to redirect to
|
||||
Header locationHeader = response.getFirstHeader("location");
|
||||
if (locationHeader == null) {
|
||||
|
@ -139,16 +142,17 @@ public class DefaultRedirectStrategy implements RedirectStrategy {
|
|||
this.log.debug("Redirect requested to location '" + location + "'");
|
||||
}
|
||||
|
||||
RequestConfig config = clientContext.getRequestConfig();
|
||||
|
||||
URI uri = createLocationURI(location);
|
||||
|
||||
HttpParams params = request.getParams();
|
||||
// rfc2616 demands the location value be a complete URI
|
||||
// Location = "Location" ":" absoluteURI
|
||||
try {
|
||||
// Drop fragment
|
||||
uri = URIUtils.rewriteURI(uri);
|
||||
if (!uri.isAbsolute()) {
|
||||
if (params.isParameterTrue(ClientPNames.REJECT_RELATIVE_REDIRECT)) {
|
||||
if (!config.isRelativeRedirectsAllowed()) {
|
||||
throw new ProtocolException("Relative redirect location '"
|
||||
+ uri + "' not allowed");
|
||||
}
|
||||
|
@ -172,7 +176,7 @@ public class DefaultRedirectStrategy implements RedirectStrategy {
|
|||
redirectLocations = new RedirectLocations();
|
||||
context.setAttribute(REDIRECT_LOCATIONS, redirectLocations);
|
||||
}
|
||||
if (params.isParameterFalse(ClientPNames.ALLOW_CIRCULAR_REDIRECTS)) {
|
||||
if (!config.isCircularRedirectsAllowed()) {
|
||||
if (redirectLocations.contains(uri)) {
|
||||
throw new CircularRedirectException("Circular redirect to '" + uri + "'");
|
||||
}
|
||||
|
|
|
@ -27,11 +27,13 @@
|
|||
|
||||
package org.apache.http.impl.client;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.http.auth.AUTH;
|
||||
import org.apache.http.auth.params.AuthPNames;
|
||||
import org.apache.http.client.AuthenticationStrategy;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
|
||||
/**
|
||||
* Default {@link AuthenticationStrategy} implementation for proxy host authentication.
|
||||
|
@ -44,7 +46,12 @@ public class ProxyAuthenticationStrategy extends AuthenticationStrategyImpl {
|
|||
public static final ProxyAuthenticationStrategy INSTANCE = new ProxyAuthenticationStrategy();
|
||||
|
||||
public ProxyAuthenticationStrategy() {
|
||||
super(HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED, AUTH.PROXY_AUTH, AuthPNames.PROXY_AUTH_PREF);
|
||||
super(HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED, AUTH.PROXY_AUTH);
|
||||
}
|
||||
|
||||
@Override
|
||||
Collection<String> getPreferredAuthSchemes(final RequestConfig config) {
|
||||
return config.getProxyPreferredAuthSchemes();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,11 +27,13 @@
|
|||
|
||||
package org.apache.http.impl.client;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.http.auth.AUTH;
|
||||
import org.apache.http.auth.params.AuthPNames;
|
||||
import org.apache.http.client.AuthenticationStrategy;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
|
||||
/**
|
||||
* Default {@link AuthenticationStrategy} implementation for proxy host authentication.
|
||||
|
@ -44,7 +46,12 @@ public class TargetAuthenticationStrategy extends AuthenticationStrategyImpl {
|
|||
public static final TargetAuthenticationStrategy INSTANCE = new TargetAuthenticationStrategy();
|
||||
|
||||
public TargetAuthenticationStrategy() {
|
||||
super(HttpStatus.SC_UNAUTHORIZED, AUTH.WWW_AUTH, AuthPNames.TARGET_AUTH_PREF);
|
||||
super(HttpStatus.SC_UNAUTHORIZED, AUTH.WWW_AUTH);
|
||||
}
|
||||
|
||||
@Override
|
||||
Collection<String> getPreferredAuthSchemes(final RequestConfig config) {
|
||||
return config.getTargetPreferredAuthSchemes();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,8 +36,8 @@ import org.apache.http.client.BackoffManager;
|
|||
import org.apache.http.client.ConnectionBackoffStrategy;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpExecutionAware;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
|
||||
/**
|
||||
* @since 4.3
|
||||
|
@ -71,7 +71,7 @@ class BackoffStrategyExec implements ClientExecChain {
|
|||
public CloseableHttpResponse execute(
|
||||
final HttpRoute route,
|
||||
final HttpRequestWrapper request,
|
||||
final HttpContext context,
|
||||
final HttpClientContext context,
|
||||
final HttpExecutionAware execAware) throws IOException, HttpException {
|
||||
if (route == null) {
|
||||
throw new IllegalArgumentException("HTTP route may not be null");
|
||||
|
|
|
@ -32,8 +32,8 @@ import java.io.IOException;
|
|||
import org.apache.http.HttpException;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpExecutionAware;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
|
||||
/**
|
||||
* This interface represents an element in the HTTP request execution chain. Each element can
|
||||
|
@ -52,7 +52,7 @@ interface ClientExecChain {
|
|||
CloseableHttpResponse execute(
|
||||
HttpRoute route,
|
||||
HttpRequestWrapper request,
|
||||
HttpContext context,
|
||||
HttpClientContext clientContext,
|
||||
HttpExecutionAware execAware) throws IOException, HttpException;
|
||||
|
||||
}
|
||||
|
|
|
@ -28,11 +28,13 @@
|
|||
package org.apache.http.impl.client.builder;
|
||||
|
||||
import java.net.ProxySelector;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.http.ConnectionReuseStrategy;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpRequestInterceptor;
|
||||
import org.apache.http.HttpResponseInterceptor;
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
|
@ -47,13 +49,15 @@ import org.apache.http.client.HttpRequestRetryHandler;
|
|||
import org.apache.http.client.RedirectStrategy;
|
||||
import org.apache.http.client.ServiceUnavailableRetryStrategy;
|
||||
import org.apache.http.client.UserTokenHandler;
|
||||
import org.apache.http.client.params.AuthPolicy;
|
||||
import org.apache.http.client.params.CookiePolicy;
|
||||
import org.apache.http.client.config.AuthSchemes;
|
||||
import org.apache.http.client.config.CookieSpecs;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.protocol.RequestAcceptEncoding;
|
||||
import org.apache.http.client.protocol.RequestAddCookies;
|
||||
import org.apache.http.client.protocol.RequestAuthCache;
|
||||
import org.apache.http.client.protocol.RequestClientConnControl;
|
||||
import org.apache.http.client.protocol.RequestDefaultHeaders;
|
||||
import org.apache.http.client.protocol.RequestExpectContinue;
|
||||
import org.apache.http.client.protocol.ResponseContentEncoding;
|
||||
import org.apache.http.client.protocol.ResponseProcessCookies;
|
||||
import org.apache.http.config.Lookup;
|
||||
|
@ -98,7 +102,6 @@ import org.apache.http.protocol.HttpProcessor;
|
|||
import org.apache.http.protocol.HttpProcessorBuilder;
|
||||
import org.apache.http.protocol.HttpRequestExecutor;
|
||||
import org.apache.http.protocol.RequestContent;
|
||||
import org.apache.http.protocol.RequestExpectContinue;
|
||||
import org.apache.http.protocol.RequestTargetHost;
|
||||
import org.apache.http.protocol.RequestUserAgent;
|
||||
import org.apache.http.util.VersionInfo;
|
||||
|
@ -125,6 +128,7 @@ import org.apache.http.util.VersionInfo;
|
|||
* <li>http.nonProxyHosts</li>
|
||||
* <li>http.keepAlive</li>
|
||||
* <li>http.maxConnections</li>
|
||||
* <li>http.user</li>
|
||||
* </ul>
|
||||
* </p>
|
||||
*
|
||||
|
@ -161,6 +165,9 @@ public class HttpClientBuilder {
|
|||
private Map<String, CookieSpecProvider> cookieSpecs;
|
||||
private CookieStore cookieStore;
|
||||
private CredentialsProvider credentialsProvider;
|
||||
private String userAgent;
|
||||
private Collection<? extends Header> defaultHeaders;
|
||||
private RequestConfig defaultConfig;
|
||||
|
||||
private boolean systemProperties;
|
||||
private boolean redirectHandlingDisabled;
|
||||
|
@ -365,6 +372,21 @@ public class HttpClientBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
public final HttpClientBuilder setUserAgent(final String userAgent) {
|
||||
this.userAgent = userAgent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public final HttpClientBuilder setDefaultHeaders(final Collection<? extends Header> defaultHeaders) {
|
||||
this.defaultHeaders = defaultHeaders;
|
||||
return this;
|
||||
}
|
||||
|
||||
public final HttpClientBuilder setDefaultConfig(final RequestConfig defaultConfig) {
|
||||
this.defaultConfig = defaultConfig;
|
||||
return this;
|
||||
}
|
||||
|
||||
public final HttpClientBuilder disableRedirectHandling() {
|
||||
redirectHandlingDisabled = true;
|
||||
return this;
|
||||
|
@ -489,10 +511,17 @@ public class HttpClientBuilder {
|
|||
HttpProcessor httpprocessor = this.httpprocessor;
|
||||
if (httpprocessor == null) {
|
||||
|
||||
VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.http.client",
|
||||
HttpClientBuilder.class.getClassLoader());
|
||||
String release = vi != null ? vi.getRelease() : VersionInfo.UNAVAILABLE;
|
||||
String defaultAgent = "Apache-HttpClient/" + release + " (java 1.5)";
|
||||
String userAgent = this.userAgent;
|
||||
if (userAgent == null) {
|
||||
if (systemProperties) {
|
||||
userAgent = System.getProperty("http.agent");
|
||||
} else {
|
||||
VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.http.client",
|
||||
HttpClientBuilder.class.getClassLoader());
|
||||
String release = vi != null ? vi.getRelease() : VersionInfo.UNAVAILABLE;
|
||||
userAgent = "Apache-HttpClient/" + release + " (java 1.5)";
|
||||
}
|
||||
}
|
||||
|
||||
HttpProcessorBuilder b = HttpProcessorBuilder.create();
|
||||
if (requestFirst != null) {
|
||||
|
@ -506,11 +535,11 @@ public class HttpClientBuilder {
|
|||
}
|
||||
}
|
||||
b.addAll(
|
||||
new RequestDefaultHeaders(),
|
||||
new RequestDefaultHeaders(defaultHeaders),
|
||||
new RequestContent(),
|
||||
new RequestTargetHost(),
|
||||
new RequestClientConnControl(),
|
||||
new RequestUserAgent(defaultAgent),
|
||||
new RequestUserAgent(userAgent),
|
||||
new RequestExpectContinue());
|
||||
if (!cookieManagementDisabled) {
|
||||
b.add(new RequestAddCookies());
|
||||
|
@ -585,11 +614,11 @@ public class HttpClientBuilder {
|
|||
Lookup<AuthSchemeProvider> authSchemeRegistry = this.authSchemeRegistry;
|
||||
if (authSchemeRegistry == null) {
|
||||
RegistryBuilder<AuthSchemeProvider> b = RegistryBuilder.<AuthSchemeProvider>create();
|
||||
b.register(AuthPolicy.BASIC, new BasicSchemeFactory())
|
||||
.register(AuthPolicy.DIGEST, new DigestSchemeFactory())
|
||||
.register(AuthPolicy.NTLM, new NTLMSchemeFactory())
|
||||
.register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory())
|
||||
.register(AuthPolicy.KERBEROS, new KerberosSchemeFactory())
|
||||
b.register(AuthSchemes.BASIC, new BasicSchemeFactory())
|
||||
.register(AuthSchemes.DIGEST, new DigestSchemeFactory())
|
||||
.register(AuthSchemes.NTLM, new NTLMSchemeFactory())
|
||||
.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory())
|
||||
.register(AuthSchemes.KERBEROS, new KerberosSchemeFactory())
|
||||
.build();
|
||||
if (authShemes != null) {
|
||||
for (Map.Entry<String, AuthSchemeProvider> entry: authShemes.entrySet()) {
|
||||
|
@ -601,12 +630,12 @@ public class HttpClientBuilder {
|
|||
Lookup<CookieSpecProvider> cookieSpecRegistry = this.cookieSpecRegistry;
|
||||
if (cookieSpecRegistry == null) {
|
||||
RegistryBuilder<CookieSpecProvider> b = RegistryBuilder.<CookieSpecProvider>create();
|
||||
b.register(CookiePolicy.BEST_MATCH, new BestMatchSpecFactory())
|
||||
.register(CookiePolicy.BROWSER_COMPATIBILITY, new BrowserCompatSpecFactory())
|
||||
.register(CookiePolicy.NETSCAPE, new NetscapeDraftSpecFactory())
|
||||
.register(CookiePolicy.RFC_2109, new RFC2109SpecFactory())
|
||||
.register(CookiePolicy.RFC_2965, new RFC2965SpecFactory())
|
||||
.register(CookiePolicy.IGNORE_COOKIES, new IgnoreSpecFactory());
|
||||
b.register(CookieSpecs.BEST_MATCH, new BestMatchSpecFactory())
|
||||
.register(CookieSpecs.BROWSER_COMPATIBILITY, new BrowserCompatSpecFactory())
|
||||
.register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecFactory())
|
||||
.register(CookieSpecs.RFC_2109, new RFC2109SpecFactory())
|
||||
.register(CookieSpecs.RFC_2965, new RFC2965SpecFactory())
|
||||
.register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecFactory());
|
||||
if (cookieSpecs != null) {
|
||||
for (Map.Entry<String, CookieSpecProvider> entry: cookieSpecs.entrySet()) {
|
||||
b.register(entry.getKey(), entry.getValue());
|
||||
|
@ -632,7 +661,8 @@ public class HttpClientBuilder {
|
|||
cookieSpecRegistry,
|
||||
authSchemeRegistry,
|
||||
defaultCookieStore,
|
||||
defaultCredentialsProvider);
|
||||
defaultCredentialsProvider,
|
||||
defaultConfig != null ? defaultConfig : RequestConfig.DEFAULT);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -66,7 +66,6 @@ class HttpRequestWrapper extends AbstractHttpMessage implements HttpRequest {
|
|||
} else {
|
||||
this.uri = null;
|
||||
}
|
||||
setParams(request.getParams());
|
||||
setHeaders(request.getAllHeaders());
|
||||
}
|
||||
|
||||
|
|
|
@ -39,9 +39,12 @@ import org.apache.http.auth.AuthState;
|
|||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.CookieStore;
|
||||
import org.apache.http.client.CredentialsProvider;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.Configurable;
|
||||
import org.apache.http.client.methods.HttpExecutionAware;
|
||||
import org.apache.http.client.params.ClientPNames;
|
||||
import org.apache.http.client.params.HttpParamConfig;
|
||||
import org.apache.http.client.protocol.ClientContext;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.config.Lookup;
|
||||
|
@ -54,9 +57,8 @@ import org.apache.http.conn.routing.HttpRoutePlanner;
|
|||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
import org.apache.http.cookie.CookieSpecProvider;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.params.DefaultedHttpParams;
|
||||
import org.apache.http.params.BasicHttpParams;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.params.SyncBasicHttpParams;
|
||||
import org.apache.http.protocol.BasicHttpContext;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
|
||||
|
@ -64,6 +66,7 @@ import org.apache.http.protocol.HttpContext;
|
|||
* @since 4.3
|
||||
*/
|
||||
@ThreadSafe
|
||||
@SuppressWarnings("deprecation")
|
||||
class InternalHttpClient extends CloseableHttpClient {
|
||||
|
||||
private final ClientExecChain execChain;
|
||||
|
@ -73,6 +76,7 @@ class InternalHttpClient extends CloseableHttpClient {
|
|||
private final Lookup<AuthSchemeProvider> authSchemeRegistry;
|
||||
private final CookieStore cookieStore;
|
||||
private final CredentialsProvider credentialsProvider;
|
||||
private final RequestConfig defaultConfig;
|
||||
private final HttpParams params;
|
||||
|
||||
public InternalHttpClient(
|
||||
|
@ -82,7 +86,8 @@ class InternalHttpClient extends CloseableHttpClient {
|
|||
final Lookup<CookieSpecProvider> cookieSpecRegistry,
|
||||
final Lookup<AuthSchemeProvider> authSchemeRegistry,
|
||||
final CookieStore cookieStore,
|
||||
final CredentialsProvider credentialsProvider) {
|
||||
final CredentialsProvider credentialsProvider,
|
||||
final RequestConfig defaultConfig) {
|
||||
super();
|
||||
if (execChain == null) {
|
||||
throw new IllegalArgumentException("HTTP client exec chain may not be null");
|
||||
|
@ -100,7 +105,8 @@ class InternalHttpClient extends CloseableHttpClient {
|
|||
this.authSchemeRegistry = authSchemeRegistry;
|
||||
this.cookieStore = cookieStore;
|
||||
this.credentialsProvider = credentialsProvider;
|
||||
this.params = new SyncBasicHttpParams();
|
||||
this.defaultConfig = defaultConfig != null ? defaultConfig : RequestConfig.DEFAULT;
|
||||
this.params = new BasicHttpParams();
|
||||
}
|
||||
|
||||
private HttpRoute determineRoute(
|
||||
|
@ -117,7 +123,7 @@ class InternalHttpClient extends CloseableHttpClient {
|
|||
return this.routePlanner.determineRoute(host, request, context);
|
||||
}
|
||||
|
||||
private HttpContext setupContext(final HttpContext localContext) {
|
||||
private HttpClientContext setupContext(final HttpContext localContext) {
|
||||
HttpClientContext context = HttpClientContext.adapt(
|
||||
localContext != null ? localContext : new BasicHttpContext());
|
||||
if (context.getAttribute(ClientContext.TARGET_AUTH_STATE) == null) {
|
||||
|
@ -154,14 +160,23 @@ class InternalHttpClient extends CloseableHttpClient {
|
|||
execListner = (HttpExecutionAware) request;
|
||||
}
|
||||
try {
|
||||
HttpParams params = new DefaultedHttpParams(request.getParams(), getParams());
|
||||
HttpParams params = request.getParams();
|
||||
HttpHost virtualHost = (HttpHost) params.getParameter(ClientPNames.VIRTUAL_HOST);
|
||||
|
||||
HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(request);
|
||||
wrapper.setParams(params);
|
||||
wrapper.setVirtualHost(virtualHost);
|
||||
HttpContext localcontext = setupContext(context);
|
||||
HttpClientContext localcontext = setupContext(context);
|
||||
HttpRoute route = determineRoute(target, wrapper, localcontext);
|
||||
RequestConfig config = null;
|
||||
if (request instanceof Configurable) {
|
||||
config = ((Configurable) request).getConfig();
|
||||
} else {
|
||||
config = HttpParamConfig.getRequestConfig(params);
|
||||
}
|
||||
if (config == null) {
|
||||
config = this.defaultConfig;
|
||||
}
|
||||
localcontext.setRequestConfig(config);
|
||||
return this.execChain.execute(route, wrapper, localcontext, execListner);
|
||||
} catch (HttpException httpException) {
|
||||
throw new ClientProtocolException(httpException);
|
||||
|
@ -173,10 +188,9 @@ class InternalHttpClient extends CloseableHttpClient {
|
|||
}
|
||||
|
||||
public void close() {
|
||||
connManager.shutdown();
|
||||
this.connManager.shutdown();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public ClientConnectionManager getConnectionManager() {
|
||||
|
||||
return new ClientConnectionManager() {
|
||||
|
|
|
@ -41,7 +41,6 @@ import org.apache.http.HttpHost;
|
|||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpRequestInterceptor;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.http.annotation.ThreadSafe;
|
||||
import org.apache.http.auth.AUTH;
|
||||
import org.apache.http.auth.AuthProtocolState;
|
||||
|
@ -49,9 +48,9 @@ import org.apache.http.auth.AuthState;
|
|||
import org.apache.http.client.AuthenticationStrategy;
|
||||
import org.apache.http.client.NonRepeatableRequestException;
|
||||
import org.apache.http.client.UserTokenHandler;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpExecutionAware;
|
||||
import org.apache.http.client.params.HttpClientParams;
|
||||
import org.apache.http.client.protocol.ClientContext;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.client.protocol.RequestClientConnControl;
|
||||
|
@ -68,11 +67,7 @@ import org.apache.http.impl.client.RequestAbortedException;
|
|||
import org.apache.http.impl.client.TunnelRefusedException;
|
||||
import org.apache.http.impl.conn.ConnectionShutdownException;
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.apache.http.params.HttpConnectionParams;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.params.HttpProtocolParams;
|
||||
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.protocol.ImmutableHttpProcessor;
|
||||
|
@ -80,30 +75,6 @@ import org.apache.http.protocol.RequestUserAgent;
|
|||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* The following parameters can be used to customize the behavior of this
|
||||
* class:
|
||||
* <ul>
|
||||
* <li>{@link org.apache.http.params.CoreProtocolPNames#PROTOCOL_VERSION}</li>
|
||||
* <li>{@link org.apache.http.params.CoreProtocolPNames#STRICT_TRANSFER_ENCODING}</li>
|
||||
* <li>{@link org.apache.http.params.CoreProtocolPNames#HTTP_ELEMENT_CHARSET}</li>
|
||||
* <li>{@link org.apache.http.params.CoreProtocolPNames#USE_EXPECT_CONTINUE}</li>
|
||||
* <li>{@link org.apache.http.params.CoreProtocolPNames#WAIT_FOR_CONTINUE}</li>
|
||||
* <li>{@link org.apache.http.params.CoreProtocolPNames#USER_AGENT}</li>
|
||||
* <li>{@link org.apache.http.params.CoreConnectionPNames#SOCKET_BUFFER_SIZE}</li>
|
||||
* <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_LINE_LENGTH}</li>
|
||||
* <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_HEADER_COUNT}</li>
|
||||
* <li>{@link org.apache.http.params.CoreConnectionPNames#SO_TIMEOUT}</li>
|
||||
* <li>{@link org.apache.http.params.CoreConnectionPNames#SO_LINGER}</li>
|
||||
* <li>{@link org.apache.http.params.CoreConnectionPNames#SO_REUSEADDR}</li>
|
||||
* <li>{@link org.apache.http.params.CoreConnectionPNames#TCP_NODELAY}</li>
|
||||
* <li>{@link org.apache.http.params.CoreConnectionPNames#CONNECTION_TIMEOUT}</li>
|
||||
* <li>{@link org.apache.http.params.CoreConnectionPNames#STALE_CONNECTION_CHECK}</li>
|
||||
* <li>{@link org.apache.http.auth.params.AuthPNames#CREDENTIAL_CHARSET}</li>
|
||||
* <li>{@link org.apache.http.client.params.ClientPNames#HANDLE_AUTHENTICATION}</li>
|
||||
* <li>{@link org.apache.http.client.params.ClientPNames#CONN_MANAGER_TIMEOUT}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
@ThreadSafe
|
||||
|
@ -170,7 +141,7 @@ class MainClientExec implements ClientExecChain {
|
|||
public CloseableHttpResponse execute(
|
||||
final HttpRoute route,
|
||||
final HttpRequestWrapper request,
|
||||
final HttpContext context,
|
||||
final HttpClientContext context,
|
||||
final HttpExecutionAware execAware) throws IOException, HttpException {
|
||||
if (route == null) {
|
||||
throw new IllegalArgumentException("HTTP route may not be null");
|
||||
|
@ -182,22 +153,18 @@ class MainClientExec implements ClientExecChain {
|
|||
throw new IllegalArgumentException("HTTP context may not be null");
|
||||
}
|
||||
|
||||
HttpClientContext clientContext = HttpClientContext.adapt(context);
|
||||
|
||||
AuthState targetAuthState = clientContext.getTargetAuthState();
|
||||
AuthState targetAuthState = context.getTargetAuthState();
|
||||
if (targetAuthState == null) {
|
||||
targetAuthState = new AuthState();
|
||||
context.setAttribute(ClientContext.TARGET_AUTH_STATE, targetAuthState);
|
||||
}
|
||||
AuthState proxyAuthState = clientContext.getProxyAuthState();
|
||||
AuthState proxyAuthState = context.getProxyAuthState();
|
||||
if (proxyAuthState == null) {
|
||||
proxyAuthState = new AuthState();
|
||||
context.setAttribute(ClientContext.PROXY_AUTH_STATE, proxyAuthState);
|
||||
}
|
||||
|
||||
HttpParams params = request.getParams();
|
||||
|
||||
Object userToken = clientContext.getUserToken();
|
||||
Object userToken = context.getUserToken();
|
||||
|
||||
final ConnectionRequest connRequest = connManager.requestConnection(route, userToken);
|
||||
if (execAware != null) {
|
||||
|
@ -209,17 +176,19 @@ class MainClientExec implements ClientExecChain {
|
|||
}
|
||||
}
|
||||
|
||||
RequestConfig config = context.getRequestConfig();
|
||||
|
||||
HttpClientConnection managedConn;
|
||||
try {
|
||||
long timeout = HttpClientParams.getConnectionManagerTimeout(params);
|
||||
managedConn = connRequest.get(timeout, TimeUnit.MILLISECONDS);
|
||||
int timeout = config.getConnectionRequestTimeout();
|
||||
managedConn = connRequest.get(timeout > 0 ? timeout : 0, TimeUnit.MILLISECONDS);
|
||||
} catch(InterruptedException interrupted) {
|
||||
throw new RequestAbortedException("Request aborted", interrupted);
|
||||
}
|
||||
|
||||
context.setAttribute(ExecutionContext.HTTP_CONNECTION, managedConn);
|
||||
|
||||
if (HttpConnectionParams.isStaleCheckingEnabled(params)) {
|
||||
if (config.isStaleConnectionCheckEnabled()) {
|
||||
// validate connection
|
||||
if (managedConn.isOpen()) {
|
||||
this.log.debug("Stale connection check");
|
||||
|
@ -266,7 +235,10 @@ class MainClientExec implements ClientExecChain {
|
|||
break;
|
||||
}
|
||||
} else {
|
||||
managedConn.setSocketTimeout(HttpConnectionParams.getSoTimeout(params));
|
||||
int timeout = config.getSocketTimeout();
|
||||
if (timeout >= 0) {
|
||||
managedConn.setSocketTimeout(timeout);
|
||||
}
|
||||
}
|
||||
|
||||
if (execAware != null && execAware.isAborted()) {
|
||||
|
@ -291,7 +263,6 @@ class MainClientExec implements ClientExecChain {
|
|||
}
|
||||
|
||||
response = requestExecutor.execute(request, managedConn, context);
|
||||
response.setParams(params);
|
||||
|
||||
// The connection is in or can be brought to a re-usable state.
|
||||
if (reuseStrategy.keepAlive(response, context)) {
|
||||
|
@ -385,8 +356,9 @@ class MainClientExec implements ClientExecChain {
|
|||
final HttpClientConnection managedConn,
|
||||
final HttpRoute route,
|
||||
final HttpRequest request,
|
||||
final HttpContext context) throws HttpException, IOException {
|
||||
HttpParams params = request.getParams();
|
||||
final HttpClientContext context) throws HttpException, IOException {
|
||||
RequestConfig config = context.getRequestConfig();
|
||||
int timeout = config.getConnectTimeout();
|
||||
RouteTracker tracker = new RouteTracker(route);
|
||||
int step;
|
||||
do {
|
||||
|
@ -397,17 +369,24 @@ class MainClientExec implements ClientExecChain {
|
|||
|
||||
case HttpRouteDirector.CONNECT_TARGET:
|
||||
this.connManager.connect(
|
||||
managedConn, route.getTargetHost(), route.getLocalAddress(), context);
|
||||
managedConn,
|
||||
route.getTargetHost(), route.getLocalAddress(),
|
||||
timeout > 0 ? timeout : 0,
|
||||
context);
|
||||
tracker.connectTarget(route.isSecure());
|
||||
break;
|
||||
case HttpRouteDirector.CONNECT_PROXY:
|
||||
this.connManager.connect(
|
||||
managedConn, route.getProxyHost(), route.getLocalAddress(), context);
|
||||
managedConn,
|
||||
route.getProxyHost(), route.getLocalAddress(),
|
||||
timeout > 0 ? timeout : 0,
|
||||
context);
|
||||
HttpHost proxy = route.getProxyHost();
|
||||
tracker.connectProxy(proxy, false);
|
||||
break;
|
||||
case HttpRouteDirector.TUNNEL_TARGET: {
|
||||
boolean secure = createTunnelToTarget(proxyAuthState, managedConn, route, request, context);
|
||||
boolean secure = createTunnelToTarget(
|
||||
proxyAuthState, managedConn, route, request, context);
|
||||
this.log.debug("Tunnel to target created.");
|
||||
tracker.tunnelTarget(secure);
|
||||
} break;
|
||||
|
@ -454,24 +433,27 @@ class MainClientExec implements ClientExecChain {
|
|||
final HttpClientConnection managedConn,
|
||||
final HttpRoute route,
|
||||
final HttpRequest request,
|
||||
final HttpContext context) throws HttpException, IOException {
|
||||
final HttpClientContext context) throws HttpException, IOException {
|
||||
|
||||
RequestConfig config = context.getRequestConfig();
|
||||
int timeout = config.getConnectTimeout();
|
||||
|
||||
HttpParams params = request.getParams();
|
||||
HttpHost target = route.getTargetHost();
|
||||
HttpHost proxy = route.getProxyHost();
|
||||
HttpResponse response = null;
|
||||
|
||||
String authority = target.toHostString();
|
||||
ProtocolVersion ver = HttpProtocolParams.getVersion(params);
|
||||
HttpRequest connect = new BasicHttpRequest("CONNECT", authority, ver);
|
||||
connect.setParams(params);
|
||||
HttpRequest connect = new BasicHttpRequest("CONNECT", authority, request.getProtocolVersion());
|
||||
|
||||
this.requestExecutor.preProcess(connect, this.proxyHttpProcessor, context);
|
||||
|
||||
for (;;) {
|
||||
if (!managedConn.isOpen()) {
|
||||
this.connManager.connect(
|
||||
managedConn, route.getProxyHost(), route.getLocalAddress(), context);
|
||||
managedConn,
|
||||
route.getProxyHost(), route.getLocalAddress(),
|
||||
timeout > 0 ? timeout : 0,
|
||||
context);
|
||||
}
|
||||
|
||||
connect.removeHeaders(AUTH.PROXY_AUTH_RESP);
|
||||
|
@ -485,7 +467,7 @@ class MainClientExec implements ClientExecChain {
|
|||
response.getStatusLine());
|
||||
}
|
||||
|
||||
if (HttpClientParams.isAuthenticating(params)) {
|
||||
if (config.isAuthenticationEnabled()) {
|
||||
if (this.authenticator.isAuthenticationRequested(proxy, response,
|
||||
this.proxyAuthStrategy, proxyAuthState, context)) {
|
||||
if (this.authenticator.handleAuthChallenge(proxy, response,
|
||||
|
@ -538,7 +520,7 @@ class MainClientExec implements ClientExecChain {
|
|||
private boolean createTunnelToProxy(
|
||||
final HttpRoute route,
|
||||
final int hop,
|
||||
final HttpContext context) throws HttpException, IOException {
|
||||
final HttpClientContext context) throws HttpException, IOException {
|
||||
|
||||
// Have a look at createTunnelToTarget and replicate the parts
|
||||
// you need in a custom derived class. If your proxies don't require
|
||||
|
@ -558,11 +540,10 @@ class MainClientExec implements ClientExecChain {
|
|||
final HttpRoute route,
|
||||
final HttpRequestWrapper request,
|
||||
final HttpResponse response,
|
||||
final HttpContext context) throws HttpException, IOException {
|
||||
|
||||
HttpParams params = request.getParams();
|
||||
if (HttpClientParams.isAuthenticating(params)) {
|
||||
HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
|
||||
final HttpClientContext context) throws HttpException, IOException {
|
||||
RequestConfig config = context.getRequestConfig();
|
||||
if (config.isAuthenticationEnabled()) {
|
||||
HttpHost target = context.getTargetHost();
|
||||
if (target == null) {
|
||||
target = route.getTargetHost();
|
||||
}
|
||||
|
|
|
@ -47,7 +47,6 @@ import org.apache.http.client.utils.URIUtils;
|
|||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.impl.auth.BasicScheme;
|
||||
import org.apache.http.protocol.ExecutionContext;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.apache.http.protocol.HttpProcessor;
|
||||
|
||||
/**
|
||||
|
@ -107,7 +106,7 @@ class ProtocolExec implements ClientExecChain {
|
|||
public CloseableHttpResponse execute(
|
||||
final HttpRoute route,
|
||||
final HttpRequestWrapper request,
|
||||
final HttpContext context,
|
||||
final HttpClientContext context,
|
||||
final HttpExecutionAware execAware) throws IOException, HttpException {
|
||||
if (route == null) {
|
||||
throw new IllegalArgumentException("HTTP route may not be null");
|
||||
|
@ -119,12 +118,10 @@ class ProtocolExec implements ClientExecChain {
|
|||
throw new IllegalArgumentException("HTTP context may not be null");
|
||||
}
|
||||
|
||||
HttpClientContext clientContext = HttpClientContext.adapt(context);
|
||||
|
||||
HttpHost target = route.getTargetHost();
|
||||
|
||||
// Get user info from the URI
|
||||
AuthState targetAuthState = clientContext.getTargetAuthState();
|
||||
AuthState targetAuthState = context.getTargetAuthState();
|
||||
if (targetAuthState != null) {
|
||||
String userinfo = request.getURI().getUserInfo();
|
||||
if (userinfo != null) {
|
||||
|
|
|
@ -41,27 +41,16 @@ import org.apache.http.auth.AuthScheme;
|
|||
import org.apache.http.auth.AuthState;
|
||||
import org.apache.http.client.RedirectException;
|
||||
import org.apache.http.client.RedirectStrategy;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpExecutionAware;
|
||||
import org.apache.http.client.params.ClientPNames;
|
||||
import org.apache.http.client.params.HttpClientParams;
|
||||
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.params.HttpParams;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
/**
|
||||
* The following parameters can be used to customize the behavior of this
|
||||
* class:
|
||||
* <ul>
|
||||
* <li>{@link org.apache.http.client.params.ClientPNames#HANDLE_REDIRECTS}</li>
|
||||
* <li>{@link org.apache.http.client.params.ClientPNames#MAX_REDIRECTS}</li>
|
||||
* <li>{@link org.apache.http.client.params.ClientPNames#ALLOW_CIRCULAR_REDIRECTS}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
@ThreadSafe
|
||||
|
@ -95,7 +84,7 @@ class RedirectExec implements ClientExecChain {
|
|||
public CloseableHttpResponse execute(
|
||||
final HttpRoute route,
|
||||
final HttpRequestWrapper request,
|
||||
final HttpContext context,
|
||||
final HttpClientContext context,
|
||||
final HttpExecutionAware execAware) throws IOException, HttpException {
|
||||
if (route == null) {
|
||||
throw new IllegalArgumentException("HTTP route may not be null");
|
||||
|
@ -107,17 +96,15 @@ class RedirectExec implements ClientExecChain {
|
|||
throw new IllegalArgumentException("HTTP context may not be null");
|
||||
}
|
||||
|
||||
HttpClientContext clientContext = HttpClientContext.adapt(context);
|
||||
|
||||
HttpParams params = request.getParams();
|
||||
int maxRedirects = params.getIntParameter(ClientPNames.MAX_REDIRECTS, 100);
|
||||
RequestConfig config = context.getRequestConfig();
|
||||
int maxRedirects = config.getMaxRedirects() > 0 ? config.getMaxRedirects() : 50;
|
||||
HttpRoute currentRoute = route;
|
||||
HttpRequestWrapper currentRequest = request;
|
||||
for (int redirectCount = 0;;) {
|
||||
CloseableHttpResponse response = requestExecutor.execute(
|
||||
currentRoute, currentRequest, context, execAware);
|
||||
try {
|
||||
if (HttpClientParams.isRedirecting(params) &&
|
||||
if (config.isRedirectsEnabled() &&
|
||||
this.redirectStrategy.isRedirected(currentRequest, response, context)) {
|
||||
|
||||
if (redirectCount >= maxRedirects) {
|
||||
|
@ -129,7 +116,6 @@ class RedirectExec implements ClientExecChain {
|
|||
HttpRequest original = currentRequest.getOriginal();
|
||||
currentRequest = HttpRequestWrapper.wrap(redirect);
|
||||
currentRequest.setHeaders(original.getAllHeaders());
|
||||
currentRequest.setParams(params);
|
||||
|
||||
URI uri = currentRequest.getURI();
|
||||
HttpHost newTarget = URIUtils.extractHost(uri);
|
||||
|
@ -140,12 +126,12 @@ class RedirectExec implements ClientExecChain {
|
|||
|
||||
// Reset virtual host and auth states if redirecting to another host
|
||||
if (!currentRoute.getTargetHost().equals(newTarget)) {
|
||||
AuthState targetAuthState = clientContext.getTargetAuthState();
|
||||
AuthState targetAuthState = context.getTargetAuthState();
|
||||
if (targetAuthState != null) {
|
||||
this.log.debug("Resetting target auth state");
|
||||
targetAuthState.reset();
|
||||
}
|
||||
AuthState proxyAuthState = clientContext.getProxyAuthState();
|
||||
AuthState proxyAuthState = context.getProxyAuthState();
|
||||
if (proxyAuthState != null) {
|
||||
AuthScheme authScheme = proxyAuthState.getAuthScheme();
|
||||
if (authScheme != null && authScheme.isConnectionBased()) {
|
||||
|
|
|
@ -40,8 +40,8 @@ import org.apache.http.client.NonRepeatableRequestException;
|
|||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpExecutionAware;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
|
||||
/**
|
||||
* @since 4.3
|
||||
|
@ -70,7 +70,7 @@ class RetryExec implements ClientExecChain {
|
|||
public CloseableHttpResponse execute(
|
||||
final HttpRoute route,
|
||||
final HttpRequestWrapper request,
|
||||
final HttpContext context,
|
||||
final HttpClientContext context,
|
||||
final HttpExecutionAware execAware) throws IOException, HttpException {
|
||||
if (route == null) {
|
||||
throw new IllegalArgumentException("HTTP route may not be null");
|
||||
|
|
|
@ -37,8 +37,8 @@ import org.apache.http.annotation.ThreadSafe;
|
|||
import org.apache.http.client.ServiceUnavailableRetryStrategy;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpExecutionAware;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
|
||||
/**
|
||||
* {@link ClientExecChain} implementation that can automatically retry the request in case of
|
||||
|
@ -72,7 +72,7 @@ class ServiceUnavailableRetryExec implements ClientExecChain {
|
|||
public CloseableHttpResponse execute(
|
||||
final HttpRoute route,
|
||||
final HttpRequestWrapper request,
|
||||
final HttpContext context,
|
||||
final HttpClientContext context,
|
||||
final HttpExecutionAware execAware) throws IOException, HttpException {
|
||||
for (int c = 1;; c++) {
|
||||
CloseableHttpResponse response = this.requestExecutor.execute(
|
||||
|
|
|
@ -308,6 +308,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
|||
final HttpClientConnection conn,
|
||||
final HttpHost host,
|
||||
final InetAddress local,
|
||||
final int connectTimeout,
|
||||
final HttpContext context) throws IOException {
|
||||
if (conn == null) {
|
||||
throw new IllegalArgumentException("Connection may not be null");
|
||||
|
@ -320,7 +321,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
|||
}
|
||||
InetSocketAddress localAddress = local != null ? new InetSocketAddress(local, 0) : null;
|
||||
this.connectionOperator.connect(this.conn, host, localAddress,
|
||||
this.connConfig.getConnectTimeout(), this.socketConfig, context);
|
||||
connectTimeout, this.socketConfig, context);
|
||||
}
|
||||
|
||||
public void upgrade(
|
||||
|
|
|
@ -33,8 +33,9 @@ import org.apache.http.HttpException;
|
|||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.conn.SchemePortResolver;
|
||||
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;
|
||||
|
@ -44,14 +45,6 @@ import org.apache.http.protocol.HttpContext;
|
|||
* is based on {@link org.apache.http.conn.params.ConnRoutePNames parameters}.
|
||||
* It will not make use of any Java system properties, nor of system or
|
||||
* browser proxy settings.
|
||||
* <p>
|
||||
* The following parameters can be used to customize the behavior of this
|
||||
* class:
|
||||
* <ul>
|
||||
* <li>{@link org.apache.http.conn.params.ConnRoutePNames#DEFAULT_PROXY}</li>
|
||||
* <li>{@link org.apache.http.conn.params.ConnRoutePNames#LOCAL_ADDRESS}</li>
|
||||
* <li>{@link org.apache.http.conn.params.ConnRoutePNames#FORCED_ROUTE}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
|
@ -76,15 +69,13 @@ public class DefaultRoutePlanner implements HttpRoutePlanner {
|
|||
if (request == null) {
|
||||
throw new IllegalArgumentException("Request may not be null");
|
||||
}
|
||||
// If we have a forced route, we can do without a target.
|
||||
HttpRoute route = ConnRouteParams.getForcedRoute(request.getParams());
|
||||
if (route != null) {
|
||||
return route;
|
||||
}
|
||||
// If we get here, there is no forced route.
|
||||
// So we need a target to compute a route.
|
||||
InetAddress local = ConnRouteParams.getLocalAddress(request.getParams());
|
||||
HttpClientContext clientContext = HttpClientContext.adapt(context);
|
||||
RequestConfig config = clientContext.getRequestConfig();
|
||||
InetAddress local = config.getLocalAddress();
|
||||
HttpHost proxy = determineProxy(host, request, context);
|
||||
if (proxy == null) {
|
||||
proxy = config.getDefaultProxy();
|
||||
}
|
||||
|
||||
HttpHost target;
|
||||
if (host.getPort() <= 0) {
|
||||
|
@ -97,18 +88,17 @@ public class DefaultRoutePlanner implements HttpRoutePlanner {
|
|||
}
|
||||
boolean secure = target.getSchemeName().equalsIgnoreCase("https");
|
||||
if (proxy == null) {
|
||||
route = new HttpRoute(target, local, secure);
|
||||
return new HttpRoute(target, local, secure);
|
||||
} else {
|
||||
route = new HttpRoute(target, local, proxy, secure);
|
||||
return new HttpRoute(target, local, proxy, secure);
|
||||
}
|
||||
return route;
|
||||
}
|
||||
|
||||
protected HttpHost determineProxy(
|
||||
final HttpHost target,
|
||||
final HttpRequest request,
|
||||
final HttpContext context) throws HttpException {
|
||||
return ConnRouteParams.getDefaultProxy(request.getParams());
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -193,6 +193,7 @@ abstract class HttpClientConnectionManagerBase implements HttpClientConnectionMa
|
|||
final HttpClientConnection managedConn,
|
||||
final HttpHost host,
|
||||
final InetAddress local,
|
||||
final int connectTimeout,
|
||||
final HttpContext context) throws IOException {
|
||||
if (managedConn == null) {
|
||||
throw new IllegalArgumentException("Connection may not be null");
|
||||
|
@ -213,7 +214,7 @@ abstract class HttpClientConnectionManagerBase implements HttpClientConnectionMa
|
|||
|
||||
InetSocketAddress localAddress = local != null ? new InetSocketAddress(local, 0) : null;
|
||||
this.connectionOperator.connect(conn, host, localAddress,
|
||||
connConfig.getConnectTimeout(), socketConfig, context);
|
||||
connectTimeout, socketConfig, context);
|
||||
}
|
||||
|
||||
public void upgrade(
|
||||
|
|
|
@ -33,7 +33,6 @@ import org.apache.http.Header;
|
|||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.entity.InputStreamEntity;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.params.HttpProtocolParams;
|
||||
import org.apache.http.util.LangUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -43,11 +42,9 @@ public class TestHttpRequestBase {
|
|||
@Test
|
||||
public void testBasicProperties() throws Exception {
|
||||
HttpGet httpget = new HttpGet("http://host/path");
|
||||
httpget.getParams().setParameter(
|
||||
HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);
|
||||
Assert.assertEquals("GET", httpget.getRequestLine().getMethod());
|
||||
Assert.assertEquals("http://host/path", httpget.getRequestLine().getUri());
|
||||
Assert.assertEquals(HttpVersion.HTTP_1_0, httpget.getRequestLine().getProtocolVersion());
|
||||
Assert.assertEquals(HttpVersion.HTTP_1_1, httpget.getRequestLine().getProtocolVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -62,8 +59,6 @@ public class TestHttpRequestBase {
|
|||
httpget.addHeader("h1", "this header");
|
||||
httpget.addHeader("h2", "that header");
|
||||
httpget.addHeader("h3", "all sorts of headers");
|
||||
httpget.getParams().setParameter("p1", Integer.valueOf(1));
|
||||
httpget.getParams().setParameter("p2", "whatever");
|
||||
HttpGet clone = (HttpGet) httpget.clone();
|
||||
|
||||
Assert.assertEquals(httpget.getMethod(), clone.getMethod());
|
||||
|
@ -73,11 +68,6 @@ public class TestHttpRequestBase {
|
|||
Header[] headers2 = clone.getAllHeaders();
|
||||
|
||||
Assert.assertTrue(LangUtils.equals(headers1, headers2));
|
||||
Assert.assertTrue(httpget.getParams() != clone.getParams());
|
||||
|
||||
Assert.assertEquals(Integer.valueOf(1), clone.getParams().getParameter("p1"));
|
||||
Assert.assertEquals("whatever", clone.getParams().getParameter("p2"));
|
||||
Assert.assertEquals(null, clone.getParams().getParameter("p3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -86,8 +76,6 @@ public class TestHttpRequestBase {
|
|||
httppost.addHeader("h1", "this header");
|
||||
httppost.addHeader("h2", "that header");
|
||||
httppost.addHeader("h3", "all sorts of headers");
|
||||
httppost.getParams().setParameter("p1", Integer.valueOf(1));
|
||||
httppost.getParams().setParameter("p2", "whatever");
|
||||
HttpPost clone = (HttpPost) httppost.clone();
|
||||
|
||||
Assert.assertEquals(httppost.getMethod(), clone.getMethod());
|
||||
|
@ -97,11 +85,6 @@ public class TestHttpRequestBase {
|
|||
Header[] headers2 = clone.getAllHeaders();
|
||||
|
||||
Assert.assertTrue(LangUtils.equals(headers1, headers2));
|
||||
Assert.assertTrue(httppost.getParams() != clone.getParams());
|
||||
|
||||
Assert.assertEquals(Integer.valueOf(1), clone.getParams().getParameter("p1"));
|
||||
Assert.assertEquals("whatever", clone.getParams().getParameter("p2"));
|
||||
Assert.assertEquals(null, clone.getParams().getParameter("p3"));
|
||||
|
||||
Assert.assertNull(clone.getEntity());
|
||||
|
||||
|
|
|
@ -33,11 +33,10 @@ import org.apache.http.Header;
|
|||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpEntityEnclosingRequest;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.entity.BasicHttpEntity;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.params.BasicHttpParams;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -89,14 +88,14 @@ public class TestRequestBuilder {
|
|||
@Test
|
||||
public void testCopy() throws Exception {
|
||||
HttpEntity entity = new StringEntity("stuff");
|
||||
HttpParams params = new BasicHttpParams();
|
||||
RequestConfig config = RequestConfig.custom().build();
|
||||
HttpUriRequest request = RequestBuilder.createPut()
|
||||
.setUri(URI.create("/stuff"))
|
||||
.setVersion(HttpVersion.HTTP_1_0)
|
||||
.addHeader("header1", "stuff")
|
||||
.setHeader("header2", "more stuff")
|
||||
.setEntity(entity)
|
||||
.setParams(params)
|
||||
.setConfig(config)
|
||||
.build();
|
||||
Assert.assertNotNull(request);
|
||||
Assert.assertEquals("PUT", request.getMethod());
|
||||
|
@ -109,20 +108,21 @@ public class TestRequestBuilder {
|
|||
Assert.assertEquals(URI.create("/other-stuff"), copy.getURI());
|
||||
Assert.assertTrue(copy instanceof HttpEntityEnclosingRequest);
|
||||
Assert.assertSame(entity, ((HttpEntityEnclosingRequest) copy).getEntity());
|
||||
Assert.assertSame(params, copy.getParams());
|
||||
Assert.assertTrue(copy instanceof Configurable);
|
||||
Assert.assertSame(config, ((Configurable) copy).getConfig());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClone() throws Exception {
|
||||
HttpEntity entity = new StringEntity("stuff");
|
||||
HttpParams params = new BasicHttpParams();
|
||||
RequestConfig config = RequestConfig.custom().build();
|
||||
HttpUriRequest request = RequestBuilder.createPut()
|
||||
.setUri(URI.create("/stuff"))
|
||||
.setVersion(HttpVersion.HTTP_1_0)
|
||||
.addHeader("header1", "stuff")
|
||||
.setHeader("header2", "more stuff")
|
||||
.setEntity(entity)
|
||||
.setParams(params)
|
||||
.setConfig(config)
|
||||
.build();
|
||||
Assert.assertNotNull(request);
|
||||
Assert.assertEquals("PUT", request.getMethod());
|
||||
|
@ -136,8 +136,8 @@ public class TestRequestBuilder {
|
|||
Assert.assertTrue(clone instanceof HttpEntityEnclosingRequest);
|
||||
Assert.assertNotNull(((HttpEntityEnclosingRequest) clone).getEntity());
|
||||
Assert.assertNotSame(entity, ((HttpEntityEnclosingRequest) clone).getEntity());
|
||||
Assert.assertNotNull(clone.getParams());
|
||||
Assert.assertNotSame(params, clone.getParams());
|
||||
Assert.assertTrue(clone instanceof Configurable);
|
||||
Assert.assertSame(config, ((Configurable) clone).getConfig());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -151,7 +151,7 @@ public class TestRequestBuilder {
|
|||
@Test
|
||||
public void testGettersAndMutators() throws Exception {
|
||||
HttpEntity entity = new StringEntity("stuff");
|
||||
HttpParams params = new BasicHttpParams();
|
||||
RequestConfig config = RequestConfig.custom().build();
|
||||
Header h1 = new BasicHeader("header1", "stuff");
|
||||
Header h2 = new BasicHeader("header1", "more-stuff");
|
||||
RequestBuilder builder = RequestBuilder.createPut()
|
||||
|
@ -160,7 +160,7 @@ public class TestRequestBuilder {
|
|||
.addHeader(h1)
|
||||
.addHeader(h2)
|
||||
.setEntity(entity)
|
||||
.setParams(params);
|
||||
.setConfig(config);
|
||||
Assert.assertEquals("PUT", builder.getMethod());
|
||||
Assert.assertEquals(URI.create("/stuff"), builder.getUri());
|
||||
Assert.assertEquals(HttpVersion.HTTP_1_0, builder.getVersion());
|
||||
|
@ -168,7 +168,7 @@ public class TestRequestBuilder {
|
|||
Assert.assertSame(h2, builder.getLastHeader("header1"));
|
||||
Assert.assertEquals(2, builder.getHeaders("header1").length);
|
||||
Assert.assertSame(entity, builder.getEntity());
|
||||
Assert.assertSame(params, builder.getParams());
|
||||
Assert.assertSame(config, builder.getConfig());
|
||||
|
||||
builder.setMethod(null)
|
||||
.setUri((String) null)
|
||||
|
@ -177,7 +177,7 @@ public class TestRequestBuilder {
|
|||
.removeHeaders("header1")
|
||||
.removeHeader(h2)
|
||||
.setEntity(null)
|
||||
.setParams(null);
|
||||
.setConfig(null);
|
||||
Assert.assertEquals(null, builder.getMethod());
|
||||
Assert.assertEquals(null, builder.getUri());
|
||||
Assert.assertEquals(null, builder.getVersion());
|
||||
|
@ -185,7 +185,7 @@ public class TestRequestBuilder {
|
|||
Assert.assertSame(null, builder.getLastHeader("header1"));
|
||||
Assert.assertEquals(0, builder.getHeaders("header1").length);
|
||||
Assert.assertSame(null, builder.getEntity());
|
||||
Assert.assertSame(null, builder.getParams());
|
||||
Assert.assertSame(null, builder.getConfig());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,8 +33,8 @@ import org.apache.http.HttpHost;
|
|||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpRequestInterceptor;
|
||||
import org.apache.http.client.CookieStore;
|
||||
import org.apache.http.client.params.AllClientPNames;
|
||||
import org.apache.http.client.params.CookiePolicy;
|
||||
import org.apache.http.client.config.CookieSpecs;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.config.Lookup;
|
||||
import org.apache.http.config.RegistryBuilder;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
|
@ -84,12 +84,12 @@ public class TestRequestAddCookies {
|
|||
this.cookieStore.addCookie(cookie2);
|
||||
|
||||
this.cookieSpecRegistry = RegistryBuilder.<CookieSpecProvider>create()
|
||||
.register(CookiePolicy.BEST_MATCH, new BestMatchSpecFactory())
|
||||
.register(CookiePolicy.BROWSER_COMPATIBILITY, new BrowserCompatSpecFactory())
|
||||
.register(CookiePolicy.NETSCAPE, new NetscapeDraftSpecFactory())
|
||||
.register(CookiePolicy.RFC_2109, new RFC2109SpecFactory())
|
||||
.register(CookiePolicy.RFC_2965, new RFC2965SpecFactory())
|
||||
.register(CookiePolicy.IGNORE_COOKIES, new IgnoreSpecFactory())
|
||||
.register(CookieSpecs.BEST_MATCH, new BestMatchSpecFactory())
|
||||
.register(CookieSpecs.BROWSER_COMPATIBILITY, new BrowserCompatSpecFactory())
|
||||
.register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecFactory())
|
||||
.register(CookieSpecs.RFC_2109, new RFC2109SpecFactory())
|
||||
.register(CookieSpecs.RFC_2965, new RFC2965SpecFactory())
|
||||
.register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecFactory())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
@ -256,13 +256,14 @@ public class TestRequestAddCookies {
|
|||
@Test
|
||||
public void testAddCookiesUsingExplicitCookieSpec() throws Exception {
|
||||
HttpRequest request = new BasicHttpRequest("GET", "/");
|
||||
request.getParams().setParameter(AllClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);
|
||||
|
||||
RequestConfig config = RequestConfig.custom()
|
||||
.setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY).build();
|
||||
HttpRoute route = new HttpRoute(this.target, null, false);
|
||||
|
||||
HttpContext context = new BasicHttpContext();
|
||||
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
|
||||
context.setAttribute(ClientContext.ROUTE, route);
|
||||
context.setAttribute(ClientContext.REQUEST_CONFIG, config);
|
||||
context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
|
||||
context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@ import junit.framework.Assert;
|
|||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpRequestInterceptor;
|
||||
import org.apache.http.client.params.AllClientPNames;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.apache.http.protocol.BasicHttpContext;
|
||||
|
@ -55,10 +54,9 @@ public class TestRequestDefaultHeaders {
|
|||
HttpRequest request = new BasicHttpRequest("CONNECT", "www.somedomain.com");
|
||||
List<Header> defheaders = new ArrayList<Header>();
|
||||
defheaders.add(new BasicHeader("custom", "stuff"));
|
||||
request.getParams().setParameter(AllClientPNames.DEFAULT_HEADERS, defheaders);
|
||||
HttpContext context = new BasicHttpContext();
|
||||
|
||||
HttpRequestInterceptor interceptor = new RequestDefaultHeaders();
|
||||
HttpRequestInterceptor interceptor = new RequestDefaultHeaders(defheaders);
|
||||
interceptor.process(request, context);
|
||||
Header header1 = request.getFirstHeader("custom");
|
||||
Assert.assertNull(header1);
|
||||
|
@ -70,10 +68,9 @@ public class TestRequestDefaultHeaders {
|
|||
request.addHeader("custom", "stuff");
|
||||
List<Header> defheaders = new ArrayList<Header>();
|
||||
defheaders.add(new BasicHeader("custom", "more stuff"));
|
||||
request.getParams().setParameter(AllClientPNames.DEFAULT_HEADERS, defheaders);
|
||||
HttpContext context = new BasicHttpContext();
|
||||
|
||||
HttpRequestInterceptor interceptor = new RequestDefaultHeaders();
|
||||
HttpRequestInterceptor interceptor = new RequestDefaultHeaders(defheaders);
|
||||
interceptor.process(request, context);
|
||||
Header[] headers = request.getHeaders("custom");
|
||||
Assert.assertNotNull(headers);
|
||||
|
|
|
@ -0,0 +1,126 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* 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.client.protocol;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.apache.http.protocol.BasicHttpContext;
|
||||
import org.apache.http.protocol.HTTP;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestRequestExpectContinue {
|
||||
|
||||
@Test
|
||||
public void testRequestExpectContinueGenerated() throws Exception {
|
||||
HttpContext context = new BasicHttpContext();
|
||||
RequestConfig config = RequestConfig.custom().setExpectContinueEnabled(true).build();
|
||||
context.setAttribute(ClientContext.REQUEST_CONFIG, config);
|
||||
BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
|
||||
String s = "whatever";
|
||||
StringEntity entity = new StringEntity(s, "US-ASCII");
|
||||
request.setEntity(entity);
|
||||
RequestExpectContinue interceptor = new RequestExpectContinue();
|
||||
interceptor.process(request, context);
|
||||
Header header = request.getFirstHeader(HTTP.EXPECT_DIRECTIVE);
|
||||
Assert.assertNotNull(header);
|
||||
Assert.assertEquals(HTTP.EXPECT_CONTINUE, header.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestExpectContinueNotGenerated() throws Exception {
|
||||
HttpContext context = new BasicHttpContext(null);
|
||||
RequestConfig config = RequestConfig.custom().setExpectContinueEnabled(false).build();
|
||||
context.setAttribute(ClientContext.REQUEST_CONFIG, config);
|
||||
BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
|
||||
String s = "whatever";
|
||||
StringEntity entity = new StringEntity(s, "US-ASCII");
|
||||
request.setEntity(entity);
|
||||
RequestExpectContinue interceptor = new RequestExpectContinue();
|
||||
interceptor.process(request, context);
|
||||
Header header = request.getFirstHeader(HTTP.EXPECT_DIRECTIVE);
|
||||
Assert.assertNull(header);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestExpectContinueHTTP10() throws Exception {
|
||||
HttpContext context = new BasicHttpContext(null);
|
||||
RequestConfig config = RequestConfig.custom().setExpectContinueEnabled(true).build();
|
||||
context.setAttribute(ClientContext.REQUEST_CONFIG, config);
|
||||
BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest(
|
||||
"POST", "/", HttpVersion.HTTP_1_0);
|
||||
String s = "whatever";
|
||||
StringEntity entity = new StringEntity(s, "US-ASCII");
|
||||
request.setEntity(entity);
|
||||
RequestExpectContinue interceptor = new RequestExpectContinue();
|
||||
interceptor.process(request, context);
|
||||
Header header = request.getFirstHeader(HTTP.EXPECT_DIRECTIVE);
|
||||
Assert.assertNull(header);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestExpectContinueZeroContent() throws Exception {
|
||||
HttpContext context = new BasicHttpContext(null);
|
||||
RequestConfig config = RequestConfig.custom().setExpectContinueEnabled(true).build();
|
||||
context.setAttribute(ClientContext.REQUEST_CONFIG, config);
|
||||
BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
|
||||
String s = "";
|
||||
StringEntity entity = new StringEntity(s, "US-ASCII");
|
||||
request.setEntity(entity);
|
||||
RequestExpectContinue interceptor = new RequestExpectContinue();
|
||||
interceptor.process(request, context);
|
||||
Header header = request.getFirstHeader(HTTP.EXPECT_DIRECTIVE);
|
||||
Assert.assertNull(header);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestExpectContinueInvalidInput() throws Exception {
|
||||
RequestExpectContinue interceptor = new RequestExpectContinue();
|
||||
try {
|
||||
interceptor.process(null, null);
|
||||
Assert.fail("IllegalArgumentException should have been thrown");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestExpectContinueIgnoreNonenclosingRequests() throws Exception {
|
||||
HttpContext context = new BasicHttpContext(null);
|
||||
BasicHttpRequest request = new BasicHttpRequest("POST", "/");
|
||||
RequestExpectContinue interceptor = new RequestExpectContinue();
|
||||
interceptor.process(request, context);
|
||||
Assert.assertEquals(0, request.getAllHeaders().length);
|
||||
}
|
||||
|
||||
}
|
|
@ -27,6 +27,7 @@
|
|||
package org.apache.http.impl.auth;
|
||||
|
||||
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.auth.AuthScheme;
|
||||
|
@ -62,8 +63,12 @@ public class TestBasicScheme {
|
|||
buffer.append((char)germanChar);
|
||||
}
|
||||
|
||||
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("dh", buffer.toString());
|
||||
Header header = BasicScheme.authenticate(credentials, "ISO-8859-1", false);
|
||||
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("dh", buffer.toString());
|
||||
BasicScheme authscheme = new BasicScheme(Consts.ISO_8859_1);
|
||||
|
||||
HttpRequest request = new BasicHttpRequest("GET", "/");
|
||||
HttpContext context = new BasicHttpContext();
|
||||
Header header = authscheme.authenticate(creds, request, context);
|
||||
Assert.assertEquals("Basic ZGg65C32Lfw=", header.getValue());
|
||||
}
|
||||
|
||||
|
|
|
@ -41,10 +41,10 @@ import org.apache.http.auth.AuthScheme;
|
|||
import org.apache.http.auth.AuthSchemeProvider;
|
||||
import org.apache.http.auth.AuthScope;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
import org.apache.http.auth.params.AuthPNames;
|
||||
import org.apache.http.client.AuthCache;
|
||||
import org.apache.http.client.CredentialsProvider;
|
||||
import org.apache.http.client.params.AuthPolicy;
|
||||
import org.apache.http.client.config.AuthSchemes;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.protocol.ClientContext;
|
||||
import org.apache.http.config.Registry;
|
||||
import org.apache.http.config.RegistryBuilder;
|
||||
|
@ -274,8 +274,10 @@ public class TestAuthenticationStrategy {
|
|||
public void testCustomAuthPreference() throws Exception {
|
||||
TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
|
||||
HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
|
||||
response.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF,
|
||||
Arrays.asList(new String[] {AuthPolicy.BASIC } ));
|
||||
RequestConfig config = RequestConfig.custom()
|
||||
.setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC))
|
||||
.build();
|
||||
|
||||
HttpHost authhost = new HttpHost("somehost", 80);
|
||||
HttpContext context = new BasicHttpContext();
|
||||
|
||||
|
@ -287,6 +289,7 @@ public class TestAuthenticationStrategy {
|
|||
.register("basic", new BasicSchemeFactory())
|
||||
.register("digest", new DigestSchemeFactory()).build();
|
||||
context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY, authSchemeRegistry);
|
||||
context.setAttribute(ClientContext.REQUEST_CONFIG, config);
|
||||
|
||||
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
|
||||
credentialsProvider.setCredentials(new AuthScope("somehost", 80),
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.apache.http.HttpResponse;
|
|||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.ProtocolException;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.HttpDelete;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpHead;
|
||||
|
@ -42,7 +43,7 @@ import org.apache.http.client.methods.HttpPost;
|
|||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.apache.http.client.methods.HttpTrace;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.client.params.ClientPNames;
|
||||
import org.apache.http.client.protocol.ClientContext;
|
||||
import org.apache.http.entity.BasicHttpEntity;
|
||||
import org.apache.http.message.BasicHttpResponse;
|
||||
import org.apache.http.protocol.BasicHttpContext;
|
||||
|
@ -254,8 +255,10 @@ public class TestDefaultRedirectStrategy {
|
|||
DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
|
||||
HttpContext context = new BasicHttpContext();
|
||||
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, new HttpHost("localhost"));
|
||||
RequestConfig config = RequestConfig.custom().setRelativeRedirectsAllowed(false).build();
|
||||
context.setAttribute(ClientContext.REQUEST_CONFIG, config);
|
||||
|
||||
HttpGet httpget = new HttpGet("http://localhost/");
|
||||
httpget.getParams().setParameter(ClientPNames.REJECT_RELATIVE_REDIRECT, Boolean.TRUE);
|
||||
HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
|
||||
HttpStatus.SC_MOVED_TEMPORARILY, "Redirect");
|
||||
response.addHeader("Location", "/stuff");
|
||||
|
@ -268,7 +271,8 @@ public class TestDefaultRedirectStrategy {
|
|||
HttpContext context = new BasicHttpContext();
|
||||
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, new HttpHost("localhost"));
|
||||
HttpGet httpget = new HttpGet("http://localhost/");
|
||||
httpget.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, Boolean.TRUE);
|
||||
RequestConfig config = RequestConfig.custom().setCircularRedirectsAllowed(true).build();
|
||||
context.setAttribute(ClientContext.REQUEST_CONFIG, config);
|
||||
HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
|
||||
HttpStatus.SC_MOVED_TEMPORARILY, "Redirect");
|
||||
response.addHeader("Location", "http://localhost/stuff");
|
||||
|
@ -295,7 +299,8 @@ public class TestDefaultRedirectStrategy {
|
|||
HttpContext context = new BasicHttpContext();
|
||||
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, new HttpHost("localhost"));
|
||||
HttpGet httpget = new HttpGet("http://localhost/");
|
||||
httpget.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, Boolean.FALSE);
|
||||
RequestConfig config = RequestConfig.custom().setCircularRedirectsAllowed(false).build();
|
||||
context.setAttribute(ClientContext.REQUEST_CONFIG, config);
|
||||
HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
|
||||
HttpStatus.SC_MOVED_TEMPORARILY, "Redirect");
|
||||
response.addHeader("Location", "http://localhost/stuff");
|
||||
|
|
|
@ -297,6 +297,7 @@ public class TestAbortHandling extends IntegrationTestBase {
|
|||
Mockito.any(HttpClientConnection.class),
|
||||
Mockito.any(HttpHost.class),
|
||||
Mockito.any(InetAddress.class),
|
||||
Mockito.anyInt(),
|
||||
Mockito.any(HttpContext.class));
|
||||
|
||||
Mockito.when(connmgr.requestConnection(
|
||||
|
@ -457,6 +458,7 @@ public class TestAbortHandling extends IntegrationTestBase {
|
|||
final HttpClientConnection conn,
|
||||
final HttpHost host,
|
||||
final InetAddress localAddress,
|
||||
final int connectTimeout,
|
||||
final HttpContext context) throws IOException {
|
||||
throw new UnsupportedOperationException("just a mockup");
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ import org.apache.http.client.AuthCache;
|
|||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.CredentialsProvider;
|
||||
import org.apache.http.client.NonRepeatableRequestException;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpPut;
|
||||
|
@ -58,7 +59,6 @@ import org.apache.http.localserver.BasicAuthTokenExtractor;
|
|||
import org.apache.http.localserver.LocalTestServer;
|
||||
import org.apache.http.localserver.RequestBasicAuth;
|
||||
import org.apache.http.localserver.ResponseBasicUnauthorized;
|
||||
import org.apache.http.params.CoreProtocolPNames;
|
||||
import org.apache.http.protocol.BasicHttpContext;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.apache.http.protocol.HttpExpectationVerifier;
|
||||
|
@ -240,12 +240,13 @@ public class TestClientAuthentication extends IntegrationTestBase {
|
|||
|
||||
this.httpclient = HttpClients.custom().setCredentialsProvider(credsProvider).build();
|
||||
|
||||
RequestConfig config = RequestConfig.custom().setExpectContinueEnabled(true).build();
|
||||
HttpPut httpput = new HttpPut("/");
|
||||
httpput.setConfig(config);
|
||||
httpput.setEntity(new InputStreamEntity(
|
||||
new ByteArrayInputStream(
|
||||
new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 } ),
|
||||
-1));
|
||||
httpput.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true);
|
||||
|
||||
HttpResponse response = this.httpclient.execute(getServerHttp(), httpput);
|
||||
HttpEntity entity = response.getEntity();
|
||||
|
@ -262,12 +263,13 @@ public class TestClientAuthentication extends IntegrationTestBase {
|
|||
|
||||
this.httpclient = HttpClients.custom().setCredentialsProvider(credsProvider).build();
|
||||
|
||||
RequestConfig config = RequestConfig.custom().setExpectContinueEnabled(true).build();
|
||||
HttpPut httpput = new HttpPut("/");
|
||||
httpput.setConfig(config);
|
||||
httpput.setEntity(new InputStreamEntity(
|
||||
new ByteArrayInputStream(
|
||||
new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 } ),
|
||||
-1));
|
||||
httpput.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
|
||||
|
||||
try {
|
||||
this.httpclient.execute(getServerHttp(), httpput);
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
package org.apache.http.impl.client.integration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.apache.http.Consts;
|
||||
|
@ -41,8 +41,8 @@ import org.apache.http.auth.AuthScheme;
|
|||
import org.apache.http.auth.AuthScope;
|
||||
import org.apache.http.auth.Credentials;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
import org.apache.http.auth.params.AuthPNames;
|
||||
import org.apache.http.client.CredentialsProvider;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.auth.BasicScheme;
|
||||
|
@ -51,7 +51,6 @@ import org.apache.http.impl.client.HttpClients;
|
|||
import org.apache.http.impl.client.TargetAuthenticationStrategy;
|
||||
import org.apache.http.localserver.LocalTestServer;
|
||||
import org.apache.http.localserver.RequestBasicAuth;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.protocol.BasicHttpContext;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.apache.http.protocol.HttpProcessor;
|
||||
|
@ -178,18 +177,19 @@ public class TestClientReauthentication extends IntegrationTestBase {
|
|||
TestCredentialsProvider credsProvider = new TestCredentialsProvider(
|
||||
new UsernamePasswordCredentials("test", "test"));
|
||||
|
||||
RequestConfig config = RequestConfig.custom()
|
||||
.setTargetPreferredAuthSchemes(Arrays.asList("MyBasic"))
|
||||
.build();
|
||||
this.httpclient = HttpClients.custom()
|
||||
.registerAuthScheme("MyBasic", myBasicAuthSchemeFactory)
|
||||
.setTargetAuthenticationStrategy(myAuthStrategy)
|
||||
.setCredentialsProvider(credsProvider)
|
||||
.build();
|
||||
|
||||
this.httpclient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF,
|
||||
Collections.singletonList("MyBasic"));
|
||||
|
||||
HttpContext context = new BasicHttpContext();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
HttpGet httpget = new HttpGet("/");
|
||||
httpget.setConfig(config);
|
||||
HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
|
||||
HttpEntity entity = response.getEntity();
|
||||
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
|
||||
|
|
|
@ -31,7 +31,6 @@ import java.io.IOException;
|
|||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpClientConnection;
|
||||
import org.apache.http.HttpException;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpRequestInterceptor;
|
||||
import org.apache.http.HttpResponse;
|
||||
|
@ -41,7 +40,6 @@ import org.apache.http.client.HttpRequestRetryHandler;
|
|||
import org.apache.http.client.NonRepeatableRequestException;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.params.ClientPNames;
|
||||
import org.apache.http.entity.InputStreamEntity;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
|
@ -81,156 +79,6 @@ public class TestClientRequestExecution extends IntegrationTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultHostAtClientLevel() throws Exception {
|
||||
int port = this.localServer.getServiceAddress().getPort();
|
||||
this.localServer.register("*", new SimpleService());
|
||||
|
||||
HttpHost target = new HttpHost("localhost", port);
|
||||
|
||||
this.httpclient = HttpClients.custom().build();
|
||||
this.httpclient.getParams().setParameter(ClientPNames.DEFAULT_HOST, target);
|
||||
|
||||
String s = "/path";
|
||||
HttpGet httpget = new HttpGet(s);
|
||||
|
||||
HttpResponse response = this.httpclient.execute(httpget);
|
||||
EntityUtils.consume(response.getEntity());
|
||||
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultHostHeader() throws Exception {
|
||||
int port = this.localServer.getServiceAddress().getPort();
|
||||
String hostname = getServerHttp().getHostName();
|
||||
this.localServer.register("*", new SimpleService());
|
||||
|
||||
HttpContext context = new BasicHttpContext();
|
||||
|
||||
String s = "http://localhost:" + port;
|
||||
HttpGet httpget = new HttpGet(s);
|
||||
|
||||
this.httpclient = HttpClients.custom().build();
|
||||
HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
|
||||
EntityUtils.consume(response.getEntity());
|
||||
|
||||
HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
|
||||
ExecutionContext.HTTP_REQUEST);
|
||||
|
||||
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
|
||||
// Check that Host header is generated as expected
|
||||
Header[] headers = reqWrapper.getHeaders("host");
|
||||
Assert.assertNotNull(headers);
|
||||
Assert.assertEquals(1, headers.length);
|
||||
Assert.assertEquals(hostname + ":" + port, headers[0].getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
// HTTPCLIENT-1092
|
||||
public void testVirtualHostHeader() throws Exception {
|
||||
int port = this.localServer.getServiceAddress().getPort();
|
||||
this.localServer.register("*", new SimpleService());
|
||||
|
||||
HttpContext context = new BasicHttpContext();
|
||||
|
||||
String s = "http://localhost:" + port;
|
||||
HttpGet httpget = new HttpGet(s);
|
||||
|
||||
this.httpclient = HttpClients.custom().build();
|
||||
String virtHost = "virtual";
|
||||
httpget.getParams().setParameter(ClientPNames.VIRTUAL_HOST, new HttpHost(virtHost, port));
|
||||
HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
|
||||
EntityUtils.consume(response.getEntity());
|
||||
|
||||
HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
|
||||
ExecutionContext.HTTP_REQUEST);
|
||||
|
||||
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
|
||||
// Check that Host header is generated as expected
|
||||
Header[] headers = reqWrapper.getHeaders("host");
|
||||
Assert.assertNotNull(headers);
|
||||
Assert.assertEquals(1, headers.length);
|
||||
Assert.assertEquals(virtHost+":"+port,headers[0].getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
// Test that virtual port is propagated if provided
|
||||
// This is not expected to be used much, if ever
|
||||
// HTTPCLIENT-1092
|
||||
public void testVirtualHostPortHeader() throws Exception {
|
||||
int port = this.localServer.getServiceAddress().getPort();
|
||||
this.localServer.register("*", new SimpleService());
|
||||
|
||||
HttpContext context = new BasicHttpContext();
|
||||
|
||||
String s = "http://localhost:" + port;
|
||||
HttpGet httpget = new HttpGet(s);
|
||||
|
||||
this.httpclient = HttpClients.custom().build();
|
||||
String virtHost = "virtual";
|
||||
int virtPort = 9876;
|
||||
httpget.getParams().setParameter(ClientPNames.VIRTUAL_HOST, new HttpHost(virtHost, virtPort));
|
||||
HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
|
||||
EntityUtils.consume(response.getEntity());
|
||||
|
||||
HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
|
||||
ExecutionContext.HTTP_REQUEST);
|
||||
|
||||
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
|
||||
// Check that Host header is generated as expected
|
||||
Header[] headers = reqWrapper.getHeaders("host");
|
||||
Assert.assertNotNull(headers);
|
||||
Assert.assertEquals(1, headers.length);
|
||||
Assert.assertEquals(virtHost+":"+virtPort,headers[0].getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClientLevelVirtualHostHeader() throws Exception {
|
||||
int port = this.localServer.getServiceAddress().getPort();
|
||||
this.localServer.register("*", new SimpleService());
|
||||
|
||||
HttpContext context = new BasicHttpContext();
|
||||
|
||||
String s = "http://localhost:" + port;
|
||||
HttpGet httpget = new HttpGet(s);
|
||||
|
||||
this.httpclient = HttpClients.custom().build();
|
||||
String virtHost = "virtual";
|
||||
this.httpclient.getParams().setParameter(ClientPNames.VIRTUAL_HOST, new HttpHost(virtHost, port));
|
||||
HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
|
||||
EntityUtils.consume(response.getEntity());
|
||||
|
||||
HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
|
||||
ExecutionContext.HTTP_REQUEST);
|
||||
|
||||
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
|
||||
// Check that Host header is generated as expected
|
||||
Header[] headers = reqWrapper.getHeaders("host");
|
||||
Assert.assertNotNull(headers);
|
||||
Assert.assertEquals(1, headers.length);
|
||||
Assert.assertEquals(virtHost+":"+port,headers[0].getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultHostAtRequestLevel() throws Exception {
|
||||
int port = this.localServer.getServiceAddress().getPort();
|
||||
this.localServer.register("*", new SimpleService());
|
||||
|
||||
HttpHost target1 = new HttpHost("whatever", 80);
|
||||
HttpHost target2 = new HttpHost("localhost", port);
|
||||
|
||||
this.httpclient = HttpClients.custom().build();
|
||||
this.httpclient.getParams().setParameter(ClientPNames.DEFAULT_HOST, target1);
|
||||
|
||||
String s = "/path";
|
||||
HttpGet httpget = new HttpGet(s);
|
||||
httpget.getParams().setParameter(ClientPNames.DEFAULT_HOST, target2);
|
||||
|
||||
HttpResponse response = this.httpclient.execute(httpget);
|
||||
EntityUtils.consume(response.getEntity());
|
||||
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
|
||||
}
|
||||
|
||||
private static class FaultyHttpRequestExecutor extends HttpRequestExecutor {
|
||||
|
||||
private static final String MARKER = "marker";
|
||||
|
|
|
@ -112,7 +112,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
|
|||
HttpContext context = new BasicHttpContext();
|
||||
|
||||
HttpClientConnection conn = getConnection(mgr, route);
|
||||
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context);
|
||||
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
|
||||
|
||||
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
|
||||
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
|
||||
|
@ -146,7 +146,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
|
|||
conn = getConnection(mgr, route);
|
||||
Assert.assertFalse("connection should have been closed", conn.isOpen());
|
||||
|
||||
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context);
|
||||
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
|
||||
|
||||
// repeat the communication, no need to prepare the request again
|
||||
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
|
||||
|
@ -200,7 +200,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
|
|||
HttpContext context = new BasicHttpContext();
|
||||
|
||||
HttpClientConnection conn = getConnection(mgr, route);
|
||||
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context);
|
||||
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
|
||||
|
||||
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
|
||||
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
|
||||
|
@ -235,7 +235,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
|
|||
Assert.assertFalse("connection should have been closed", conn.isOpen());
|
||||
|
||||
// repeat the communication, no need to prepare the request again
|
||||
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context);
|
||||
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
|
||||
|
||||
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
|
||||
response = exec.execute(request, conn, context);
|
||||
|
@ -270,7 +270,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
|
|||
Assert.assertTrue("connection should have been closed", !conn.isOpen());
|
||||
|
||||
// repeat the communication, no need to prepare the request again
|
||||
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context);
|
||||
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
|
||||
|
||||
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
|
||||
response = exec.execute(request, conn, context);
|
||||
|
@ -297,7 +297,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
|
|||
HttpContext context = new BasicHttpContext();
|
||||
|
||||
HttpClientConnection conn = getConnection(mgr, route);
|
||||
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context);
|
||||
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
|
||||
|
||||
Assert.assertEquals(1, mgr.getTotalStats().getLeased());
|
||||
Assert.assertEquals(1, mgr.getStats(route).getLeased());
|
||||
|
@ -337,7 +337,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
|
|||
HttpContext context = new BasicHttpContext();
|
||||
|
||||
HttpClientConnection conn = getConnection(mgr, route);
|
||||
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context);
|
||||
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
|
||||
|
||||
Assert.assertEquals(1, mgr.getTotalStats().getLeased());
|
||||
Assert.assertEquals(1, mgr.getStats(route).getLeased());
|
||||
|
@ -385,7 +385,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
|
|||
new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);
|
||||
|
||||
HttpClientConnection conn = getConnection(mgr, route);
|
||||
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context);
|
||||
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
|
||||
|
||||
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
|
||||
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
|
||||
|
@ -457,7 +457,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
|
|||
abortingThread.start();
|
||||
|
||||
try {
|
||||
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context);
|
||||
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
|
||||
Assert.fail("expected SocketException");
|
||||
} catch(SocketException expected) {}
|
||||
|
||||
|
@ -510,7 +510,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
|
|||
abortingThread.start();
|
||||
|
||||
try {
|
||||
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context);
|
||||
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
|
||||
Assert.fail("IOException expected");
|
||||
} catch(IOException expected) {
|
||||
}
|
||||
|
@ -564,7 +564,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
|
|||
abortingThread.start();
|
||||
|
||||
try {
|
||||
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context);
|
||||
mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
|
||||
Assert.fail("IOException expected");
|
||||
} catch(IOException expected) {
|
||||
}
|
||||
|
|
|
@ -37,8 +37,6 @@ import org.apache.http.HttpStatus;
|
|||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.http.client.CookieStore;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.params.ClientPNames;
|
||||
import org.apache.http.client.params.CookiePolicy;
|
||||
import org.apache.http.client.protocol.ClientContext;
|
||||
import org.apache.http.cookie.Cookie;
|
||||
import org.apache.http.cookie.SM;
|
||||
|
@ -64,7 +62,7 @@ public class TestCookie2Support extends IntegrationTestBase {
|
|||
@Before
|
||||
public void setUp() throws Exception {
|
||||
startServer();
|
||||
this.httpclient = HttpClients.custom().build();
|
||||
this.httpclient = HttpClients.createDefault();
|
||||
}
|
||||
|
||||
private static class CookieVer0Service implements HttpRequestHandler {
|
||||
|
@ -86,8 +84,6 @@ public class TestCookie2Support extends IntegrationTestBase {
|
|||
public void testCookieVersionSupportHeader1() throws Exception {
|
||||
this.localServer.register("*", new CookieVer0Service());
|
||||
|
||||
this.httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH);
|
||||
|
||||
CookieStore cookieStore = new BasicCookieStore();
|
||||
HttpContext context = new BasicHttpContext();
|
||||
context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
|
||||
|
@ -133,8 +129,6 @@ public class TestCookie2Support extends IntegrationTestBase {
|
|||
public void testCookieVersionSupportHeader2() throws Exception {
|
||||
this.localServer.register("*", new CookieVer1Service());
|
||||
|
||||
this.httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH);
|
||||
|
||||
CookieStore cookieStore = new BasicCookieStore();
|
||||
HttpContext context = new BasicHttpContext();
|
||||
context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
|
||||
|
@ -179,8 +173,6 @@ public class TestCookie2Support extends IntegrationTestBase {
|
|||
public void testCookieVersionSupportHeader3() throws Exception {
|
||||
this.localServer.register("*", new CookieVer2Service());
|
||||
|
||||
this.httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH);
|
||||
|
||||
CookieStore cookieStore = new BasicCookieStore();
|
||||
HttpContext context = new BasicHttpContext();
|
||||
context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
|
||||
|
@ -226,8 +218,6 @@ public class TestCookie2Support extends IntegrationTestBase {
|
|||
public void testSetCookieVersionMix() throws Exception {
|
||||
this.localServer.register("*", new SetCookieVersionMixService());
|
||||
|
||||
this.httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH);
|
||||
|
||||
CookieStore cookieStore = new BasicCookieStore();
|
||||
HttpContext context = new BasicHttpContext();
|
||||
context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
|
||||
|
|
|
@ -27,8 +27,7 @@
|
|||
package org.apache.http.impl.client.integration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpException;
|
||||
|
@ -43,9 +42,9 @@ import org.apache.http.client.CircularRedirectException;
|
|||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.CookieStore;
|
||||
import org.apache.http.client.RedirectException;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.params.ClientPNames;
|
||||
import org.apache.http.client.protocol.ClientContext;
|
||||
import org.apache.http.cookie.SM;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
|
@ -400,10 +399,13 @@ public class TestRedirects extends IntegrationTestBase {
|
|||
HttpHost target = getServerHttp();
|
||||
this.localServer.register("*", new CircularRedirectService());
|
||||
|
||||
this.httpclient.getParams().setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
|
||||
this.httpclient.getParams().setIntParameter(ClientPNames.MAX_REDIRECTS, 5);
|
||||
RequestConfig config = RequestConfig.custom()
|
||||
.setCircularRedirectsAllowed(true)
|
||||
.setMaxRedirects(5)
|
||||
.build();
|
||||
|
||||
HttpGet httpget = new HttpGet("/circular-oldlocation/");
|
||||
httpget.setConfig(config);
|
||||
try {
|
||||
this.httpclient.execute(target, httpget);
|
||||
} catch (ClientProtocolException e) {
|
||||
|
@ -417,10 +419,12 @@ public class TestRedirects extends IntegrationTestBase {
|
|||
HttpHost target = getServerHttp();
|
||||
this.localServer.register("*", new CircularRedirectService());
|
||||
|
||||
this.httpclient.getParams().setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, false);
|
||||
RequestConfig config = RequestConfig.custom()
|
||||
.setCircularRedirectsAllowed(false)
|
||||
.build();
|
||||
|
||||
HttpGet httpget = new HttpGet("/circular-oldlocation/");
|
||||
|
||||
httpget.setConfig(config);
|
||||
try {
|
||||
this.httpclient.execute(target, httpget);
|
||||
} catch (ClientProtocolException e) {
|
||||
|
@ -478,9 +482,9 @@ public class TestRedirects extends IntegrationTestBase {
|
|||
|
||||
HttpContext context = new BasicHttpContext();
|
||||
|
||||
this.httpclient.getParams().setBooleanParameter(
|
||||
ClientPNames.REJECT_RELATIVE_REDIRECT, false);
|
||||
RequestConfig config = RequestConfig.custom().setRelativeRedirectsAllowed(true).build();
|
||||
HttpGet httpget = new HttpGet("/oldlocation/");
|
||||
httpget.setConfig(config);
|
||||
|
||||
HttpResponse response = this.httpclient.execute(target, httpget, context);
|
||||
EntityUtils.consume(response.getEntity());
|
||||
|
@ -502,9 +506,9 @@ public class TestRedirects extends IntegrationTestBase {
|
|||
|
||||
HttpContext context = new BasicHttpContext();
|
||||
|
||||
this.httpclient.getParams().setBooleanParameter(
|
||||
ClientPNames.REJECT_RELATIVE_REDIRECT, false);
|
||||
RequestConfig config = RequestConfig.custom().setRelativeRedirectsAllowed(true).build();
|
||||
HttpGet httpget = new HttpGet("/test/oldlocation");
|
||||
httpget.setConfig(config);
|
||||
|
||||
HttpResponse response = this.httpclient.execute(target, httpget, context);
|
||||
EntityUtils.consume(response.getEntity());
|
||||
|
@ -524,10 +528,9 @@ public class TestRedirects extends IntegrationTestBase {
|
|||
HttpHost target = getServerHttp();
|
||||
this.localServer.register("*", new RelativeRedirectService());
|
||||
|
||||
this.httpclient.getParams().setBooleanParameter(
|
||||
ClientPNames.REJECT_RELATIVE_REDIRECT, true);
|
||||
RequestConfig config = RequestConfig.custom().setRelativeRedirectsAllowed(false).build();
|
||||
HttpGet httpget = new HttpGet("/oldlocation/");
|
||||
|
||||
httpget.setConfig(config);
|
||||
try {
|
||||
this.httpclient.execute(target, httpget);
|
||||
} catch (ClientProtocolException e) {
|
||||
|
@ -597,17 +600,15 @@ public class TestRedirects extends IntegrationTestBase {
|
|||
|
||||
@Test
|
||||
public void testDefaultHeadersRedirect() throws Exception {
|
||||
this.httpclient = HttpClients.custom()
|
||||
.setDefaultHeaders(Arrays.asList(new BasicHeader(HTTP.USER_AGENT, "my-test-client")))
|
||||
.build();
|
||||
HttpHost target = getServerHttp();
|
||||
|
||||
this.localServer.register("*", new BasicRedirectService());
|
||||
|
||||
HttpContext context = new BasicHttpContext();
|
||||
|
||||
List<Header> defaultHeaders = new ArrayList<Header>(1);
|
||||
defaultHeaders.add(new BasicHeader(HTTP.USER_AGENT, "my-test-client"));
|
||||
|
||||
this.httpclient.getParams().setParameter(ClientPNames.DEFAULT_HEADERS, defaultHeaders);
|
||||
|
||||
HttpGet httpget = new HttpGet("/oldlocation/");
|
||||
|
||||
|
||||
|
|
|
@ -35,19 +35,17 @@ import org.apache.http.HttpRequest;
|
|||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.auth.AuthScheme;
|
||||
import org.apache.http.auth.AuthSchemeProvider;
|
||||
import org.apache.http.auth.AuthScope;
|
||||
import org.apache.http.auth.Credentials;
|
||||
import org.apache.http.client.CredentialsProvider;
|
||||
import org.apache.http.client.config.AuthSchemes;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.params.AuthPolicy;
|
||||
import org.apache.http.client.params.ClientPNames;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.auth.SPNegoScheme;
|
||||
import org.apache.http.impl.auth.SPNegoSchemeFactory;
|
||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.apache.http.protocol.HttpRequestHandler;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
@ -132,16 +130,15 @@ public class TestSPNegoScheme extends IntegrationTestBase {
|
|||
|
||||
}
|
||||
|
||||
private static class NegotiateSchemeFactoryWithMockGssManager extends SPNegoSchemeFactory {
|
||||
private static class NegotiateSchemeProviderWithMockGssManager implements AuthSchemeProvider {
|
||||
|
||||
NegotiateSchemeWithMockGssManager scheme;
|
||||
|
||||
NegotiateSchemeFactoryWithMockGssManager() throws Exception {
|
||||
NegotiateSchemeProviderWithMockGssManager() throws Exception {
|
||||
scheme = new NegotiateSchemeWithMockGssManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthScheme newInstance(HttpParams params) {
|
||||
public AuthScheme create(HttpContext context) {
|
||||
return scheme;
|
||||
}
|
||||
|
||||
|
@ -158,21 +155,19 @@ public class TestSPNegoScheme extends IntegrationTestBase {
|
|||
|
||||
HttpHost target = new HttpHost("localhost", port);
|
||||
|
||||
SPNegoSchemeFactory nsf = new NegotiateSchemeFactoryWithMockGssManager();
|
||||
AuthSchemeProvider nsf = new NegotiateSchemeProviderWithMockGssManager();
|
||||
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
|
||||
Credentials use_jaas_creds = new UseJaasCredentials();
|
||||
credentialsProvider.setCredentials(new AuthScope(null, -1, null), use_jaas_creds);
|
||||
|
||||
this.httpclient = HttpClients.custom()
|
||||
.registerAuthScheme(AuthPolicy.SPNEGO, nsf)
|
||||
.registerAuthScheme(AuthSchemes.SPNEGO, nsf)
|
||||
.setCredentialsProvider(credentialsProvider)
|
||||
.build();
|
||||
|
||||
this.httpclient.getParams().setParameter(ClientPNames.DEFAULT_HOST, target);
|
||||
|
||||
String s = "/path";
|
||||
HttpGet httpget = new HttpGet(s);
|
||||
HttpResponse response = this.httpclient.execute(httpget);
|
||||
HttpResponse response = this.httpclient.execute(target, httpget);
|
||||
EntityUtils.consume(response.getEntity());
|
||||
|
||||
Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getStatusLine().getStatusCode());
|
||||
|
@ -189,21 +184,20 @@ public class TestSPNegoScheme extends IntegrationTestBase {
|
|||
|
||||
HttpHost target = new HttpHost("localhost", port);
|
||||
|
||||
NegotiateSchemeFactoryWithMockGssManager nsf = new NegotiateSchemeFactoryWithMockGssManager();
|
||||
AuthSchemeProvider nsf = new NegotiateSchemeProviderWithMockGssManager();
|
||||
|
||||
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
|
||||
Credentials use_jaas_creds = new UseJaasCredentials();
|
||||
credentialsProvider.setCredentials(new AuthScope(null, -1, null), use_jaas_creds);
|
||||
|
||||
this.httpclient = HttpClients.custom()
|
||||
.registerAuthScheme(AuthPolicy.SPNEGO, nsf)
|
||||
.registerAuthScheme(AuthSchemes.SPNEGO, nsf)
|
||||
.setCredentialsProvider(credentialsProvider)
|
||||
.build();
|
||||
this.httpclient.getParams().setParameter(ClientPNames.DEFAULT_HOST, target);
|
||||
|
||||
String s = "/path";
|
||||
HttpGet httpget = new HttpGet(s);
|
||||
HttpResponse response = this.httpclient.execute(httpget);
|
||||
HttpResponse response = this.httpclient.execute(target, httpget);
|
||||
EntityUtils.consume(response.getEntity());
|
||||
|
||||
Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getStatusLine().getStatusCode());
|
||||
|
|
|
@ -39,9 +39,6 @@ import org.apache.http.client.methods.HttpGet;
|
|||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||
import org.apache.http.params.BasicHttpParams;
|
||||
import org.apache.http.params.HttpConnectionParams;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.protocol.BasicHttpContext;
|
||||
import org.apache.http.protocol.ExecutionContext;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
|
@ -88,9 +85,6 @@ public class TestStatefulConnManagement extends IntegrationTestBase {
|
|||
|
||||
HttpHost target = new HttpHost("localhost", port);
|
||||
|
||||
HttpParams params = new BasicHttpParams();
|
||||
HttpConnectionParams.setConnectionTimeout(params, 10);
|
||||
|
||||
PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
|
||||
mgr.setMaxTotal(workerCount);
|
||||
mgr.setDefaultMaxPerRoute(workerCount);
|
||||
|
|
|
@ -33,6 +33,8 @@ import org.apache.http.HttpVersion;
|
|||
import org.apache.http.conn.SchemePortResolver;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.apache.http.protocol.BasicHttpContext;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -57,7 +59,8 @@ public class TestDefaultRoutePlanner {
|
|||
HttpHost target = new HttpHost("somehost", 80, "http");
|
||||
HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
|
||||
|
||||
HttpRoute route = routePlanner.determineRoute(target, request, null);
|
||||
HttpContext context = new BasicHttpContext();
|
||||
HttpRoute route = routePlanner.determineRoute(target, request, context);
|
||||
|
||||
Assert.assertEquals(target, route.getTargetHost());
|
||||
Assert.assertEquals(1, route.getHopCount());
|
||||
|
@ -71,7 +74,8 @@ public class TestDefaultRoutePlanner {
|
|||
Mockito.when(schemePortResolver.resolve(target)).thenReturn(443);
|
||||
HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
|
||||
|
||||
HttpRoute route = routePlanner.determineRoute(target, request, null);
|
||||
HttpContext context = new BasicHttpContext();
|
||||
HttpRoute route = routePlanner.determineRoute(target, request, context);
|
||||
|
||||
Assert.assertEquals(new HttpHost("somehost", 443, "https"), route.getTargetHost());
|
||||
Assert.assertEquals(1, route.getHopCount());
|
||||
|
|
|
@ -41,6 +41,8 @@ import org.apache.http.HttpVersion;
|
|||
import org.apache.http.conn.SchemePortResolver;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.apache.http.protocol.BasicHttpContext;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -67,7 +69,8 @@ public class TestSystemDefaultRoutePlanner {
|
|||
HttpHost target = new HttpHost("somehost", 80, "http");
|
||||
HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
|
||||
|
||||
HttpRoute route = routePlanner.determineRoute(target, request, null);
|
||||
HttpContext context = new BasicHttpContext();
|
||||
HttpRoute route = routePlanner.determineRoute(target, request, context);
|
||||
|
||||
Assert.assertEquals(target, route.getTargetHost());
|
||||
Assert.assertEquals(1, route.getHopCount());
|
||||
|
@ -81,7 +84,8 @@ public class TestSystemDefaultRoutePlanner {
|
|||
Mockito.when(schemePortResolver.resolve(target)).thenReturn(443);
|
||||
HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
|
||||
|
||||
HttpRoute route = routePlanner.determineRoute(target, request, null);
|
||||
HttpContext context = new BasicHttpContext();
|
||||
HttpRoute route = routePlanner.determineRoute(target, request, context);
|
||||
|
||||
Assert.assertEquals(new HttpHost("somehost", 443, "https"), route.getTargetHost());
|
||||
Assert.assertEquals(1, route.getHopCount());
|
||||
|
@ -107,7 +111,8 @@ public class TestSystemDefaultRoutePlanner {
|
|||
HttpRequest request =
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
|
||||
|
||||
HttpRoute route = routePlanner.determineRoute(target, request, null);
|
||||
HttpContext context = new BasicHttpContext();
|
||||
HttpRoute route = routePlanner.determineRoute(target, request, context);
|
||||
|
||||
Assert.assertEquals(target, route.getTargetHost());
|
||||
Assert.assertEquals(2, route.getHopCount());
|
||||
|
|
Loading…
Reference in New Issue