Javadoc updates

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1514638 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2013-08-16 10:16:48 +00:00
parent a418347845
commit ee1fec2a8c
10 changed files with 261 additions and 63 deletions

View File

@ -43,7 +43,10 @@ import org.apache.http.protocol.HttpContext;
* send a sequence of requests in order to execute one initial request. * send a sequence of requests in order to execute one initial request.
* *
* @since 4.0 * @since 4.0
*
* @deprecated (4.3) No longer used
*/ */
@Deprecated
public interface RequestDirector { public interface RequestDirector {

View File

@ -42,62 +42,6 @@ import java.io.IOException;
* execution. It imposes no restrictions or particular details on the request * execution. It imposes no restrictions or particular details on the request
* execution process and leaves the specifics of state management, * execution process and leaves the specifics of state management,
* authentication and redirect handling up to individual implementations. * authentication and redirect handling up to individual implementations.
* This should make it easier to decorate the interface with additional
* functionality such as response content caching.
* <p/>
* The usual execution flow can be demonstrated by the code snippet below:
* <PRE>
* MinimalHttpClient httpclient = HttpClientBuilder.buildDefault();
*
* // Prepare a request object
* HttpGet httpget = new HttpGet("http://www.apache.org/");
*
* // Execute the request
* HttpResponse response = httpclient.execute(httpget);
*
* // Examine the response status
* System.out.println(response.getStatusLine());
*
* // Get hold of the response entity
* HttpEntity entity = response.getEntity();
*
* // If the response does not enclose an entity, there is no need
* // to worry about connection release
* if (entity != null) {
* InputStream instream = entity.getContent();
* try {
*
* BufferedReader reader = new BufferedReader(
* new InputStreamReader(instream));
* // do something useful with the response
* System.out.println(reader.readLine());
*
* } catch (IOException ex) {
*
* // In case of an IOException the connection will be released
* // back to the connection manager automatically
* throw ex;
*
* } catch (RuntimeException ex) {
*
* // In case of an unexpected exception you may want to abort
* // the HTTP request in order to shut down the underlying
* // connection and release it back to the connection manager.
* httpget.abort();
* throw ex;
*
* } finally {
*
* // Closing the input stream will trigger connection release
* instream.close();
*
* }
*
* // When HttpClient instance is no longer needed, it can be closed
* // to ensure immediate deallocation of all system resources
* httpclient.close();
* }
* </PRE>
* *
* @since 4.0 * @since 4.0
*/ */

View File

@ -86,62 +86,179 @@ public class RequestConfig implements Cloneable {
this.socketTimeout = socketTimeout; this.socketTimeout = socketTimeout;
} }
/**
* Determines whether the 'Expect: 100-Continue' handshake is enabled
* for entity enclosing methods. The purpose of the 'Expect: 100-Continue'
* handshake is to allow a client that is sending a request message with
* a request body to determine if the origin server is willing to
* accept the request (based on the request headers) before the client
* sends the request body.
* <p/>
* The use of the 'Expect: 100-continue' handshake can result in
* a noticeable performance improvement for entity enclosing requests
* (such as POST and PUT) that require the target server's
* authentication.
* <p/>
* 'Expect: 100-continue' handshake should be used with caution, as it
* may cause problems with HTTP servers and proxies that do not support
* HTTP/1.1 protocol.
* <p/>
* Default: <code>false</code>
*/
public boolean isExpectContinueEnabled() { public boolean isExpectContinueEnabled() {
return expectContinueEnabled; return expectContinueEnabled;
} }
/**
* Returns HTTP proxy to be used for request execution.
* <p/>
* Default: <code>null</code>
*/
public HttpHost getProxy() { public HttpHost getProxy() {
return proxy; return proxy;
} }
/**
* Returns local address to be used for request execution.
* <p/>
* On machines with multiple network interfaces, this parameter
* can be used to select the network interface from which the
* connection originates.
* <p/>
* Default: <code>null</code>
*/
public InetAddress getLocalAddress() { public InetAddress getLocalAddress() {
return localAddress; return localAddress;
} }
/**
* Determines whether stale connection check is to be used. The stale
* connection check can cause up to 30 millisecond overhead per request and
* should be used only when appropriate. For performance critical
* operations this check should be disabled.
* <p/>
* Default: <code>true</code>
*/
public boolean isStaleConnectionCheckEnabled() { public boolean isStaleConnectionCheckEnabled() {
return staleConnectionCheckEnabled; return staleConnectionCheckEnabled;
} }
/**
* Determines the name of the cookie specification to be used for HTTP state
* management.
* <p/>
* Default: <code>null</code>
*/
public String getCookieSpec() { public String getCookieSpec() {
return cookieSpec; return cookieSpec;
} }
/**
* Determines whether redirects should be handled automatically.
* <p/>
* Default: <code>true</code>
*/
public boolean isRedirectsEnabled() { public boolean isRedirectsEnabled() {
return redirectsEnabled; return redirectsEnabled;
} }
/**
* Determines whether relative redirects should be rejected. HTTP specification
* requires the location value be an absolute URI.
* <p/>
* Default: <code>true</code>
*/
public boolean isRelativeRedirectsAllowed() { public boolean isRelativeRedirectsAllowed() {
return relativeRedirectsAllowed; return relativeRedirectsAllowed;
} }
/**
* Determines whether circular redirects (redirects to the same location) should
* be allowed. The HTTP spec is not sufficiently clear whether circular redirects
* are permitted, therefore optionally they can be enabled
* <p/>
* Default: <code>false</code>
*/
public boolean isCircularRedirectsAllowed() { public boolean isCircularRedirectsAllowed() {
return circularRedirectsAllowed; return circularRedirectsAllowed;
} }
/**
* Returns the maximum number of redirects to be followed. The limit on number
* of redirects is intended to prevent infinite loops.
* <p/>
* Default: <code>50</code>
*/
public int getMaxRedirects() { public int getMaxRedirects() {
return maxRedirects; return maxRedirects;
} }
/**
* Determines whether authentication should be handled automatically.
* <p/>
* Default: <code>true</code>
*/
public boolean isAuthenticationEnabled() { public boolean isAuthenticationEnabled() {
return authenticationEnabled; return authenticationEnabled;
} }
/**
* Determines the order of preference for supported authentication schemes
* when authenticating with the target host.
* <p/>
* Default: <code>null</code>
*/
public Collection<String> getTargetPreferredAuthSchemes() { public Collection<String> getTargetPreferredAuthSchemes() {
return targetPreferredAuthSchemes; return targetPreferredAuthSchemes;
} }
/**
* Determines the order of preference for supported authentication schemes
* when authenticating with the proxy host.
* <p/>
* Default: <code>null</code>
*/
public Collection<String> getProxyPreferredAuthSchemes() { public Collection<String> getProxyPreferredAuthSchemes() {
return proxyPreferredAuthSchemes; return proxyPreferredAuthSchemes;
} }
/**
* Returns the timeout in milliseconds used when requesting a connection
* from the connection manager. A timeout value of zero is interpreted
* as an infinite timeout.
* <p/>
* A timeout value of zero is interpreted as an infinite timeout.
* A negative value is interpreted as undefined (system default).
* <p/>
* Default: <code>-1</code>
*/
public int getConnectionRequestTimeout() { public int getConnectionRequestTimeout() {
return connectionRequestTimeout; return connectionRequestTimeout;
} }
/**
* Determines the timeout in milliseconds until a connection is established.
* A timeout value of zero is interpreted as an infinite timeout.
* <p/>
* A timeout value of zero is interpreted as an infinite timeout.
* A negative value is interpreted as undefined (system default).
* <p/>
* Default: <code>-1</code>
*/
public int getConnectTimeout() { public int getConnectTimeout() {
return connectTimeout; return connectTimeout;
} }
/**
* Defines the socket timeout (<code>SO_TIMEOUT</code>) in milliseconds,
* which is the timeout for waiting for data or, put differently,
* a maximum period inactivity between two consecutive data packets).
* <p/>
* A timeout value of zero is interpreted as an infinite timeout.
* A negative value is interpreted as undefined (system default).
* <p/>
* Default: <code>-1</code>
*/
public int getSocketTimeout() { public int getSocketTimeout() {
return socketTimeout; return socketTimeout;
} }

View File

@ -46,6 +46,20 @@ import org.apache.http.entity.SerializableEntity;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
/** /**
* Builder for {@link HttpEntity} instances.
* <p/>
* Several setter methods of this builder are mutually exclusive. In case of multiple invocations
* of the following methods only the last one will have effect:
* <ul>
* <li>{@link #setText(String)}</li>
* <li>{@link #setBinary(byte[])}</li>
* <li>{@link #setStream(java.io.InputStream)}</li>
* <li>{@link #setSerializable(java.io.Serializable)}</li>
* <li>{@link #setParameters(java.util.List)}</li>
* <li>{@link #setParameters(org.apache.http.NameValuePair...)}</li>
* <li>{@link #setFile(java.io.File)}</li>
* </ul>
*
* @since 4.3 * @since 4.3
*/ */
@NotThreadSafe @NotThreadSafe
@ -79,101 +93,210 @@ public class EntityBuilder {
this.file = null; this.file = null;
} }
/**
* Returns entity content as a string if set using {@link #setText(String)} method.
*/
public String getText() { public String getText() {
return text; return text;
} }
/**
* Sets entity content as a string. This method is mutually exclusive with
* {@link #setBinary(byte[])},
* {@link #setStream(java.io.InputStream)} ,
* {@link #setSerializable(java.io.Serializable)} ,
* {@link #setParameters(java.util.List)},
* {@link #setParameters(org.apache.http.NameValuePair...)}
* {@link #setFile(java.io.File)} methods.
*/
public EntityBuilder setText(final String text) { public EntityBuilder setText(final String text) {
clearContent(); clearContent();
this.text = text; this.text = text;
return this; return this;
} }
/**
* Returns entity content as a byte array if set using
* {@link #setBinary(byte[])} method.
*/
public byte[] getBinary() { public byte[] getBinary() {
return binary; return binary;
} }
/**
* Sets entity content as a byte array. This method is mutually exclusive with
* {@link #setText(String)},
* {@link #setStream(java.io.InputStream)} ,
* {@link #setSerializable(java.io.Serializable)} ,
* {@link #setParameters(java.util.List)},
* {@link #setParameters(org.apache.http.NameValuePair...)}
* {@link #setFile(java.io.File)} methods.
*/
public EntityBuilder setBinary(final byte[] binary) { public EntityBuilder setBinary(final byte[] binary) {
clearContent(); clearContent();
this.binary = binary; this.binary = binary;
return this; return this;
} }
/**
* Returns entity content as a {@link InputStream} if set using
* {@link #setStream(java.io.InputStream)} method.
*/
public InputStream getStream() { public InputStream getStream() {
return stream; return stream;
} }
/**
* Sets entity content as a {@link InputStream}. This method is mutually exclusive with
* {@link #setText(String)},
* {@link #setBinary(byte[])},
* {@link #setSerializable(java.io.Serializable)} ,
* {@link #setParameters(java.util.List)},
* {@link #setParameters(org.apache.http.NameValuePair...)}
* {@link #setFile(java.io.File)} methods.
*/
public EntityBuilder setStream(final InputStream stream) { public EntityBuilder setStream(final InputStream stream) {
clearContent(); clearContent();
this.stream = stream; this.stream = stream;
return this; return this;
} }
/**
* Returns entity content as a parameter list if set using
* {@link #setParameters(java.util.List)} or
* {@link #setParameters(org.apache.http.NameValuePair...)} methods.
*/
public List<NameValuePair> getParameters() { public List<NameValuePair> getParameters() {
return parameters; return parameters;
} }
/**
* Sets entity content as a parameter list. This method is mutually exclusive with
* {@link #setText(String)},
* {@link #setBinary(byte[])},
* {@link #setStream(java.io.InputStream)} ,
* {@link #setSerializable(java.io.Serializable)} ,
* {@link #setFile(java.io.File)} methods.
*/
public EntityBuilder setParameters(final List<NameValuePair> parameters) { public EntityBuilder setParameters(final List<NameValuePair> parameters) {
clearContent(); clearContent();
this.parameters = parameters; this.parameters = parameters;
return this; return this;
} }
/**
* Sets entity content as a parameter list. This method is mutually exclusive with
* {@link #setText(String)},
* {@link #setBinary(byte[])},
* {@link #setStream(java.io.InputStream)} ,
* {@link #setSerializable(java.io.Serializable)} ,
* {@link #setFile(java.io.File)} methods.
*/
public EntityBuilder setParameters(final NameValuePair... parameters) { public EntityBuilder setParameters(final NameValuePair... parameters) {
return setParameters(Arrays.asList(parameters)); return setParameters(Arrays.asList(parameters));
} }
/**
* Returns entity content as a {@link Serializable} if set using
* {@link #setSerializable(java.io.Serializable)} method.
*/
public Serializable getSerializable() { public Serializable getSerializable() {
return serializable; return serializable;
} }
/**
* Sets entity content as a {@link Serializable}. This method is mutually exclusive with
* {@link #setText(String)},
* {@link #setBinary(byte[])},
* {@link #setStream(java.io.InputStream)} ,
* {@link #setParameters(java.util.List)},
* {@link #setParameters(org.apache.http.NameValuePair...)}
* {@link #setFile(java.io.File)} methods.
*/
public EntityBuilder setSerializable(final Serializable serializable) { public EntityBuilder setSerializable(final Serializable serializable) {
clearContent(); clearContent();
this.serializable = serializable; this.serializable = serializable;
return this; return this;
} }
/**
* Returns entity content as a {@link File} if set using
* {@link #setFile(java.io.File)} method.
*/
public File getFile() { public File getFile() {
return file; return file;
} }
/**
* Sets entity content as a {@link File}. This method is mutually exclusive with
* {@link #setText(String)},
* {@link #setBinary(byte[])},
* {@link #setStream(java.io.InputStream)} ,
* {@link #setParameters(java.util.List)},
* {@link #setParameters(org.apache.http.NameValuePair...)}
* {@link #setSerializable(java.io.Serializable)} methods.
*/
public EntityBuilder setFile(final File file) { public EntityBuilder setFile(final File file) {
clearContent(); clearContent();
this.file = file; this.file = file;
return this; return this;
} }
/**
* Returns {@link ContentType} of the entity, if set.
*/
public ContentType getContentType() { public ContentType getContentType() {
return contentType; return contentType;
} }
/**
* Sets {@link ContentType} of the entity.
*/
public EntityBuilder setContentType(final ContentType contentType) { public EntityBuilder setContentType(final ContentType contentType) {
this.contentType = contentType; this.contentType = contentType;
return this; return this;
} }
/**
* Returns content encoding of the entity, if set.
*/
public String getContentEncoding() { public String getContentEncoding() {
return contentEncoding; return contentEncoding;
} }
/**
* Sets content encoding of the entity.
*/
public EntityBuilder setContentEncoding(final String contentEncoding) { public EntityBuilder setContentEncoding(final String contentEncoding) {
this.contentEncoding = contentEncoding; this.contentEncoding = contentEncoding;
return this; return this;
} }
/**
* Returns <code>true</code> if entity is to be chunk coded, <code>false</code> otherwise.
*/
public boolean isChunked() { public boolean isChunked() {
return chunked; return chunked;
} }
/**
* Makes entity chunk coded.
*/
public EntityBuilder chunked() { public EntityBuilder chunked() {
this.chunked = true; this.chunked = true;
return this; return this;
} }
/**
* Returns <code>true</code> if entity is to be GZIP compressed, <code>false</code> otherwise.
*/
public boolean isGzipCompress() { public boolean isGzipCompress() {
return gzipCompress; return gzipCompress;
} }
/**
* Makes entity GZIP compressed.
*/
public EntityBuilder gzipCompress() { public EntityBuilder gzipCompress() {
this.gzipCompress = true; this.gzipCompress = true;
return this; return this;
@ -183,6 +306,9 @@ public class EntityBuilder {
return this.contentType != null ? this.contentType : def; return this.contentType != null ? this.contentType : def;
} }
/**
* Creates new instance of {@link HttpEntity} based on the current state.
*/
public HttpEntity build() { public HttpEntity build() {
final AbstractHttpEntity e; final AbstractHttpEntity e;
if (this.text != null) { if (this.text != null) {

View File

@ -36,6 +36,9 @@ import org.apache.http.client.config.RequestConfig;
*/ */
public interface Configurable { public interface Configurable {
/**
* Returns actual request configuration.
*/
RequestConfig getConfig(); RequestConfig getConfig();
} }

View File

@ -51,6 +51,14 @@ import org.apache.http.protocol.HTTP;
import org.apache.http.util.Args; import org.apache.http.util.Args;
/** /**
* Builder for {@link HttpUriRequest} instances.
* <p/>
* Please note that this class treats parameters differently depending on composition
* of the request: if the request has a content entity explicitly set with
* {@link #setEntity(org.apache.http.HttpEntity)} or it is not an entity enclosing method
* (such as POST or PUT), parameters will be added to the query component of the request URI.
* Otherwise, parameters will be added as a URL encoded {@link UrlEncodedFormEntity entity}.
*
* @since 4.3 * @since 4.3
*/ */
@NotThreadSafe @NotThreadSafe
@ -293,8 +301,7 @@ public class RequestBuilder {
} }
} }
if (entity == null) { if (entity == null) {
final InternalRequest request = new InternalRequest(method); result = new InternalRequest(method);
result = request;
} else { } else {
final InternalEntityEclosingRequest request = new InternalEntityEclosingRequest(method); final InternalEntityEclosingRequest request = new InternalEntityEclosingRequest(method);
request.setEntity(entity); request.setEntity(entity);

View File

@ -45,8 +45,7 @@ import org.apache.http.util.Args;
* other headers. This class handles dates as defined by RFC 2616 section * other headers. This class handles dates as defined by RFC 2616 section
* 3.3.1 as well as some other common non-standard formats. * 3.3.1 as well as some other common non-standard formats.
* *
* * @since 4.3
* @since 4.0
*/ */
@Immutable @Immutable
public final class DateUtils { public final class DateUtils {

View File

@ -36,7 +36,7 @@ import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
/** /**
* Static helpers for dealing with {@link HttpResponse}s. * Convenience methods for closing response and client objects.
* *
* @since 4.2 * @since 4.2
*/ */

View File

@ -40,7 +40,7 @@ import org.apache.http.conn.util.InetAddressUtils;
import org.apache.http.message.BasicNameValuePair; import org.apache.http.message.BasicNameValuePair;
/** /**
* {@link URI} builder for HTTP requests. * Builder for {@link URI} instances.
* *
* @since 4.2 * @since 4.2
*/ */

View File

@ -41,7 +41,6 @@ import org.apache.http.protocol.HttpContext;
/** /**
* HttpAsyncClientWithFuture wraps calls to execute with a {@link HttpRequestFutureTask} * HttpAsyncClientWithFuture wraps calls to execute with a {@link HttpRequestFutureTask}
* and schedules them using the provided executor service. Scheduled calls may be cancelled. * and schedules them using the provided executor service. Scheduled calls may be cancelled.
* Similar to the non-blockcing HttpAsyncClient, a callback handler api is provided.
*/ */
@ThreadSafe @ThreadSafe
public class FutureRequestExecutionService implements Closeable { public class FutureRequestExecutionService implements Closeable {