Javadoc updates
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1515547 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
95886bc41d
commit
c0c92b814c
|
@ -68,20 +68,23 @@ import org.apache.http.util.EntityUtils;
|
|||
import org.apache.http.util.VersionInfo;
|
||||
|
||||
/**
|
||||
* <p>CachingExec is intended to transparently add client-side caching
|
||||
* to the HttpClient {@link ClientExecChain execution chain}.
|
||||
* The current implementation is conditionally compliant with HTTP/1.1
|
||||
* (meaning all the MUST and MUST NOTs are obeyed), although quite a lot,
|
||||
* though not all, of the SHOULDs and SHOULD NOTs are obeyed too.</p>
|
||||
*
|
||||
* <p>Folks that would like to experiment with alternative storage backends
|
||||
* Request executor in the request execution chain that is responsible for
|
||||
* transparent client-side caching. The current implementation is conditionally
|
||||
* compliant with HTTP/1.1 (meaning all the MUST and MUST NOTs are obeyed),
|
||||
* although quite a lot, though not all, of the SHOULDs and SHOULD NOTs
|
||||
* are obeyed too.
|
||||
* <p/>
|
||||
* Folks that would like to experiment with alternative storage backends
|
||||
* should look at the {@link HttpCacheStorage} interface and the related
|
||||
* package documentation there. You may also be interested in the provided
|
||||
* {@link org.apache.http.impl.client.cache.ehcache.EhcacheHttpCacheStorage
|
||||
* EhCache} and {@link
|
||||
* org.apache.http.impl.client.cache.memcached.MemcachedHttpCacheStorage
|
||||
* memcached} storage backends.</p>
|
||||
* </p>
|
||||
* memcached} storage backends.
|
||||
* <p/>
|
||||
* Further responsibilities such as communication with the opposite
|
||||
* endpoint is delegated to the next executor in the request execution
|
||||
* chain.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
|
|
|
@ -34,7 +34,10 @@ import org.apache.http.impl.client.HttpClientBuilder;
|
|||
import org.apache.http.impl.execchain.ClientExecChain;
|
||||
|
||||
/**
|
||||
* @since (4.3)
|
||||
* Builder for {@link org.apache.http.impl.client.CloseableHttpClient}
|
||||
* instances capable of client-side caching.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
public class CachingHttpClientBuilder extends HttpClientBuilder {
|
||||
|
||||
|
|
|
@ -33,6 +33,9 @@ import org.apache.http.annotation.Immutable;
|
|||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
|
||||
/**
|
||||
* Factory methods for {@link CloseableHttpClient} instances
|
||||
* capable of client-side caching.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
@Immutable
|
||||
|
@ -42,14 +45,28 @@ public class CachingHttpClients {
|
|||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates builder object for construction of custom
|
||||
* {@link CloseableHttpClient} instances.
|
||||
*/
|
||||
public static CachingHttpClientBuilder custom() {
|
||||
return CachingHttpClientBuilder.create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link CloseableHttpClient} instance that uses a memory bound
|
||||
* response cache.
|
||||
*/
|
||||
public static CloseableHttpClient createMemoryBound() {
|
||||
return CachingHttpClientBuilder.create().build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link CloseableHttpClient} instance that uses a file system
|
||||
* bound response cache.
|
||||
*
|
||||
* @param cacheDir location of response cache.
|
||||
*/
|
||||
public static CloseableHttpClient createFileBound(final File cacheDir) {
|
||||
return CachingHttpClientBuilder.create().setCacheDir(cacheDir).build();
|
||||
}
|
||||
|
|
|
@ -36,11 +36,11 @@ import org.apache.http.util.CharArrayBuffer;
|
|||
|
||||
/**
|
||||
* Logs all data written to the wire LOG.
|
||||
*
|
||||
*
|
||||
* @since 4.0
|
||||
* @deprecated (4.3) no longer used.
|
||||
*/
|
||||
@Immutable
|
||||
@Deprecated
|
||||
public class LoggingSessionOutputBuffer implements SessionOutputBuffer {
|
||||
|
||||
/** Original data transmitter. */
|
|
@ -30,8 +30,8 @@ package org.apache.http.client.methods;
|
|||
import org.apache.http.concurrent.Cancellable;
|
||||
|
||||
/**
|
||||
* Interface to be implemented by any object that wishes to be notified of request execution
|
||||
* events.
|
||||
* Interface to be implemented by any object that wishes to be notified of
|
||||
* blocking I/O operations that could be cancelled.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
|
|
|
@ -48,8 +48,9 @@ import org.apache.http.protocol.HttpContext;
|
|||
import org.apache.http.protocol.HttpCoreContext;
|
||||
|
||||
/**
|
||||
* Implementation of {@link HttpContext} that provides convenience
|
||||
* setters for user assignable attributes and getter for readable attributes.
|
||||
* Adaptor class that provides convenience type safe setters and getters
|
||||
* for common {@link HttpContext} attributes used in the course
|
||||
* of HTTP request execution.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
|
@ -158,7 +159,7 @@ public class HttpClientContext extends HttpCoreContext {
|
|||
return getAttribute(HTTP_ROUTE, HttpRoute.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked") // type parameter
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<URI> getRedirectLocations() {
|
||||
return getAttribute(REDIRECT_LOCATIONS, List.class);
|
||||
}
|
||||
|
@ -180,7 +181,7 @@ public class HttpClientContext extends HttpCoreContext {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected <T> Lookup<T> getLookup(final String name, final Class<T> clazz) {
|
||||
private <T> Lookup<T> getLookup(final String name, final Class<T> clazz) {
|
||||
return getAttribute(name, Lookup.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,8 @@ import org.apache.http.HttpClientConnection;
|
|||
import org.apache.http.concurrent.Cancellable;
|
||||
|
||||
/**
|
||||
* Encapsulates a request for a {@link HttpClientConnection}.
|
||||
* Represents a request for a {@link HttpClientConnection} whose life cycle
|
||||
* is managed by a connection manager.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
|
@ -43,8 +44,7 @@ public interface ConnectionRequest extends Cancellable {
|
|||
/**
|
||||
* Obtains a connection within a given time.
|
||||
* This method will block until a connection becomes available,
|
||||
* the timeout expires, or the connection manager is
|
||||
* {@link ClientConnectionManager#shutdown() shut down}.
|
||||
* the timeout expires, or the connection manager is shut down.
|
||||
* Timeouts are handled with millisecond precision.
|
||||
*
|
||||
* If {@link #cancel()} is called while this is blocking or
|
||||
|
|
|
@ -49,45 +49,91 @@ import org.apache.http.protocol.HttpContext;
|
|||
*/
|
||||
public interface HttpClientConnectionManager {
|
||||
|
||||
|
||||
/**
|
||||
* Returns a new {@link ClientConnectionRequest}, from which a
|
||||
* Returns a new {@link ConnectionRequest}, from which a
|
||||
* {@link HttpClientConnection} can be obtained or the request can be
|
||||
* aborted.
|
||||
* <p/>
|
||||
* Please note that newly allocated connections can be returned
|
||||
* in the closed state. The consumer of that connection is responsible
|
||||
* for fully establishing the route the to the connection target
|
||||
* by calling {@link #connect(org.apache.http.HttpClientConnection,
|
||||
* org.apache.http.conn.routing.HttpRoute, int,
|
||||
* org.apache.http.protocol.HttpContext) connect} in order to connect
|
||||
* directly to the target or to the first proxy hop, optionally calling
|
||||
* {@link #upgrade(org.apache.http.HttpClientConnection,
|
||||
* org.apache.http.conn.routing.HttpRoute,
|
||||
* org.apache.http.protocol.HttpContext) upgrade} method to upgrade
|
||||
* the connection after having executed <code>CONNECT</code> method to
|
||||
* all intermediate proxy hops and and finally calling {@link #routeComplete(
|
||||
* org.apache.http.HttpClientConnection,
|
||||
* org.apache.http.conn.routing.HttpRoute,
|
||||
* org.apache.http.protocol.HttpContext) routeComplete} to mark the route
|
||||
* as fully completed.
|
||||
*
|
||||
* @param route HTTP route of the requested connection.
|
||||
* @param state expected state of the connection or <code>null</code>
|
||||
* if the connection is not expected to carry any state.
|
||||
*/
|
||||
ConnectionRequest requestConnection(
|
||||
HttpRoute route, Object state);
|
||||
ConnectionRequest requestConnection(HttpRoute route, Object state);
|
||||
|
||||
/**
|
||||
* Releases a connection for use by others.
|
||||
* You may optionally specify how long the connection is valid
|
||||
* to be reused. Values <= 0 are considered to be valid forever.
|
||||
* If the connection is not marked as reusable, the connection will
|
||||
* not be reused regardless of the valid duration.
|
||||
* Releases the connection back to the manager making it potentially
|
||||
* re-usable by other consumers. Optionally, the maximum period
|
||||
* of how long the manager should keep the connection alive can be
|
||||
* defined using <code>validDuration</code> and <code>timeUnit</code>
|
||||
* parameters.
|
||||
*
|
||||
* If the connection has been released before,
|
||||
* the call will be ignored.
|
||||
*
|
||||
* @param conn the connection to release
|
||||
* @param validDuration the duration of time this connection is valid for reuse
|
||||
* @param timeUnit the unit of time validDuration is measured in
|
||||
* @param conn the managed connection to release.
|
||||
* @param validDuration the duration of time this connection is valid for reuse.
|
||||
* @param timeUnit the time unit.
|
||||
*
|
||||
* @see #closeExpiredConnections()
|
||||
*/
|
||||
void releaseConnection(
|
||||
HttpClientConnection conn, Object newState, long validDuration, TimeUnit timeUnit);
|
||||
|
||||
/**
|
||||
* Connects the underlying connection socket to the connection target in case
|
||||
* of a direct route or to the first proxy hop in case of a route via a proxy
|
||||
* (or multiple proxies).
|
||||
*
|
||||
* @param conn the managed connection.
|
||||
* @param route the route of the connection.
|
||||
* @param connectTimeout connect timeout in milliseconds.
|
||||
* @param context the actual HTTP context.
|
||||
* @throws IOException
|
||||
*/
|
||||
void connect(
|
||||
HttpClientConnection conn,
|
||||
HttpRoute route,
|
||||
int connectTimeout,
|
||||
HttpContext context) throws IOException;
|
||||
|
||||
/**
|
||||
* Upgrades the underlying connection socket to TLS/SSL (or another layering
|
||||
* protocol) after having executed <code>CONNECT</code> method to all
|
||||
* intermediate proxy hops
|
||||
*
|
||||
* @param conn the managed connection.
|
||||
* @param route the route of the connection.
|
||||
* @param context the actual HTTP context.
|
||||
* @throws IOException
|
||||
*/
|
||||
void upgrade(
|
||||
HttpClientConnection conn,
|
||||
HttpRoute route,
|
||||
HttpContext context) throws IOException;
|
||||
|
||||
/**
|
||||
* Marks the connection as fully established with all its intermediate
|
||||
* hops completed.
|
||||
*
|
||||
* @param conn the managed connection.
|
||||
* @param route the route of the connection.
|
||||
* @param context the actual HTTP context.
|
||||
* @throws IOException
|
||||
*/
|
||||
void routeComplete(
|
||||
HttpClientConnection conn,
|
||||
HttpRoute route,
|
||||
|
@ -95,6 +141,7 @@ public interface HttpClientConnectionManager {
|
|||
|
||||
/**
|
||||
* Closes idle connections in the pool.
|
||||
* <p/>
|
||||
* Open connections in the pool that have not been used for the
|
||||
* timespan given by the argument will be closed.
|
||||
* Currently allocated connections are not subject to this method.
|
||||
|
@ -111,6 +158,7 @@ public interface HttpClientConnectionManager {
|
|||
|
||||
/**
|
||||
* Closes all expired connections in the pool.
|
||||
* <p/>
|
||||
* Open connections in the pool that have not been used for
|
||||
* the timespan defined when the connection was released will be closed.
|
||||
* Currently allocated connections are not subject to this method.
|
||||
|
|
|
@ -36,16 +36,34 @@ import org.apache.http.HttpClientConnection;
|
|||
import org.apache.http.HttpInetConnection;
|
||||
|
||||
/**
|
||||
* Extended interface that exposes {@link Socket} bind method and SSL session details.
|
||||
* Represents a managed connection whose state and life cycle is managed by
|
||||
* a connection manager. This interface extends {@link HttpClientConnection}
|
||||
* with methods to bind the connection to an arbitrary socket and
|
||||
* to obtain SSL session details.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
public interface ManagedHttpClientConnection extends HttpClientConnection, HttpInetConnection {
|
||||
|
||||
/**
|
||||
* Returns connection ID which is expected to be unique
|
||||
* for the life span of the connection manager.
|
||||
*/
|
||||
String getId();
|
||||
|
||||
/**
|
||||
* Binds this connection to the given socket. The connection
|
||||
* is considered open if it is bound and the underlying socket
|
||||
* is connection to a remote host.
|
||||
*
|
||||
* @param socket the socket to bind the connection to.
|
||||
* @throws IOException
|
||||
*/
|
||||
void bind(Socket socket) throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the underlying socket.
|
||||
*/
|
||||
Socket getSocket();
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,7 +29,7 @@ package org.apache.http.conn;
|
|||
import org.apache.http.HttpHost;
|
||||
|
||||
/**
|
||||
* Default port resolver for protocol schemes.
|
||||
* Strategy for default port resolution for protocol schemes.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
|
|
|
@ -31,8 +31,7 @@ import org.apache.http.annotation.Immutable;
|
|||
import org.apache.http.util.Args;
|
||||
|
||||
/**
|
||||
* Basic implementation of an {@link HttpRouteDirector HttpRouteDirector}.
|
||||
* This implementation is stateless and therefore thread-safe.
|
||||
* Basic {@link HttpRouteDirector} implementation.
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
|
|
|
@ -41,8 +41,6 @@ import org.apache.http.util.LangUtils;
|
|||
|
||||
/**
|
||||
* The route for a request.
|
||||
* Instances of this class are unmodifiable and therefore suitable
|
||||
* for use as lookup keys.
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
|
|
|
@ -36,7 +36,7 @@ import org.apache.http.protocol.HttpContext;
|
|||
* Encapsulates logic to compute a {@link HttpRoute} to a target host.
|
||||
* Implementations may for example be based on parameters, or on the
|
||||
* standard Java system properties.
|
||||
* <p>
|
||||
* <p/>
|
||||
* Implementations of this interface must be thread-safe. Access to shared
|
||||
* data must be synchronized as methods of this interface may be executed
|
||||
* from multiple threads.
|
||||
|
|
|
@ -35,7 +35,7 @@ import org.apache.http.HttpHost;
|
|||
import org.apache.http.protocol.HttpContext;
|
||||
|
||||
/**
|
||||
* A factory for creating and connecting sockets.
|
||||
* A factory for creating and connecting connection sockets.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
|
@ -44,7 +44,7 @@ public interface ConnectionSocketFactory {
|
|||
/**
|
||||
* Creates new, unconnected socket. The socket should subsequently be passed to
|
||||
* {@link #connectSocket(int, Socket, HttpHost, InetSocketAddress, InetSocketAddress,
|
||||
* HttpContext)}.
|
||||
* HttpContext) connectSocket} method.
|
||||
*
|
||||
* @return a new socket
|
||||
*
|
||||
|
@ -53,7 +53,7 @@ public interface ConnectionSocketFactory {
|
|||
Socket createSocket(HttpContext context) throws IOException;
|
||||
|
||||
/**
|
||||
* Connects a socket to the target host with the given resolved remote address.
|
||||
* Connects the socket to the target host with the given resolved remote address.
|
||||
*
|
||||
* @param connectTimeout connect timeout.
|
||||
* @param sock the socket to connect, as obtained from {@link #createSocket(HttpContext)}.
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.apache.commons.logging.LogFactory;
|
|||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
import org.apache.http.auth.AUTH;
|
||||
import org.apache.http.auth.AuthenticationException;
|
||||
import org.apache.http.auth.Credentials;
|
||||
|
@ -52,6 +53,7 @@ import org.ietf.jgss.Oid;
|
|||
/**
|
||||
* @since 4.2
|
||||
*/
|
||||
@NotThreadSafe
|
||||
public abstract class GGSSchemeBase extends AuthSchemeBase {
|
||||
|
||||
enum State {
|
||||
|
|
|
@ -28,6 +28,7 @@ package org.apache.http.impl.auth;
|
|||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
import org.apache.http.auth.AuthenticationException;
|
||||
import org.apache.http.auth.Credentials;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
|
@ -40,6 +41,7 @@ import org.ietf.jgss.Oid;
|
|||
*
|
||||
* @since 4.2
|
||||
*/
|
||||
@NotThreadSafe
|
||||
public class KerberosScheme extends GGSSchemeBase {
|
||||
|
||||
private static final String KERBEROS_OID = "1.2.840.113554.1.2.2";
|
||||
|
|
|
@ -36,6 +36,7 @@ import javax.crypto.Cipher;
|
|||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
import org.apache.http.util.EncodingUtils;
|
||||
|
||||
/**
|
||||
|
@ -44,6 +45,7 @@ import org.apache.http.util.EncodingUtils;
|
|||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
@NotThreadSafe
|
||||
final class NTLMEngineImpl implements NTLMEngine {
|
||||
|
||||
// Flags we use; descriptions according to:
|
||||
|
|
|
@ -28,6 +28,7 @@ package org.apache.http.impl.auth;
|
|||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
import org.apache.http.auth.AuthenticationException;
|
||||
import org.apache.http.auth.Credentials;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
|
@ -41,6 +42,7 @@ import org.ietf.jgss.Oid;
|
|||
*
|
||||
* @since 4.2
|
||||
*/
|
||||
@NotThreadSafe
|
||||
public class SPNegoScheme extends GGSSchemeBase {
|
||||
|
||||
private static final String SPNEGO_OID = "1.3.6.1.5.5.2";
|
||||
|
|
|
@ -68,13 +68,11 @@ 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[] {
|
||||
AuthSchemes.SPNEGO,
|
||||
Collections.unmodifiableList(Arrays.asList(AuthSchemes.SPNEGO,
|
||||
AuthSchemes.KERBEROS,
|
||||
AuthSchemes.NTLM,
|
||||
AuthSchemes.DIGEST,
|
||||
AuthSchemes.BASIC
|
||||
}));
|
||||
AuthSchemes.BASIC));
|
||||
|
||||
private final int challengeCode;
|
||||
private final String headerName;
|
||||
|
|
|
@ -50,7 +50,7 @@ import org.apache.http.util.Args;
|
|||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
/**
|
||||
* Minimal implementation of {@link HttpClient} that also implements {@link Closeable}.
|
||||
* Base implementation of {@link HttpClient} that also implements {@link Closeable}.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
|
|
|
@ -113,22 +113,26 @@ import org.apache.http.util.TextUtils;
|
|||
import org.apache.http.util.VersionInfo;
|
||||
|
||||
/**
|
||||
* {@link CloseableHttpClient} builder.
|
||||
* <p>
|
||||
* The following system properties are taken into account by this class
|
||||
* if the {@link #useSystemProperties()} method is called.
|
||||
* Builder for {@link CloseableHttpClient} instances.
|
||||
* <p/>
|
||||
* When a particular component is not explicitly this class will
|
||||
* use its default implementation. System properties will be taken
|
||||
* into account when configuring the default implementations when
|
||||
* {@link #useSystemProperties()} method is called prior to calling
|
||||
* {@link #build()}.
|
||||
* <ul>
|
||||
* <li>ssl.TrustManagerFactory.algorithm</li>
|
||||
* <li>javax.net.ssl.trustStoreType</li>
|
||||
* <li>javax.net.ssl.trustStore</li>
|
||||
* <li>javax.net.ssl.trustStoreProvider</li>
|
||||
* <li>javax.net.ssl.trustStorePassword</li>
|
||||
* <li>java.home</li>
|
||||
* <li>ssl.KeyManagerFactory.algorithm</li>
|
||||
* <li>javax.net.ssl.keyStoreType</li>
|
||||
* <li>javax.net.ssl.keyStore</li>
|
||||
* <li>javax.net.ssl.keyStoreProvider</li>
|
||||
* <li>javax.net.ssl.keyStorePassword</li>
|
||||
* <li>https.protocols</li>
|
||||
* <li>https.cipherSuites</li>
|
||||
* <li>http.proxyHost</li>
|
||||
* <li>http.proxyPort</li>
|
||||
* <li>http.nonProxyHosts</li>
|
||||
|
@ -136,7 +140,10 @@ import org.apache.http.util.VersionInfo;
|
|||
* <li>http.maxConnections</li>
|
||||
* <li>http.agent</li>
|
||||
* </ul>
|
||||
* </p>
|
||||
* <p/>
|
||||
* Please note that some settings used by this class can be mutually
|
||||
* exclusive and may not apply when building {@link CloseableHttpClient}
|
||||
* instances.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
|
@ -199,83 +206,198 @@ public class HttpClientBuilder {
|
|||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns {@link HttpRequestExecutor} instance.
|
||||
*/
|
||||
public final HttpClientBuilder setRequestExecutor(final HttpRequestExecutor requestExec) {
|
||||
this.requestExec = requestExec;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns {@link X509HostnameVerifier} instance.
|
||||
* <p/>
|
||||
* Please note this value can be overridden by the {@link #setConnectionManager(
|
||||
* org.apache.http.conn.HttpClientConnectionManager)} and the {@link #setSSLSocketFactory(
|
||||
* org.apache.http.conn.socket.LayeredConnectionSocketFactory)} methods.
|
||||
*/
|
||||
public final HttpClientBuilder setHostnameVerifier(final X509HostnameVerifier hostnameVerifier) {
|
||||
this.hostnameVerifier = hostnameVerifier;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns {@link SSLContext} instance.
|
||||
* <p/>
|
||||
* <p/>
|
||||
* Please note this value can be overridden by the {@link #setConnectionManager(
|
||||
* org.apache.http.conn.HttpClientConnectionManager)} and the {@link #setSSLSocketFactory(
|
||||
* org.apache.http.conn.socket.LayeredConnectionSocketFactory)} methods.
|
||||
*/
|
||||
public final HttpClientBuilder setSslcontext(final SSLContext sslcontext) {
|
||||
this.sslcontext = sslcontext;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns {@link LayeredConnectionSocketFactory} instance.
|
||||
* <p/>
|
||||
* Please note this value can be overridden by the {@link #setConnectionManager(
|
||||
* org.apache.http.conn.HttpClientConnectionManager)} method.
|
||||
*/
|
||||
public final HttpClientBuilder setSSLSocketFactory(
|
||||
final LayeredConnectionSocketFactory sslSocketFactory) {
|
||||
this.sslSocketFactory = sslSocketFactory;
|
||||
return this;
|
||||
}
|
||||
|
||||
public final HttpClientBuilder setSslcontext(final SSLContext sslcontext) {
|
||||
this.sslcontext = sslcontext;
|
||||
/**
|
||||
* Assigns maximum total connection value.
|
||||
* <p/>
|
||||
* Please note this value can be overridden by the {@link #setConnectionManager(
|
||||
* org.apache.http.conn.HttpClientConnectionManager)} method.
|
||||
*/
|
||||
public final HttpClientBuilder setMaxConnTotal(final int maxConnTotal) {
|
||||
this.maxConnTotal = maxConnTotal;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns maximum connection per route value.
|
||||
* <p/>
|
||||
* Please note this value can be overridden by the {@link #setConnectionManager(
|
||||
* org.apache.http.conn.HttpClientConnectionManager)} method.
|
||||
*/
|
||||
public final HttpClientBuilder setMaxConnPerRoute(final int maxConnPerRoute) {
|
||||
this.maxConnPerRoute = maxConnPerRoute;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns default {@link SocketConfig}.
|
||||
* <p/>
|
||||
* Please note this value can be overridden by the {@link #setConnectionManager(
|
||||
* org.apache.http.conn.HttpClientConnectionManager)} method.
|
||||
*/
|
||||
public final HttpClientBuilder setDefaultSocketConfig(final SocketConfig config) {
|
||||
this.defaultSocketConfig = config;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns default {@link ConnectionConfig}.
|
||||
* <p/>
|
||||
* Please note this value can be overridden by the {@link #setConnectionManager(
|
||||
* org.apache.http.conn.HttpClientConnectionManager)} method.
|
||||
*/
|
||||
public final HttpClientBuilder setDefaultConnectionConfig(final ConnectionConfig config) {
|
||||
this.defaultConnectionConfig = config;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns {@link HttpClientConnectionManager} instance.
|
||||
*/
|
||||
public final HttpClientBuilder setConnectionManager(
|
||||
final HttpClientConnectionManager connManager) {
|
||||
this.connManager = connManager;
|
||||
return this;
|
||||
}
|
||||
|
||||
public final HttpClientBuilder setSchemePortResolver(
|
||||
final SchemePortResolver schemePortResolver) {
|
||||
this.schemePortResolver = schemePortResolver;
|
||||
return this;
|
||||
}
|
||||
|
||||
public final HttpClientBuilder setMaxConnTotal(final int maxConnTotal) {
|
||||
this.maxConnTotal = maxConnTotal;
|
||||
return this;
|
||||
}
|
||||
|
||||
public final HttpClientBuilder setMaxConnPerRoute(final int maxConnPerRoute) {
|
||||
this.maxConnPerRoute = maxConnPerRoute;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns {@link ConnectionReuseStrategy} instance.
|
||||
*/
|
||||
public final HttpClientBuilder setConnectionReuseStrategy(
|
||||
final ConnectionReuseStrategy reuseStrategy) {
|
||||
this.reuseStrategy = reuseStrategy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns {@link ConnectionKeepAliveStrategy} instance.
|
||||
*/
|
||||
public final HttpClientBuilder setKeepAliveStrategy(
|
||||
final ConnectionKeepAliveStrategy keepAliveStrategy) {
|
||||
this.keepAliveStrategy = keepAliveStrategy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public final HttpClientBuilder setUserTokenHandler(final UserTokenHandler userTokenHandler) {
|
||||
this.userTokenHandler = userTokenHandler;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns {@link AuthenticationStrategy} instance for proxy
|
||||
* authentication.
|
||||
*/
|
||||
public final HttpClientBuilder setTargetAuthenticationStrategy(
|
||||
final AuthenticationStrategy targetAuthStrategy) {
|
||||
this.targetAuthStrategy = targetAuthStrategy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns {@link AuthenticationStrategy} instance for target
|
||||
* host authentication.
|
||||
*/
|
||||
public final HttpClientBuilder setProxyAuthenticationStrategy(
|
||||
final AuthenticationStrategy proxyAuthStrategy) {
|
||||
this.proxyAuthStrategy = proxyAuthStrategy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public final HttpClientBuilder setHttpProcessor(final HttpProcessor httpprocessor) {
|
||||
this.httpprocessor = httpprocessor;
|
||||
/**
|
||||
* Assigns {@link UserTokenHandler} instance.
|
||||
* <p/>
|
||||
* Please note this value can be overridden by the {@link #disableConnectionState()}
|
||||
* method.
|
||||
*/
|
||||
public final HttpClientBuilder setUserTokenHandler(final UserTokenHandler userTokenHandler) {
|
||||
this.userTokenHandler = userTokenHandler;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables connection state tracking.
|
||||
*/
|
||||
public final HttpClientBuilder disableConnectionState() {
|
||||
connectionStateDisabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns {@link SchemePortResolver} instance.
|
||||
*/
|
||||
public final HttpClientBuilder setSchemePortResolver(
|
||||
final SchemePortResolver schemePortResolver) {
|
||||
this.schemePortResolver = schemePortResolver;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns <tt>User-Agent</tt> value.
|
||||
* <p/>
|
||||
* Please note this value can be overridden by the {@link #setHttpProcessor(
|
||||
* org.apache.http.protocol.HttpProcessor)} method.
|
||||
*/
|
||||
public final HttpClientBuilder setUserAgent(final String userAgent) {
|
||||
this.userAgent = userAgent;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns default request header values.
|
||||
* <p/>
|
||||
* Please note this value can be overridden by the {@link #setHttpProcessor(
|
||||
* org.apache.http.protocol.HttpProcessor)} method.
|
||||
*/
|
||||
public final HttpClientBuilder setDefaultHeaders(final Collection<? extends Header> defaultHeaders) {
|
||||
this.defaultHeaders = defaultHeaders;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds this protocol interceptor to the head of the protocol processing list.
|
||||
* <p/>
|
||||
* Please note this value can be overridden by the {@link #setHttpProcessor(
|
||||
* org.apache.http.protocol.HttpProcessor)} method.
|
||||
*/
|
||||
public final HttpClientBuilder addInterceptorFirst(final HttpResponseInterceptor itcp) {
|
||||
if (itcp == null) {
|
||||
return this;
|
||||
|
@ -287,6 +409,12 @@ public class HttpClientBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds this protocol interceptor to the tail of the protocol processing list.
|
||||
* <p/>
|
||||
* Please note this value can be overridden by the {@link #setHttpProcessor(
|
||||
* org.apache.http.protocol.HttpProcessor)} method.
|
||||
*/
|
||||
public final HttpClientBuilder addInterceptorLast(final HttpResponseInterceptor itcp) {
|
||||
if (itcp == null) {
|
||||
return this;
|
||||
|
@ -298,6 +426,12 @@ public class HttpClientBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds this protocol interceptor to the head of the protocol processing list.
|
||||
* <p/>
|
||||
* Please note this value can be overridden by the {@link #setHttpProcessor(
|
||||
* org.apache.http.protocol.HttpProcessor)} method.
|
||||
*/
|
||||
public final HttpClientBuilder addInterceptorFirst(final HttpRequestInterceptor itcp) {
|
||||
if (itcp == null) {
|
||||
return this;
|
||||
|
@ -309,6 +443,12 @@ public class HttpClientBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds this protocol interceptor to the tail of the protocol processing list.
|
||||
* <p/>
|
||||
* Please note this value can be overridden by the {@link #setHttpProcessor(
|
||||
* org.apache.http.protocol.HttpProcessor)} method.
|
||||
*/
|
||||
public final HttpClientBuilder addInterceptorLast(final HttpRequestInterceptor itcp) {
|
||||
if (itcp == null) {
|
||||
return this;
|
||||
|
@ -320,134 +460,209 @@ public class HttpClientBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables state (cookie) management.
|
||||
* <p/>
|
||||
* Please note this value can be overridden by the {@link #setHttpProcessor(
|
||||
* org.apache.http.protocol.HttpProcessor)} method.
|
||||
*/
|
||||
public final HttpClientBuilder disableCookieManagement() {
|
||||
this.cookieManagementDisabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables automatic content decompression.
|
||||
* <p/>
|
||||
* Please note this value can be overridden by the {@link #setHttpProcessor(
|
||||
* org.apache.http.protocol.HttpProcessor)} method.
|
||||
*/
|
||||
public final HttpClientBuilder disableContentCompression() {
|
||||
contentCompressionDisabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables authentication scheme caching.
|
||||
* <p/>
|
||||
* Please note this value can be overridden by the {@link #setHttpProcessor(
|
||||
* org.apache.http.protocol.HttpProcessor)} method.
|
||||
*/
|
||||
public final HttpClientBuilder disableAuthCaching() {
|
||||
this.authCachingDisabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns {@link HttpProcessor} instance.
|
||||
*/
|
||||
public final HttpClientBuilder setHttpProcessor(final HttpProcessor httpprocessor) {
|
||||
this.httpprocessor = httpprocessor;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns {@link HttpRequestRetryHandler} instance.
|
||||
* <p/>
|
||||
* Please note this value can be overridden by the {@link #disableAutomaticRetries()}
|
||||
* method.
|
||||
*/
|
||||
public final HttpClientBuilder setRetryHandler(final HttpRequestRetryHandler retryHandler) {
|
||||
this.retryHandler = retryHandler;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables automatic request recovery and re-execution.
|
||||
*/
|
||||
public final HttpClientBuilder disableAutomaticRetries() {
|
||||
automaticRetriesDisabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns default proxy value.
|
||||
* <p/>
|
||||
* Please note this value can be overridden by the {@link #setRoutePlanner(
|
||||
* org.apache.http.conn.routing.HttpRoutePlanner) and
|
||||
* {@link #disableRedirectHandling()} methods.
|
||||
*/
|
||||
public final HttpClientBuilder setProxy(final HttpHost proxy) {
|
||||
this.proxy = proxy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns {@link HttpRoutePlanner} instance.
|
||||
* <p/>
|
||||
* Please note this value can be overridden by the {@link #disableRedirectHandling()}
|
||||
* method.
|
||||
*/
|
||||
public final HttpClientBuilder setRoutePlanner(final HttpRoutePlanner routePlanner) {
|
||||
this.routePlanner = routePlanner;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns {@link RedirectStrategy} instance.
|
||||
*/
|
||||
public final HttpClientBuilder setRedirectStrategy(final RedirectStrategy redirectStrategy) {
|
||||
this.redirectStrategy = redirectStrategy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables automatic redirect handling.
|
||||
*/
|
||||
public final HttpClientBuilder disableRedirectHandling() {
|
||||
redirectHandlingDisabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns {@link ConnectionBackoffStrategy} instance.
|
||||
*/
|
||||
public final HttpClientBuilder setConnectionBackoffStrategy(
|
||||
final ConnectionBackoffStrategy connectionBackoffStrategy) {
|
||||
this.connectionBackoffStrategy = connectionBackoffStrategy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns {@link BackoffManager} instance.
|
||||
*/
|
||||
public final HttpClientBuilder setBackoffManager(final BackoffManager backoffManager) {
|
||||
this.backoffManager = backoffManager;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns {@link ServiceUnavailableRetryStrategy} instance.
|
||||
*/
|
||||
public final HttpClientBuilder setServiceUnavailableRetryStrategy(
|
||||
final ServiceUnavailableRetryStrategy serviceUnavailStrategy) {
|
||||
this.serviceUnavailStrategy = serviceUnavailStrategy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns default {@link CookieStore} instance which will be used for
|
||||
* request execution if not explicitly set in the client execution context.
|
||||
*/
|
||||
public final HttpClientBuilder setDefaultCookieStore(final CookieStore cookieStore) {
|
||||
this.cookieStore = cookieStore;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns default {@link CredentialsProvider} instance which will be used
|
||||
* for request execution if not explicitly set in the client execution
|
||||
* context.
|
||||
*/
|
||||
public final HttpClientBuilder setDefaultCredentialsProvider(
|
||||
final CredentialsProvider credentialsProvider) {
|
||||
this.credentialsProvider = credentialsProvider;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns default {@link org.apache.http.auth.AuthScheme} registry which will
|
||||
* be used for request execution if not explicitly set in the client execution
|
||||
* context.
|
||||
*/
|
||||
public final HttpClientBuilder setDefaultAuthSchemeRegistry(
|
||||
final Lookup<AuthSchemeProvider> authSchemeRegistry) {
|
||||
this.authSchemeRegistry = authSchemeRegistry;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns default {@link org.apache.http.cookie.CookieSpec} registry which will
|
||||
* be used for request execution if not explicitly set in the client execution
|
||||
* context.
|
||||
*/
|
||||
public final HttpClientBuilder setDefaultCookieSpecRegistry(
|
||||
final Lookup<CookieSpecProvider> cookieSpecRegistry) {
|
||||
this.cookieSpecRegistry = cookieSpecRegistry;
|
||||
return this;
|
||||
}
|
||||
|
||||
public final HttpClientBuilder setUserAgent(final String userAgent) {
|
||||
this.userAgent = userAgent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public final HttpClientBuilder setProxy(final HttpHost proxy) {
|
||||
this.proxy = proxy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public final HttpClientBuilder setDefaultHeaders(final Collection<? extends Header> defaultHeaders) {
|
||||
this.defaultHeaders = defaultHeaders;
|
||||
return this;
|
||||
}
|
||||
|
||||
public final HttpClientBuilder setDefaultSocketConfig(final SocketConfig config) {
|
||||
this.defaultSocketConfig = config;
|
||||
return this;
|
||||
}
|
||||
|
||||
public final HttpClientBuilder setDefaultConnectionConfig(final ConnectionConfig config) {
|
||||
this.defaultConnectionConfig = config;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns default {@link RequestConfig} instance which will be used
|
||||
* for request execution if not explicitly set in the client execution
|
||||
* context.
|
||||
*/
|
||||
public final HttpClientBuilder setDefaultRequestConfig(final RequestConfig config) {
|
||||
this.defaultRequestConfig = config;
|
||||
return this;
|
||||
}
|
||||
|
||||
public final HttpClientBuilder disableRedirectHandling() {
|
||||
redirectHandlingDisabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public final HttpClientBuilder disableAutomaticRetries() {
|
||||
automaticRetriesDisabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public final HttpClientBuilder disableConnectionState() {
|
||||
connectionStateDisabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public final HttpClientBuilder disableContentCompression() {
|
||||
contentCompressionDisabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public final HttpClientBuilder disableCookieManagement() {
|
||||
this.cookieManagementDisabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public final HttpClientBuilder disableAuthCaching() {
|
||||
this.authCachingDisabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use system properties when creating and configuring default
|
||||
* implementations.
|
||||
*/
|
||||
public final HttpClientBuilder useSystemProperties() {
|
||||
systemProperties = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* For internal use.
|
||||
*/
|
||||
protected ClientExecChain decorateMainExec(final ClientExecChain mainExec) {
|
||||
return mainExec;
|
||||
}
|
||||
|
||||
/**
|
||||
* For internal use.
|
||||
*/
|
||||
protected ClientExecChain decorateProtocolExec(final ClientExecChain protocolExec) {
|
||||
return protocolExec;
|
||||
}
|
||||
|
||||
/**
|
||||
* For internal use.
|
||||
*/
|
||||
protected void addCloseable(final Closeable closeable) {
|
||||
if (closeable == null) {
|
||||
return;
|
||||
|
@ -511,13 +726,12 @@ public class HttpClientBuilder {
|
|||
poolingmgr.setDefaultMaxPerRoute(max);
|
||||
poolingmgr.setMaxTotal(2 * max);
|
||||
}
|
||||
} else {
|
||||
if (maxConnTotal > 0) {
|
||||
poolingmgr.setMaxTotal(maxConnTotal);
|
||||
}
|
||||
if (maxConnPerRoute > 0) {
|
||||
poolingmgr.setDefaultMaxPerRoute(maxConnPerRoute);
|
||||
}
|
||||
}
|
||||
if (maxConnTotal > 0) {
|
||||
poolingmgr.setMaxTotal(maxConnTotal);
|
||||
}
|
||||
if (maxConnPerRoute > 0) {
|
||||
poolingmgr.setDefaultMaxPerRoute(maxConnPerRoute);
|
||||
}
|
||||
connManager = poolingmgr;
|
||||
}
|
||||
|
@ -554,11 +768,6 @@ public class HttpClientBuilder {
|
|||
userTokenHandler = NoopUserTokenHandler.INSTANCE;
|
||||
}
|
||||
}
|
||||
SchemePortResolver schemePortResolver = this.schemePortResolver;
|
||||
if (schemePortResolver == null) {
|
||||
schemePortResolver = DefaultSchemePortResolver.INSTANCE;
|
||||
}
|
||||
|
||||
ClientExecChain execChain = new MainClientExec(
|
||||
requestExec,
|
||||
connManager,
|
||||
|
@ -644,9 +853,12 @@ public class HttpClientBuilder {
|
|||
execChain = new RetryExec(execChain, retryHandler);
|
||||
}
|
||||
|
||||
// Add redirect executor, if not disabled
|
||||
HttpRoutePlanner routePlanner = this.routePlanner;
|
||||
if (routePlanner == null) {
|
||||
SchemePortResolver schemePortResolver = this.schemePortResolver;
|
||||
if (schemePortResolver == null) {
|
||||
schemePortResolver = DefaultSchemePortResolver.INSTANCE;
|
||||
}
|
||||
if (proxy != null) {
|
||||
routePlanner = new DefaultProxyRoutePlanner(proxy, schemePortResolver);
|
||||
} else if (systemProperties) {
|
||||
|
@ -656,6 +868,7 @@ public class HttpClientBuilder {
|
|||
routePlanner = new DefaultRoutePlanner(schemePortResolver);
|
||||
}
|
||||
}
|
||||
// Add redirect executor, if not disabled
|
||||
if (!redirectHandlingDisabled) {
|
||||
RedirectStrategy redirectStrategy = this.redirectStrategy;
|
||||
if (redirectStrategy == null) {
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.apache.http.conn.HttpClientConnectionManager;
|
|||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||
|
||||
/**
|
||||
* Factory methods for {@link CloseableHttpClient} instances.
|
||||
* @since 4.3
|
||||
*/
|
||||
@Immutable
|
||||
|
@ -41,22 +42,42 @@ public class HttpClients {
|
|||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates builder object for construction of custom
|
||||
* {@link CloseableHttpClient} instances.
|
||||
*/
|
||||
public static HttpClientBuilder custom() {
|
||||
return HttpClientBuilder.create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link CloseableHttpClient} instance with default
|
||||
* configuration.
|
||||
*/
|
||||
public static CloseableHttpClient createDefault() {
|
||||
return HttpClientBuilder.create().build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link CloseableHttpClient} instance with default
|
||||
* configuration based on ssytem properties.
|
||||
*/
|
||||
public static CloseableHttpClient createSystem() {
|
||||
return HttpClientBuilder.create().useSystemProperties().build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link CloseableHttpClient} instance that implements
|
||||
* the most basic HTTP protocol support.
|
||||
*/
|
||||
public static CloseableHttpClient createMinimal() {
|
||||
return new MinimalHttpClient(new PoolingHttpClientConnectionManager());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link CloseableHttpClient} instance that implements
|
||||
* the most basic HTTP protocol support.
|
||||
*/
|
||||
public static CloseableHttpClient createMinimal(final HttpClientConnectionManager connManager) {
|
||||
return new MinimalHttpClient(connManager);
|
||||
}
|
||||
|
|
|
@ -69,6 +69,8 @@ import org.apache.http.util.Args;
|
|||
import org.apache.http.util.Asserts;
|
||||
|
||||
/**
|
||||
* Internal class.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
@ThreadSafe
|
||||
|
|
|
@ -57,6 +57,8 @@ import org.apache.http.protocol.HttpRequestExecutor;
|
|||
import org.apache.http.util.Args;
|
||||
|
||||
/**
|
||||
* Internal class.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
@ThreadSafe
|
||||
|
|
|
@ -35,7 +35,6 @@ import org.apache.http.HttpEntity;
|
|||
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;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.auth.AUTH;
|
||||
|
@ -78,8 +77,11 @@ import org.apache.http.protocol.RequestUserAgent;
|
|||
import org.apache.http.util.Args;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
/**
|
||||
* ProxyClient can be used to establish a tunnel via an HTTP proxy.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ProxyClient {
|
||||
public final class ProxyClient {
|
||||
|
||||
private final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory;
|
||||
private final ConnectionConfig connectionConfig;
|
||||
|
@ -103,10 +105,8 @@ public class ProxyClient {
|
|||
this.connFactory = connFactory != null ? connFactory : ManagedHttpClientConnectionFactory.INSTANCE;
|
||||
this.connectionConfig = connectionConfig != null ? connectionConfig : ConnectionConfig.DEFAULT;
|
||||
this.requestConfig = requestConfig != null ? requestConfig : RequestConfig.DEFAULT;
|
||||
this.httpProcessor = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
|
||||
new RequestClientConnControl(),
|
||||
new RequestUserAgent()
|
||||
} );
|
||||
this.httpProcessor = new ImmutableHttpProcessor(new RequestClientConnControl(),
|
||||
new RequestUserAgent());
|
||||
this.requestExec = new HttpRequestExecutor();
|
||||
this.proxyAuthStrategy = new ProxyAuthenticationStrategy();
|
||||
this.authenticator = new HttpAuthenticator();
|
||||
|
@ -122,7 +122,6 @@ public class ProxyClient {
|
|||
|
||||
/**
|
||||
* @deprecated (4.3) use {@link ProxyClient#ProxyClient(HttpConnectionFactory, ConnectionConfig, RequestConfig)}
|
||||
* @param params
|
||||
*/
|
||||
@Deprecated
|
||||
public ProxyClient(final HttpParams params) {
|
||||
|
@ -177,7 +176,7 @@ public class ProxyClient {
|
|||
final ManagedHttpClientConnection conn = this.connFactory.create(
|
||||
route, this.connectionConfig);
|
||||
final HttpContext context = new BasicHttpContext();
|
||||
HttpResponse response = null;
|
||||
HttpResponse response;
|
||||
|
||||
final HttpRequest connect = new BasicHttpRequest(
|
||||
"CONNECT", host.toHostString(), HttpVersion.HTTP_1_1);
|
||||
|
|
|
@ -38,7 +38,7 @@ import org.apache.http.annotation.Immutable;
|
|||
* {@link org.apache.http.client.HttpRequestRetryHandler} which assumes
|
||||
* that all requested HTTP methods which should be idempotent according
|
||||
* to RFC-2616 are in fact idempotent and can be retried.
|
||||
*
|
||||
* <p/>
|
||||
* According to RFC-2616 section 9.1.2 the idempotent HTTP methods are:
|
||||
* GET, HEAD, PUT, DELETE, OPTIONS, and TRACE
|
||||
*
|
||||
|
|
|
@ -41,7 +41,8 @@ import org.apache.http.client.config.AuthSchemes;
|
|||
import org.apache.http.util.Args;
|
||||
|
||||
/**
|
||||
* Implementation of {@link CredentialsProvider} backed by system {@link Authenticator}.
|
||||
* Implementation of {@link CredentialsProvider} backed by standard
|
||||
* JRE {@link Authenticator}.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
|
|
|
@ -37,7 +37,7 @@ import org.apache.http.HttpResponseFactory;
|
|||
import org.apache.http.NoHttpResponseException;
|
||||
import org.apache.http.ProtocolException;
|
||||
import org.apache.http.StatusLine;
|
||||
import org.apache.http.annotation.ThreadSafe;
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
import org.apache.http.config.MessageConstraints;
|
||||
import org.apache.http.impl.DefaultHttpResponseFactory;
|
||||
import org.apache.http.impl.io.AbstractMessageParser;
|
||||
|
@ -55,7 +55,7 @@ import org.apache.http.util.CharArrayBuffer;
|
|||
* @since 4.2
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@ThreadSafe // no public methods
|
||||
@NotThreadSafe
|
||||
public class DefaultHttpResponseParser extends AbstractMessageParser<HttpResponse> {
|
||||
|
||||
private final Log log = LogFactory.getLog(getClass());
|
||||
|
|
|
@ -40,6 +40,7 @@ import javax.net.ssl.SSLSocket;
|
|||
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
import org.apache.http.config.MessageConstraints;
|
||||
import org.apache.http.conn.ManagedHttpClientConnection;
|
||||
import org.apache.http.entity.ContentLengthStrategy;
|
||||
|
@ -49,8 +50,10 @@ import org.apache.http.io.HttpMessageWriterFactory;
|
|||
import org.apache.http.protocol.HttpContext;
|
||||
|
||||
/**
|
||||
* Default {@link ManagedHttpClientConnection} implementation.
|
||||
* @since 4.3
|
||||
*/
|
||||
@NotThreadSafe
|
||||
public class DefaultManagedHttpClientConnection extends DefaultBHttpClientConnection
|
||||
implements ManagedHttpClientConnection, HttpContext {
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
package org.apache.http.impl.conn;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.http.conn.SchemePortResolver;
|
||||
import org.apache.http.conn.UnsupportedSchemeException;
|
||||
import org.apache.http.util.Args;
|
||||
|
@ -36,6 +37,7 @@ import org.apache.http.util.Args;
|
|||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
@Immutable
|
||||
public class DefaultSchemePortResolver implements SchemePortResolver {
|
||||
|
||||
public static final DefaultSchemePortResolver INSTANCE = new DefaultSchemePortResolver();
|
||||
|
|
|
@ -38,7 +38,7 @@ import org.apache.http.conn.DnsResolver;
|
|||
import org.apache.http.util.Args;
|
||||
|
||||
/**
|
||||
* In-memory DNS resolver implementation.
|
||||
* In-memory {@link DnsResolver} implementation.
|
||||
*
|
||||
* @since 4.2
|
||||
*/
|
||||
|
|
|
@ -27,13 +27,18 @@
|
|||
|
||||
package org.apache.http.impl.conn;
|
||||
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* Internal class.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
public class LoggingInputStream extends InputStream {
|
||||
@NotThreadSafe
|
||||
class LoggingInputStream extends InputStream {
|
||||
|
||||
private final InputStream in;
|
||||
private final Wire wire;
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.apache.commons.logging.Log;
|
|||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
import org.apache.http.config.MessageConstraints;
|
||||
import org.apache.http.entity.ContentLengthStrategy;
|
||||
import org.apache.http.io.HttpMessageParserFactory;
|
||||
|
@ -43,6 +44,7 @@ import java.net.Socket;
|
|||
import java.nio.charset.CharsetDecoder;
|
||||
import java.nio.charset.CharsetEncoder;
|
||||
|
||||
@NotThreadSafe
|
||||
class LoggingManagedHttpClientConnection extends DefaultManagedHttpClientConnection {
|
||||
|
||||
private final Log log;
|
||||
|
|
|
@ -27,13 +27,18 @@
|
|||
|
||||
package org.apache.http.impl.conn;
|
||||
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* Internal class.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
public class LoggingOutputStream extends OutputStream {
|
||||
@NotThreadSafe
|
||||
class LoggingOutputStream extends OutputStream {
|
||||
|
||||
private final OutputStream out;
|
||||
private final Wire wire;
|
||||
|
|
|
@ -47,6 +47,7 @@ import org.apache.http.io.HttpMessageParserFactory;
|
|||
import org.apache.http.io.HttpMessageWriterFactory;
|
||||
|
||||
/**
|
||||
* Factory for {@link ManagedHttpClientConnection} instances.
|
||||
* @since 4.3
|
||||
*/
|
||||
@Immutable
|
||||
|
|
|
@ -40,9 +40,6 @@ public class SystemDefaultDnsResolver implements DnsResolver {
|
|||
|
||||
public static final SystemDefaultDnsResolver INSTANCE = new SystemDefaultDnsResolver();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public InetAddress[] resolve(final String host) throws UnknownHostException {
|
||||
return InetAddress.getAllByName(host);
|
||||
}
|
||||
|
|
|
@ -43,13 +43,9 @@ import org.apache.http.protocol.HttpContext;
|
|||
|
||||
/**
|
||||
* {@link org.apache.http.conn.routing.HttpRoutePlanner} implementation
|
||||
* based on {@link ProxySelector}.
|
||||
* By default, it will pick up the proxy settings of the JVM, either
|
||||
* from system properties or from the browser running the application.
|
||||
* Additionally, it interprets some
|
||||
* {@link org.apache.http.conn.params.ConnRoutePNames parameters},
|
||||
* though not the {@link
|
||||
* org.apache.http.conn.params.ConnRoutePNames#DEFAULT_PROXY DEFAULT_PROXY}.
|
||||
* based on {@link ProxySelector}. By default, this class will pick up
|
||||
* the proxy settings of the JVM, either from system properties
|
||||
* or from the browser running the application.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
|
@ -74,14 +70,14 @@ public class SystemDefaultRoutePlanner extends DefaultRoutePlanner {
|
|||
final HttpHost target,
|
||||
final HttpRequest request,
|
||||
final HttpContext context) throws HttpException {
|
||||
URI targetURI = null;
|
||||
final URI targetURI;
|
||||
try {
|
||||
targetURI = new URI(target.toURI());
|
||||
} catch (final URISyntaxException ex) {
|
||||
throw new HttpException("Cannot convert host to URI: " + target, ex);
|
||||
}
|
||||
final List<Proxy> proxies = this.proxySelector.select(targetURI);
|
||||
final Proxy p = chooseProxy(proxies, target, request, context);
|
||||
final Proxy p = chooseProxy(proxies);
|
||||
HttpHost result = null;
|
||||
if (p.type() == Proxy.Type.HTTP) {
|
||||
// convert the socket address to an HttpHost
|
||||
|
@ -106,11 +102,7 @@ public class SystemDefaultRoutePlanner extends DefaultRoutePlanner {
|
|||
|
||||
}
|
||||
|
||||
private Proxy chooseProxy(
|
||||
final List<Proxy> proxies,
|
||||
final HttpHost target,
|
||||
final HttpRequest request,
|
||||
final HttpContext context) {
|
||||
private Proxy chooseProxy(final List<Proxy> proxies) {
|
||||
Proxy result = null;
|
||||
// check the list for one we can use
|
||||
for (int i=0; (result == null) && (i < proxies.size()); i++) {
|
||||
|
|
|
@ -50,6 +50,21 @@ import org.apache.http.conn.routing.HttpRoute;
|
|||
*/
|
||||
public interface ClientExecChain {
|
||||
|
||||
/**
|
||||
* Executes th request either by transmitting it to the target server or
|
||||
* by passing it onto the next executor in the request execution chain.
|
||||
*
|
||||
* @param route connection route.
|
||||
* @param request current request.
|
||||
* @param clientContext current HTTP context.
|
||||
* @param execAware receiver of notifications of blocking I/O operations.
|
||||
* @return HTTP response either received from the opposite endpoint
|
||||
* or generated locally.
|
||||
* @throws IOException in case of a I/O error.
|
||||
* (this type of exceptions are potentially recoverable).
|
||||
* @throws HttpException in case of an HTTP protocol error
|
||||
* (usually this type of exceptions are non-recoverable).
|
||||
*/
|
||||
CloseableHttpResponse execute(
|
||||
HttpRoute route,
|
||||
HttpRequestWrapper request,
|
||||
|
|
|
@ -41,7 +41,6 @@ import org.apache.http.HttpEntityEnclosingRequest;
|
|||
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;
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.http.auth.AUTH;
|
||||
|
@ -75,6 +74,13 @@ import org.apache.http.util.Args;
|
|||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
/**
|
||||
* The last request executor in the HTTP request execution chain
|
||||
* that is responsible for execution of request / response
|
||||
* exchanges with the opposite endpoint.
|
||||
* This executor will automatically retry the request in case
|
||||
* of an authentication challenge by an intermediate proxy or
|
||||
* by the target server.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
@Immutable
|
||||
|
@ -110,10 +116,8 @@ public class MainClientExec implements ClientExecChain {
|
|||
Args.notNull(proxyAuthStrategy, "Proxy authentication strategy");
|
||||
Args.notNull(userTokenHandler, "User token handler");
|
||||
this.authenticator = new HttpAuthenticator();
|
||||
this.proxyHttpProcessor = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
|
||||
new RequestClientConnControl(),
|
||||
new RequestUserAgent()
|
||||
} );
|
||||
this.proxyHttpProcessor = new ImmutableHttpProcessor(
|
||||
new RequestClientConnControl(), new RequestUserAgent());
|
||||
this.routeDirector = new BasicRouteDirector();
|
||||
this.requestExecutor = requestExecutor;
|
||||
this.connManager = connManager;
|
||||
|
@ -196,7 +200,7 @@ public class MainClientExec implements ClientExecChain {
|
|||
execAware.setCancellable(connHolder);
|
||||
}
|
||||
|
||||
HttpResponse response = null;
|
||||
HttpResponse response;
|
||||
for (int execCount = 1;; execCount++) {
|
||||
|
||||
if (execCount > 1 && !Proxies.isRepeatable(request)) {
|
||||
|
@ -268,7 +272,7 @@ public class MainClientExec implements ClientExecChain {
|
|||
}
|
||||
|
||||
if (needAuthentication(
|
||||
targetAuthState, proxyAuthState, route, request, response, context)) {
|
||||
targetAuthState, proxyAuthState, route, response, context)) {
|
||||
// Make sure the response body is fully consumed, if present
|
||||
final HttpEntity entity = response.getEntity();
|
||||
if (connHolder.isReusable()) {
|
||||
|
@ -423,7 +427,7 @@ public class MainClientExec implements ClientExecChain {
|
|||
|
||||
final HttpHost target = route.getTargetHost();
|
||||
final HttpHost proxy = route.getProxyHost();
|
||||
HttpResponse response = null;
|
||||
HttpResponse response;
|
||||
|
||||
final String authority = target.toHostString();
|
||||
final HttpRequest connect = new BasicHttpRequest("CONNECT", authority, request.getProtocolVersion());
|
||||
|
@ -521,7 +525,6 @@ public class MainClientExec implements ClientExecChain {
|
|||
final AuthState targetAuthState,
|
||||
final AuthState proxyAuthState,
|
||||
final HttpRoute route,
|
||||
final HttpRequestWrapper request,
|
||||
final HttpResponse response,
|
||||
final HttpClientContext context) {
|
||||
final RequestConfig config = context.getRequestConfig();
|
||||
|
|
|
@ -41,7 +41,6 @@ import org.apache.http.HttpEntity;
|
|||
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;
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
|
@ -66,6 +65,12 @@ import org.apache.http.util.Args;
|
|||
import org.apache.http.util.VersionInfo;
|
||||
|
||||
/**
|
||||
* Request executor that implements the most fundamental aspects of
|
||||
* the HTTP specification and the most straight-forward request / response
|
||||
* exchange with the target server. This executor does not support
|
||||
* execution via proxy and will make no attempts to retry the request
|
||||
* in case of a redirect, authentication challenge or I/O error.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
@Immutable
|
||||
|
@ -88,13 +93,12 @@ public class MinimalClientExec implements ClientExecChain {
|
|||
Args.notNull(connManager, "Client connection manager");
|
||||
Args.notNull(reuseStrategy, "Connection reuse strategy");
|
||||
Args.notNull(keepAliveStrategy, "Connection keep alive strategy");
|
||||
this.httpProcessor = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
|
||||
this.httpProcessor = new ImmutableHttpProcessor(
|
||||
new RequestContent(),
|
||||
new RequestTargetHost(),
|
||||
new RequestClientConnControl(),
|
||||
new RequestUserAgent(VersionInfo.getUserAgent(
|
||||
"Apache-HttpClient", "org.apache.http.client", getClass())),
|
||||
} );
|
||||
"Apache-HttpClient", "org.apache.http.client", getClass())));
|
||||
this.requestExecutor = requestExecutor;
|
||||
this.connManager = connManager;
|
||||
this.reuseStrategy = reuseStrategy;
|
||||
|
|
|
@ -55,6 +55,16 @@ import org.apache.http.protocol.HttpProcessor;
|
|||
import org.apache.http.util.Args;
|
||||
|
||||
/**
|
||||
* Request executor in the request execution chain that is responsible
|
||||
* for implementation of HTTP specification requirements.
|
||||
* Internally this executor relies on a {@link HttpProcessor} to populate
|
||||
* requisite HTTP request headers, process HTTP response headers and update
|
||||
* session state in {@link HttpClientContext}.
|
||||
* <p/>
|
||||
* Further responsibilities such as communication with the opposite
|
||||
* endpoint is delegated to the next executor in the request execution
|
||||
* chain.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
@Immutable
|
||||
|
|
|
@ -55,6 +55,13 @@ import org.apache.http.util.Args;
|
|||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
/**
|
||||
* Request executor in the request execution chain that is responsible
|
||||
* for handling of request redirects.
|
||||
* <p/>
|
||||
* Further responsibilities such as communication with the opposite
|
||||
* endpoint is delegated to the next executor in the request execution
|
||||
* chain.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
@ThreadSafe
|
||||
|
|
|
@ -44,6 +44,14 @@ import org.apache.http.conn.routing.HttpRoute;
|
|||
import org.apache.http.util.Args;
|
||||
|
||||
/**
|
||||
* Request executor in the request execution chain that is responsible
|
||||
* for making a decision whether a request failed due to an I/O error
|
||||
* should be re-executed.
|
||||
* <p/>
|
||||
* Further responsibilities such as communication with the opposite
|
||||
* endpoint is delegated to the next executor in the request execution
|
||||
* chain.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
@Immutable
|
||||
|
|
|
@ -43,8 +43,13 @@ import org.apache.http.conn.routing.HttpRoute;
|
|||
import org.apache.http.util.Args;
|
||||
|
||||
/**
|
||||
* {@link ClientExecChain} implementation that can automatically retry the request in case of
|
||||
* a non-2xx response using the {@link ServiceUnavailableRetryStrategy} interface.
|
||||
* Request executor in the request execution chain that is responsible
|
||||
* for making a decision whether a request that received a non-2xx response
|
||||
* from the target server should be re-executed.
|
||||
* <p/>
|
||||
* Further responsibilities such as communication with the opposite
|
||||
* endpoint is delegated to the next executor in the request execution
|
||||
* chain.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.apache.http.HttpEntity;
|
|||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.mime.MultipartEntity;
|
||||
import org.apache.http.entity.mime.MultipartEntityBuilder;
|
||||
import org.apache.http.entity.mime.content.FileBody;
|
||||
import org.apache.http.entity.mime.content.StringBody;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
|
@ -57,9 +57,11 @@ public class ClientMultipartFormPost {
|
|||
FileBody bin = new FileBody(new File(args[0]));
|
||||
StringBody comment = new StringBody("A binary file of some kind", ContentType.TEXT_PLAIN);
|
||||
|
||||
MultipartEntity reqEntity = new MultipartEntity();
|
||||
reqEntity.addPart("bin", bin);
|
||||
reqEntity.addPart("comment", comment);
|
||||
HttpEntity reqEntity = MultipartEntityBuilder.create()
|
||||
.addPart("bin", bin)
|
||||
.addPart("comment", comment)
|
||||
.build();
|
||||
|
||||
|
||||
httppost.setEntity(reqEntity);
|
||||
|
||||
|
|
Loading…
Reference in New Issue