TABS -> SPACES

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@937479 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2010-04-23 19:19:23 +00:00
parent 2fd0728ca2
commit 4defb0689f
327 changed files with 3794 additions and 3794 deletions

View File

@ -52,21 +52,21 @@ public class Benchmark {
connector.setRequestBufferSize(12 * 1024);
connector.setResponseBufferSize(12 * 1024);
connector.setAcceptors(2);
QueuedThreadPool threadpool = new QueuedThreadPool();
threadpool.setMinThreads(25);
threadpool.setMaxThreads(200);
Server server = new Server();
server.addConnector(connector);
server.setThreadPool(threadpool);
server.setHandler(new RandomDataHandler());
server.start();
int port = connector.getLocalPort();
int n = 200000;
int contentLen = 2048;
TestHttpAgent[] agents = new TestHttpAgent[] {
new TestHttpClient3(),
new TestHttpJRE(),
@ -78,7 +78,7 @@ public class Benchmark {
for (TestHttpAgent agent: agents) {
agent.init();
}
byte[] content = new byte[contentLen];
int r = Math.abs(content.hashCode());
for (int i = 0; i < content.length; i++) {
@ -87,7 +87,7 @@ public class Benchmark {
URI target1 = new URI("http", null, "localhost", port, "/rnd", "c=" + contentLen, null);
URI target2 = new URI("http", null, "localhost", port, "/echo", null, null);
try {
for (TestHttpAgent agent: agents) {
System.out.println("=================================");
@ -95,7 +95,7 @@ public class Benchmark {
System.out.println("---------------------------------");
System.out.println(n + " GET requests");
System.out.println("---------------------------------");
long startTime1 = System.currentTimeMillis();
Stats stats1 = agent.get(target1, n);
long finishTime1 = System.currentTimeMillis();
@ -103,7 +103,7 @@ public class Benchmark {
System.out.println("---------------------------------");
System.out.println(n + " POST requests");
System.out.println("---------------------------------");
long startTime2 = System.currentTimeMillis();
Stats stats2 = agent.post(target2, content, n);
long finishTime2 = System.currentTimeMillis();
@ -117,15 +117,15 @@ public class Benchmark {
}
static class RandomDataHandler extends AbstractHandler {
public RandomDataHandler() {
super();
}
public void handle(
final String target,
final Request baseRequest,
final HttpServletRequest request,
final String target,
final Request baseRequest,
final HttpServletRequest request,
final HttpServletResponse response) throws IOException, ServletException {
if (target.equals("/rnd")) {
rnd(request, response);
@ -140,7 +140,7 @@ public class Benchmark {
}
private void rnd(
final HttpServletRequest request,
final HttpServletRequest request,
final HttpServletResponse response) throws IOException, ServletException {
int count = 100;
String s = request.getParameter("c");
@ -153,10 +153,10 @@ public class Benchmark {
writer.flush();
return;
}
response.setStatus(200);
response.setContentLength(count);
OutputStream outstream = response.getOutputStream();
byte[] tmp = new byte[1024];
int r = Math.abs(tmp.hashCode());
@ -171,28 +171,28 @@ public class Benchmark {
}
outstream.flush();
}
private void echo(
final HttpServletRequest request,
final HttpServletRequest request,
final HttpServletResponse response) throws IOException, ServletException {
ByteArrayOutputStream2 buffer = new ByteArrayOutputStream2();
ByteArrayOutputStream2 buffer = new ByteArrayOutputStream2();
InputStream instream = request.getInputStream();
if (instream != null) {
IO.copy(instream, buffer);
buffer.flush();
}
byte[] content = buffer.getBuf();
response.setStatus(200);
response.setContentLength(content.length);
OutputStream outstream = response.getOutputStream();
outstream.write(content);
outstream.flush();
}
}
}

View File

@ -34,7 +34,7 @@ public class Stats {
private String serverName = "unknown";
private long contentLen = 0;
private long totalContentLen = 0;
public Stats() {
super();
}
@ -78,13 +78,13 @@ public class Stats {
public void setTotalContentLen(long totalContentLen) {
this.totalContentLen = totalContentLen;
}
public static void printStats(
final URI targetURI, long startTime, long finishTime, final Stats stats) {
float totalTimeSec = (float) (finishTime - startTime) / 1000;
float reqsPerSec = (float) stats.getSuccessCount() / totalTimeSec;
float timePerReqMs = (float) (finishTime - startTime) / (float) stats.getSuccessCount();
System.out.print("Server Software:\t");
System.out.println(stats.getServerName());
System.out.println();
@ -111,5 +111,5 @@ public class Stats {
System.out.print(timePerReqMs);
System.out.println(" [ms] (mean)");
}
}

View File

@ -30,11 +30,11 @@ import java.net.URI;
public interface TestHttpAgent {
void init() throws Exception;
String getClientName();
Stats get(URI target, int count) throws Exception;
Stats post(URI target, byte[] content, int n) throws Exception;
}

View File

@ -41,7 +41,7 @@ import org.apache.commons.httpclient.params.HttpMethodParams;
public class TestHttpClient3 implements TestHttpAgent {
private final HttpClient httpclient;
public TestHttpClient3() {
super();
this.httpclient = new HttpClient();
@ -59,14 +59,14 @@ public class TestHttpClient3 implements TestHttpAgent {
public Stats execute(final HttpMethod httpmethod, int n) throws Exception {
Stats stats = new Stats();
int successCount = 0;
int failureCount = 0;
long contentLen = 0;
long totalContentLen = 0;
byte[] buffer = new byte[4096];
for (int i = 0; i < n; i++) {
try {
this.httpclient.executeMethod(httpmethod);
@ -97,7 +97,7 @@ public class TestHttpClient3 implements TestHttpAgent {
stats.setTotalContentLen(totalContentLen);
return stats;
}
public Stats get(final URI target, int n) throws Exception {
GetMethod httpget = new GetMethod(target.toASCIIString());
return execute(httpget, n);
@ -120,13 +120,13 @@ public class TestHttpClient3 implements TestHttpAgent {
}
URI targetURI = new URI(args[0]);
int n = Integer.parseInt(args[1]);
TestHttpClient3 test = new TestHttpClient3();
TestHttpClient3 test = new TestHttpClient3();
long startTime = System.currentTimeMillis();
Stats stats = test.get(targetURI, n);
long finishTime = System.currentTimeMillis();
Stats.printStats(targetURI, startTime, finishTime, stats);
}

View File

@ -48,7 +48,7 @@ import org.apache.http.util.VersionInfo;
public class TestHttpClient4 implements TestHttpAgent {
private final HttpClient httpclient;
public TestHttpClient4() {
super();
HttpParams params = new SyncBasicHttpParams();
@ -60,7 +60,7 @@ public class TestHttpClient4 implements TestHttpAgent {
false);
params.setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE,
8 * 1024);
this.httpclient = new DefaultHttpClient(params);
}
@ -69,14 +69,14 @@ public class TestHttpClient4 implements TestHttpAgent {
public Stats execute(final HttpUriRequest request, int n) throws Exception {
Stats stats = new Stats();
int successCount = 0;
int failureCount = 0;
long contentLen = 0;
long totalContentLen = 0;
byte[] buffer = new byte[4096];
for (int i = 0; i < n; i++) {
HttpResponse response = this.httpclient.execute(request);
HttpEntity entity = response.getEntity();
@ -109,23 +109,23 @@ public class TestHttpClient4 implements TestHttpAgent {
stats.setContentLen(contentLen);
stats.setTotalContentLen(totalContentLen);
return stats;
}
}
public Stats get(final URI target, int n) throws Exception {
HttpGet httpget = new HttpGet(target);
return execute(httpget, n);
}
public Stats post(final URI target, byte[] content, int n) throws Exception {
HttpPost httppost = new HttpPost(target);
httppost.setEntity(new ByteArrayEntity(content));
return execute(httppost, n);
}
public String getClientName() {
VersionInfo vinfo = VersionInfo.loadVersionInfo("org.apache.http.client",
VersionInfo vinfo = VersionInfo.loadVersionInfo("org.apache.http.client",
Thread.currentThread().getContextClassLoader());
return "Apache HttpClient 4 (ver: " +
return "Apache HttpClient 4 (ver: " +
((vinfo != null) ? vinfo.getRelease() : VersionInfo.UNAVAILABLE) + ")";
}
@ -136,14 +136,14 @@ public class TestHttpClient4 implements TestHttpAgent {
}
URI targetURI = new URI(args[0]);
int n = Integer.parseInt(args[1]);
TestHttpClient4 test = new TestHttpClient4();
TestHttpClient4 test = new TestHttpClient4();
long startTime = System.currentTimeMillis();
Stats stats = test.get(targetURI, n);
long finishTime = System.currentTimeMillis();
Stats.printStats(targetURI, startTime, finishTime, stats);
}
}
}

View File

@ -66,7 +66,7 @@ public class TestHttpCore implements TestHttpAgent {
private final HttpProcessor httpproc;
private final HttpRequestExecutor httpexecutor;
private final ConnectionReuseStrategy connStrategy;
public TestHttpCore() {
super();
this.params = new SyncBasicHttpParams();
@ -78,32 +78,32 @@ public class TestHttpCore implements TestHttpAgent {
false);
this.params.setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE,
8 * 1024);
this.httpproc = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
new RequestContent(),
new RequestTargetHost(),
new RequestConnControl(),
new RequestUserAgent()
}, null);
this.httpexecutor = new HttpRequestExecutor();
this.connStrategy = new DefaultConnectionReuseStrategy();
}
public void init() {
}
public Stats execute(
final HttpHost targetHost, final HttpRequest request, int n) throws Exception {
Stats stats = new Stats();
int successCount = 0;
int failureCount = 0;
long contentLen = 0;
long totalContentLen = 0;
byte[] buffer = new byte[4096];
HttpContext context = new BasicHttpContext();
@ -122,7 +122,7 @@ public class TestHttpCore implements TestHttpAgent {
this.httpexecutor.preProcess(request, this.httpproc, context);
HttpResponse response = this.httpexecutor.execute(request, conn, context);
this.httpexecutor.postProcess(response, this.httpproc, context);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
@ -161,7 +161,7 @@ public class TestHttpCore implements TestHttpAgent {
stats.setTotalContentLen(totalContentLen);
return stats;
}
public Stats get(final URI target, int n) throws Exception {
HttpHost targetHost = new HttpHost(target.getHost(), target.getPort());
StringBuilder buffer = new StringBuilder();
@ -173,7 +173,7 @@ public class TestHttpCore implements TestHttpAgent {
BasicHttpRequest httpget = new BasicHttpRequest("GET", buffer.toString());
return execute(targetHost, httpget, n);
}
public Stats post(final URI target, byte[] content, int n) throws Exception {
HttpHost targetHost = new HttpHost(target.getHost(), target.getPort());
StringBuilder buffer = new StringBuilder();
@ -182,16 +182,16 @@ public class TestHttpCore implements TestHttpAgent {
buffer.append("?");
buffer.append(target.getQuery());
}
BasicHttpEntityEnclosingRequest httppost = new BasicHttpEntityEnclosingRequest("POST",
BasicHttpEntityEnclosingRequest httppost = new BasicHttpEntityEnclosingRequest("POST",
buffer.toString());
httppost.setEntity(new ByteArrayEntity(content));
return execute(targetHost, httppost, n);
}
public String getClientName() {
VersionInfo vinfo = VersionInfo.loadVersionInfo("org.apache.http",
VersionInfo vinfo = VersionInfo.loadVersionInfo("org.apache.http",
Thread.currentThread().getContextClassLoader());
return "Apache HttpCore 4 (ver: " +
return "Apache HttpCore 4 (ver: " +
((vinfo != null) ? vinfo.getRelease() : VersionInfo.UNAVAILABLE) + ")";
}
@ -203,13 +203,13 @@ public class TestHttpCore implements TestHttpAgent {
URI targetURI = new URI(args[0]);
int n = Integer.parseInt(args[1]);
TestHttpCore test = new TestHttpCore();
TestHttpCore test = new TestHttpCore();
long startTime = System.currentTimeMillis();
Stats stats = test.get(targetURI, n);
long finishTime = System.currentTimeMillis();
Stats.printStats(targetURI, startTime, finishTime, stats);
}
}

View File

@ -37,25 +37,25 @@ public class TestHttpJRE implements TestHttpAgent {
public TestHttpJRE() {
super();
}
public void init() {
}
public Stats execute(final URI targetURI, byte[] content, int n) throws Exception {
Stats stats = new Stats();
int successCount = 0;
int failureCount = 0;
long contentLen = 0;
long totalContentLen = 0;
byte[] buffer = new byte[4096];
URL url = targetURI.toURL();
for (int i = 0; i < n; i++) {
HttpURLConnection c = (HttpURLConnection) url.openConnection();
if (content != null) {
c.setRequestMethod("POST");
c.setFixedLengthStreamingMode(content.length);
@ -96,15 +96,15 @@ public class TestHttpJRE implements TestHttpAgent {
stats.setTotalContentLen(totalContentLen);
return stats;
}
public Stats get(final URI target, int n) throws Exception {
return execute(target, null, n);
}
public Stats post(final URI target, byte[] content, int n) throws Exception {
return execute(target, content, n);
}
public String getClientName() {
return "JRE HTTP " + System.getProperty("java.version");
}
@ -117,13 +117,13 @@ public class TestHttpJRE implements TestHttpAgent {
URI targetURI = new URI(args[0]);
int n = Integer.parseInt(args[1]);
TestHttpJRE test = new TestHttpJRE();
TestHttpJRE test = new TestHttpJRE();
long startTime = System.currentTimeMillis();
Stats stats = test.get(targetURI, n);
long finishTime = System.currentTimeMillis();
Stats.printStats(targetURI, startTime, finishTime, stats);
}
}
}

View File

@ -37,7 +37,7 @@ import org.eclipse.jetty.server.Server;
public class TestJettyHttpClient implements TestHttpAgent {
private final HttpClient client;
public TestJettyHttpClient() {
super();
this.client = new HttpClient();
@ -45,7 +45,7 @@ public class TestJettyHttpClient implements TestHttpAgent {
this.client.setRequestBufferSize(8 * 1024);
this.client.setResponseBufferSize(8 * 1024);
}
public void init() throws Exception {
this.client.start();
}
@ -53,11 +53,11 @@ public class TestJettyHttpClient implements TestHttpAgent {
public Stats execute(final URI targetURI, byte[] content, int n) throws Exception {
Stats stats = new Stats();
int successCount = 0;
int failureCount = 0;
long totalContentLen = 0;
for (int i = 0; i < n; i++) {
SimpleHttpExchange exchange = new SimpleHttpExchange();
exchange.setURL(targetURI.toASCIIString());
@ -66,7 +66,7 @@ public class TestJettyHttpClient implements TestHttpAgent {
exchange.setMethod("POST");
exchange.setRequestContent(new ByteArrayBuffer(content));
}
try {
this.client.send(exchange);
exchange.waitForDone();
@ -89,15 +89,15 @@ public class TestJettyHttpClient implements TestHttpAgent {
stats.setTotalContentLen(totalContentLen);
return stats;
}
public Stats get(final URI target, int n) throws Exception {
return execute(target, null, n);
}
public Stats post(final URI target, byte[] content, int n) throws Exception {
return execute(target, content, n);
}
public String getClientName() {
return "Jetty " + Server.getVersion();
}
@ -110,34 +110,34 @@ public class TestJettyHttpClient implements TestHttpAgent {
URI targetURI = new URI(args[0]);
int n = Integer.parseInt(args[1]);
TestJettyHttpClient test = new TestJettyHttpClient();
TestJettyHttpClient test = new TestJettyHttpClient();
long startTime = System.currentTimeMillis();
Stats stats = test.get(targetURI, n);
long finishTime = System.currentTimeMillis();
Stats.printStats(targetURI, startTime, finishTime, stats);
}
static class SimpleHttpExchange extends HttpExchange {
private final Buffer serverHeader = new ByteArrayBuffer("Server");
long contentLen = 0;
int status = 0;
String server;
protected void onResponseStatus(
final Buffer version, int status, final Buffer reason) throws IOException {
this.status = status;
super.onResponseStatus(version, status, reason);
}
@Override
protected void onResponseHeader(final Buffer name, final Buffer value) throws IOException {
super.onResponseHeader(name, value);
if (name.equalsIgnoreCase(this.serverHeader)) {
this.server = value.toString("ASCII");
this.server = value.toString("ASCII");
}
}
@ -146,7 +146,7 @@ public class TestJettyHttpClient implements TestHttpAgent {
this.contentLen += content.length();
super.onResponseContent(content);
}
};
}
}

View File

@ -58,7 +58,7 @@ import org.apache.http.message.BasicHeader;
* .html?RESTAuthentication.html}
*/
public class AWSScheme implements AuthScheme {
private static final String HMAC_SHA1_ALGORITHM = "HmacSHA1";
public static final String NAME = "AWS";
@ -66,7 +66,7 @@ public class AWSScheme implements AuthScheme {
}
public Header authenticate(
final Credentials credentials,
final Credentials credentials,
final HttpRequest request) throws AuthenticationException {
// If the Date header has not been provided add it as it is required
if (request.getFirstHeader("Date") == null) {
@ -102,7 +102,7 @@ public class AWSScheme implements AuthScheme {
/**
* Computes RFC 2104-compliant HMAC signature.
*
*
* @param data
* The data to be signed.
* @param key
@ -112,7 +112,7 @@ public class AWSScheme implements AuthScheme {
* when signature generation fails
*/
private static String calculateRFC2104HMAC(
final String data,
final String data,
final String key) throws AuthenticationException {
try {
// get an hmac_sha1 key from the raw key bytes
@ -131,14 +131,14 @@ public class AWSScheme implements AuthScheme {
} catch (InvalidKeyException ex) {
throw new AuthenticationException("Failed to generate HMAC: " + ex.getMessage(), ex);
} catch (NoSuchAlgorithmException ex) {
throw new AuthenticationException(HMAC_SHA1_ALGORITHM +
throw new AuthenticationException(HMAC_SHA1_ALGORITHM +
" algorithm is not supported", ex);
}
}
/**
* Returns the canonicalized AMZ headers.
*
*
* @param headers
* The list of request headers.
* @return The canonicalized AMZ headers.
@ -179,7 +179,7 @@ public class AWSScheme implements AuthScheme {
/**
* Returns the canonicalized resource.
*
*
* @param uri
* The resource uri
* @param hostName

View File

@ -36,9 +36,9 @@ import org.apache.http.params.HttpParams;
* {@link AWSScheme} instances.
*/
public class AWSSchemeFactory implements AuthSchemeFactory {
public AuthScheme newInstance(final HttpParams params) {
return new AWSScheme();
}
}

View File

@ -51,7 +51,7 @@ public class BouncySpnegoTokenGenerator implements SpnegoTokenGenerator {
private final DERObjectIdentifier spnegoOid;
private final DERObjectIdentifier kerbOid;
public BouncySpnegoTokenGenerator() {
super();
this.spnegoOid = new DERObjectIdentifier("1.3.6.1.5.5.2");
@ -60,7 +60,7 @@ public class BouncySpnegoTokenGenerator implements SpnegoTokenGenerator {
public byte [] generateSpnegoDERObject(byte [] kerbTicket) throws IOException {
DEROctetString ourKerberosTicket = new DEROctetString(kerbTicket);
DERSequence kerbOidSeq = new DERSequence(kerbOid);
DERTaggedObject tagged0 = new DERTaggedObject(0, kerbOidSeq);
DERTaggedObject tagged2 = new DERTaggedObject(2, ourKerberosTicket);
@ -69,22 +69,22 @@ public class BouncySpnegoTokenGenerator implements SpnegoTokenGenerator {
v.add(tagged2);
DERSequence seq = new DERSequence(v);
DERTaggedObject taggedSpnego = new DERTaggedObject(0, seq);
ByteArrayOutputStream out = new ByteArrayOutputStream();
ASN1OutputStream asn1Out = new ASN1OutputStream(out);
ASN1Object spnegoOIDASN1 = (ASN1Object) spnegoOid.toASN1Object();
ASN1Object taggedSpnegoASN1 = (ASN1Object) taggedSpnego.toASN1Object();
int length = spnegoOIDASN1.getDEREncoded().length + taggedSpnegoASN1.getDEREncoded().length;
byte [] lenBytes = writeLength(length);
byte[] appWrap = new byte[lenBytes.length + 1];
appWrap[0] = 0x60;
for(int i=1; i < appWrap.length; i++){
appWrap[i] = lenBytes[i-1];
}
asn1Out.write(appWrap);
asn1Out.writeObject(spnegoOid.toASN1Object());
asn1Out.writeObject(taggedSpnego.toASN1Object());
@ -101,7 +101,7 @@ public class BouncySpnegoTokenGenerator implements SpnegoTokenGenerator {
ASN1InputStream ourSpnego = new ASN1InputStream( manipBytes );
log.debug(ASN1Dump.dumpAsString(ourSpnego.readObject()));
}
return in.readObject().getDEREncoded();
}
@ -114,7 +114,7 @@ public class BouncySpnegoTokenGenerator implements SpnegoTokenGenerator {
while ((val >>>= 8) != 0) {
size++;
}
out.write((byte) (size | 0x80));
for (int i = (size - 1) * 8; i >= 0; i -= 8) {
@ -125,5 +125,5 @@ public class BouncySpnegoTokenGenerator implements SpnegoTokenGenerator {
}
return out.toByteArray();
}
}

View File

@ -31,7 +31,7 @@ import org.apache.http.annotation.Immutable;
/**
* Constants and static helpers related to the HTTP authentication.
*
*
*
* @since 4.0
*/
@ -57,8 +57,8 @@ public final class AUTH {
* The proxy authenticate response header.
*/
public static final String PROXY_AUTH_RESP = "Proxy-Authorization";
private AUTH() {
}
}

View File

@ -30,7 +30,7 @@ import org.apache.http.Header;
import org.apache.http.HttpRequest;
/**
* This interface represents an abstract challenge-response oriented
* This interface represents an abstract challenge-response oriented
* authentication scheme.
* <p>
* An authentication scheme should be able to support the following
@ -43,15 +43,15 @@ import org.apache.http.HttpRequest;
* <li>Provide the realm this authentication scheme is applicable to,
* if available
* <li>Generate authorization string for the given set of credentials
* and the HTTP request in response to the authorization challenge.
* and the HTTP request in response to the authorization challenge.
* </ul>
* <p>
* Authentication schemes may be stateful involving a series of
* Authentication schemes may be stateful involving a series of
* challenge-response exchanges.
* <p>
* IMPORTANT: implementations of this interface MUST also implement {@link ContextAwareAuthScheme}
* interface in order to remain API compatible with newer versions of HttpClient.
*
* interface in order to remain API compatible with newer versions of HttpClient.
*
* @since 4.0
*/
@ -59,25 +59,25 @@ public interface AuthScheme {
/**
* Processes the given challenge token. Some authentication schemes
* may involve multiple challenge-response exchanges. Such schemes must be able
* to maintain the state information when dealing with sequential challenges
*
* may involve multiple challenge-response exchanges. Such schemes must be able
* to maintain the state information when dealing with sequential challenges
*
* @param header the challenge header
*/
void processChallenge(final Header header) throws MalformedChallengeException;
/**
* Returns textual designation of the given authentication scheme.
*
*
* @return the name of the given authentication scheme
*/
String getSchemeName();
/**
* Returns authentication parameter with the given name, if available.
*
*
* @param name The name of the parameter to be returned
*
*
* @return the parameter with the given name
*/
String getParameter(final String name);
@ -86,45 +86,45 @@ public interface AuthScheme {
* Returns authentication realm. If the concept of an authentication
* realm is not applicable to the given authentication scheme, returns
* <code>null</code>.
*
*
* @return the authentication realm
*/
String getRealm();
/**
* Tests if the authentication scheme is provides authorization on a per
* connection basis instead of usual per request basis
*
*
* @return <tt>true</tt> if the scheme is connection based, <tt>false</tt>
* if the scheme is request based.
*/
boolean isConnectionBased();
boolean isConnectionBased();
/**
* Authentication process may involve a series of challenge-response exchanges.
* This method tests if the authorization process has been completed, either
* successfully or unsuccessfully, that is, all the required authorization
* successfully or unsuccessfully, that is, all the required authorization
* challenges have been processed in their entirety.
*
* @return <tt>true</tt> if the authentication process has been completed,
*
* @return <tt>true</tt> if the authentication process has been completed,
* <tt>false</tt> otherwise.
*/
boolean isComplete();
boolean isComplete();
/**
* Produces an authorization string for the given set of {@link Credentials}.
*
*
* @param credentials The set of credentials to be used for athentication
* @param request The request being authenticated
* @throws AuthenticationException if authorization string cannot
* @throws AuthenticationException if authorization string cannot
* be generated due to an authentication failure
*
*
* @return the authorization string
*
*
* @deprecated Use {@link ContextAwareAuthScheme#authenticate(Credentials, HttpRequest, org.apache.http.protocol.HttpContext)}
*/
@Deprecated
Header authenticate(Credentials credentials, HttpRequest request)
Header authenticate(Credentials credentials, HttpRequest request)
throws AuthenticationException;
}

View File

@ -30,7 +30,7 @@ package org.apache.http.auth;
import org.apache.http.params.HttpParams;
/**
* Factory for {@link AuthScheme} implementations.
* Factory for {@link AuthScheme} implementations.
*
* @since 4.0
*/
@ -38,9 +38,9 @@ public interface AuthSchemeFactory {
/**
* Creates an instance of {@link AuthScheme} using given HTTP parameters.
*
*
* @param params HTTP parameters.
*
*
* @return auth scheme.
*/
AuthScheme newInstance(HttpParams params);

View File

@ -39,36 +39,36 @@ import org.apache.http.params.HttpParams;
/**
* Authentication scheme registry that can be used to obtain the corresponding
* authentication scheme implementation for a given type of authorization challenge.
*
*
* @since 4.0
*/
@ThreadSafe
public final class AuthSchemeRegistry {
private final ConcurrentHashMap<String,AuthSchemeFactory> registeredSchemes;
public AuthSchemeRegistry() {
super();
this.registeredSchemes = new ConcurrentHashMap<String,AuthSchemeFactory>();
}
/**
* Registers a {@link AuthSchemeFactory} with the given identifier. If a factory with the
* given name already exists it will be overridden. This name is the same one used to
* Registers a {@link AuthSchemeFactory} with the given identifier. If a factory with the
* given name already exists it will be overridden. This name is the same one used to
* retrieve the {@link AuthScheme authentication scheme} from {@link #getAuthScheme}.
*
*
* <p>
* Please note that custom authentication preferences, if used, need to be updated accordingly
* Please note that custom authentication preferences, if used, need to be updated accordingly
* for the new {@link AuthScheme authentication scheme} to take effect.
* </p>
*
* </p>
*
* @param name the identifier for this scheme
* @param factory the {@link AuthSchemeFactory} class to register
*
*
* @see #getAuthScheme
*/
public void register(
final String name,
final String name,
final AuthSchemeFactory factory) {
if (name == null) {
throw new IllegalArgumentException("Name may not be null");
@ -80,9 +80,9 @@ public final class AuthSchemeRegistry {
}
/**
* Unregisters the class implementing an {@link AuthScheme authentication scheme} with
* Unregisters the class implementing an {@link AuthScheme authentication scheme} with
* the given name.
*
*
* @param name the identifier of the class to unregister
*/
public void unregister(final String name) {
@ -94,16 +94,16 @@ public final class AuthSchemeRegistry {
/**
* Gets the {@link AuthScheme authentication scheme} with the given name.
*
*
* @param name the {@link AuthScheme authentication scheme} identifier
* @param params the {@link HttpParams HTTP parameters} for the authentication
* scheme.
*
* scheme.
*
* @return {@link AuthScheme authentication scheme}
*
*
* @throws IllegalStateException if a scheme with the given name cannot be found
*/
public AuthScheme getAuthScheme(final String name, final HttpParams params)
public AuthScheme getAuthScheme(final String name, final HttpParams params)
throws IllegalStateException {
if (name == null) {
@ -115,22 +115,22 @@ public final class AuthSchemeRegistry {
} else {
throw new IllegalStateException("Unsupported authentication scheme: " + name);
}
}
}
/**
* Obtains a list containing the names of all registered {@link AuthScheme authentication
* Obtains a list containing the names of all registered {@link AuthScheme authentication
* schemes}
*
*
* @return list of registered scheme names
*/
public List<String> getSchemeNames() {
return new ArrayList<String>(registeredSchemes.keySet());
}
return new ArrayList<String>(registeredSchemes.keySet());
}
/**
* Populates the internal collection of registered {@link AuthScheme authentication schemes}
* Populates the internal collection of registered {@link AuthScheme authentication schemes}
* with the content of the map passed as a parameter.
*
*
* @param map authentication schemes
*/
public void setItems(final Map<String, AuthSchemeFactory> map) {
@ -140,5 +140,5 @@ public final class AuthSchemeRegistry {
registeredSchemes.clear();
registeredSchemes.putAll(map);
}
}

View File

@ -32,75 +32,75 @@ import org.apache.http.annotation.Immutable;
import org.apache.http.util.LangUtils;
/**
/**
* The class represents an authentication scope consisting of a host name,
* a port number, a realm name and an authentication scheme name which
* a port number, a realm name and an authentication scheme name which
* {@link Credentials Credentials} apply to.
*
*
*
*
* @since 4.0
*/
@Immutable
public class AuthScope {
/**
* The <tt>null</tt> value represents any host. In the future versions of
* HttpClient the use of this parameter will be discontinued.
/**
* The <tt>null</tt> value represents any host. In the future versions of
* HttpClient the use of this parameter will be discontinued.
*/
public static final String ANY_HOST = null;
/**
* The <tt>-1</tt> value represents any port.
/**
* The <tt>-1</tt> value represents any port.
*/
public static final int ANY_PORT = -1;
/**
* The <tt>null</tt> value represents any realm.
/**
* The <tt>null</tt> value represents any realm.
*/
public static final String ANY_REALM = null;
/**
* The <tt>null</tt> value represents any authentication scheme.
/**
* The <tt>null</tt> value represents any authentication scheme.
*/
public static final String ANY_SCHEME = null;
/**
* Default scope matching any host, port, realm and authentication scheme.
* In the future versions of HttpClient the use of this parameter will be
* discontinued.
/**
* Default scope matching any host, port, realm and authentication scheme.
* In the future versions of HttpClient the use of this parameter will be
* discontinued.
*/
public static final AuthScope ANY = new AuthScope(ANY_HOST, ANY_PORT, ANY_REALM, ANY_SCHEME);
/** The authentication scheme the credentials apply to. */
private final String scheme;
/** The realm the credentials apply to. */
private final String realm;
/** The host the credentials apply to. */
private final String host;
/** The port the credentials apply to. */
private final int port;
/** Creates a new credentials scope for the given
* <tt>host</tt>, <tt>port</tt>, <tt>realm</tt>, and
/** Creates a new credentials scope for the given
* <tt>host</tt>, <tt>port</tt>, <tt>realm</tt>, and
* <tt>authentication scheme</tt>.
*
*
* @param host the host the credentials apply to. May be set
* to <tt>null</tt> if credenticals are applicable to
* any host.
* any host.
* @param port the port the credentials apply to. May be set
* to negative value if credenticals are applicable to
* any port.
* @param realm the realm the credentials apply to. May be set
* any port.
* @param realm the realm the credentials apply to. May be set
* to <tt>null</tt> if credenticals are applicable to
* any realm.
* @param scheme the authentication scheme the credentials apply to.
* any realm.
* @param scheme the authentication scheme the credentials apply to.
* May be set to <tt>null</tt> if credenticals are applicable to
* any authentication scheme.
* any authentication scheme.
*/
public AuthScope(final String host, int port,
public AuthScope(final String host, int port,
final String realm, final String scheme)
{
this.host = (host == null) ? ANY_HOST: host.toLowerCase(Locale.ENGLISH);
@ -108,41 +108,41 @@ public class AuthScope {
this.realm = (realm == null) ? ANY_REALM: realm;
this.scheme = (scheme == null) ? ANY_SCHEME: scheme.toUpperCase(Locale.ENGLISH);
}
/** Creates a new credentials scope for the given
/** Creates a new credentials scope for the given
* <tt>host</tt>, <tt>port</tt>, <tt>realm</tt>, and any
* authentication scheme.
*
*
* @param host the host the credentials apply to. May be set
* to <tt>null</tt> if credenticals are applicable to
* any host.
* any host.
* @param port the port the credentials apply to. May be set
* to negative value if credenticals are applicable to
* any port.
* @param realm the realm the credentials apply to. May be set
* any port.
* @param realm the realm the credentials apply to. May be set
* to <tt>null</tt> if credenticals are applicable to
* any realm.
* any realm.
*/
public AuthScope(final String host, int port, final String realm) {
this(host, port, realm, ANY_SCHEME);
}
/** Creates a new credentials scope for the given
/** Creates a new credentials scope for the given
* <tt>host</tt>, <tt>port</tt>, any realm name, and any
* authentication scheme.
*
*
* @param host the host the credentials apply to. May be set
* to <tt>null</tt> if credenticals are applicable to
* any host.
* any host.
* @param port the port the credentials apply to. May be set
* to negative value if credenticals are applicable to
* any port.
* any port.
*/
public AuthScope(final String host, int port) {
this(host, port, ANY_REALM, ANY_SCHEME);
}
/**
/**
* Creates a copy of the given credentials scope.
*/
public AuthScope(final AuthScope authscope) {
@ -155,7 +155,7 @@ public class AuthScope {
this.realm = authscope.getRealm();
this.scheme = authscope.getScheme();
}
/**
* @return the host
*/
@ -185,10 +185,10 @@ public class AuthScope {
}
/**
* Tests if the authentication scopes match.
*
* @return the match factor. Negative value signifies no match.
* Non-negative signifies a match. The greater the returned value
* Tests if the authentication scopes match.
*
* @return the match factor. Negative value signifies no match.
* Non-negative signifies a match. The greater the returned value
* the closer the match.
*/
public int match(final AuthScope that) {
@ -239,8 +239,8 @@ public class AuthScope {
return super.equals(o);
}
AuthScope that = (AuthScope) o;
return
LangUtils.equals(this.host, that.host)
return
LangUtils.equals(this.host, that.host)
&& this.port == that.port
&& LangUtils.equals(this.realm, that.realm)
&& LangUtils.equals(this.scheme, that.scheme);
@ -273,7 +273,7 @@ public class AuthScope {
}
return buffer.toString();
}
/**
* @see java.lang.Object#hashCode()
*/

View File

@ -32,7 +32,7 @@ import org.apache.http.annotation.NotThreadSafe;
/**
* This class provides detailed information about the state of the
* authentication process.
*
*
*
* @since 4.0
*/
@ -44,13 +44,13 @@ public class AuthState {
/** Actual authentication scope */
private AuthScope authScope;
/** Credentials selected for authentication */
private Credentials credentials;
/**
* Default constructor.
*
*
*/
public AuthState() {
super();
@ -68,10 +68,10 @@ public class AuthState {
public boolean isValid() {
return this.authScheme != null;
}
/**
* Assigns the given {@link AuthScheme authentication scheme}.
*
*
* @param authScheme the {@link AuthScheme authentication scheme}
*/
public void setAuthScheme(final AuthScheme authScheme) {
@ -84,27 +84,27 @@ public class AuthState {
/**
* Returns the {@link AuthScheme authentication scheme}.
*
*
* @return {@link AuthScheme authentication scheme}
*/
public AuthScheme getAuthScheme() {
return this.authScheme;
}
/**
/**
* Returns user {@link Credentials} selected for authentication if available
*
*
* @return user credentials if available, <code>null</code otherwise
*/
public Credentials getCredentials() {
return this.credentials;
}
/**
/**
* Sets user {@link Credentials} to be used for authentication
*
*
* @param credentials User credentials
*/
public void setCredentials(final Credentials credentials) {
@ -112,25 +112,25 @@ public class AuthState {
}
/**
/**
* Returns actual {@link AuthScope} if available
*
*
* @return actual authentication scope if available, <code>null</code otherwise
*/
public AuthScope getAuthScope() {
return this.authScope;
}
/**
/**
* Sets actual {@link AuthScope}.
*
*
* @param authScope Authentication scope
*/
public void setAuthScope(final AuthScope authScope) {
this.authScope = authScope;
}
@Override
public String toString() {
StringBuilder buffer = new StringBuilder();
@ -141,5 +141,5 @@ public class AuthState {
buffer.append("]");
return buffer.toString();
}
}

View File

@ -33,7 +33,7 @@ import org.apache.http.ProtocolException;
/**
* Signals a failure in authentication process
*
*
*
* @since 4.0
*/
@Immutable
@ -42,7 +42,7 @@ public class AuthenticationException extends ProtocolException {
private static final long serialVersionUID = -6794031905674764776L;
/**
* Creates a new AuthenticationException with a <tt>null</tt> detail message.
* Creates a new AuthenticationException with a <tt>null</tt> detail message.
*/
public AuthenticationException() {
super();
@ -50,7 +50,7 @@ public class AuthenticationException extends ProtocolException {
/**
* Creates a new AuthenticationException with the specified message.
*
*
* @param message the exception detail message
*/
public AuthenticationException(String message) {
@ -59,7 +59,7 @@ public class AuthenticationException extends ProtocolException {
/**
* Creates a new AuthenticationException with the specified detail message and cause.
*
*
* @param message the exception detail message
* @param cause the <tt>Throwable</tt> that caused this exception, or <tt>null</tt>
* if the cause is unavailable, unknown, or not a <tt>Throwable</tt>

View File

@ -35,7 +35,7 @@ import org.apache.http.util.LangUtils;
/**
* Basic user principal used for HTTP authentication
*
*
* @since 4.0
*/
@Immutable
@ -44,7 +44,7 @@ public final class BasicUserPrincipal implements Principal, Serializable {
private static final long serialVersionUID = -2266305184969850467L;
private final String username;
public BasicUserPrincipal(final String username) {
super();
if (username == null) {
@ -52,7 +52,7 @@ public final class BasicUserPrincipal implements Principal, Serializable {
}
this.username = username;
}
public String getName() {
return this.username;
}

View File

@ -32,31 +32,31 @@ import org.apache.http.protocol.HttpContext;
/**
* This interface represents an extended authentication scheme
* that requires access to {@link HttpContext} in order to
* that requires access to {@link HttpContext} in order to
* generate an authorization string.
*
* TODO: Fix AuthScheme interface in the next major version
*
*
* @since 4.1
*/
public interface ContextAwareAuthScheme extends AuthScheme {
/**
* Produces an authorization string for the given set of
* Produces an authorization string for the given set of
* {@link Credentials}.
*
*
* @param credentials The set of credentials to be used for athentication
* @param request The request being authenticated
* @param context HTTP context
* @throws AuthenticationException if authorization string cannot
* @throws AuthenticationException if authorization string cannot
* be generated due to an authentication failure
*
*
* @return the authorization string
*/
Header authenticate(
Credentials credentials,
Credentials credentials,
HttpRequest request,
HttpContext context) throws AuthenticationException;
}

View File

@ -29,7 +29,7 @@ package org.apache.http.auth;
import java.security.Principal;
/**
* This interface represents a set of credentials consisting of a security
* This interface represents a set of credentials consisting of a security
* principal and a secret (password) that can be used to establish user
* identity
*
@ -40,5 +40,5 @@ public interface Credentials {
Principal getUserPrincipal();
String getPassword();
}

View File

@ -29,10 +29,10 @@ package org.apache.http.auth;
import org.apache.http.annotation.Immutable;
/**
* Authentication credentials required to respond to a authentication
* Authentication credentials required to respond to a authentication
* challenge are invalid
*
*
*
* @since 4.0
*/
@Immutable
@ -41,7 +41,7 @@ public class InvalidCredentialsException extends AuthenticationException {
private static final long serialVersionUID = -4834003835215460648L;
/**
* Creates a new InvalidCredentialsException with a <tt>null</tt> detail message.
* Creates a new InvalidCredentialsException with a <tt>null</tt> detail message.
*/
public InvalidCredentialsException() {
super();
@ -49,7 +49,7 @@ public class InvalidCredentialsException extends AuthenticationException {
/**
* Creates a new InvalidCredentialsException with the specified message.
*
*
* @param message the exception detail message
*/
public InvalidCredentialsException(String message) {
@ -58,7 +58,7 @@ public class InvalidCredentialsException extends AuthenticationException {
/**
* Creates a new InvalidCredentialsException with the specified detail message and cause.
*
*
* @param message the exception detail message
* @param cause the <tt>Throwable</tt> that caused this exception, or <tt>null</tt>
* if the cause is unavailable, unknown, or not a <tt>Throwable</tt>

View File

@ -31,10 +31,10 @@ import org.apache.http.annotation.Immutable;
import org.apache.http.ProtocolException;
/**
* Signals that authentication challenge is in some way invalid or
* Signals that authentication challenge is in some way invalid or
* illegal in the given context
*
*
*
* @since 4.0
*/
@Immutable
@ -43,7 +43,7 @@ public class MalformedChallengeException extends ProtocolException {
private static final long serialVersionUID = 814586927989932284L;
/**
* Creates a new MalformedChallengeException with a <tt>null</tt> detail message.
* Creates a new MalformedChallengeException with a <tt>null</tt> detail message.
*/
public MalformedChallengeException() {
super();
@ -51,7 +51,7 @@ public class MalformedChallengeException extends ProtocolException {
/**
* Creates a new MalformedChallengeException with the specified message.
*
*
* @param message the exception detail message
*/
public MalformedChallengeException(String message) {
@ -60,7 +60,7 @@ public class MalformedChallengeException extends ProtocolException {
/**
* Creates a new MalformedChallengeException with the specified detail message and cause.
*
*
* @param message the exception detail message
* @param cause the <tt>Throwable</tt> that caused this exception, or <tt>null</tt>
* if the cause is unavailable, unknown, or not a <tt>Throwable</tt>

View File

@ -34,10 +34,10 @@ import org.apache.http.annotation.Immutable;
import org.apache.http.util.LangUtils;
/**
* {@link Credentials} implementation for Microsoft Windows platforms that includes
/**
* {@link Credentials} implementation for Microsoft Windows platforms that includes
* Windows specific attributes such as name of the domain the user belongs to.
*
*
* @since 4.0
*/
@Immutable
@ -50,12 +50,12 @@ public class NTCredentials implements Credentials, Serializable {
/** Password */
private final String password;
/** The host the authentication request is originating from. */
private final String workstation;
/**
* The constructor with the fully qualified username and password combined
* The constructor with the fully qualified username and password combined
* string argument.
*
* @param usernamePassword the domain/username:password formed string
@ -63,7 +63,7 @@ public class NTCredentials implements Credentials, Serializable {
public NTCredentials(String usernamePassword) {
super();
if (usernamePassword == null) {
throw new IllegalArgumentException("Username:password string may not be null");
throw new IllegalArgumentException("Username:password string may not be null");
}
String username;
int atColon = usernamePassword.indexOf(':');
@ -92,13 +92,13 @@ public class NTCredentials implements Credentials, Serializable {
* @param userName The user name. This should not include the domain to authenticate with.
* For example: "user" is correct whereas "DOMAIN\\user" is not.
* @param password The password.
* @param workstation The workstation the authentication request is originating from.
* @param workstation The workstation the authentication request is originating from.
* Essentially, the computer name for this machine.
* @param domain The domain to authenticate within.
*/
public NTCredentials(
final String userName,
final String password,
final String userName,
final String password,
final String workstation,
final String domain) {
super();
@ -117,11 +117,11 @@ public class NTCredentials implements Credentials, Serializable {
public Principal getUserPrincipal() {
return this.principal;
}
public String getUserName() {
return this.principal.getUsername();
}
public String getPassword() {
return this.password;
}
@ -143,7 +143,7 @@ public class NTCredentials implements Credentials, Serializable {
public String getWorkstation() {
return this.workstation;
}
@Override
public int hashCode() {
int hash = LangUtils.HASH_SEED;

View File

@ -34,16 +34,16 @@ import org.apache.http.annotation.Immutable;
import org.apache.http.util.LangUtils;
/**
/**
* Microsoft Windows specific user principal implementation.
*
*
* @since 4.0
*/
@Immutable
public class NTUserPrincipal implements Principal, Serializable {
private static final long serialVersionUID = -6870169797924406894L;
private final String username;
private final String domain;
private final String ntname;
@ -75,7 +75,7 @@ public class NTUserPrincipal implements Principal, Serializable {
public String getName() {
return this.ntname;
}
public String getDomain() {
return this.domain;
}

View File

@ -34,7 +34,7 @@ import org.apache.http.annotation.Immutable;
import org.apache.http.util.LangUtils;
/**
* Simple {@link Credentials} implementation based on a user name / password
* Simple {@link Credentials} implementation based on a user name / password
* pair.
*
* @since 4.0
@ -46,7 +46,7 @@ public class UsernamePasswordCredentials implements Credentials, Serializable {
private final BasicUserPrincipal principal;
private final String password;
/**
* The constructor with the username and password combined string argument.
*
@ -56,7 +56,7 @@ public class UsernamePasswordCredentials implements Credentials, Serializable {
public UsernamePasswordCredentials(String usernamePassword) {
super();
if (usernamePassword == null) {
throw new IllegalArgumentException("Username:password string may not be null");
throw new IllegalArgumentException("Username:password string may not be null");
}
int atColon = usernamePassword.indexOf(':');
if (atColon >= 0) {
@ -78,7 +78,7 @@ public class UsernamePasswordCredentials implements Credentials, Serializable {
public UsernamePasswordCredentials(String userName, String password) {
super();
if (userName == null) {
throw new IllegalArgumentException("Username may not be null");
throw new IllegalArgumentException("Username may not be null");
}
this.principal = new BasicUserPrincipal(userName);
this.password = password;

View File

@ -31,39 +31,39 @@ import org.apache.http.auth.AuthScheme;
/**
* Parameter names for HTTP authentication classes.
*
*
* @since 4.0
*/
public interface AuthPNames {
/**
* Defines the charset to be used when encoding
* Defines the charset to be used when encoding
* {@link org.apache.http.auth.Credentials}.
* <p>
* This parameter expects a value of type {@link String}.
*/
public static final String CREDENTIAL_CHARSET = "http.auth.credential-charset";
public static final String CREDENTIAL_CHARSET = "http.auth.credential-charset";
/**
* Defines the order of preference for supported {@link AuthScheme}s when
* authenticating with the target host.
* Defines the order of preference for supported {@link AuthScheme}s when
* authenticating with the target host.
* <p>
* This parameter expects a value of type {@link java.util.Collection}. The
* collection is expected to contain {@link String} instances representing
* a name of an authentication scheme as returned by
* {@link AuthScheme#getSchemeName()}.
* This parameter expects a value of type {@link java.util.Collection}. The
* collection is expected to contain {@link String} instances representing
* a name of an authentication scheme as returned by
* {@link AuthScheme#getSchemeName()}.
*/
public static final String TARGET_AUTH_PREF = "http.auth.target-scheme-pref";
public static final String TARGET_AUTH_PREF = "http.auth.target-scheme-pref";
/**
* Defines the order of preference for supported {@link AuthScheme}s when
* authenticating with the proxy host.
* Defines the order of preference for supported {@link AuthScheme}s when
* authenticating with the proxy host.
* <p>
* This parameter expects a value of type {@link java.util.Collection}. The
* collection is expected to contain {@link String} instances representing
* a name of an authentication scheme as returned by
* {@link AuthScheme#getSchemeName()}.
* This parameter expects a value of type {@link java.util.Collection}. The
* collection is expected to contain {@link String} instances representing
* a name of an authentication scheme as returned by
* {@link AuthScheme#getSchemeName()}.
*/
public static final String PROXY_AUTH_PREF = "http.auth.proxy-scheme-pref";
public static final String PROXY_AUTH_PREF = "http.auth.proxy-scheme-pref";
}

View File

@ -31,8 +31,8 @@ import org.apache.http.params.HttpAbstractParamBean;
import org.apache.http.params.HttpParams;
/**
* This is a Java Bean class that can be used to wrap an instance of
* {@link HttpParams} and manipulate HTTP authentication parameters
* This is a Java Bean class that can be used to wrap an instance of
* {@link HttpParams} and manipulate HTTP authentication parameters
* using Java Beans conventions.
*
* @since 4.0
@ -46,5 +46,5 @@ public class AuthParamBean extends HttpAbstractParamBean {
public void setCredentialCharset (final String charset) {
AuthParams.setCredentialCharset(params, charset);
}
}

View File

@ -33,9 +33,9 @@ import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HTTP;
/**
* An adaptor for manipulating HTTP authentication parameters
* An adaptor for manipulating HTTP authentication parameters
* in {@link HttpParams}.
*
*
* @since 4.0
*
* @see AuthPNames
@ -48,10 +48,10 @@ public final class AuthParams {
}
/**
* Obtains the charset for encoding
* Obtains the charset for encoding
* {@link org.apache.http.auth.Credentials}.If not configured,
* {@link HTTP#DEFAULT_PROTOCOL_CHARSET}is used instead.
*
*
* @return The charset
*/
public static String getCredentialCharset(final HttpParams params) {
@ -70,7 +70,7 @@ public final class AuthParams {
/**
* Sets the charset to be used when encoding
* {@link org.apache.http.auth.Credentials}.
*
*
* @param charset The charset
*/
public static void setCredentialCharset(final HttpParams params, final String charset) {

View File

@ -30,10 +30,10 @@ import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScheme;
/**
* Abstract {@link AuthScheme} cache. Initialized {@link AuthScheme} objects
* from this cache can be used to preemptively authenticate against known
* Abstract {@link AuthScheme} cache. Initialized {@link AuthScheme} objects
* from this cache can be used to preemptively authenticate against known
* hosts.
*
*
* @since 4.1
*/
public interface AuthCache {
@ -45,5 +45,5 @@ public interface AuthCache {
void remove(HttpHost host);
void clear();
}

View File

@ -38,12 +38,12 @@ import org.apache.http.protocol.HttpContext;
/**
/**
* A handler for determining if an HTTP response represents an authentication
* challenge that was sent back to the client as a result of authentication
* A handler for determining if an HTTP response represents an authentication
* challenge that was sent back to the client as a result of authentication
* failure.
* <p>
* Implementations of this interface must be thread-safe. Access to shared
* data must be synchronized as methods of this interface may be executed
* data must be synchronized as methods of this interface may be executed
* from multiple threads.
*
* @since 4.0
@ -51,8 +51,8 @@ import org.apache.http.protocol.HttpContext;
public interface AuthenticationHandler {
/**
* Determines if the given HTTP response response represents
* an authentication challenge that was sent back as a result
* Determines if the given HTTP response response represents
* an authentication challenge that was sent back as a result
* of authentication failure
* @param response HTTP response.
* @param context HTTP context.
@ -60,25 +60,25 @@ public interface AuthenticationHandler {
* <code>false</code> otherwise.
*/
boolean isAuthenticationRequested(
HttpResponse response,
HttpResponse response,
HttpContext context);
/**
* Extracts from the given HTTP response a collection of authentication
* Extracts from the given HTTP response a collection of authentication
* challenges, each of which represents an authentication scheme supported
* by the authentication host.
*
* by the authentication host.
*
* @param response HTTP response.
* @param context HTTP context.
* @return a collection of challenges keyed by names of corresponding
* authentication schemes.
* @throws MalformedChallengeException if one of the authentication
* @return a collection of challenges keyed by names of corresponding
* authentication schemes.
* @throws MalformedChallengeException if one of the authentication
* challenges is not valid or malformed.
*/
Map<String, Header> getChallenges(
HttpResponse response,
HttpResponse response,
HttpContext context) throws MalformedChallengeException;
/**
* Selects one authentication challenge out of all available and
* creates and generates {@link AuthScheme} instance capable of
@ -91,8 +91,8 @@ public interface AuthenticationHandler {
* could not be selected.
*/
AuthScheme selectScheme(
Map<String, Header> challenges,
HttpResponse response,
Map<String, Header> challenges,
HttpResponse response,
HttpContext context) throws AuthenticationException;
}

View File

@ -30,8 +30,8 @@ import org.apache.http.annotation.Immutable;
/**
* Signals a circular redirect
*
*
*
*
* @since 4.0
*/
@Immutable
@ -40,7 +40,7 @@ public class CircularRedirectException extends RedirectException {
private static final long serialVersionUID = 6830063487001091803L;
/**
* Creates a new CircularRedirectException with a <tt>null</tt> detail message.
* Creates a new CircularRedirectException with a <tt>null</tt> detail message.
*/
public CircularRedirectException() {
super();
@ -48,7 +48,7 @@ public class CircularRedirectException extends RedirectException {
/**
* Creates a new CircularRedirectException with the specified detail message.
*
*
* @param message The exception detail message
*/
public CircularRedirectException(String message) {
@ -57,7 +57,7 @@ public class CircularRedirectException extends RedirectException {
/**
* Creates a new CircularRedirectException with the specified detail message and cause.
*
*
* @param message the exception detail message
* @param cause the <tt>Throwable</tt> that caused this exception, or <tt>null</tt>
* if the cause is unavailable, unknown, or not a <tt>Throwable</tt>

View File

@ -37,7 +37,7 @@ import org.apache.http.annotation.Immutable;
*/
@Immutable
public class ClientProtocolException extends IOException {
private static final long serialVersionUID = -5596590843227115865L;
public ClientProtocolException() {
@ -47,15 +47,15 @@ public class ClientProtocolException extends IOException {
public ClientProtocolException(String s) {
super(s);
}
public ClientProtocolException(Throwable cause) {
initCause(cause);
}
public ClientProtocolException(String message, Throwable cause) {
super(message);
initCause(cause);
}
}

View File

@ -34,31 +34,31 @@ import org.apache.http.cookie.Cookie;
/**
* This interface represents an abstract store for {@link Cookie}
* objects.
*
*
* @since 4.0
*/
public interface CookieStore {
/**
* Adds an {@link Cookie}, replacing any existing equivalent cookies.
* If the given cookie has already expired it will not be added, but existing
* If the given cookie has already expired it will not be added, but existing
* values will still be removed.
*
*
* @param cookie the {@link Cookie cookie} to be added
*/
void addCookie(Cookie cookie);
/**
* Returns all cookies contained in this store.
*
*
* @return all cookies
*/
List<Cookie> getCookies();
/**
* Removes all of {@link Cookie}s in this store that have expired by
* the specified {@link java.util.Date}.
*
* Removes all of {@link Cookie}s in this store that have expired by
* the specified {@link java.util.Date}.
*
* @return true if any cookies were purged.
*/
boolean clearExpired(Date date);
@ -67,5 +67,5 @@ public interface CookieStore {
* Clears all cookies.
*/
void clear();
}

View File

@ -30,25 +30,25 @@ import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
/**
* Abstract credentials provider that maintains a collection of user
* Abstract credentials provider that maintains a collection of user
* credentials.
* <p>
* Implementations of this interface must be thread-safe. Access to shared
* data must be synchronized as methods of this interface may be executed
* data must be synchronized as methods of this interface may be executed
* from multiple threads.
*
*
* @since 4.0
*/
public interface CredentialsProvider {
/**
* Sets the {@link Credentials credentials} for the given authentication
/**
* Sets the {@link Credentials credentials} for the given authentication
* scope. Any previous credentials for the given scope will be overwritten.
*
*
* @param authscope the {@link AuthScope authentication scope}
* @param credentials the authentication {@link Credentials credentials}
* @param credentials the authentication {@link Credentials credentials}
* for the given scope.
*
*
* @see #getCredentials(AuthScope)
*/
void setCredentials(AuthScope authscope, Credentials credentials);
@ -57,8 +57,8 @@ public interface CredentialsProvider {
* Get the {@link Credentials credentials} for the given authentication scope.
*
* @param authscope the {@link AuthScope authentication scope}
* @return the credentials
*
* @return the credentials
*
* @see #setCredentials(AuthScope, Credentials)
*/
Credentials getCredentials(AuthScope authscope);
@ -67,5 +67,5 @@ public interface CredentialsProvider {
* Clears all credentials.
*/
void clear();
}

View File

@ -38,65 +38,65 @@ import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;
/**
* This interface represents only the most basic contract for HTTP request
* execution. It imposes no restrictions or particular details on the request
* execution process and leaves the specifics of state management,
* 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.
* This interface represents only the most basic contract for HTTP request
* execution. It imposes no restrictions or particular details on the request
* execution process and leaves the specifics of state management,
* 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>
* HttpClient httpclient = new DefaultHttpClient();
*
*
* // Prepare a request object
* HttpGet httpget = new HttpGet("http://www.apache.org/");
*
* 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
* // 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,
*
* // When HttpClient instance is no longer needed,
* // shut down the connection manager to ensure
* // immediate deallocation of all system resources
* httpclient.getConnectionManager().shutdown();
* httpclient.getConnectionManager().shutdown();
* }
* </PRE>
*
@ -212,7 +212,7 @@ public interface HttpClient {
* @throws ClientProtocolException in case of an http protocol error
*/
<T> T execute(
HttpUriRequest request,
HttpUriRequest request,
ResponseHandler<? extends T> responseHandler)
throws IOException, ClientProtocolException;
@ -228,13 +228,13 @@ public interface HttpClient {
* @throws ClientProtocolException in case of an http protocol error
*/
<T> T execute(
HttpUriRequest request,
HttpUriRequest request,
ResponseHandler<? extends T> responseHandler,
HttpContext context)
throws IOException, ClientProtocolException;
/**
* Executes a request to the target using the default context and
* Executes a request to the target using the default context and
* processes the response using the given response handler.
*
* @param target the target host for the request.
@ -249,13 +249,13 @@ public interface HttpClient {
* @throws ClientProtocolException in case of an http protocol error
*/
<T> T execute(
HttpHost target,
HttpHost target,
HttpRequest request,
ResponseHandler<? extends T> responseHandler)
throws IOException, ClientProtocolException;
/**
* Executes a request to the target using the given context and
* Executes a request to the target using the given context and
* processes the response using the given response handler.
*
* @param target the target host for the request.
@ -272,10 +272,10 @@ public interface HttpClient {
* @throws ClientProtocolException in case of an http protocol error
*/
<T> T execute(
HttpHost target,
HttpHost target,
HttpRequest request,
ResponseHandler<? extends T> responseHandler,
ResponseHandler<? extends T> responseHandler,
HttpContext context)
throws IOException, ClientProtocolException;
}

View File

@ -32,11 +32,11 @@ import java.io.IOException;
import org.apache.http.protocol.HttpContext;
/**
* A handler for determining if an HttpRequest should be retried after a
* A handler for determining if an HttpRequest should be retried after a
* recoverable exception during execution.
* <p>
* Implementations of this interface must be thread-safe. Access to shared
* data must be synchronized as methods of this interface may be executed
* data must be synchronized as methods of this interface may be executed
* from multiple threads.
*
* @since 4.0
@ -46,12 +46,12 @@ public interface HttpRequestRetryHandler {
/**
* Determines if a method should be retried after an IOException
* occurs during execution.
*
*
* @param exception the exception that occurred
* @param executionCount the number of times this method has been
* @param executionCount the number of times this method has been
* unsuccessfully executed
* @param context the context for the request execution
*
*
* @return <code>true</code> if the method should be retried, <code>false</code>
* otherwise
*/

View File

@ -35,11 +35,11 @@ import org.apache.http.annotation.Immutable;
*/
@Immutable
public class HttpResponseException extends ClientProtocolException {
private static final long serialVersionUID = -7186627969477257933L;
private final int statusCode;
public HttpResponseException(int statusCode, final String s) {
super(s);
this.statusCode = statusCode;
@ -48,5 +48,5 @@ public class HttpResponseException extends ClientProtocolException {
public int getStatusCode() {
return this.statusCode;
}
}

View File

@ -31,10 +31,10 @@ import org.apache.http.annotation.Immutable;
import org.apache.http.ProtocolException;
/**
* Signals failure to retry the request due to non-repeatable request
* Signals failure to retry the request due to non-repeatable request
* entity.
*
*
*
*
* @since 4.0
*/
@Immutable
@ -43,7 +43,7 @@ public class NonRepeatableRequestException extends ProtocolException {
private static final long serialVersionUID = 82685265288806048L;
/**
* Creates a new NonRepeatableEntityException with a <tt>null</tt> detail message.
* Creates a new NonRepeatableEntityException with a <tt>null</tt> detail message.
*/
public NonRepeatableRequestException() {
super();
@ -51,7 +51,7 @@ public class NonRepeatableRequestException extends ProtocolException {
/**
* Creates a new NonRepeatableEntityException with the specified detail message.
*
*
* @param message The exception detail message
*/
public NonRepeatableRequestException(String message) {
@ -60,14 +60,14 @@ public class NonRepeatableRequestException extends ProtocolException {
/**
* Creates a new NonRepeatableEntityException with the specified detail message.
*
*
* @param message The exception detail message
* @param cause the cause
*/
public NonRepeatableRequestException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@ -32,8 +32,8 @@ import org.apache.http.ProtocolException;
/**
* Signals violation of HTTP specification caused by an invalid redirect
*
*
*
*
* @since 4.0
*/
@Immutable
@ -42,7 +42,7 @@ public class RedirectException extends ProtocolException {
private static final long serialVersionUID = 4418824536372559326L;
/**
* Creates a new RedirectException with a <tt>null</tt> detail message.
* Creates a new RedirectException with a <tt>null</tt> detail message.
*/
public RedirectException() {
super();
@ -50,7 +50,7 @@ public class RedirectException extends ProtocolException {
/**
* Creates a new RedirectException with the specified detail message.
*
*
* @param message The exception detail message
*/
public RedirectException(String message) {
@ -59,7 +59,7 @@ public class RedirectException extends ProtocolException {
/**
* Creates a new RedirectException with the specified detail message and cause.
*
*
* @param message the exception detail message
* @param cause the <tt>Throwable</tt> that caused this exception, or <tt>null</tt>
* if the cause is unavailable, unknown, or not a <tt>Throwable</tt>

View File

@ -34,16 +34,16 @@ import org.apache.http.ProtocolException;
import org.apache.http.protocol.HttpContext;
/**
* A handler for determining if an HTTP request should be redirected to
* A handler for determining if an HTTP request should be redirected to
* a new location in response to an HTTP response received from the target
* server.
* <p>
* Implementations of this interface must be thread-safe. Access to shared
* data must be synchronized as methods of this interface may be executed
* data must be synchronized as methods of this interface may be executed
* from multiple threads.
*
* @since 4.0
*
*
* @deprecated use {@link RedirectStrategy}
*/
@Deprecated
@ -52,24 +52,24 @@ public interface RedirectHandler {
/**
* Determines if a request should be redirected to a new location
* given the response from the target server.
*
*
* @param response the response received from the target server
* @param context the context for the request execution
*
*
* @return <code>true</code> if the request should be redirected, <code>false</code>
* otherwise
*/
boolean isRedirectRequested(HttpResponse response, HttpContext context);
/**
* Determines the location request is expected to be redirected to
* Determines the location request is expected to be redirected to
* given the response from the target server and the current request
* execution context.
*
*
* @param response the response received from the target server
* @param context the context for the request execution
*
* @return redirect URI
*
* @return redirect URI
*/
URI getLocationURI(HttpResponse response, HttpContext context)
throws ProtocolException;

View File

@ -34,12 +34,12 @@ import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.protocol.HttpContext;
/**
* A strategy for determining if an HTTP request should be redirected to
* A strategy for determining if an HTTP request should be redirected to
* a new location in response to an HTTP response received from the target
* server.
* <p>
* Implementations of this interface must be thread-safe. Access to shared
* data must be synchronized as methods of this interface may be executed
* data must be synchronized as methods of this interface may be executed
* from multiple threads.
*
* @since 4.1
@ -49,33 +49,33 @@ public interface RedirectStrategy {
/**
* Determines if a request should be redirected to a new location
* given the response from the target server.
*
*
* @param request the executed request
* @param response the response received from the target server
* @param context the context for the request execution
*
*
* @return <code>true</code> if the request should be redirected, <code>false</code>
* otherwise
*/
boolean isRedirected(
HttpRequest request,
HttpResponse response,
HttpResponse response,
HttpContext context) throws ProtocolException;
/**
* Determines the redirect location given the response from the target
* server and the current request execution context and generates a new
* Determines the redirect location given the response from the target
* server and the current request execution context and generates a new
* request to be sent to the location.
*
*
* @param request the executed request
* @param response the response received from the target server
* @param context the context for the request execution
*
* @return redirected request
*
* @return redirected request
*/
HttpUriRequest getRedirect(
HttpRequest request,
HttpResponse response,
HttpResponse response,
HttpContext context) throws ProtocolException;
}

View File

@ -31,10 +31,10 @@ import java.io.IOException;
import org.apache.http.HttpResponse;
/**
* Handler that encapsulates the process of generating a response object
* Handler that encapsulates the process of generating a response object
* from a {@link HttpResponse}.
*
*
*
*
* @since 4.0
*/
public interface ResponseHandler<T> {
@ -42,13 +42,13 @@ public interface ResponseHandler<T> {
/**
* Processes an {@link HttpResponse} and returns some value
* corresponding to that response.
*
*
* @param response The response to process
* @return A value determined by the response
*
*
* @throws ClientProtocolException in case of an http protocol error
* @throws IOException in case of a problem or the connection was aborted
*/
T handleResponse(HttpResponse response) throws ClientProtocolException, IOException;
}

View File

@ -30,27 +30,27 @@ package org.apache.http.client;
import org.apache.http.protocol.HttpContext;
/**
* A handler for determining if the given execution context is user specific
* or not. The token object returned by this handler is expected to uniquely
* identify the current user if the context is user specific or to be
* <code>null</code> if the context does not contain any resources or details
* A handler for determining if the given execution context is user specific
* or not. The token object returned by this handler is expected to uniquely
* identify the current user if the context is user specific or to be
* <code>null</code> if the context does not contain any resources or details
* specific to the current user.
* <p/>
* The user token will be used to ensure that user specific resources will not
* be shared with or reused by other users.
*
*
* @since 4.0
*/
public interface UserTokenHandler {
/**
* The token object returned by this method is expected to uniquely
* identify the current user if the context is user specific or to be
* The token object returned by this method is expected to uniquely
* identify the current user if the context is user specific or to be
* <code>null</code> if it is not.
*
*
* @param context the execution context
*
* @return user token that uniquely identifies the user or
*
* @return user token that uniquely identifies the user or
* <code>null</null> if the context is not user specific.
*/
Object getUserToken(HttpContext context);

View File

@ -34,7 +34,7 @@ import org.apache.http.entity.HttpEntityWrapper;
/**
* Common base class for decompressing {@link HttpEntity} implementations.
*
*
* @since 4.1
*/
abstract class DecompressingEntity extends HttpEntityWrapper {
@ -46,7 +46,7 @@ abstract class DecompressingEntity extends HttpEntityWrapper {
/**
* Creates a new {@link DecompressingEntity}.
*
*
* @param wrapped
* the non-null {@link HttpEntity} to be wrapped
*/
@ -64,9 +64,9 @@ abstract class DecompressingEntity extends HttpEntityWrapper {
}
InputStream instream = getContent();
byte[] buffer = new byte[BUFFER_SIZE];
int l;
while ((l = instream.read(buffer)) != -1) {

View File

@ -37,22 +37,22 @@ import org.apache.http.HttpEntity;
import org.apache.http.entity.HttpEntityWrapper;
/**
* {@link HttpEntityWrapper} responsible for handling deflate Content Coded responses. In RFC2616
* terms, <code>deflate</code> means a <code>zlib</code> stream as defined in RFC1950. Some server
* implementations have misinterpreted RFC2616 to mean that a <code>deflate</code> stream as
* defined in RFC1951 should be used (or maybe they did that since that's how IE behaves?). It's
* confusing that <code>deflate</code> in HTTP 1.1 means <code>zlib</code> streams rather than
* <code>deflate</code> streams. We handle both types in here, since that's what is seen on the
* {@link HttpEntityWrapper} responsible for handling deflate Content Coded responses. In RFC2616
* terms, <code>deflate</code> means a <code>zlib</code> stream as defined in RFC1950. Some server
* implementations have misinterpreted RFC2616 to mean that a <code>deflate</code> stream as
* defined in RFC1951 should be used (or maybe they did that since that's how IE behaves?). It's
* confusing that <code>deflate</code> in HTTP 1.1 means <code>zlib</code> streams rather than
* <code>deflate</code> streams. We handle both types in here, since that's what is seen on the
* internet. Moral - prefer <code>gzip</code>!
*
*
* @see GzipDecompressingEntity
*
*
* @since 4.1
*/
public class DeflateDecompressingEntity extends DecompressingEntity {
/**
* Creates a new {@link DeflateDecompressingEntity} which will wrap the specified
* Creates a new {@link DeflateDecompressingEntity} which will wrap the specified
* {@link HttpEntity}.
*
* @param entity
@ -80,17 +80,17 @@ public class DeflateDecompressingEntity extends DecompressingEntity {
*
* * DICTID is four bytes, and only present if FLG.FDICT is set.
*
* Sniff the content. Does it look like a zlib stream, with a CMF, etc? c.f. RFC1950,
* Sniff the content. Does it look like a zlib stream, with a CMF, etc? c.f. RFC1950,
* section 2.2. http://tools.ietf.org/html/rfc1950#page-4
*
* We need to see if it looks like a proper zlib stream, or whether it is just a deflate
* stream. RFC2616 calls zlib streams deflate. Confusing, isn't it? That's why some servers
* We need to see if it looks like a proper zlib stream, or whether it is just a deflate
* stream. RFC2616 calls zlib streams deflate. Confusing, isn't it? That's why some servers
* implement deflate Content-Encoding using deflate streams, rather than zlib streams.
*
* We could start looking at the bytes, but to be honest, someone else has already read
* the RFCs and implemented that for us. So we'll just use the JDK libraries and exception
* handling to do this. If that proves slow, then we could potentially change this to check
* the first byte - does it look like a CMF? What about the second byte - does it look like
* We could start looking at the bytes, but to be honest, someone else has already read
* the RFCs and implemented that for us. So we'll just use the JDK libraries and exception
* handling to do this. If that proves slow, then we could potentially change this to check
* the first byte - does it look like a CMF? What about the second byte - does it look like
* a FLG, etc.
*/
@ -135,14 +135,14 @@ public class DeflateDecompressingEntity extends DecompressingEntity {
}
/*
* We read something without a problem, so it's a valid zlib stream. Just need to reset
* We read something without a problem, so it's a valid zlib stream. Just need to reset
* and return an unused InputStream now.
*/
pushback.unread(peeked, 0, headerLength);
return new InflaterInputStream(pushback);
} catch (DataFormatException e) {
/* Presume that it's an RFC1951 deflate stream rather than RFC1950 zlib stream and try
/* Presume that it's an RFC1951 deflate stream rather than RFC1950 zlib stream and try
* again. */
pushback.unread(peeked, 0, headerLength);
return new InflaterInputStream(pushback, new Inflater(true));

View File

@ -35,13 +35,13 @@ import org.apache.http.entity.HttpEntityWrapper;
/**
* {@link HttpEntityWrapper} for handling gzip Content Coded responses.
*
*
* @since 4.1
*/
public class GzipDecompressingEntity extends DecompressingEntity {
/**
* Creates a new {@link GzipDecompressingEntity} which will wrap the specified
* Creates a new {@link GzipDecompressingEntity} which will wrap the specified
* {@link HttpEntity}.
*
* @param entity

View File

@ -44,27 +44,27 @@ import org.apache.http.protocol.HTTP;
*/
@NotThreadSafe // AbstractHttpEntity is not thread-safe
public class UrlEncodedFormEntity extends StringEntity {
/**
* Constructs a new {@link UrlEncodedFormEntity} with the list
* of parameters in the specified encoding.
*
*
* @param parameters list of name/value pairs
* @param encoding encoding the name/value pairs be encoded with
* @throws UnsupportedEncodingException if the encoding isn't supported
*/
public UrlEncodedFormEntity (
final List <? extends NameValuePair> parameters,
final List <? extends NameValuePair> parameters,
final String encoding) throws UnsupportedEncodingException {
super(URLEncodedUtils.format(parameters, encoding), encoding);
setContentType(URLEncodedUtils.CONTENT_TYPE + HTTP.CHARSET_PARAM +
setContentType(URLEncodedUtils.CONTENT_TYPE + HTTP.CHARSET_PARAM +
(encoding != null ? encoding : HTTP.DEFAULT_CONTENT_CHARSET));
}
/**
* Constructs a new {@link UrlEncodedFormEntity} with the list
* of parameters with the default encoding of {@link HTTP#DEFAULT_CONTENT_CHARSET}
*
*
* @param parameters list of name/value pairs
* @throws UnsupportedEncodingException if the default encoding isn't supported
*/
@ -72,5 +72,5 @@ public class UrlEncodedFormEntity extends StringEntity {
final List <? extends NameValuePair> parameters) throws UnsupportedEncodingException {
this(parameters, HTTP.DEFAULT_CONTENT_CHARSET);
}
}

View File

@ -37,7 +37,7 @@ import org.apache.http.conn.ManagedClientConnection;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
/**
* Interface representing an HTTP request that can be aborted by shutting
* Interface representing an HTTP request that can be aborted by shutting
* down the underlying HTTP connection.
*
*
@ -50,12 +50,12 @@ public interface AbortableHttpRequest {
* Sets the {@link ClientConnectionRequest} callback that can be
* used to abort a long-lived request for a connection.
* If the request is already aborted, throws an {@link IOException}.
*
*
* @see ClientConnectionManager
* @see ThreadSafeClientConnManager
*/
void setConnectionRequest(ClientConnectionRequest connRequest) throws IOException;
/**
* Sets the {@link ConnectionReleaseTrigger} callback that can
* be used to abort an active connection.
@ -69,7 +69,7 @@ public interface AbortableHttpRequest {
* return immediately. If the request has not started, it will abort after
* the next execution. Aborting this request will cause all subsequent
* executions with this request to fail.
*
*
* @see HttpClient#execute(HttpUriRequest)
* @see HttpClient#execute(org.apache.http.HttpHost,
* org.apache.http.HttpRequest)

View File

@ -51,7 +51,7 @@ public class HttpDelete extends HttpRequestBase {
public final static String METHOD_NAME = "DELETE";
public HttpDelete() {
super();
}
@ -62,7 +62,7 @@ public class HttpDelete extends HttpRequestBase {
}
/**
* @throws IllegalArgumentException if the uri is invalid.
* @throws IllegalArgumentException if the uri is invalid.
*/
public HttpDelete(final String uri) {
super();

View File

@ -36,17 +36,17 @@ import org.apache.http.client.utils.CloneUtils;
import org.apache.http.protocol.HTTP;
/**
* Basic implementation of an entity enclosing HTTP request
* Basic implementation of an entity enclosing HTTP request
* that can be modified
*
*
* @since 4.0
*/
@NotThreadSafe // HttpRequestBase is @NotThreadSafe
public abstract class HttpEntityEnclosingRequestBase
public abstract class HttpEntityEnclosingRequestBase
extends HttpRequestBase implements HttpEntityEnclosingRequest {
private HttpEntity entity;
public HttpEntityEnclosingRequestBase() {
super();
}
@ -58,7 +58,7 @@ public abstract class HttpEntityEnclosingRequestBase
public void setEntity(final HttpEntity entity) {
this.entity = entity;
}
public boolean expectContinue() {
Header expect = getFirstHeader(HTTP.EXPECT_DIRECTIVE);
return expect != null && HTTP.EXPECT_CONTINUE.equalsIgnoreCase(expect.getValue());
@ -66,7 +66,7 @@ public abstract class HttpEntityEnclosingRequestBase
@Override
public Object clone() throws CloneNotSupportedException {
HttpEntityEnclosingRequestBase clone =
HttpEntityEnclosingRequestBase clone =
(HttpEntityEnclosingRequestBase) super.clone();
if (this.entity != null) {
clone.entity = (HttpEntity) CloneUtils.clone(this.entity);

View File

@ -44,14 +44,14 @@ import org.apache.http.annotation.NotThreadSafe;
* process, unless that text happens to be the output of the process.
* </blockquote>
* </p>
*
*
* @since 4.0
*/
@NotThreadSafe
public class HttpGet extends HttpRequestBase {
public final static String METHOD_NAME = "GET";
public HttpGet() {
super();
}
@ -62,7 +62,7 @@ public class HttpGet extends HttpRequestBase {
}
/**
* @throws IllegalArgumentException if the uri is invalid.
* @throws IllegalArgumentException if the uri is invalid.
*/
public HttpGet(final String uri) {
super();
@ -73,5 +73,5 @@ public class HttpGet extends HttpRequestBase {
public String getMethod() {
return METHOD_NAME;
}
}

View File

@ -34,7 +34,7 @@ import org.apache.http.annotation.NotThreadSafe;
/**
* HTTP HEAD method.
* <p>
* The HTTP HEAD method is defined in section 9.4 of
* The HTTP HEAD method is defined in section 9.4 of
* <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>:
* <blockquote>
* The HEAD method is identical to GET except that the server MUST NOT
@ -54,7 +54,7 @@ import org.apache.http.annotation.NotThreadSafe;
public class HttpHead extends HttpRequestBase {
public final static String METHOD_NAME = "HEAD";
public HttpHead() {
super();
}
@ -65,7 +65,7 @@ public class HttpHead extends HttpRequestBase {
}
/**
* @throws IllegalArgumentException if the uri is invalid.
* @throws IllegalArgumentException if the uri is invalid.
*/
public HttpHead(final String uri) {
super();
@ -76,5 +76,5 @@ public class HttpHead extends HttpRequestBase {
public String getMethod() {
return METHOD_NAME;
}
}

View File

@ -41,7 +41,7 @@ import org.apache.http.HttpResponse;
/**
* HTTP OPTIONS method.
* <p>
* The HTTP OPTIONS method is defined in section 9.2 of
* The HTTP OPTIONS method is defined in section 9.2 of
* <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>:
* <blockquote>
* The OPTIONS method represents a request for information about the
@ -52,14 +52,14 @@ import org.apache.http.HttpResponse;
* or initiating a resource retrieval.
* </blockquote>
* </p>
*
*
* @since 4.0
*/
@NotThreadSafe
public class HttpOptions extends HttpRequestBase {
public final static String METHOD_NAME = "OPTIONS";
public HttpOptions() {
super();
}
@ -70,7 +70,7 @@ public class HttpOptions extends HttpRequestBase {
}
/**
* @throws IllegalArgumentException if the uri is invalid.
* @throws IllegalArgumentException if the uri is invalid.
*/
public HttpOptions(final String uri) {
super();
@ -81,12 +81,12 @@ public class HttpOptions extends HttpRequestBase {
public String getMethod() {
return METHOD_NAME;
}
public Set<String> getAllowedMethods(final HttpResponse response) {
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
HeaderIterator it = response.headerIterator("Allow");
Set<String> methods = new HashSet<String>();
while (it.hasNext()) {
@ -98,5 +98,5 @@ public class HttpOptions extends HttpRequestBase {
}
return methods;
}
}

View File

@ -34,7 +34,7 @@ import org.apache.http.annotation.NotThreadSafe;
/**
* HTTP POST method.
* <p>
* The HTTP POST method is defined in section 9.5 of
* The HTTP POST method is defined in section 9.5 of
* <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>:
* <blockquote>
* The POST method is used to request that the origin server accept the entity
@ -43,7 +43,7 @@ import org.apache.http.annotation.NotThreadSafe;
* method to cover the following functions:
* <ul>
* <li>Annotation of existing resources</li>
* <li>Posting a message to a bulletin board, newsgroup, mailing list, or
* <li>Posting a message to a bulletin board, newsgroup, mailing list, or
* similar group of articles</li>
* <li>Providing a block of data, such as the result of submitting a form,
* to a data-handling process</li>
@ -58,18 +58,18 @@ import org.apache.http.annotation.NotThreadSafe;
public class HttpPost extends HttpEntityEnclosingRequestBase {
public final static String METHOD_NAME = "POST";
public HttpPost() {
super();
}
public HttpPost(final URI uri) {
super();
setURI(uri);
}
/**
* @throws IllegalArgumentException if the uri is invalid.
* @throws IllegalArgumentException if the uri is invalid.
*/
public HttpPost(final String uri) {
super();
@ -80,5 +80,5 @@ public class HttpPost extends HttpEntityEnclosingRequestBase {
public String getMethod() {
return METHOD_NAME;
}
}

View File

@ -34,13 +34,13 @@ import org.apache.http.annotation.NotThreadSafe;
/**
* HTTP PUT method.
* <p>
* The HTTP PUT method is defined in section 9.6 of
* The HTTP PUT method is defined in section 9.6 of
* <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>:
* <blockquote>
* The PUT method requests that the enclosed entity be stored under the
* supplied Request-URI. If the Request-URI refers to an already
* existing resource, the enclosed entity SHOULD be considered as a
* modified version of the one residing on the origin server.
* modified version of the one residing on the origin server.
* </blockquote>
* </p>
*
@ -50,18 +50,18 @@ import org.apache.http.annotation.NotThreadSafe;
public class HttpPut extends HttpEntityEnclosingRequestBase {
public final static String METHOD_NAME = "PUT";
public HttpPut() {
super();
}
public HttpPut(final URI uri) {
super();
setURI(uri);
}
/**
* @throws IllegalArgumentException if the uri is invalid.
* @throws IllegalArgumentException if the uri is invalid.
*/
public HttpPut(final String uri) {
super();
@ -72,5 +72,5 @@ public class HttpPut extends HttpEntityEnclosingRequestBase {
public String getMethod() {
return METHOD_NAME;
}
}

View File

@ -52,17 +52,17 @@ import org.apache.http.params.HttpProtocolParams;
* @since 4.0
*/
@NotThreadSafe
public abstract class HttpRequestBase extends AbstractHttpMessage
public abstract class HttpRequestBase extends AbstractHttpMessage
implements HttpUriRequest, AbortableHttpRequest, Cloneable {
private Lock abortLock;
private boolean aborted;
private URI uri;
private ClientConnectionRequest connRequest;
private ConnectionReleaseTrigger releaseTrigger;
public HttpRequestBase() {
super();
this.abortLock = new ReentrantLock();
@ -75,15 +75,15 @@ public abstract class HttpRequestBase extends AbstractHttpMessage
}
/**
* Returns the original request URI.
* Returns the original request URI.
* <p>
* Please note URI remains unchanged in the course of request execution and
* Please note URI remains unchanged in the course of request execution and
* is not updated if the request is redirected to another location.
*/
public URI getURI() {
return this.uri;
}
public RequestLine getRequestLine() {
String method = getMethod();
ProtocolVersion ver = getProtocolVersion();
@ -109,7 +109,7 @@ public abstract class HttpRequestBase extends AbstractHttpMessage
if (this.aborted) {
throw new IOException("Request already aborted");
}
this.releaseTrigger = null;
this.connRequest = connRequest;
} finally {
@ -124,30 +124,30 @@ public abstract class HttpRequestBase extends AbstractHttpMessage
if (this.aborted) {
throw new IOException("Request already aborted");
}
this.connRequest = null;
this.releaseTrigger = releaseTrigger;
} finally {
this.abortLock.unlock();
}
}
public void abort() {
ClientConnectionRequest localRequest;
ConnectionReleaseTrigger localTrigger;
this.abortLock.lock();
try {
if (this.aborted) {
return;
}
}
this.aborted = true;
localRequest = connRequest;
localTrigger = releaseTrigger;
} finally {
this.abortLock.unlock();
}
}
// Trigger the callbacks outside of the lock, to prevent
// deadlocks in the scenario where the callbacks have
@ -164,7 +164,7 @@ public abstract class HttpRequestBase extends AbstractHttpMessage
}
}
}
public boolean isAborted() {
return this.aborted;
}
@ -180,5 +180,5 @@ public abstract class HttpRequestBase extends AbstractHttpMessage
clone.params = (HttpParams) CloneUtils.clone(this.params);
return clone;
}
}

View File

@ -34,7 +34,7 @@ import org.apache.http.annotation.NotThreadSafe;
/**
* HTTP TRACE method.
* <p>
* The HTTP TRACE method is defined in section 9.6 of
* The HTTP TRACE method is defined in section 9.6 of
* <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>:
* <blockquote>
* The TRACE method is used to invoke a remote, application-layer loop-
@ -46,14 +46,14 @@ import org.apache.http.annotation.NotThreadSafe;
* MUST NOT include an entity.
* </blockquote>
* </p>
*
*
* @since 4.0
*/
@NotThreadSafe
public class HttpTrace extends HttpRequestBase {
public final static String METHOD_NAME = "TRACE";
public HttpTrace() {
super();
}
@ -62,9 +62,9 @@ public class HttpTrace extends HttpRequestBase {
super();
setURI(uri);
}
/**
* @throws IllegalArgumentException if the uri is invalid.
* @throws IllegalArgumentException if the uri is invalid.
*/
public HttpTrace(final String uri) {
super();
@ -75,5 +75,5 @@ public class HttpTrace extends HttpRequestBase {
public String getMethod() {
return METHOD_NAME;
}
}

View File

@ -32,7 +32,7 @@ import java.net.URI;
import org.apache.http.HttpRequest;
/**
* Extended version of the {@link HttpRequest} interface that provides
* Extended version of the {@link HttpRequest} interface that provides
* convenience methods to access request properties such as request URI
* and method type.
*
@ -41,7 +41,7 @@ import org.apache.http.HttpRequest;
* @since 4.0
*/
public interface HttpUriRequest extends HttpRequest {
/**
* Returns the HTTP method this request uses, such as <code>GET</code>,
* <code>PUT</code>, <code>POST</code>, or other.
@ -51,32 +51,32 @@ public interface HttpUriRequest extends HttpRequest {
/**
* Returns the URI this request uses, such as
* <code>http://example.org/path/to/file</code>.
*
*
* Implementations are encouraged to return
* the URI that was initially requested.
*
*
* To find the final URI after any redirects have been processed,
* please see the section entitled
* please see the section entitled
* <a href="http://hc.apache.org/httpcomponents-client/tutorial/html/fundamentals.html#d4e205">HTTP execution context</a>
* in the
* in the
* <a href="http://hc.apache.org/httpcomponents-client/tutorial/html">HttpClient Tutorial</a>
*/
URI getURI();
/**
* Aborts execution of the request.
*
* @throws UnsupportedOperationException if the abort operation
* Aborts execution of the request.
*
* @throws UnsupportedOperationException if the abort operation
* is not supported / cannot be implemented.
*/
void abort() throws UnsupportedOperationException;
/**
* Tests if the request execution has been aborted.
*
*
* @return <code>true</code> if the request execution has been aborted,
* <code>false</code> otherwise.
*/
boolean isAborted();
}

View File

@ -32,14 +32,14 @@
<body>
The API for client-side HTTP communication.
<p/>
The usual execution flow can be demonstrated by the
The usual execution flow can be demonstrated by the
code snippet below:
<PRE>
HttpClient httpclient = new DefaultHttpClient();
// Prepare a request object
HttpGet httpget = new HttpGet("http://www.apache.org/");
HttpGet httpget = new HttpGet("http://www.apache.org/");
// Execute the request
HttpResponse response = httpclient.execute(httpget);
@ -55,31 +55,31 @@ HttpEntity entity = response.getEntity();
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
// 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();
}
}

View File

@ -30,7 +30,7 @@ package org.apache.http.client.params;
import org.apache.http.annotation.Immutable;
/**
* Standard authentication schemes supported by HttpClient.
* Standard authentication schemes supported by HttpClient.
*
* @since 4.0
*/
@ -40,30 +40,30 @@ public final class AuthPolicy {
private AuthPolicy() {
super();
}
/**
* The NTLM scheme is a proprietary Microsoft Windows Authentication
* protocol (considered to be the most secure among currently supported
* 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";
/**
/**
* Digest authentication scheme as defined in RFC2617.
*/
public static final String DIGEST = "Digest";
/**
/**
* Basic authentication scheme as defined in RFC2617 (considered inherently
* insecure, but most widely supported)
*/
public static final String BASIC = "Basic";
/**
/**
* SPNEGO/Kerberos Authentication scheme.
*
*
* @since 4.1
*/
public static final String SPNEGO = "negotiate";
}

View File

@ -28,7 +28,7 @@ package org.apache.http.client.params;
/**
* Parameter names for HTTP client parameters.
*
*
* @since 4.0
*/
public interface ClientPNames {
@ -38,16 +38,16 @@ public interface ClientPNames {
* <p>
* This parameter expects a value of type {@link String}.
* </p>
*/
*/
public static final String CONNECTION_MANAGER_FACTORY_CLASS_NAME = "http.connection-manager.factory-class-name";
/**
* @deprecated use #CONNECTION_MANAGER_FACTORY_CLASS_NAME
*/
@Deprecated
public static final String CONNECTION_MANAGER_FACTORY = "http.connection-manager.factory-object";
/**
/**
* Defines whether redirects should be handled automatically
* <p>
* This parameter expects a value of type {@link Boolean}.
@ -56,26 +56,26 @@ public interface ClientPNames {
public static final String HANDLE_REDIRECTS = "http.protocol.handle-redirects";
/**
* Defines whether relative redirects should be rejected. HTTP specification
* Defines whether relative redirects should be rejected. HTTP specification
* requires the location value be an absolute URI.
* <p>
* This parameter expects a value of type {@link Boolean}.
* </p>
*/
public static final String REJECT_RELATIVE_REDIRECT = "http.protocol.reject-relative-redirect";
public static final String REJECT_RELATIVE_REDIRECT = "http.protocol.reject-relative-redirect";
/**
* Defines the maximum number of redirects to be followed.
* The limit on number of redirects is intended to prevent infinite loops.
/**
* Defines the maximum number of redirects to be followed.
* The limit on number of redirects is intended to prevent infinite loops.
* <p>
* This parameter expects a value of type {@link Integer}.
* </p>
*/
public static final String MAX_REDIRECTS = "http.protocol.max-redirects";
/**
* Defines whether circular redirects (redirects to the same location) should be allowed.
* The HTTP spec is not sufficiently clear whether circular redirects are permitted,
/**
* Defines 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>
* This parameter expects a value of type {@link Boolean}.
@ -98,25 +98,25 @@ public interface ClientPNames {
* </p>
*/
public static final String COOKIE_POLICY = "http.protocol.cookie-policy";
/**
* Defines the virtual host name to be used in the <code>Host</code>
* Defines the virtual host name to be used in the <code>Host</code>
* request header instead of the physical host name.
* <p>
* This parameter expects a value of type {@link org.apache.http.HttpHost}.
* This parameter expects a value of type {@link org.apache.http.HttpHost}.
* </p>
*/
public static final String VIRTUAL_HOST = "http.virtual-host";
public static final String VIRTUAL_HOST = "http.virtual-host";
/**
* Defines the request headers to be sent per default with each request.
* <p>
* This parameter expects a value of type {@link java.util.Collection}. The
* collection is expected to contain {@link org.apache.http.Header}s.
* This parameter expects a value of type {@link java.util.Collection}. The
* collection is expected to contain {@link org.apache.http.Header}s.
* </p>
*/
public static final String DEFAULT_HEADERS = "http.default-headers";
public static final String DEFAULT_HEADERS = "http.default-headers";
/**
* Defines the default host. The default value will be used if the target host is
* not explicitly specified in the request URI.

View File

@ -38,8 +38,8 @@ import org.apache.http.params.HttpAbstractParamBean;
import org.apache.http.params.HttpParams;
/**
* This is a Java Bean class that can be used to wrap an instance of
* {@link HttpParams} and manipulate HTTP client parameters using
* This is a Java Bean class that can be used to wrap an instance of
* {@link HttpParams} and manipulate HTTP client parameters using
* Java Beans conventions.
*
* @since 4.0
@ -54,7 +54,7 @@ public class ClientParamBean extends HttpAbstractParamBean {
public void setConnectionManagerFactoryClassName (final String factory) {
params.setParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME, factory);
}
@Deprecated
public void setConnectionManagerFactory(ClientConnectionManagerFactory factory) {
params.setParameter(ClientPNames.CONNECTION_MANAGER_FACTORY, factory);
@ -95,5 +95,5 @@ public class ClientParamBean extends HttpAbstractParamBean {
public void setDefaultHost (final HttpHost host) {
params.setParameter(ClientPNames.DEFAULT_HOST, host);
}
}

View File

@ -30,7 +30,7 @@ package org.apache.http.client.params;
import org.apache.http.annotation.Immutable;
/**
* Standard cookie specifications supported by HttpClient.
* Standard cookie specifications supported by HttpClient.
*
* @since 4.0
*/
@ -38,18 +38,18 @@ import org.apache.http.annotation.Immutable;
public final class CookiePolicy {
/**
* The policy that provides high degree of compatibilty
* The policy that provides high degree of compatibilty
* with common cookie management of popular HTTP agents.
*/
public static final String BROWSER_COMPATIBILITY = "compatibility";
/**
* The Netscape cookie draft compliant policy.
/**
* The Netscape cookie draft compliant policy.
*/
public static final String NETSCAPE = "netscape";
/**
* The RFC 2109 compliant policy.
/**
* The RFC 2109 compliant policy.
*/
public static final String RFC_2109 = "rfc2109";
@ -66,5 +66,5 @@ public final class CookiePolicy {
private CookiePolicy() {
super();
}
}

View File

@ -32,7 +32,7 @@ import org.apache.http.params.HttpParams;
/**
* An adaptor for manipulating HTTP client parameters in {@link HttpParams}.
*
*
* @since 4.0
*/
@Immutable
@ -47,7 +47,7 @@ public class HttpClientParams {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
return params.getBooleanParameter
(ClientPNames.HANDLE_REDIRECTS, true);
(ClientPNames.HANDLE_REDIRECTS, true);
}
public static void setRedirecting(final HttpParams params, boolean value) {
@ -55,15 +55,15 @@ public class HttpClientParams {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
params.setBooleanParameter
(ClientPNames.HANDLE_REDIRECTS, value);
(ClientPNames.HANDLE_REDIRECTS, value);
}
public static boolean isAuthenticating(final HttpParams params) {
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
return params.getBooleanParameter
(ClientPNames.HANDLE_AUTHENTICATION, true);
(ClientPNames.HANDLE_AUTHENTICATION, true);
}
public static void setAuthenticating(final HttpParams params, boolean value) {
@ -71,10 +71,10 @@ public class HttpClientParams {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
params.setBooleanParameter
(ClientPNames.HANDLE_AUTHENTICATION, value);
(ClientPNames.HANDLE_AUTHENTICATION, value);
}
public static String getCookiePolicy(final HttpParams params) {
public static String getCookiePolicy(final HttpParams params) {
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
@ -85,7 +85,7 @@ public class HttpClientParams {
}
return cookiePolicy;
}
public static void setCookiePolicy(final HttpParams params, final String cookiePolicy) {
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");

View File

@ -28,68 +28,68 @@
package org.apache.http.client.protocol;
/**
* {@link org.apache.http.protocol.HttpContext} attribute names for
* {@link org.apache.http.protocol.HttpContext} attribute names for
* client side HTTP protocol processing.
*
* @since 4.0
*/
public interface ClientContext {
/**
* Attribute name of a {@link org.apache.http.conn.scheme.Scheme}
* Attribute name of a {@link org.apache.http.conn.scheme.Scheme}
* object that represents the actual protocol scheme registry.
*/
public static final String SCHEME_REGISTRY = "http.scheme-registry";
public static final String SCHEME_REGISTRY = "http.scheme-registry";
/**
* Attribute name of a {@link org.apache.http.cookie.CookieSpecRegistry}
* Attribute name of a {@link org.apache.http.cookie.CookieSpecRegistry}
* object that represents the actual cookie specification registry.
*/
public static final String COOKIESPEC_REGISTRY = "http.cookiespec-registry";
public static final String COOKIESPEC_REGISTRY = "http.cookiespec-registry";
/**
* Attribute name of a {@link org.apache.http.cookie.CookieSpec}
* Attribute name of a {@link org.apache.http.cookie.CookieSpec}
* object that represents the actual cookie specification.
*/
public static final String COOKIE_SPEC = "http.cookie-spec";
public static final String COOKIE_SPEC = "http.cookie-spec";
/**
* Attribute name of a {@link org.apache.http.cookie.CookieOrigin}
* Attribute name of a {@link org.apache.http.cookie.CookieOrigin}
* object that represents the actual details of the origin server.
*/
public static final String COOKIE_ORIGIN = "http.cookie-origin";
public static final String COOKIE_ORIGIN = "http.cookie-origin";
/**
* Attribute name of a {@link org.apache.http.client.CookieStore}
* Attribute name of a {@link org.apache.http.client.CookieStore}
* object that represents the actual cookie store.
*/
public static final String COOKIE_STORE = "http.cookie-store";
public static final String COOKIE_STORE = "http.cookie-store";
/**
* Attribute name of a {@link org.apache.http.auth.AuthSchemeRegistry}
* Attribute name of a {@link org.apache.http.auth.AuthSchemeRegistry}
* object that represents the actual authentication scheme registry.
*/
public static final String AUTHSCHEME_REGISTRY = "http.authscheme-registry";
public static final String AUTHSCHEME_REGISTRY = "http.authscheme-registry";
/**
* Attribute name of a {@link org.apache.http.client.CredentialsProvider}
* Attribute name of a {@link org.apache.http.client.CredentialsProvider}
* object that represents the actual credentials provider.
*/
public static final String CREDS_PROVIDER = "http.auth.credentials-provider";
public static final String CREDS_PROVIDER = "http.auth.credentials-provider";
/**
* Attribute name of a {@link org.apache.http.client.AuthCache} object
* Attribute name of a {@link org.apache.http.client.AuthCache} object
* that represents the auth scheme cache.
*/
public static final String AUTH_CACHE = "http.auth.auth-cache";
public static final String AUTH_CACHE = "http.auth.auth-cache";
/**
* Attribute name of a {@link org.apache.http.auth.AuthState}
* Attribute name of a {@link org.apache.http.auth.AuthState}
* object that represents the actual target authentication state.
*/
public static final String TARGET_AUTH_STATE = "http.auth.target-scope";
public static final String TARGET_AUTH_STATE = "http.auth.target-scope";
/**
* Attribute name of a {@link org.apache.http.auth.AuthState}
* Attribute name of a {@link org.apache.http.auth.AuthState}
* object that represents the actual proxy authentication state.
*/
public static final String PROXY_AUTH_STATE = "http.auth.proxy-scope";
@ -99,11 +99,11 @@ public interface ClientContext {
*/
@Deprecated
public static final String AUTH_SCHEME_PREF = "http.auth.scheme-pref";
/**
* Attribute name of a {@link java.lang.Object} object that represents
* Attribute name of a {@link java.lang.Object} object that represents
* the actual user identity such as user {@link java.security.Principal}.
*/
public static final String USER_TOKEN = "http.user-token";
}

View File

@ -44,7 +44,7 @@ import org.apache.http.protocol.HttpContext;
*/
@NotThreadSafe
public class ClientContextConfigurer implements ClientContext {
private final HttpContext context;
public ClientContextConfigurer (final HttpContext context) {
@ -56,11 +56,11 @@ public class ClientContextConfigurer implements ClientContext {
public void setCookieSpecRegistry(final CookieSpecRegistry registry) {
this.context.setAttribute(COOKIESPEC_REGISTRY, registry);
}
public void setAuthSchemeRegistry(final AuthSchemeRegistry registry) {
this.context.setAttribute(AUTHSCHEME_REGISTRY, registry);
}
public void setCookieStore(final CookieStore store) {
this.context.setAttribute(COOKIE_STORE, store);
}

View File

@ -36,23 +36,23 @@ import org.apache.http.protocol.HttpContext;
* Class responsible for handling Content Encoding requests in HTTP.
* <p>
* Instances of this class are stateless, therefore they're thread-safe and immutable.
*
*
* @see "http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.5"
*
*
* @since 4.1
*/
@Immutable
public class RequestAcceptEncoding implements HttpRequestInterceptor {
/**
* {@inheritDoc}
*/
public void process(
final HttpRequest request,
final HttpRequest request,
final HttpContext context) throws HttpException, IOException {
/* Signal support for Accept-Encoding transfer encodings. */
request.addHeader("Accept-Encoding", "gzip,deflate");
request.addHeader("Accept-Encoding", "gzip,deflate");
}
}

View File

@ -60,29 +60,29 @@ import org.apache.http.protocol.ExecutionContext;
/**
* Request interceptor that matches cookies available in the current
* {@link CookieStore} to the request being executed and generates
* {@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:
* 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
*/
@Immutable
public class RequestAddCookies implements HttpRequestInterceptor {
private final Log log = LogFactory.getLog(getClass());
public RequestAddCookies() {
super();
}
public void process(final HttpRequest request, final HttpContext context)
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
@ -90,12 +90,12 @@ public class RequestAddCookies implements HttpRequestInterceptor {
if (context == null) {
throw new IllegalArgumentException("HTTP context may not be null");
}
String method = request.getRequestLine().getMethod();
if (method.equalsIgnoreCase("CONNECT")) {
return;
}
// Obtain cookie store
CookieStore cookieStore = (CookieStore) context.getAttribute(
ClientContext.COOKIE_STORE);
@ -103,7 +103,7 @@ public class RequestAddCookies implements HttpRequestInterceptor {
this.log.info("Cookie store not available in HTTP context");
return;
}
// Obtain the registry of cookie specs
CookieSpecRegistry registry = (CookieSpecRegistry) context.getAttribute(
ClientContext.COOKIESPEC_REGISTRY);
@ -111,14 +111,14 @@ public class RequestAddCookies implements HttpRequestInterceptor {
this.log.info("CookieSpec registry not available in HTTP context");
return;
}
// Obtain the target host (required)
HttpHost targetHost = (HttpHost) context.getAttribute(
ExecutionContext.HTTP_TARGET_HOST);
if (targetHost == null) {
throw new IllegalStateException("Target host not specified in HTTP context");
}
// Obtain the client connection (required)
ManagedClientConnection conn = (ManagedClientConnection) context.getAttribute(
ExecutionContext.HTTP_CONNECTION);
@ -130,7 +130,7 @@ public class RequestAddCookies implements HttpRequestInterceptor {
if (this.log.isDebugEnabled()) {
this.log.debug("CookieSpec selected: " + policy);
}
URI requestURI;
if (request instanceof HttpUriRequest) {
requestURI = ((HttpUriRequest) request).getURI();
@ -138,11 +138,11 @@ public class RequestAddCookies implements HttpRequestInterceptor {
try {
requestURI = new URI(request.getRequestLine().getUri());
} catch (URISyntaxException ex) {
throw new ProtocolException("Invalid request URI: " +
throw new ProtocolException("Invalid request URI: " +
request.getRequestLine().getUri(), ex);
}
}
String hostName = targetHost.getHostName();
int port = targetHost.getPort();
if (port < 0) {
@ -157,13 +157,13 @@ public class RequestAddCookies implements HttpRequestInterceptor {
port = conn.getRemotePort();
}
}
CookieOrigin cookieOrigin = new CookieOrigin(
hostName,
port,
hostName,
port,
requestURI.getPath(),
conn.isSecure());
// Get an instance of the selected cookie policy
CookieSpec cookieSpec = registry.getCookieSpec(policy, request.getParams());
// Get all cookies available in the HTTP state
@ -192,7 +192,7 @@ public class RequestAddCookies implements HttpRequestInterceptor {
request.addHeader(header);
}
}
int ver = cookieSpec.getVersion();
if (ver > 0) {
boolean needVersionHeader = false;
@ -210,11 +210,11 @@ public class RequestAddCookies implements HttpRequestInterceptor {
}
}
}
// Stick the CookieSpec and CookieOrigin instances to the HTTP context
// so they could be obtained by the response interceptor
context.setAttribute(ClientContext.COOKIE_SPEC, cookieSpec);
context.setAttribute(ClientContext.COOKIE_ORIGIN, cookieOrigin);
}
}

View File

@ -47,22 +47,22 @@ import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpContext;
/**
* Request interceptor that can preemptively authenticate against known hosts,
* if there is a cached {@link AuthScheme} instance in the local
* Request interceptor that can preemptively authenticate against known hosts,
* if there is a cached {@link AuthScheme} instance in the local
* {@link AuthCache} associated with the given target or proxy host.
*
*
* @since 4.1
*/
@Immutable
public class RequestAuthCache implements HttpRequestInterceptor {
private final Log log = LogFactory.getLog(getClass());
public RequestAuthCache() {
super();
}
public void process(final HttpRequest request, final HttpContext context)
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
@ -75,18 +75,18 @@ public class RequestAuthCache implements HttpRequestInterceptor {
if (authCache == null) {
context.setAttribute(ClientContext.AUTH_CACHE, new BasicAuthCache());
} else {
CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(
ClientContext.CREDS_PROVIDER);
HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
if (target != null) {
AuthScheme authScheme = authCache.get(target);
if (authScheme != null) {
doPreemptiveAuth(
target,
authScheme,
(AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE),
target,
authScheme,
(AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE),
credsProvider);
}
}
@ -96,9 +96,9 @@ public class RequestAuthCache implements HttpRequestInterceptor {
AuthScheme authScheme = authCache.get(proxy);
if (authScheme != null) {
doPreemptiveAuth(
proxy,
authScheme,
(AuthState) context.getAttribute(ClientContext.PROXY_AUTH_STATE),
proxy,
authScheme,
(AuthState) context.getAttribute(ClientContext.PROXY_AUTH_STATE),
credsProvider);
}
}
@ -106,18 +106,18 @@ public class RequestAuthCache implements HttpRequestInterceptor {
}
private void doPreemptiveAuth(
final HttpHost host,
final AuthScheme authScheme,
final HttpHost host,
final AuthScheme authScheme,
final AuthState authState,
final CredentialsProvider credsProvider) {
String schemeName = authScheme.getSchemeName();
if (this.log.isDebugEnabled()) {
this.log.debug("Re-using cached '" + schemeName + "' auth scheme for " + host);
}
Credentials creds = credsProvider.getCredentials(
new AuthScope(host.getHostName(), host.getPort(), schemeName));
if (creds != null) {
authState.setAuthScheme(authScheme);
authState.setCredentials(creds);
@ -125,5 +125,5 @@ public class RequestAuthCache implements HttpRequestInterceptor {
this.log.debug("No credentials for preemptive authentication");
}
}
}

View File

@ -41,22 +41,22 @@ import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
/**
* This protocol interceptor is responsible for adding <code>Connection</code>
* or <code>Proxy-Connection</code> headers to the outgoing requests, which
* is essential for managing persistence of <code>HTTP/1.0</code> connections.
*
* This protocol interceptor is responsible for adding <code>Connection</code>
* or <code>Proxy-Connection</code> headers to the outgoing requests, which
* is essential for managing persistence of <code>HTTP/1.0</code> connections.
*
* @since 4.0
*/
@Immutable
public class RequestClientConnControl implements HttpRequestInterceptor {
private static final String PROXY_CONN_DIRECTIVE = "Proxy-Connection";
public RequestClientConnControl() {
super();
}
public void process(final HttpRequest request, final HttpContext context)
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
@ -67,7 +67,7 @@ public class RequestClientConnControl implements HttpRequestInterceptor {
request.setHeader(PROXY_CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
return;
}
// Obtain the client connection (required)
ManagedClientConnection conn = (ManagedClientConnection) context.getAttribute(
ExecutionContext.HTTP_CONNECTION);
@ -76,7 +76,7 @@ public class RequestClientConnControl implements HttpRequestInterceptor {
}
HttpRoute route = conn.getRoute();
if (route.getHopCount() == 1 || route.isTunnelled()) {
if (!request.containsHeader(HTTP.CONN_DIRECTIVE)) {
request.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
@ -88,5 +88,5 @@ public class RequestClientConnControl implements HttpRequestInterceptor {
}
}
}
}

View File

@ -41,7 +41,7 @@ import org.apache.http.protocol.HttpContext;
/**
* Request interceptor that adds default request headers.
*
*
* @since 4.0
*/
@Immutable
@ -50,18 +50,18 @@ public class RequestDefaultHeaders implements HttpRequestInterceptor {
public RequestDefaultHeaders() {
super();
}
public void process(final HttpRequest request, final HttpContext context)
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
}
String method = request.getRequestLine().getMethod();
if (method.equalsIgnoreCase("CONNECT")) {
return;
}
// Add default headers
@SuppressWarnings("unchecked")
Collection<Header> defHeaders = (Collection<Header>) request.getParams().getParameter(
@ -73,5 +73,5 @@ public class RequestDefaultHeaders implements HttpRequestInterceptor {
}
}
}
}

View File

@ -46,22 +46,22 @@ import org.apache.http.auth.Credentials;
import org.apache.http.protocol.HttpContext;
/**
* Generates authentication header for the proxy host, if required,
* based on the actual state of the HTTP authentication context.
*
* Generates authentication header for the proxy host, if required,
* based on the actual state of the HTTP authentication context.
*
* @since 4.0
*/
@Immutable
public class RequestProxyAuthentication implements HttpRequestInterceptor {
private final Log log = LogFactory.getLog(getClass());
public RequestProxyAuthentication() {
super();
}
@SuppressWarnings("deprecation")
public void process(final HttpRequest request, final HttpContext context)
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
@ -73,7 +73,7 @@ public class RequestProxyAuthentication implements HttpRequestInterceptor {
if (request.containsHeader(AUTH.PROXY_AUTH_RESP)) {
return;
}
// Obtain authentication state
AuthState authState = (AuthState) context.getAttribute(
ClientContext.PROXY_AUTH_STATE);
@ -85,7 +85,7 @@ public class RequestProxyAuthentication implements HttpRequestInterceptor {
if (authScheme == null) {
return;
}
Credentials creds = authState.getCredentials();
if (creds == null) {
this.log.debug("User credentials not available");
@ -108,5 +108,5 @@ public class RequestProxyAuthentication implements HttpRequestInterceptor {
}
}
}
}

View File

@ -46,22 +46,22 @@ import org.apache.http.auth.Credentials;
import org.apache.http.protocol.HttpContext;
/**
* Generates authentication header for the target host, if required,
* based on the actual state of the HTTP authentication context.
*
* Generates authentication header for the target host, if required,
* based on the actual state of the HTTP authentication context.
*
* @since 4.0
*/
@Immutable
public class RequestTargetAuthentication implements HttpRequestInterceptor {
private final Log log = LogFactory.getLog(getClass());
public RequestTargetAuthentication() {
super();
}
@SuppressWarnings("deprecation")
public void process(final HttpRequest request, final HttpContext context)
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
@ -74,11 +74,11 @@ public class RequestTargetAuthentication implements HttpRequestInterceptor {
if (method.equalsIgnoreCase("CONNECT")) {
return;
}
if (request.containsHeader(AUTH.WWW_AUTH_RESP)) {
return;
}
// Obtain authentication state
AuthState authState = (AuthState) context.getAttribute(
ClientContext.TARGET_AUTH_STATE);
@ -90,7 +90,7 @@ public class RequestTargetAuthentication implements HttpRequestInterceptor {
if (authScheme == null) {
return;
}
Credentials creds = authState.getCredentials();
if (creds == null) {
this.log.debug("User credentials not available");
@ -114,5 +114,5 @@ public class RequestTargetAuthentication implements HttpRequestInterceptor {
}
}
}
}

View File

@ -45,22 +45,22 @@ import org.apache.http.protocol.HttpContext;
/**
* Response interceptor that adds successfully completed {@link AuthScheme}s
* to the local {@link AuthCache} instance. Cached {@link AuthScheme}s can be
* re-used when executing requests against known hosts, thus avoiding
* additional authentication round-trips.
*
* to the local {@link AuthCache} instance. Cached {@link AuthScheme}s can be
* re-used when executing requests against known hosts, thus avoiding
* additional authentication round-trips.
*
* @since 4.1
*/
@Immutable
public class ResponseAuthCache implements HttpResponseInterceptor {
private final Log log = LogFactory.getLog(getClass());
public ResponseAuthCache() {
super();
}
public void process(final HttpResponse response, final HttpContext context)
public void process(final HttpResponse response, final HttpContext context)
throws HttpException, IOException {
if (response == null) {
throw new IllegalArgumentException("HTTP request may not be null");
@ -70,31 +70,31 @@ public class ResponseAuthCache implements HttpResponseInterceptor {
}
AuthCache authCache = (AuthCache) context.getAttribute(ClientContext.AUTH_CACHE);
if (authCache != null) {
cache(authCache,
cache(authCache,
(HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST),
(AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE));
cache(authCache,
cache(authCache,
(HttpHost) context.getAttribute(ExecutionContext.HTTP_PROXY_HOST),
(AuthState) context.getAttribute(ClientContext.PROXY_AUTH_STATE));
}
}
private void cache(final AuthCache authCache, final HttpHost host, final AuthState authState) {
if (authState == null) {
return;
}
AuthScheme authScheme = authState.getAuthScheme();
if (authScheme == null || !authScheme.isComplete()) {
return;
}
String schemeName = authScheme.getSchemeName();
if (!schemeName.equalsIgnoreCase(AuthPolicy.BASIC) &&
if (!schemeName.equalsIgnoreCase(AuthPolicy.BASIC) &&
!schemeName.equalsIgnoreCase(AuthPolicy.DIGEST)) {
return;
}
if (authState.getAuthScope() != null) {
if (authState.getCredentials() != null) {
if (this.log.isDebugEnabled()) {
@ -106,5 +106,5 @@ public class ResponseAuthCache implements HttpResponseInterceptor {
}
}
}
}

View File

@ -40,11 +40,11 @@ import org.apache.http.client.entity.GzipDecompressingEntity;
import org.apache.http.protocol.HttpContext;
/**
* {@link HttpResponseInterceptor} responsible for processing Content-Encoding
* {@link HttpResponseInterceptor} responsible for processing Content-Encoding
* responses.
* <p>
* Instances of this class are stateless and immutable, therefore threadsafe.
*
*
* @since 4.1
*
*/
@ -55,12 +55,12 @@ public class ResponseContentEncoding implements HttpResponseInterceptor {
* {@inheritDoc}
*/
public void process(
final HttpResponse response,
final HttpResponse response,
final HttpContext context) throws HttpException, IOException {
HttpEntity entity = response.getEntity();
// It wasn't a 304 Not Modified response, 204 No Content or similar
if (entity != null) {
if (entity != null) {
Header ceheader = entity.getContentEncoding();
if (ceheader != null) {
HeaderElement[] codecs = ceheader.getElements();
@ -72,7 +72,7 @@ public class ResponseContentEncoding implements HttpResponseInterceptor {
response.setEntity(new DeflateDecompressingEntity(response.getEntity()));
return;
} else if ("identity".equalsIgnoreCase(codec.getName())) {
/* Don't need to transform the content - no-op */
return;
} else {

View File

@ -48,21 +48,21 @@ import org.apache.http.cookie.SM;
import org.apache.http.protocol.HttpContext;
/**
* Response interceptor that populates the current {@link CookieStore} with data
* Response interceptor that populates the current {@link CookieStore} with data
* contained in response cookies received in the given the HTTP response.
*
*
* @since 4.0
*/
@Immutable
public class ResponseProcessCookies implements HttpResponseInterceptor {
private final Log log = LogFactory.getLog(getClass());
public ResponseProcessCookies() {
super();
}
public void process(final HttpResponse response, final HttpContext context)
public void process(final HttpResponse response, final HttpContext context)
throws HttpException, IOException {
if (response == null) {
throw new IllegalArgumentException("HTTP request may not be null");
@ -70,7 +70,7 @@ public class ResponseProcessCookies implements HttpResponseInterceptor {
if (context == null) {
throw new IllegalArgumentException("HTTP context may not be null");
}
// Obtain actual CookieSpec instance
CookieSpec cookieSpec = (CookieSpec) context.getAttribute(
ClientContext.COOKIE_SPEC);
@ -93,7 +93,7 @@ public class ResponseProcessCookies implements HttpResponseInterceptor {
}
HeaderIterator it = response.headerIterator(SM.SET_COOKIE);
processCookies(it, cookieSpec, cookieOrigin, cookieStore);
// see if the cookie spec supports cookie versioning.
if (cookieSpec.getVersion() > 0) {
// process set-cookie2 headers.
@ -102,9 +102,9 @@ public class ResponseProcessCookies implements HttpResponseInterceptor {
processCookies(it, cookieSpec, cookieOrigin, cookieStore);
}
}
private void processCookies(
final HeaderIterator iterator,
final HeaderIterator iterator,
final CookieSpec cookieSpec,
final CookieOrigin cookieOrigin,
final CookieStore cookieStore) {
@ -136,5 +136,5 @@ public class ResponseProcessCookies implements HttpResponseInterceptor {
}
}
}
}

View File

@ -30,7 +30,7 @@
-->
</head>
<body>
Additional request and response interceptors for HTTP state and
Additional request and response interceptors for HTTP state and
authentication management.
</body>
</html>

View File

@ -59,7 +59,7 @@ public class CloneUtils {
} catch (InvocationTargetException ex) {
Throwable cause = ex.getCause();
if (cause instanceof CloneNotSupportedException) {
throw ((CloneNotSupportedException) cause);
throw ((CloneNotSupportedException) cause);
} else {
throw new Error("Unexpected exception", cause);
}
@ -70,7 +70,7 @@ public class CloneUtils {
throw new CloneNotSupportedException();
}
}
/**
* This class should not be instantiated.
*/

View File

@ -45,7 +45,7 @@ public class JdkIdn implements Idn {
private final Method toUnicode;
/**
*
*
* @throws ClassNotFoundException if java.net.IDN is not available
*/
public JdkIdn() throws ClassNotFoundException {
@ -71,5 +71,5 @@ public class JdkIdn implements Idn {
throw new RuntimeException(t.getMessage(), t);
}
}
}

View File

@ -50,9 +50,9 @@ public class Punycode {
}
impl = _impl;
}
public static String toUnicode(String punycode) {
return impl.toUnicode(punycode);
}
}

View File

@ -50,7 +50,7 @@ public class Rfc3492Idn implements Idn {
private static final int initial_n = 128;
private static final char delimiter = '-';
private static final String ACE_PREFIX = "xn--";
private int adapt(int delta, int numpoints, boolean firsttime) {
if (firsttime) delta = delta / damp;
else delta = delta / 2;
@ -62,7 +62,7 @@ public class Rfc3492Idn implements Idn {
}
return k + (((base - tmin + 1) * delta) / (delta + skew));
}
private int digit(char c) {
if ((c >= 'A') && (c <= 'Z')) return (c - 'A');
if ((c >= 'a') && (c <= 'z')) return (c - 'a');
@ -81,7 +81,7 @@ public class Rfc3492Idn implements Idn {
}
return unicode.toString();
}
protected String decode(String input) {
int n = initial_n;
int i = 0;
@ -122,5 +122,5 @@ public class Rfc3492Idn implements Idn {
}
return output.toString();
}
}

View File

@ -48,7 +48,7 @@ public class URIUtils {
* used instead of
* {@link URI#URI(String, String, String, int, String, String, String)}
* or any of the other URI multi-argument URI constructors.
*
*
* @param scheme
* Scheme name
* @param host
@ -61,7 +61,7 @@ public class URIUtils {
* Query
* @param fragment
* Fragment
*
*
* @throws URISyntaxException
* If both a scheme and a path are given but the path is
* relative, if the URI string constructed from the given
@ -76,7 +76,7 @@ public class URIUtils {
final String path,
final String query,
final String fragment) throws URISyntaxException {
StringBuilder buffer = new StringBuilder();
if (host != null) {
if (scheme != null) {
@ -111,19 +111,19 @@ public class URIUtils {
* and port are taken from the target host, but whose path, query and
* fragment are taken from the existing URI. The fragment is only used if
* dropFragment is false.
*
*
* @param uri
* Contains the path, query and fragment to use.
* @param target
* Contains the scheme, host and port to use.
* @param dropFragment
* True if the fragment should not be copied.
*
*
* @throws URISyntaxException
* If the resulting URI is invalid.
*/
public static URI rewriteURI(
final URI uri,
final URI uri,
final HttpHost target,
boolean dropFragment) throws URISyntaxException {
if (uri == null) {
@ -131,23 +131,23 @@ public class URIUtils {
}
if (target != null) {
return URIUtils.createURI(
target.getSchemeName(),
target.getHostName(),
target.getPort(),
normalizePath(uri.getRawPath()),
uri.getRawQuery(),
target.getSchemeName(),
target.getHostName(),
target.getPort(),
normalizePath(uri.getRawPath()),
uri.getRawQuery(),
dropFragment ? null : uri.getRawFragment());
} else {
return URIUtils.createURI(
null,
null,
-1,
normalizePath(uri.getRawPath()),
uri.getRawQuery(),
null,
null,
-1,
normalizePath(uri.getRawPath()),
uri.getRawQuery(),
dropFragment ? null : uri.getRawFragment());
}
}
private static String normalizePath(final String path) {
if (path == null) {
return null;
@ -168,18 +168,18 @@ public class URIUtils {
}
return buffer.toString();
}
/**
* A convenience method for
* {@link URIUtils#rewriteURI(URI, HttpHost, boolean)} that always keeps the
* fragment.
*/
public static URI rewriteURI(
final URI uri,
final URI uri,
final HttpHost target) throws URISyntaxException {
return rewriteURI(uri, target, false);
}
/**
* Resolves a URI reference against a base URI. Work-around for bug in
* java.net.URI (<http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4708535>)
@ -226,7 +226,7 @@ public class URIUtils {
/**
* Resolves a reference starting with a query string.
*
*
* @param baseURI the base URI
* @param reference the URI reference starting with a query string
* @return the resulting URI
@ -241,7 +241,7 @@ public class URIUtils {
/**
* Removes dot segments according to RFC 3986, section 5.2.4
*
*
* @param uri the original URI
* @return the URI without dot segments
*/

View File

@ -66,7 +66,7 @@ public class URLEncodedUtils {
* NameValuePairs, one for a=1, one for b=2, and one for c=3.
* <p>
* This is typically useful while parsing an HTTP PUT.
*
*
* @param uri
* uri to parse
* @param encoding
@ -88,7 +88,7 @@ public class URLEncodedUtils {
* Content-Encoding header.
* <p>
* This is typically used while parsing an HTTP POST.
*
*
* @param entity
* The entity to parse
* @throws IOException
@ -97,10 +97,10 @@ public class URLEncodedUtils {
public static List <NameValuePair> parse (
final HttpEntity entity) throws IOException {
List <NameValuePair> result = Collections.emptyList();
String contentType = null;
String charset = null;
Header h = entity.getContentType();
if (h != null) {
HeaderElement[] elems = h.getElements();
@ -113,7 +113,7 @@ public class URLEncodedUtils {
}
}
}
if (contentType != null && contentType.equalsIgnoreCase(CONTENT_TYPE)) {
final String content = EntityUtils.toString(entity, HTTP.ASCII);
if (content != null && content.length() > 0) {
@ -149,7 +149,7 @@ public class URLEncodedUtils {
* example, a scanner containing the string <code>a=1&b=2&c=3</code> would
* add the {@link NameValuePair NameValuePairs} a=1, b=2, and c=3 to the
* list of parameters.
*
*
* @param parameters
* List to add parameters to.
* @param scanner
@ -158,8 +158,8 @@ public class URLEncodedUtils {
* Encoding to use when decoding the parameters.
*/
public static void parse (
final List <NameValuePair> parameters,
final Scanner scanner,
final List <NameValuePair> parameters,
final Scanner scanner,
final String encoding) {
scanner.useDelimiter(PARAMETER_SEPARATOR);
while (scanner.hasNext()) {
@ -178,12 +178,12 @@ public class URLEncodedUtils {
/**
* Returns a String that is suitable for use as an <code>application/x-www-form-urlencoded</code>
* list of parameters in an HTTP PUT or HTTP POST.
*
*
* @param parameters The parameters to include.
* @param encoding The encoding to use.
*/
public static String format (
final List <? extends NameValuePair> parameters,
final List <? extends NameValuePair> parameters,
final String encoding) {
final StringBuilder result = new StringBuilder();
for (final NameValuePair parameter : parameters) {
@ -201,7 +201,7 @@ public class URLEncodedUtils {
private static String decode (final String content, final String encoding) {
try {
return URLDecoder.decode(content,
return URLDecoder.decode(content,
encoding != null ? encoding : HTTP.DEFAULT_CONTENT_CHARSET);
} catch (UnsupportedEncodingException problem) {
throw new IllegalArgumentException(problem);
@ -210,11 +210,11 @@ public class URLEncodedUtils {
private static String encode (final String content, final String encoding) {
try {
return URLEncoder.encode(content,
return URLEncoder.encode(content,
encoding != null ? encoding : HTTP.DEFAULT_CONTENT_CHARSET);
} catch (UnsupportedEncodingException problem) {
throw new IllegalArgumentException(problem);
}
}
}

View File

@ -33,7 +33,7 @@ import java.io.IOException;
import org.apache.http.annotation.NotThreadSafe;
/**
* Basic implementation of {@link EofSensorWatcher}. The underlying connection
* Basic implementation of {@link EofSensorWatcher}. The underlying connection
* is released on close or EOF.
*
* @since 4.0

View File

@ -33,14 +33,14 @@ import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.conn.scheme.SchemeRegistry;
/**
* Management interface for {@link ManagedClientConnection client connections}.
* The purpose of an HTTP connection manager is to serve as a factory for new
* HTTP connections, manage persistent connections and synchronize access to
* persistent connections making sure that only one thread of execution can
* Management interface for {@link ManagedClientConnection client connections}.
* The purpose of an HTTP connection manager is to serve as a factory for new
* HTTP connections, manage persistent connections and synchronize access to
* persistent connections making sure that only one thread of execution can
* have access to a connection at a time.
* <p>
* Implementations of this interface must be thread-safe. Access to shared
* data must be synchronized as methods of this interface may be executed
* data must be synchronized as methods of this interface may be executed
* from multiple threads.
*
* @since 4.0
@ -53,7 +53,7 @@ public interface ClientConnectionManager {
* @return the scheme registry, never <code>null</code>
*/
SchemeRegistry getSchemeRegistry();
/**
* Returns a new {@link ClientConnectionRequest}, from which a
* {@link ManagedClientConnection} can be obtained or the request can be
@ -67,14 +67,14 @@ public interface ClientConnectionManager {
* 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.
*
*
* 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
*
*
* @see #closeExpiredConnections()
*/
void releaseConnection(ManagedClientConnection conn, long validDuration, TimeUnit timeUnit);
@ -85,12 +85,12 @@ public interface ClientConnectionManager {
* timespan given by the argument will be closed.
* Currently allocated connections are not subject to this method.
* Times will be checked with milliseconds precision
*
*
* All expired connections will also be closed.
*
*
* @param idletime the idle time of connections to be closed
* @param tunit the unit for the <code>idletime</code>
*
*
* @see #closeExpiredConnections()
*/
void closeIdleConnections(long idletime, TimeUnit tunit);

View File

@ -32,14 +32,14 @@ import org.apache.http.params.HttpParams;
/**
* A factory for creating new {@link ClientConnectionManager} instances.
*
*
*
* @since 4.0
*/
public interface ClientConnectionManagerFactory {
public interface ClientConnectionManagerFactory {
ClientConnectionManager newInstance(
HttpParams params,
HttpParams params,
SchemeRegistry schemeRegistry);
}

View File

@ -37,9 +37,9 @@ import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;
/**
* ClientConnectionOperator represents a strategy for creating
* {@link OperatedClientConnection} instances and updating the underlying
* {@link Socket} of those objects. Implementations will most likely make use
* ClientConnectionOperator represents a strategy for creating
* {@link OperatedClientConnection} instances and updating the underlying
* {@link Socket} of those objects. Implementations will most likely make use
* of {@link SchemeSocketFactory}s to create {@link Socket} instances.
* <p>
* The methods in this interface allow the creation of plain and layered
@ -47,7 +47,7 @@ import org.apache.http.protocol.HttpContext;
* is not within the scope of the operator.
* <p>
* Implementations of this interface must be thread-safe. Access to shared
* data must be synchronized as methods of this interface may be executed
* data must be synchronized as methods of this interface may be executed
* from multiple threads.
*
* @since 4.0

View File

@ -35,18 +35,18 @@ import java.util.concurrent.TimeUnit;
* @since 4.0
*/
public interface ClientConnectionRequest {
/**
* 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}.
* Timeouts are handled with millisecond precision.
*
*
* If {@link #abortRequest()} is called while this is blocking or
* before this began, an {@link InterruptedException} will
* be thrown.
*
*
* @param timeout the timeout, 0 or negative for no timeout
* @param tunit the unit for the <code>timeout</code>,
* may be <code>null</code> only if there is no timeout
@ -59,9 +59,9 @@ public interface ClientConnectionRequest {
* @throws InterruptedException
* if the calling thread is interrupted while waiting
*/
ManagedClientConnection getConnection(long timeout, TimeUnit tunit)
ManagedClientConnection getConnection(long timeout, TimeUnit tunit)
throws InterruptedException, ConnectionPoolTimeoutException;
/**
* Aborts the call to {@link #getConnection(long, TimeUnit)},
* causing it to throw an {@link InterruptedException}.

View File

@ -34,8 +34,8 @@ import org.apache.http.annotation.Immutable;
/**
* A timeout while connecting to an HTTP server or waiting for an
* available connection from an HttpConnectionManager.
*
*
*
*
* @since 4.0
*/
@Immutable
@ -52,8 +52,8 @@ public class ConnectTimeoutException extends InterruptedIOException {
/**
* Creates a ConnectTimeoutException with the specified detail message.
*
* @param message The exception detail message
*
* @param message The exception detail message
*/
public ConnectTimeoutException(final String message) {
super(message);

View File

@ -35,32 +35,32 @@ import org.apache.http.protocol.HttpContext;
* idle before being reused.
* <p>
* Implementations of this interface must be thread-safe. Access to shared
* data must be synchronized as methods of this interface may be executed
* data must be synchronized as methods of this interface may be executed
* from multiple threads.
*
*
* @since 4.0
*/
public interface ConnectionKeepAliveStrategy {
/**
* Returns the duration of time which this connection can be safely kept
* idle. If the connection is left idle for longer than this period of time,
* it MUST not reused. A value of 0 or less may be returned to indicate that
* there is no suitable suggestion.
*
*
* When coupled with a {@link ConnectionReuseStrategy}, if
* {@link ConnectionReuseStrategy#keepAlive(HttpResponse, HttpContext)}
* returns true, this allows you to control how long the reuse will last. If
* keepAlive returns false, this should have no meaningful impact
*
*
* @param response
* The last response received over the connection.
* @param context
* the context in which the connection is being used.
*
*
* @return the duration in ms for which it is safe to keep the connection
* idle, or <=0 if no suggested duration.
*/
long getKeepAliveDuration(HttpResponse response, HttpContext context);
}

View File

@ -30,10 +30,10 @@ package org.apache.http.conn;
import org.apache.http.annotation.Immutable;
/**
* A timeout while waiting for an available connection
* A timeout while waiting for an available connection
* from a connection manager.
*
*
*
*
* @since 4.0
*/
@Immutable
@ -50,8 +50,8 @@ public class ConnectionPoolTimeoutException extends ConnectTimeoutException {
/**
* Creates a ConnectTimeoutException with the specified detail message.
*
* @param message The exception detail message
*
* @param message The exception detail message
*/
public ConnectionPoolTimeoutException(String message) {
super(message);

View File

@ -29,7 +29,7 @@ package org.apache.http.conn;
import java.io.IOException;
/**
* Interface for releasing a connection. This can be implemented by various
* Interface for releasing a connection. This can be implemented by various
* "trigger" objects which are associated with a connection, for example
* a {@link EofSensorInputStream stream} or an {@link BasicManagedEntity entity}
* or the {@link ManagedClientConnection connection} itself.
@ -48,7 +48,7 @@ public interface ConnectionReleaseTrigger {
* remainder of a response entity. Use
* {@link #abortConnection abortConnection} for a hard release. The
* connection may be reused as specified by the duration.
*
*
* @throws IOException
* in case of an IO problem. The connection will be released
* anyway.

View File

@ -62,7 +62,7 @@ public class EofSensorInputStream extends InputStream implements ConnectionRelea
* Indicates whether this stream itself is closed.
* If it isn't, but {@link #wrappedStream wrappedStream}
* is <code>null</code>, we're running in EOF mode.
* All read operations will indicate EOF without accessing
* All read operations will indicate EOF without accessing
* the underlying stream. After closing this stream, read
* operations will trigger an {@link IOException IOException}.
*

View File

@ -30,7 +30,7 @@ import java.io.InputStream;
import java.io.IOException;
/**
* A watcher for {@link EofSensorInputStream}. Each stream will notify its
* A watcher for {@link EofSensorInputStream}. Each stream will notify its
* watcher at most once.
*
* @since 4.0
@ -77,7 +77,7 @@ public interface EofSensorWatcher {
* before aborting. Otherwise, {@link #eofDetected eofDetected} is called.
* <p/>
* This method will also be invoked when an input operation causes an
* IOException to be thrown to make sure the input stream gets shut down.
* IOException to be thrown to make sure the input stream gets shut down.
*
* @param wrapped the underlying stream which has not reached EOF
*

View File

@ -44,7 +44,7 @@ public class HttpHostConnectException extends ConnectException {
private static final long serialVersionUID = -3194482710275220224L;
private final HttpHost host;
public HttpHostConnectException(final HttpHost host, final ConnectException cause) {
super("Connection to " + host + " refused");
this.host = host;
@ -54,5 +54,5 @@ public class HttpHostConnectException extends ConnectException {
public HttpHost getHost() {
return this.host;
}
}

View File

@ -199,21 +199,21 @@ public interface ManagedClientConnection extends
*/
boolean isMarkedReusable();
/**
* Assigns a state object to this connection. Connection managers may make
/**
* Assigns a state object to this connection. Connection managers may make
* use of the connection state when allocating persistent connections.
*
*
* @param state The state object
*/
void setState(Object state);
/**
* Returns the state object associated with this connection.
*
*
* @return The state object
*/
Object getState();
/**
* Sets the duration that this connection can remain idle before it is
* reused. The connection should not be used again if this time elapses. The

View File

@ -45,14 +45,14 @@ import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
/**
* Socket factory that implements a simple multi-home fail-over on connect failure,
* Socket factory that implements a simple multi-home fail-over on connect failure,
* provided the same hostname resolves to multiple {@link InetAddress}es. Please note
* the {@link #connectSocket(Socket, String, int, InetAddress, int, HttpParams)}
* method cannot be reliably interrupted by closing the socket returned by the
* {@link #createSocket()} method.
*
* @since 4.0
*
*
* @deprecated Do not use. For multihome support socket factories must implement
* {@link SchemeSocketFactory} interface.
*/
@ -88,21 +88,21 @@ public final class MultihomePlainSocketFactory implements SocketFactory {
}
/**
* Attempts to connects the socket to any of the {@link InetAddress}es the
* given host name resolves to. If connection to all addresses fail, the
* Attempts to connects the socket to any of the {@link InetAddress}es the
* given host name resolves to. If connection to all addresses fail, the
* last I/O exception is propagated to the caller.
*
*
* @param sock socket to connect to any of the given addresses
* @param host Host name to connect to
* @param port the port to connect to
* @param localAddress local address
* @param localPort local port
* @param params HTTP parameters
*
* @param params HTTP parameters
*
* @throws IOException if an error occurs during the connection
* @throws SocketTimeoutException if timeout expires before connecting
*/
public Socket connectSocket(Socket sock, String host, int port,
public Socket connectSocket(Socket sock, String host, int port,
InetAddress localAddress, int localPort,
HttpParams params)
throws IOException {

View File

@ -36,7 +36,7 @@ import org.apache.http.HttpInetConnection;
import org.apache.http.params.HttpParams;
/**
* A client-side connection that relies on outside logic to connect sockets to the
* A client-side connection that relies on outside logic to connect sockets to the
* appropriate hosts. It can be operated directly by an application, or through an
* {@link ClientConnectionOperator operator}.
*
@ -84,7 +84,7 @@ public interface OperatedClientConnection extends HttpClientConnection, HttpInet
* Signals that this connection is in the process of being open.
* <p>
* By calling this method, the connection can be re-initialized
* with a new Socket instance before {@link #openCompleted} is called.
* with a new Socket instance before {@link #openCompleted} is called.
* This enabled the connection to close that socket if
* {@link org.apache.http.HttpConnection#shutdown shutdown}
* is called before it is fully open. Closing an unconnected socket
@ -93,10 +93,10 @@ public interface OperatedClientConnection extends HttpClientConnection, HttpInet
* or it returns successfully and then opens this connection
* which was just shut down.
* <p>
* This method can be called multiple times if the connection
* is layered over another protocol. <b>Note:</b> This method
* will <i>not</i> close the previously used socket. It is
* the caller's responsibility to close that socket if it is
* This method can be called multiple times if the connection
* is layered over another protocol. <b>Note:</b> This method
* will <i>not</i> close the previously used socket. It is
* the caller's responsibility to close that socket if it is
* no longer required.
* <p>
* The caller must invoke {@link #openCompleted} in order to complete

View File

@ -30,7 +30,7 @@
-->
</head>
<body>
The client-side connection management and handling API that provides interfaces
The client-side connection management and handling API that provides interfaces
and implementations for opening and managing client side HTTP connections.
<p>
The lowest layer of connection handling is comprised of
@ -39,18 +39,18 @@ and
{@link org.apache.http.conn.ClientConnectionOperator ClientConnectionOperator}.
The connection interface extends the core
{@link org.apache.http.HttpClientConnection HttpClientConnection}
by operations to set and update a socket. An operator encapsulates the logic to
open and layer sockets, typically using a
{@link org.apache.http.conn.scheme.SocketFactory}. The socket factory for
a protocol {@link org.apache.http.conn.scheme.Scheme} such as "http" or "https"
by operations to set and update a socket. An operator encapsulates the logic to
open and layer sockets, typically using a
{@link org.apache.http.conn.scheme.SocketFactory}. The socket factory for
a protocol {@link org.apache.http.conn.scheme.Scheme} such as "http" or "https"
can be looked up in a {@link org.apache.http.conn.scheme.SchemeRegistry}.
Applications without a need for sophisticated connection management can use
Applications without a need for sophisticated connection management can use
this layer directly.
</p>
<p>
On top of that lies the connection management layer. A
{@link org.apache.http.conn.ClientConnectionManager} internally manages
operated connections, but hands out instances of
{@link org.apache.http.conn.ClientConnectionManager} internally manages
operated connections, but hands out instances of
{@link org.apache.http.conn.ManagedClientConnection}.
This interface abstracts from the underlying socket operations and
provides convenient methods for opening and updating sockets in order
@ -61,12 +61,12 @@ automatically.
<p>
Connections obtained from a manager have to be returned after use.
This can be {@link org.apache.http.conn.ConnectionReleaseTrigger triggered}
on various levels, either by releasing the
{@link org.apache.http.conn.ManagedClientConnection connection} directly,
or by calling a method on
an {@link org.apache.http.conn.BasicManagedEntity entity} received from
the connection, or by closing the
{@link org.apache.http.conn.EofSensorInputStream stream} from which
on various levels, either by releasing the
{@link org.apache.http.conn.ManagedClientConnection connection} directly,
or by calling a method on
an {@link org.apache.http.conn.BasicManagedEntity entity} received from
the connection, or by closing the
{@link org.apache.http.conn.EofSensorInputStream stream} from which
that entity is being read.
</p>
<p>

Some files were not shown because too many files have changed in this diff Show More