summaryrefslogtreecommitdiffstats
path: root/src/org/apache/http/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/apache/http/client')
-rw-r--r--src/org/apache/http/client/AuthenticationHandler.java61
-rw-r--r--src/org/apache/http/client/CircularRedirectException.java70
-rw-r--r--src/org/apache/http/client/ClientProtocolException.java60
-rw-r--r--src/org/apache/http/client/CookieStore.java76
-rw-r--r--src/org/apache/http/client/CredentialsProvider.java72
-rw-r--r--src/org/apache/http/client/HttpClient.java249
-rw-r--r--src/org/apache/http/client/HttpRequestRetryHandler.java66
-rw-r--r--src/org/apache/http/client/HttpResponseException.java51
-rw-r--r--src/org/apache/http/client/NonRepeatableRequestException.java63
-rw-r--r--src/org/apache/http/client/RedirectException.java72
-rw-r--r--src/org/apache/http/client/RedirectHandler.java79
-rw-r--r--src/org/apache/http/client/RequestDirector.java92
-rw-r--r--src/org/apache/http/client/ResponseHandler.java59
-rw-r--r--src/org/apache/http/client/UserTokenHandler.java64
-rw-r--r--src/org/apache/http/client/entity/UrlEncodedFormEntity.java76
-rw-r--r--src/org/apache/http/client/methods/AbortableHttpRequest.java91
-rw-r--r--src/org/apache/http/client/methods/HttpDelete.java76
-rw-r--r--src/org/apache/http/client/methods/HttpEntityEnclosingRequestBase.java81
-rw-r--r--src/org/apache/http/client/methods/HttpGet.java83
-rw-r--r--src/org/apache/http/client/methods/HttpHead.java83
-rw-r--r--src/org/apache/http/client/methods/HttpOptions.java105
-rw-r--r--src/org/apache/http/client/methods/HttpPost.java87
-rw-r--r--src/org/apache/http/client/methods/HttpPut.java79
-rw-r--r--src/org/apache/http/client/methods/HttpRequestBase.java182
-rw-r--r--src/org/apache/http/client/methods/HttpTrace.java82
-rw-r--r--src/org/apache/http/client/methods/HttpUriRequest.java80
-rw-r--r--src/org/apache/http/client/methods/package.html40
-rw-r--r--src/org/apache/http/client/package.html41
-rw-r--r--src/org/apache/http/client/params/AllClientPNames.java65
-rw-r--r--src/org/apache/http/client/params/AuthPolicy.java58
-rw-r--r--src/org/apache/http/client/params/ClientPNames.java139
-rw-r--r--src/org/apache/http/client/params/ClientParamBean.java92
-rw-r--r--src/org/apache/http/client/params/CookiePolicy.java66
-rw-r--r--src/org/apache/http/client/params/HttpClientParams.java101
-rw-r--r--src/org/apache/http/client/params/package.html40
-rw-r--r--src/org/apache/http/client/protocol/ClientContext.java52
-rw-r--r--src/org/apache/http/client/protocol/ClientContextConfigurer.java72
-rw-r--r--src/org/apache/http/client/protocol/RequestAddCookies.java192
-rw-r--r--src/org/apache/http/client/protocol/RequestDefaultHeaders.java74
-rw-r--r--src/org/apache/http/client/protocol/RequestProxyAuthentication.java104
-rw-r--r--src/org/apache/http/client/protocol/RequestTargetAuthentication.java105
-rw-r--r--src/org/apache/http/client/protocol/ResponseProcessCookies.java146
-rw-r--r--src/org/apache/http/client/protocol/package.html40
-rw-r--r--src/org/apache/http/client/utils/CloneUtils.java75
-rw-r--r--src/org/apache/http/client/utils/URIUtils.java209
-rw-r--r--src/org/apache/http/client/utils/URLEncodedUtils.java191
-rw-r--r--src/org/apache/http/client/utils/package.html40
47 files changed, 4181 insertions, 0 deletions
diff --git a/src/org/apache/http/client/AuthenticationHandler.java b/src/org/apache/http/client/AuthenticationHandler.java
new file mode 100644
index 0000000..dacc1b8
--- /dev/null
+++ b/src/org/apache/http/client/AuthenticationHandler.java
@@ -0,0 +1,61 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/AuthenticationHandler.java $
+ * $Revision: 603318 $
+ * $Date: 2007-12-11 10:06:50 -0800 (Tue, 11 Dec 2007) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client;
+
+import java.util.Map;
+
+import org.apache.http.Header;
+import org.apache.http.HttpResponse;
+import org.apache.http.auth.AuthScheme;
+import org.apache.http.auth.AuthenticationException;
+import org.apache.http.auth.MalformedChallengeException;
+import org.apache.http.protocol.HttpContext;
+
+/**
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ */
+public interface AuthenticationHandler {
+
+ boolean isAuthenticationRequested(
+ HttpResponse response,
+ HttpContext context);
+
+ Map<String, Header> getChallenges(
+ HttpResponse response,
+ HttpContext context) throws MalformedChallengeException;
+
+ AuthScheme selectScheme(
+ Map<String, Header> challenges,
+ HttpResponse response,
+ HttpContext context) throws AuthenticationException;
+
+}
diff --git a/src/org/apache/http/client/CircularRedirectException.java b/src/org/apache/http/client/CircularRedirectException.java
new file mode 100644
index 0000000..08dca63
--- /dev/null
+++ b/src/org/apache/http/client/CircularRedirectException.java
@@ -0,0 +1,70 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/CircularRedirectException.java $
+ * $Revision: 558123 $
+ * $Date: 2007-07-20 13:29:58 -0700 (Fri, 20 Jul 2007) $
+ *
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client;
+
+/**
+ * Signals a circular redirect
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @since 4.0
+ */
+public class CircularRedirectException extends RedirectException {
+
+ private static final long serialVersionUID = 6830063487001091803L;
+
+ /**
+ * Creates a new CircularRedirectException with a <tt>null</tt> detail message.
+ */
+ public CircularRedirectException() {
+ super();
+ }
+
+ /**
+ * Creates a new CircularRedirectException with the specified detail message.
+ *
+ * @param message The exception detail message
+ */
+ public CircularRedirectException(String message) {
+ super(message);
+ }
+
+ /**
+ * 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>
+ */
+ public CircularRedirectException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/src/org/apache/http/client/ClientProtocolException.java b/src/org/apache/http/client/ClientProtocolException.java
new file mode 100644
index 0000000..b5a991a
--- /dev/null
+++ b/src/org/apache/http/client/ClientProtocolException.java
@@ -0,0 +1,60 @@
+/*
+ * $HeadURL: $
+ * $Revision: $
+ * $Date: $
+ *
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client;
+
+import java.io.IOException;
+
+/**
+ * Signals an error in the HTTP protocol.
+ */
+public class ClientProtocolException extends IOException {
+
+ private static final long serialVersionUID = -5596590843227115865L;
+
+ public ClientProtocolException() {
+ super();
+ }
+
+ public ClientProtocolException(String s) {
+ super(s);
+ }
+
+ public ClientProtocolException(Throwable cause) {
+ initCause(cause);
+ }
+
+ public ClientProtocolException(String message, Throwable cause) {
+ super(message);
+ initCause(cause);
+ }
+
+
+}
diff --git a/src/org/apache/http/client/CookieStore.java b/src/org/apache/http/client/CookieStore.java
new file mode 100644
index 0000000..bc239ac
--- /dev/null
+++ b/src/org/apache/http/client/CookieStore.java
@@ -0,0 +1,76 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/CookieStore.java $
+ * $Revision: 604434 $
+ * $Date: 2007-12-15 06:45:48 -0800 (Sat, 15 Dec 2007) $
+ *
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client;
+
+import java.util.Date;
+import java.util.List;
+
+import org.apache.http.cookie.Cookie;
+
+/**
+ * Abstract cookie store.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @since 4.0
+ */
+public interface CookieStore {
+
+ /**
+ * Adds an {@link Cookie HTTP cookie}, replacing any existing equivalent cookies.
+ * 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 cookies} in this store that have expired by
+ * the specified {@link java.util.Date date}.
+ *
+ * @return true if any cookies were purged.
+ */
+ boolean clearExpired(Date date);
+
+ /**
+ * Clears all cookies.
+ */
+ void clear();
+
+}
diff --git a/src/org/apache/http/client/CredentialsProvider.java b/src/org/apache/http/client/CredentialsProvider.java
new file mode 100644
index 0000000..8396d84
--- /dev/null
+++ b/src/org/apache/http/client/CredentialsProvider.java
@@ -0,0 +1,72 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/CredentialsProvider.java $
+ * $Revision: 558124 $
+ * $Date: 2007-07-20 13:36:47 -0700 (Fri, 20 Jul 2007) $
+ *
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client;
+
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.Credentials;
+
+/**
+ * Abstract credentials provider.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @since 4.0
+ */
+public interface CredentialsProvider {
+
+ /**
+ * 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}
+ * for the given scope.
+ *
+ * @see #getCredentials(AuthScope)
+ */
+ void setCredentials(AuthScope authscope, Credentials credentials);
+
+ /**
+ * Get the {@link Credentials credentials} for the given authentication scope.
+ *
+ * @param authscope the {@link AuthScope authentication scope}
+ * @return the credentials
+ *
+ * @see #setCredentials(AuthScope, Credentials)
+ */
+ Credentials getCredentials(AuthScope authscope);
+
+ /**
+ * Clears all credentials.
+ */
+ void clear();
+
+}
diff --git a/src/org/apache/http/client/HttpClient.java b/src/org/apache/http/client/HttpClient.java
new file mode 100644
index 0000000..aaa09e0
--- /dev/null
+++ b/src/org/apache/http/client/HttpClient.java
@@ -0,0 +1,249 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/HttpClient.java $
+ * $Revision: 676020 $
+ * $Date: 2008-07-11 09:38:49 -0700 (Fri, 11 Jul 2008) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client;
+
+import java.io.IOException;
+
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.conn.ClientConnectionManager;
+
+/**
+ * Interface for an HTTP client.
+ * HTTP clients encapsulate a smorgasbord of objects required to
+ * execute HTTP requests while handling cookies, authentication,
+ * connection management, and other features.
+ * Thread safety of HTTP clients depends on the implementation
+ * and configuration of the specific client.
+ *
+ * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
+ *
+ *
+ * <!-- empty lines to avoid svn diff problems -->
+ * @version $Revision: 676020 $
+ *
+ * @since 4.0
+ */
+public interface HttpClient {
+
+
+ /**
+ * Obtains the parameters for this client.
+ * These parameters will become defaults for all requests being
+ * executed with this client, and for the parameters of
+ * dependent objects in this client.
+ *
+ * @return the default parameters
+ */
+ HttpParams getParams()
+ ;
+
+
+ /**
+ * Obtains the connection manager used by this client.
+ *
+ * @return the connection manager
+ */
+ ClientConnectionManager getConnectionManager()
+ ;
+
+ /**
+ * Executes a request using the default context.
+ *
+ * @param request the request to execute
+ *
+ * @return the response to the request. This is always a final response,
+ * never an intermediate response with an 1xx status code.
+ * Whether redirects or authentication challenges will be returned
+ * or handled automatically depends on the implementation and
+ * configuration of this client.
+ * @throws IOException in case of a problem or the connection was aborted
+ * @throws ClientProtocolException in case of an http protocol error
+ */
+ HttpResponse execute(HttpUriRequest request)
+ throws IOException, ClientProtocolException
+ ;
+
+
+ /**
+ * Executes a request using the given context.
+ * The route to the target will be determined by the HTTP client.
+ *
+ * @param request the request to execute
+ * @param context the context to use for the execution, or
+ * <code>null</code> to use the default context
+ *
+ * @return the response to the request. This is always a final response,
+ * never an intermediate response with an 1xx status code.
+ * Whether redirects or authentication challenges will be returned
+ * or handled automatically depends on the implementation and
+ * configuration of this client.
+ * @throws IOException in case of a problem or the connection was aborted
+ * @throws ClientProtocolException in case of an http protocol error
+ */
+ HttpResponse execute(HttpUriRequest request, HttpContext context)
+ throws IOException, ClientProtocolException
+ ;
+
+
+ /**
+ * Executes a request to the target using the default context.
+ *
+ * @param target the target host for the request.
+ * Implementations may accept <code>null</code>
+ * if they can still determine a route, for example
+ * to a default target or by inspecting the request.
+ * @param request the request to execute
+ *
+ * @return the response to the request. This is always a final response,
+ * never an intermediate response with an 1xx status code.
+ * Whether redirects or authentication challenges will be returned
+ * or handled automatically depends on the implementation and
+ * configuration of this client.
+ * @throws IOException in case of a problem or the connection was aborted
+ * @throws ClientProtocolException in case of an http protocol error
+ */
+ HttpResponse execute(HttpHost target, HttpRequest request)
+ throws IOException, ClientProtocolException
+ ;
+
+ /**
+ * Executes a request to the target using the given context.
+ *
+ * @param target the target host for the request.
+ * Implementations may accept <code>null</code>
+ * if they can still determine a route, for example
+ * to a default target or by inspecting the request.
+ * @param request the request to execute
+ * @param context the context to use for the execution, or
+ * <code>null</code> to use the default context
+ *
+ * @return the response to the request. This is always a final response,
+ * never an intermediate response with an 1xx status code.
+ * Whether redirects or authentication challenges will be returned
+ * or handled automatically depends on the implementation and
+ * configuration of this client.
+ * @throws IOException in case of a problem or the connection was aborted
+ * @throws ClientProtocolException in case of an http protocol error
+ */
+ HttpResponse execute(HttpHost target, HttpRequest request,
+ HttpContext context)
+ throws IOException, ClientProtocolException
+ ;
+
+ /**
+ * Executes a request using the default context and processes the
+ * response using the given response handler.
+ *
+ * @param request the request to execute
+ * @param responseHandler the response handler
+ *
+ * @return the response object as generated by the response handler.
+ * @throws IOException in case of a problem or the connection was aborted
+ * @throws ClientProtocolException in case of an http protocol error
+ */
+ <T> T execute(
+ HttpUriRequest request,
+ ResponseHandler<? extends T> responseHandler)
+ throws IOException, ClientProtocolException
+ ;
+
+ /**
+ * Executes a request using the given context and processes the
+ * response using the given response handler.
+ *
+ * @param request the request to execute
+ * @param responseHandler the response handler
+ *
+ * @return the response object as generated by the response handler.
+ * @throws IOException in case of a problem or the connection was aborted
+ * @throws ClientProtocolException in case of an http protocol error
+ */
+ <T> T execute(
+ HttpUriRequest request,
+ ResponseHandler<? extends T> responseHandler,
+ HttpContext context)
+ throws IOException, ClientProtocolException
+ ;
+
+ /**
+ * 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.
+ * Implementations may accept <code>null</code>
+ * if they can still determine a route, for example
+ * to a default target or by inspecting the request.
+ * @param request the request to execute
+ * @param responseHandler the response handler
+ *
+ * @return the response object as generated by the response handler.
+ * @throws IOException in case of a problem or the connection was aborted
+ * @throws ClientProtocolException in case of an http protocol error
+ */
+ <T> T execute(
+ HttpHost target,
+ HttpRequest request,
+ ResponseHandler<? extends T> responseHandler)
+ throws IOException, ClientProtocolException
+ ;
+
+ /**
+ * 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.
+ * Implementations may accept <code>null</code>
+ * if they can still determine a route, for example
+ * to a default target or by inspecting the request.
+ * @param request the request to execute
+ * @param responseHandler the response handler
+ * @param context the context to use for the execution, or
+ * <code>null</code> to use the default context
+ *
+ * @return the response object as generated by the response handler.
+ * @throws IOException in case of a problem or the connection was aborted
+ * @throws ClientProtocolException in case of an http protocol error
+ */
+ <T> T execute(
+ HttpHost target,
+ HttpRequest request,
+ ResponseHandler<? extends T> responseHandler,
+ HttpContext context)
+ throws IOException, ClientProtocolException
+ ;
+
+} // interface HttpClient
diff --git a/src/org/apache/http/client/HttpRequestRetryHandler.java b/src/org/apache/http/client/HttpRequestRetryHandler.java
new file mode 100644
index 0000000..9ef8ef9
--- /dev/null
+++ b/src/org/apache/http/client/HttpRequestRetryHandler.java
@@ -0,0 +1,66 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/HttpRequestRetryHandler.java $
+ * $Revision: 535610 $
+ * $Date: 2007-05-06 06:28:13 -0700 (Sun, 06 May 2007) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client;
+
+import java.io.IOException;
+
+import org.apache.http.protocol.HttpContext;
+
+/**
+ * A handler for determining if an HttpRequest should be retried after a
+ * recoverable exception during execution.
+ *
+ * <p>
+ * Classes implementing this interface must synchronize access to shared
+ * data as methods of this interfrace may be executed from multiple threads
+ * </p>
+ *
+ * @author Michael Becke
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ */
+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
+ * unsuccessfully executed
+ * @param context the context for the request execution
+ *
+ * @return <code>true</code> if the method should be retried, <code>false</code>
+ * otherwise
+ */
+ boolean retryRequest(IOException exception, int executionCount, HttpContext context);
+
+}
diff --git a/src/org/apache/http/client/HttpResponseException.java b/src/org/apache/http/client/HttpResponseException.java
new file mode 100644
index 0000000..4d8de91
--- /dev/null
+++ b/src/org/apache/http/client/HttpResponseException.java
@@ -0,0 +1,51 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/HttpResponseException.java $
+ * $Revision: 672425 $
+ * $Date: 2008-06-27 16:33:05 -0700 (Fri, 27 Jun 2008) $
+ *
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client;
+
+/**
+ * Signals a non 2xx HTTP response.
+ */
+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;
+ }
+
+ public int getStatusCode() {
+ return this.statusCode;
+ }
+
+}
diff --git a/src/org/apache/http/client/NonRepeatableRequestException.java b/src/org/apache/http/client/NonRepeatableRequestException.java
new file mode 100644
index 0000000..13ff4d1
--- /dev/null
+++ b/src/org/apache/http/client/NonRepeatableRequestException.java
@@ -0,0 +1,63 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/NonRepeatableRequestException.java $
+ * $Revision: 664326 $
+ * $Date: 2008-06-07 04:48:27 -0700 (Sat, 07 Jun 2008) $
+ *
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client;
+
+import org.apache.http.ProtocolException;
+
+/**
+ * Signals failure to retry the request due to non-repeatable request
+ * entity.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @since 4.0
+ */
+public class NonRepeatableRequestException extends ProtocolException {
+
+ private static final long serialVersionUID = 82685265288806048L;
+
+ /**
+ * Creates a new NonRepeatableEntityException with a <tt>null</tt> detail message.
+ */
+ public NonRepeatableRequestException() {
+ super();
+ }
+
+ /**
+ * Creates a new NonRepeatableEntityException with the specified detail message.
+ *
+ * @param message The exception detail message
+ */
+ public NonRepeatableRequestException(String message) {
+ super(message);
+ }
+
+}
diff --git a/src/org/apache/http/client/RedirectException.java b/src/org/apache/http/client/RedirectException.java
new file mode 100644
index 0000000..82ea9ea
--- /dev/null
+++ b/src/org/apache/http/client/RedirectException.java
@@ -0,0 +1,72 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/RedirectException.java $
+ * $Revision: 664066 $
+ * $Date: 2008-06-06 11:13:18 -0700 (Fri, 06 Jun 2008) $
+ *
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client;
+
+import org.apache.http.ProtocolException;
+
+/**
+ * Signals violation of HTTP specification caused by an invalid redirect
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @since 4.0
+ */
+public class RedirectException extends ProtocolException {
+
+ private static final long serialVersionUID = 4418824536372559326L;
+
+ /**
+ * Creates a new RedirectException with a <tt>null</tt> detail message.
+ */
+ public RedirectException() {
+ super();
+ }
+
+ /**
+ * Creates a new RedirectException with the specified detail message.
+ *
+ * @param message The exception detail message
+ */
+ public RedirectException(String message) {
+ super(message);
+ }
+
+ /**
+ * 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>
+ */
+ public RedirectException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/src/org/apache/http/client/RedirectHandler.java b/src/org/apache/http/client/RedirectHandler.java
new file mode 100644
index 0000000..a98b4ae
--- /dev/null
+++ b/src/org/apache/http/client/RedirectHandler.java
@@ -0,0 +1,79 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/RedirectHandler.java $
+ * $Revision: 538647 $
+ * $Date: 2007-05-16 09:41:42 -0700 (Wed, 16 May 2007) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client;
+
+import java.net.URI;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.ProtocolException;
+import org.apache.http.protocol.HttpContext;
+
+/**
+ * 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>
+ * Classes implementing this interface must synchronize access to shared
+ * data as methods of this interfrace may be executed from multiple threads
+ * </p>
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ */
+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
+ * 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
+ */
+ URI getLocationURI(HttpResponse response, HttpContext context)
+ throws ProtocolException;
+
+}
diff --git a/src/org/apache/http/client/RequestDirector.java b/src/org/apache/http/client/RequestDirector.java
new file mode 100644
index 0000000..924c312
--- /dev/null
+++ b/src/org/apache/http/client/RequestDirector.java
@@ -0,0 +1,92 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/RequestDirector.java $
+ * $Revision: 676020 $
+ * $Date: 2008-07-11 09:38:49 -0700 (Fri, 11 Jul 2008) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client;
+
+import java.io.IOException;
+
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpException;
+import org.apache.http.protocol.HttpContext;
+
+/**
+ * A client-side request director.
+ * The director decides which steps are necessary to execute a request.
+ * It establishes connections and optionally processes redirects and
+ * authentication challenges. The director may therefore generate and
+ * send a sequence of requests in order to execute one initial request.
+ *
+ * <br/><b>Note:</b>
+ * It is most likely that implementations of this interface will
+ * allocate connections, and return responses that depend on those
+ * connections for reading the response entity. Such connections
+ * MUST be released, but that is out of the scope of a request director.
+ *
+ * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
+ *
+ *
+ * <!-- empty lines to avoid svn diff problems -->
+ * @version $Revision: 676020 $
+ *
+ * @since 4.0
+ */
+public interface RequestDirector {
+
+
+ /**
+ * Executes a request.
+ * <br/><b>Note:</b>
+ * For the time being, a new director is instantiated for each request.
+ * This is the same behavior as for <code>HttpMethodDirector</code>
+ * in HttpClient 3.
+ *
+ * @param target the target host for the request.
+ * Implementations may accept <code>null</code>
+ * if they can still determine a route, for example
+ * to a default target or by inspecting the request.
+ * @param request the request to execute
+ * @param context the context for executing the request
+ *
+ * @return the final response to the request.
+ * This is never an intermediate response with status code 1xx.
+ *
+ * @throws HttpException in case of a problem
+ * @throws IOException in case of an IO problem
+ * or if the connection was aborted
+ */
+ HttpResponse execute(HttpHost target, HttpRequest request,
+ HttpContext context)
+ throws HttpException, IOException
+ ;
+
+} // class ClientRequestDirector
diff --git a/src/org/apache/http/client/ResponseHandler.java b/src/org/apache/http/client/ResponseHandler.java
new file mode 100644
index 0000000..33a3391
--- /dev/null
+++ b/src/org/apache/http/client/ResponseHandler.java
@@ -0,0 +1,59 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/ResponseHandler.java $
+ * $Revision: 677240 $
+ * $Date: 2008-07-16 04:25:47 -0700 (Wed, 16 Jul 2008) $
+ *
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client;
+
+import java.io.IOException;
+
+import org.apache.http.HttpResponse;
+
+/**
+ * Handler that encapsulates the process of generating a response object
+ * from a {@link HttpResponse}.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @since 4.0
+ */
+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;
+
+}
diff --git a/src/org/apache/http/client/UserTokenHandler.java b/src/org/apache/http/client/UserTokenHandler.java
new file mode 100644
index 0000000..f8e55d8
--- /dev/null
+++ b/src/org/apache/http/client/UserTokenHandler.java
@@ -0,0 +1,64 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/UserTokenHandler.java $
+ * $Revision: 658759 $
+ * $Date: 2008-05-21 10:06:17 -0700 (Wed, 21 May 2008) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client;
+
+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
+ * specific to the current user.
+ * <p/>
+ * The user token will be used to ensure that user specific resouces will not
+ * shared with or reused by other users.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @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
+ * <code>null</code> if it is not.
+ *
+ * @param context the execution context
+ *
+ * @return user token that uniquely identifies the user or
+ * <code>null</null> if the context is not user specific.
+ */
+ Object getUserToken(HttpContext context);
+
+}
diff --git a/src/org/apache/http/client/entity/UrlEncodedFormEntity.java b/src/org/apache/http/client/entity/UrlEncodedFormEntity.java
new file mode 100644
index 0000000..89b9c45
--- /dev/null
+++ b/src/org/apache/http/client/entity/UrlEncodedFormEntity.java
@@ -0,0 +1,76 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/entity/UrlEncodedFormEntity.java $
+ * $Revision: 655107 $
+ * $Date: 2008-05-10 08:20:42 -0700 (Sat, 10 May 2008) $
+ *
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.entity;
+
+import java.io.UnsupportedEncodingException;
+import java.util.List;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.utils.URLEncodedUtils;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.protocol.HTTP;
+
+/**
+ * An entity composed of a list of url-encoded pairs.
+ * This is typically useful while sending an HTTP POST request.
+ */
+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 String encoding) throws UnsupportedEncodingException {
+ super(URLEncodedUtils.format(parameters, encoding),
+ encoding);
+ setContentType(URLEncodedUtils.CONTENT_TYPE);
+ }
+
+ /**
+ * 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
+ */
+ public UrlEncodedFormEntity (
+ final List <? extends NameValuePair> parameters) throws UnsupportedEncodingException {
+ super(URLEncodedUtils.format(parameters, HTTP.DEFAULT_CONTENT_CHARSET),
+ HTTP.DEFAULT_CONTENT_CHARSET);
+ setContentType(URLEncodedUtils.CONTENT_TYPE);
+ }
+
+}
diff --git a/src/org/apache/http/client/methods/AbortableHttpRequest.java b/src/org/apache/http/client/methods/AbortableHttpRequest.java
new file mode 100644
index 0000000..c402609
--- /dev/null
+++ b/src/org/apache/http/client/methods/AbortableHttpRequest.java
@@ -0,0 +1,91 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/AbortableHttpRequest.java $
+ * $Revision: 639600 $
+ * $Date: 2008-03-21 04:28:15 -0700 (Fri, 21 Mar 2008) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.methods;
+
+import java.io.IOException;
+
+import org.apache.http.client.HttpClient;
+import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.ClientConnectionRequest;
+import org.apache.http.conn.ConnectionReleaseTrigger;
+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
+ * down the underlying HTTP connection.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * <!-- empty lines to avoid svn diff problems -->
+ * @version $Revision: 639600 $
+ *
+ * @since 4.0
+ */
+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.
+ * Typically, this will be the {@link ManagedClientConnection} itself.
+ * If the request is already aborted, throws an {@link IOException}.
+ */
+ void setReleaseTrigger(ConnectionReleaseTrigger releaseTrigger) throws IOException;
+
+ /**
+ * Aborts this http request. Any active execution of this method should
+ * 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)
+ * @see HttpClient#execute(HttpUriRequest,
+ * org.apache.http.protocol.HttpContext)
+ * @see HttpClient#execute(org.apache.http.HttpHost,
+ * org.apache.http.HttpRequest, org.apache.http.protocol.HttpContext)
+ */
+ void abort();
+
+}
+
diff --git a/src/org/apache/http/client/methods/HttpDelete.java b/src/org/apache/http/client/methods/HttpDelete.java
new file mode 100644
index 0000000..4a0fb77
--- /dev/null
+++ b/src/org/apache/http/client/methods/HttpDelete.java
@@ -0,0 +1,76 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpDelete.java $
+ * $Revision: 664505 $
+ * $Date: 2008-06-08 06:21:20 -0700 (Sun, 08 Jun 2008) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.methods;
+
+import java.net.URI;
+
+/**
+ * HTTP DELETE method
+ * <p>
+ * The HTTP DELETE method is defined in section 9.7 of
+ * <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>:
+ * <blockquote>
+ * The DELETE method requests that the origin server delete the resource
+ * identified by the Request-URI. [...] The client cannot
+ * be guaranteed that the operation has been carried out, even if the
+ * status code returned from the origin server indicates that the action
+ * has been completed successfully.
+ * </blockquote>
+ */
+public class HttpDelete extends HttpRequestBase {
+
+ public final static String METHOD_NAME = "DELETE";
+
+
+ public HttpDelete() {
+ super();
+ }
+
+ public HttpDelete(final URI uri) {
+ super();
+ setURI(uri);
+ }
+
+ /**
+ * @throws IllegalArgumentException if the uri is invalid.
+ */
+ public HttpDelete(final String uri) {
+ super();
+ setURI(URI.create(uri));
+ }
+
+ @Override
+ public String getMethod() {
+ return METHOD_NAME;
+ }
+
+}
diff --git a/src/org/apache/http/client/methods/HttpEntityEnclosingRequestBase.java b/src/org/apache/http/client/methods/HttpEntityEnclosingRequestBase.java
new file mode 100644
index 0000000..8ac6f01
--- /dev/null
+++ b/src/org/apache/http/client/methods/HttpEntityEnclosingRequestBase.java
@@ -0,0 +1,81 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpEntityEnclosingRequestBase.java $
+ * $Revision: 674186 $
+ * $Date: 2008-07-05 05:18:54 -0700 (Sat, 05 Jul 2008) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.methods;
+
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpEntityEnclosingRequest;
+import org.apache.http.client.utils.CloneUtils;
+import org.apache.http.protocol.HTTP;
+
+/**
+ * Basic implementation of an HTTP request that can be modified.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision: 674186 $
+ *
+ * @since 4.0
+ */
+public abstract class HttpEntityEnclosingRequestBase
+ extends HttpRequestBase implements HttpEntityEnclosingRequest {
+
+ private HttpEntity entity;
+
+ public HttpEntityEnclosingRequestBase() {
+ super();
+ }
+
+ public HttpEntity getEntity() {
+ return this.entity;
+ }
+
+ 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());
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ HttpEntityEnclosingRequestBase clone =
+ (HttpEntityEnclosingRequestBase) super.clone();
+ if (this.entity != null) {
+ clone.entity = (HttpEntity) CloneUtils.clone(this.entity);
+ }
+ return clone;
+ }
+
+}
diff --git a/src/org/apache/http/client/methods/HttpGet.java b/src/org/apache/http/client/methods/HttpGet.java
new file mode 100644
index 0000000..2908f1d
--- /dev/null
+++ b/src/org/apache/http/client/methods/HttpGet.java
@@ -0,0 +1,83 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpGet.java $
+ * $Revision: 664505 $
+ * $Date: 2008-06-08 06:21:20 -0700 (Sun, 08 Jun 2008) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.methods;
+
+import java.net.URI;
+
+/**
+ * HTTP GET method.
+ * <p>
+ * The HTTP GET method is defined in section 9.3 of
+ * <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>:
+ * <blockquote>
+ * The GET method means retrieve whatever information (in the form of an
+ * entity) is identified by the Request-URI. If the Request-URI refers
+ * to a data-producing process, it is the produced data which shall be
+ * returned as the entity in the response and not the source text of the
+ * process, unless that text happens to be the output of the process.
+ * </blockquote>
+ * </p>
+ * <p>
+ * GetMethods will follow redirect requests from the http server by default.
+ * This behavour can be disabled by calling setFollowRedirects(false).</p>
+ *
+ * @version $Revision: 664505 $
+ *
+ * @since 4.0
+ */
+public class HttpGet extends HttpRequestBase {
+
+ public final static String METHOD_NAME = "GET";
+
+ public HttpGet() {
+ super();
+ }
+
+ public HttpGet(final URI uri) {
+ super();
+ setURI(uri);
+ }
+
+ /**
+ * @throws IllegalArgumentException if the uri is invalid.
+ */
+ public HttpGet(final String uri) {
+ super();
+ setURI(URI.create(uri));
+ }
+
+ @Override
+ public String getMethod() {
+ return METHOD_NAME;
+ }
+
+}
diff --git a/src/org/apache/http/client/methods/HttpHead.java b/src/org/apache/http/client/methods/HttpHead.java
new file mode 100644
index 0000000..29e58a3
--- /dev/null
+++ b/src/org/apache/http/client/methods/HttpHead.java
@@ -0,0 +1,83 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpHead.java $
+ * $Revision: 664505 $
+ * $Date: 2008-06-08 06:21:20 -0700 (Sun, 08 Jun 2008) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.methods;
+
+import java.net.URI;
+
+/**
+ * HTTP HEAD method.
+ * <p>
+ * 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
+ * return a message-body in the response. The metainformation contained
+ * in the HTTP headers in response to a HEAD request SHOULD be identical
+ * to the information sent in response to a GET request. This method can
+ * be used for obtaining metainformation about the entity implied by the
+ * request without transferring the entity-body itself. This method is
+ * often used for testing hypertext links for validity, accessibility,
+ * and recent modification.
+ * </blockquote>
+ * </p>
+ *
+ * @version $Revision: 664505 $
+ *
+ * @since 4.0
+ */
+public class HttpHead extends HttpRequestBase {
+
+ public final static String METHOD_NAME = "HEAD";
+
+ public HttpHead() {
+ super();
+ }
+
+ public HttpHead(final URI uri) {
+ super();
+ setURI(uri);
+ }
+
+ /**
+ * @throws IllegalArgumentException if the uri is invalid.
+ */
+ public HttpHead(final String uri) {
+ super();
+ setURI(URI.create(uri));
+ }
+
+ @Override
+ public String getMethod() {
+ return METHOD_NAME;
+ }
+
+}
diff --git a/src/org/apache/http/client/methods/HttpOptions.java b/src/org/apache/http/client/methods/HttpOptions.java
new file mode 100644
index 0000000..3758360
--- /dev/null
+++ b/src/org/apache/http/client/methods/HttpOptions.java
@@ -0,0 +1,105 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpOptions.java $
+ * $Revision: 664505 $
+ * $Date: 2008-06-08 06:21:20 -0700 (Sun, 08 Jun 2008) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.methods;
+
+import java.net.URI;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.http.Header;
+import org.apache.http.HeaderElement;
+import org.apache.http.HeaderIterator;
+import org.apache.http.HttpResponse;
+
+/**
+ * HTTP OPTIONS method.
+ * <p>
+ * 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
+ * communication options available on the request/response chain
+ * identified by the Request-URI. This method allows the client to
+ * determine the options and/or requirements associated with a resource,
+ * or the capabilities of a server, without implying a resource action
+ * or initiating a resource retrieval.
+ * </blockquote>
+ * </p>
+ *
+ * @version $Revision: 664505 $
+ *
+ * @since 4.0
+ */
+public class HttpOptions extends HttpRequestBase {
+
+ public final static String METHOD_NAME = "OPTIONS";
+
+ public HttpOptions() {
+ super();
+ }
+
+ public HttpOptions(final URI uri) {
+ super();
+ setURI(uri);
+ }
+
+ /**
+ * @throws IllegalArgumentException if the uri is invalid.
+ */
+ public HttpOptions(final String uri) {
+ super();
+ setURI(URI.create(uri));
+ }
+
+ @Override
+ 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()) {
+ Header header = it.nextHeader();
+ HeaderElement[] elements = header.getElements();
+ for (HeaderElement element : elements) {
+ methods.add(element.getName());
+ }
+ }
+ return methods;
+ }
+
+}
diff --git a/src/org/apache/http/client/methods/HttpPost.java b/src/org/apache/http/client/methods/HttpPost.java
new file mode 100644
index 0000000..bc58803
--- /dev/null
+++ b/src/org/apache/http/client/methods/HttpPost.java
@@ -0,0 +1,87 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpPost.java $
+ * $Revision: 664505 $
+ * $Date: 2008-06-08 06:21:20 -0700 (Sun, 08 Jun 2008) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.methods;
+
+import java.net.URI;
+
+/**
+ * HTTP POST method.
+ * <p>
+ * 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
+ * enclosed in the request as a new subordinate of the resource identified by
+ * the Request-URI in the Request-Line. POST is designed to allow a uniform
+ * 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
+ * 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>
+ * <li>Extending a database through an append operation</li>
+ * </ul>
+ * </blockquote>
+ * </p>
+ *
+ * @version $Revision: 664505 $
+ *
+ * @since 4.0
+ */
+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.
+ */
+ public HttpPost(final String uri) {
+ super();
+ setURI(URI.create(uri));
+ }
+
+ @Override
+ public String getMethod() {
+ return METHOD_NAME;
+ }
+
+}
diff --git a/src/org/apache/http/client/methods/HttpPut.java b/src/org/apache/http/client/methods/HttpPut.java
new file mode 100644
index 0000000..5b50135
--- /dev/null
+++ b/src/org/apache/http/client/methods/HttpPut.java
@@ -0,0 +1,79 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpPut.java $
+ * $Revision: 664505 $
+ * $Date: 2008-06-08 06:21:20 -0700 (Sun, 08 Jun 2008) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.methods;
+
+import java.net.URI;
+
+/**
+ * HTTP PUT method.
+ * <p>
+ * 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.
+ * </blockquote>
+ * </p>
+ *
+ * @version $Revision: 664505 $
+ *
+ * @since 4.0
+ */
+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.
+ */
+ public HttpPut(final String uri) {
+ super();
+ setURI(URI.create(uri));
+ }
+
+ @Override
+ public String getMethod() {
+ return METHOD_NAME;
+ }
+
+}
diff --git a/src/org/apache/http/client/methods/HttpRequestBase.java b/src/org/apache/http/client/methods/HttpRequestBase.java
new file mode 100644
index 0000000..8938ea0
--- /dev/null
+++ b/src/org/apache/http/client/methods/HttpRequestBase.java
@@ -0,0 +1,182 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpRequestBase.java $
+ * $Revision: 674186 $
+ * $Date: 2008-07-05 05:18:54 -0700 (Sat, 05 Jul 2008) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.methods;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.apache.http.ProtocolVersion;
+import org.apache.http.RequestLine;
+import org.apache.http.client.utils.CloneUtils;
+import org.apache.http.conn.ClientConnectionRequest;
+import org.apache.http.conn.ConnectionReleaseTrigger;
+import org.apache.http.message.AbstractHttpMessage;
+import org.apache.http.message.BasicRequestLine;
+import org.apache.http.message.HeaderGroup;
+import org.apache.http.params.HttpParams;
+import org.apache.http.params.HttpProtocolParams;
+
+/**
+ * Basic implementation of an HTTP request that can be modified.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision: 674186 $
+ *
+ * @since 4.0
+ */
+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();
+ }
+
+ public abstract String getMethod();
+
+ public ProtocolVersion getProtocolVersion() {
+ return HttpProtocolParams.getVersion(getParams());
+ }
+
+ public URI getURI() {
+ return this.uri;
+ }
+
+ public RequestLine getRequestLine() {
+ String method = getMethod();
+ ProtocolVersion ver = getProtocolVersion();
+ URI uri = getURI();
+ String uritext = null;
+ if (uri != null) {
+ uritext = uri.toASCIIString();
+ }
+ if (uritext == null || uritext.length() == 0) {
+ uritext = "/";
+ }
+ return new BasicRequestLine(method, uritext, ver);
+ }
+
+ public void setURI(final URI uri) {
+ this.uri = uri;
+ }
+
+ public void setConnectionRequest(final ClientConnectionRequest connRequest)
+ throws IOException {
+ this.abortLock.lock();
+ try {
+ if (this.aborted) {
+ throw new IOException("Request already aborted");
+ }
+
+ this.releaseTrigger = null;
+ this.connRequest = connRequest;
+ } finally {
+ this.abortLock.unlock();
+ }
+ }
+
+ public void setReleaseTrigger(final ConnectionReleaseTrigger releaseTrigger)
+ throws IOException {
+ this.abortLock.lock();
+ try {
+ 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
+ // their own locks that may be used while calling
+ // setReleaseTrigger or setConnectionRequest.
+ if (localRequest != null) {
+ localRequest.abortRequest();
+ }
+ if (localTrigger != null) {
+ try {
+ localTrigger.abortConnection();
+ } catch (IOException ex) {
+ // ignore
+ }
+ }
+ }
+
+ public boolean isAborted() {
+ return this.aborted;
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ HttpRequestBase clone = (HttpRequestBase) super.clone();
+ clone.abortLock = new ReentrantLock();
+ clone.aborted = false;
+ clone.releaseTrigger = null;
+ clone.connRequest = null;
+ clone.headergroup = (HeaderGroup) CloneUtils.clone(this.headergroup);
+ clone.params = (HttpParams) CloneUtils.clone(this.params);
+ return clone;
+ }
+
+}
diff --git a/src/org/apache/http/client/methods/HttpTrace.java b/src/org/apache/http/client/methods/HttpTrace.java
new file mode 100644
index 0000000..94f18ff
--- /dev/null
+++ b/src/org/apache/http/client/methods/HttpTrace.java
@@ -0,0 +1,82 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpTrace.java $
+ * $Revision: 664505 $
+ * $Date: 2008-06-08 06:21:20 -0700 (Sun, 08 Jun 2008) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.methods;
+
+import java.net.URI;
+
+/**
+ * HTTP TRACE method.
+ * <p>
+ * 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-
+ * back of the request message. The final recipient of the request
+ * SHOULD reflect the message received back to the client as the
+ * entity-body of a 200 (OK) response. The final recipient is either the
+ * origin server or the first proxy or gateway to receive a Max-Forwards
+ * value of zero (0) in the request (see section 14.31). A TRACE request
+ * MUST NOT include an entity.
+ * </blockquote>
+ * </p>
+ *
+ * @version $Revision: 664505 $
+ *
+ * @since 4.0
+ */
+public class HttpTrace extends HttpRequestBase {
+
+ public final static String METHOD_NAME = "TRACE";
+
+ public HttpTrace() {
+ super();
+ }
+
+ public HttpTrace(final URI uri) {
+ super();
+ setURI(uri);
+ }
+
+ /**
+ * @throws IllegalArgumentException if the uri is invalid.
+ */
+ public HttpTrace(final String uri) {
+ super();
+ setURI(URI.create(uri));
+ }
+
+ @Override
+ public String getMethod() {
+ return METHOD_NAME;
+ }
+
+}
diff --git a/src/org/apache/http/client/methods/HttpUriRequest.java b/src/org/apache/http/client/methods/HttpUriRequest.java
new file mode 100644
index 0000000..56d064a
--- /dev/null
+++ b/src/org/apache/http/client/methods/HttpUriRequest.java
@@ -0,0 +1,80 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpUriRequest.java $
+ * $Revision: 659191 $
+ * $Date: 2008-05-22 11:26:53 -0700 (Thu, 22 May 2008) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.methods;
+
+import java.net.URI;
+
+import org.apache.http.HttpRequest;
+
+/**
+ * Extended version of the {@link HttpRequest} interface that provides
+ * convenience methods to access request properties such as request URI
+ * and method type.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * <!-- empty lines to avoid svn diff problems -->
+ * @version $Revision: 659191 $
+ *
+ * @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.
+ */
+ String getMethod();
+
+ /**
+ * Returns the URI this request uses, such as
+ * <code>http://example.org/path/to/file</code>.
+ */
+ URI getURI();
+
+ /**
+ * 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();
+
+}
diff --git a/src/org/apache/http/client/methods/package.html b/src/org/apache/http/client/methods/package.html
new file mode 100644
index 0000000..c2a602a
--- /dev/null
+++ b/src/org/apache/http/client/methods/package.html
@@ -0,0 +1,40 @@
+<html>
+<head>
+<!--
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/package.html $
+ * $Revision: 555193 $
+ * $Date: 2007-07-11 00:36:47 -0700 (Wed, 11 Jul 2007) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+-->
+</head>
+<body>
+Request implementations for the various HTTP methods like GET and POST.
+
+</body>
+</html>
diff --git a/src/org/apache/http/client/package.html b/src/org/apache/http/client/package.html
new file mode 100644
index 0000000..64c7287
--- /dev/null
+++ b/src/org/apache/http/client/package.html
@@ -0,0 +1,41 @@
+<html>
+<head>
+<!--
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/package.html $
+ * $Revision: 555193 $
+ * $Date: 2007-07-11 00:36:47 -0700 (Wed, 11 Jul 2007) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+-->
+</head>
+<body>
+The API for client-side HTTP communication and
+entry point to the <i>HttpClient</i> module.
+
+</body>
+</html>
diff --git a/src/org/apache/http/client/params/AllClientPNames.java b/src/org/apache/http/client/params/AllClientPNames.java
new file mode 100644
index 0000000..e55bca7
--- /dev/null
+++ b/src/org/apache/http/client/params/AllClientPNames.java
@@ -0,0 +1,65 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/params/AllClientPNames.java $
+ * $Revision: 576078 $
+ * $Date: 2007-09-16 04:50:41 -0700 (Sun, 16 Sep 2007) $
+ *
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.params;
+
+
+import org.apache.http.params.CoreConnectionPNames;
+import org.apache.http.params.CoreProtocolPNames;
+import org.apache.http.auth.params.AuthPNames;
+import org.apache.http.cookie.params.CookieSpecPNames;
+import org.apache.http.conn.params.ConnManagerPNames;
+import org.apache.http.conn.params.ConnConnectionPNames;
+import org.apache.http.conn.params.ConnRoutePNames;
+
+
+/**
+ * Collected parameter names for the HttpClient module.
+ * This interface combines the parameter definitions of the HttpClient
+ * module and all dependency modules or informational units.
+ * It does not define additional parameter names, but references
+ * other interfaces defining parameter names.
+ * <br/>
+ * This interface is meant as a navigation aid for developers.
+ * When referring to parameter names, you should use the interfaces
+ * in which the respective constants are actually defined.
+ *
+ * @version $Revision: 576078 $
+ *
+ * @since 4.0
+ */
+public interface AllClientPNames extends
+ CoreConnectionPNames, CoreProtocolPNames,
+ ClientPNames, AuthPNames, CookieSpecPNames,
+ ConnConnectionPNames, ConnManagerPNames, ConnRoutePNames {
+
+ // no additional definitions
+}
+
diff --git a/src/org/apache/http/client/params/AuthPolicy.java b/src/org/apache/http/client/params/AuthPolicy.java
new file mode 100644
index 0000000..5bcdd38
--- /dev/null
+++ b/src/org/apache/http/client/params/AuthPolicy.java
@@ -0,0 +1,58 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/params/AuthPolicy.java $
+ * $Revision: 534839 $
+ * $Date: 2007-05-03 06:03:41 -0700 (Thu, 03 May 2007) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.params;
+
+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
+ * 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";
+
+}
diff --git a/src/org/apache/http/client/params/ClientPNames.java b/src/org/apache/http/client/params/ClientPNames.java
new file mode 100644
index 0000000..f98eeb7
--- /dev/null
+++ b/src/org/apache/http/client/params/ClientPNames.java
@@ -0,0 +1,139 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/params/ClientPNames.java $
+ * $Revision: 659595 $
+ * $Date: 2008-05-23 09:47:14 -0700 (Fri, 23 May 2008) $
+ *
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.params;
+
+
+/**
+ * Parameter names for the HttpClient module.
+ * This does not include parameters for informational units
+ * HttpAuth, HttpCookie, or HttpConn.
+ *
+ * @version $Revision: 659595 $
+ *
+ * @since 4.0
+ */
+public interface ClientPNames {
+
+ /**
+ * Defines the class name of the default {@link org.apache.http.conn.ClientConnectionManager}
+ * <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";
+
+ /**
+ * Defines the factory to create a default {@link org.apache.http.conn.ClientConnectionManager}.
+ * <p>
+ * This parameters expects a value of type {@link org.apache.http.conn.ClientConnectionManagerFactory}.
+ * </p>
+ */
+ 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}.
+ * </p>
+ */
+ public static final String HANDLE_REDIRECTS = "http.protocol.handle-redirects";
+
+ /**
+ * Defines whether relative redirects should be rejected.
+ * <p>
+ * This parameter expects a value of type {@link Boolean}.
+ * </p>
+ */
+ 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.
+ * <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,
+ * therefore optionally they can be enabled
+ * <p>
+ * This parameter expects a value of type {@link Boolean}.
+ * </p>
+ */
+ public static final String ALLOW_CIRCULAR_REDIRECTS = "http.protocol.allow-circular-redirects";
+
+ /**
+ * Defines whether authentication should be handled automatically.
+ * <p>
+ * This parameter expects a value of type {@link Boolean}.
+ * </p>
+ */
+ public static final String HANDLE_AUTHENTICATION = "http.protocol.handle-authentication";
+
+ /**
+ * Defines the name of the cookie specification to be used for HTTP state management.
+ * <p>
+ * This parameter expects a value of type {@link String}.
+ * </p>
+ */
+ public static final String COOKIE_POLICY = "http.protocol.cookie-policy";
+
+ /**
+ * Defines the virtual host name.
+ * <p>
+ * This parameter expects a value of type {@link org.apache.http.HttpHost}.
+ * </p>
+ */
+ 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.
+ * </p>
+ */
+ 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.
+ * <p>
+ * This parameter expects a value of type {@link org.apache.http.HttpHost}.
+ * </p>
+ */
+ public static final String DEFAULT_HOST = "http.default-host";
+
+}
+
diff --git a/src/org/apache/http/client/params/ClientParamBean.java b/src/org/apache/http/client/params/ClientParamBean.java
new file mode 100644
index 0000000..76431a7
--- /dev/null
+++ b/src/org/apache/http/client/params/ClientParamBean.java
@@ -0,0 +1,92 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/params/ClientParamBean.java $
+ * $Revision: 659595 $
+ * $Date: 2008-05-23 09:47:14 -0700 (Fri, 23 May 2008) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.params;
+
+import java.util.Collection;
+
+import org.apache.http.Header;
+import org.apache.http.HttpHost;
+import org.apache.http.conn.ClientConnectionManagerFactory;
+import org.apache.http.params.HttpAbstractParamBean;
+import org.apache.http.params.HttpParams;
+
+public class ClientParamBean extends HttpAbstractParamBean {
+
+ public ClientParamBean (final HttpParams params) {
+ super(params);
+ }
+
+ public void setConnectionManagerFactoryClassName (final String factory) {
+ params.setParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME, factory);
+ }
+
+ public void setConnectionManagerFactory(ClientConnectionManagerFactory factory) {
+ params.setParameter(ClientPNames.CONNECTION_MANAGER_FACTORY, factory);
+ }
+
+ public void setHandleRedirects (final boolean handle) {
+ params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, handle);
+ }
+
+ public void setRejectRelativeRedirect (final boolean reject) {
+ params.setBooleanParameter(ClientPNames.REJECT_RELATIVE_REDIRECT, reject);
+ }
+
+ public void setMaxRedirects (final int maxRedirects) {
+ params.setIntParameter(ClientPNames.MAX_REDIRECTS, maxRedirects);
+ }
+
+ public void setAllowCircularRedirects (final boolean allow) {
+ params.setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, allow);
+ }
+
+ public void setHandleAuthentication (final boolean handle) {
+ params.setBooleanParameter(ClientPNames.HANDLE_AUTHENTICATION, handle);
+ }
+
+ public void setCookiePolicy (final String policy) {
+ params.setParameter(ClientPNames.COOKIE_POLICY, policy);
+ }
+
+ public void setVirtualHost (final HttpHost host) {
+ params.setParameter(ClientPNames.VIRTUAL_HOST, host);
+ }
+
+ public void setDefaultHeaders (final Collection <Header> headers) {
+ params.setParameter(ClientPNames.DEFAULT_HEADERS, headers);
+ }
+
+ public void setDefaultHost (final HttpHost host) {
+ params.setParameter(ClientPNames.DEFAULT_HOST, host);
+ }
+
+}
diff --git a/src/org/apache/http/client/params/CookiePolicy.java b/src/org/apache/http/client/params/CookiePolicy.java
new file mode 100644
index 0000000..04a131d
--- /dev/null
+++ b/src/org/apache/http/client/params/CookiePolicy.java
@@ -0,0 +1,66 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/params/CookiePolicy.java $
+ * $Revision: 613865 $
+ * $Date: 2008-01-21 04:04:30 -0800 (Mon, 21 Jan 2008) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.params;
+
+public final class CookiePolicy {
+
+ /**
+ * 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.
+ */
+ public static final String NETSCAPE = "netscape";
+
+ /**
+ * The RFC 2109 compliant policy.
+ */
+ public static final String RFC_2109 = "rfc2109";
+
+ /**
+ * The RFC 2965 compliant policy.
+ */
+ public static final String RFC_2965 = "rfc2965";
+
+ /**
+ * The default 'best match' policy.
+ */
+ public static final String BEST_MATCH = "best-match";
+
+ private CookiePolicy() {
+ super();
+ }
+
+}
diff --git a/src/org/apache/http/client/params/HttpClientParams.java b/src/org/apache/http/client/params/HttpClientParams.java
new file mode 100644
index 0000000..c21e2b0
--- /dev/null
+++ b/src/org/apache/http/client/params/HttpClientParams.java
@@ -0,0 +1,101 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/params/HttpClientParams.java $
+ * $Revision: 659595 $
+ * $Date: 2008-05-23 09:47:14 -0700 (Fri, 23 May 2008) $
+ *
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.params;
+
+import org.apache.http.params.HttpParams;
+
+/**
+ * An adaptor for accessing HTTP client parameters in {@link HttpParams}.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision: 659595 $
+ *
+ * @since 4.0
+ */
+public class HttpClientParams {
+
+ private HttpClientParams() {
+ super();
+ }
+
+ public static boolean isRedirecting(final HttpParams params) {
+ if (params == null) {
+ throw new IllegalArgumentException("HTTP parameters may not be null");
+ }
+ return params.getBooleanParameter
+ (ClientPNames.HANDLE_REDIRECTS, true);
+ }
+
+ public static void setRedirecting(final HttpParams params, boolean value) {
+ if (params == null) {
+ throw new IllegalArgumentException("HTTP parameters may not be null");
+ }
+ params.setBooleanParameter
+ (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);
+ }
+
+ public static void setAuthenticating(final HttpParams params, boolean value) {
+ if (params == null) {
+ throw new IllegalArgumentException("HTTP parameters may not be null");
+ }
+ params.setBooleanParameter
+ (ClientPNames.HANDLE_AUTHENTICATION, value);
+ }
+
+ public static String getCookiePolicy(final HttpParams params) {
+ if (params == null) {
+ throw new IllegalArgumentException("HTTP parameters may not be null");
+ }
+ String cookiePolicy = (String)
+ params.getParameter(ClientPNames.COOKIE_POLICY);
+ if (cookiePolicy == null) {
+ return CookiePolicy.BEST_MATCH;
+ }
+ return cookiePolicy;
+ }
+
+ public static void setCookiePolicy(final HttpParams params, final String cookiePolicy) {
+ if (params == null) {
+ throw new IllegalArgumentException("HTTP parameters may not be null");
+ }
+ params.setParameter(ClientPNames.COOKIE_POLICY, cookiePolicy);
+ }
+
+}
diff --git a/src/org/apache/http/client/params/package.html b/src/org/apache/http/client/params/package.html
new file mode 100644
index 0000000..b66cdfb
--- /dev/null
+++ b/src/org/apache/http/client/params/package.html
@@ -0,0 +1,40 @@
+<html>
+<head>
+<!--
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/params/package.html $
+ * $Revision: 555193 $
+ * $Date: 2007-07-11 00:36:47 -0700 (Wed, 11 Jul 2007) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+-->
+</head>
+<body>
+Parameters for configuring <i>HttpClient</i>.
+
+</body>
+</html>
diff --git a/src/org/apache/http/client/protocol/ClientContext.java b/src/org/apache/http/client/protocol/ClientContext.java
new file mode 100644
index 0000000..1859f9e
--- /dev/null
+++ b/src/org/apache/http/client/protocol/ClientContext.java
@@ -0,0 +1,52 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/ClientContext.java $
+ * $Revision: 658759 $
+ * $Date: 2008-05-21 10:06:17 -0700 (Wed, 21 May 2008) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.protocol;
+
+
+/**
+ * {@link org.apache.http.protocol.HttpContext Context}
+ * attribute names for client.
+ */
+public interface ClientContext {
+
+ public static final String COOKIESPEC_REGISTRY = "http.cookiespec-registry";
+ public static final String AUTHSCHEME_REGISTRY = "http.authscheme-registry";
+ public static final String COOKIE_STORE = "http.cookie-store";
+ public static final String COOKIE_SPEC = "http.cookie-spec";
+ public static final String COOKIE_ORIGIN = "http.cookie-origin";
+ public static final String CREDS_PROVIDER = "http.auth.credentials-provider";
+ public static final String TARGET_AUTH_STATE = "http.auth.target-scope";
+ public static final String PROXY_AUTH_STATE = "http.auth.proxy-scope";
+ public static final String AUTH_SCHEME_PREF = "http.auth.scheme-pref";
+ public static final String USER_TOKEN = "http.user-token";
+
+}
diff --git a/src/org/apache/http/client/protocol/ClientContextConfigurer.java b/src/org/apache/http/client/protocol/ClientContextConfigurer.java
new file mode 100644
index 0000000..f2ced63
--- /dev/null
+++ b/src/org/apache/http/client/protocol/ClientContextConfigurer.java
@@ -0,0 +1,72 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/ClientContextConfigurer.java $
+ * $Revision: 654886 $
+ * $Date: 2008-05-09 10:06:12 -0700 (Fri, 09 May 2008) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.protocol;
+
+import java.util.List;
+
+import org.apache.http.auth.AuthSchemeRegistry;
+import org.apache.http.client.CookieStore;
+import org.apache.http.client.CredentialsProvider;
+import org.apache.http.cookie.CookieSpecRegistry;
+import org.apache.http.protocol.HttpContext;
+
+public class ClientContextConfigurer implements ClientContext {
+
+ private final HttpContext context;
+
+ public ClientContextConfigurer (final HttpContext context) {
+ if (context == null)
+ throw new IllegalArgumentException("HTTP context may not be null");
+ this.context = context;
+ }
+
+ 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);
+ }
+
+ public void setCredentialsProvider(final CredentialsProvider provider) {
+ this.context.setAttribute(CREDS_PROVIDER, provider);
+ }
+
+ public void setAuthSchemePref(final List<String> list) {
+ this.context.setAttribute(AUTH_SCHEME_PREF, list);
+ }
+
+}
diff --git a/src/org/apache/http/client/protocol/RequestAddCookies.java b/src/org/apache/http/client/protocol/RequestAddCookies.java
new file mode 100644
index 0000000..0de8c40
--- /dev/null
+++ b/src/org/apache/http/client/protocol/RequestAddCookies.java
@@ -0,0 +1,192 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java $
+ * $Revision: 673450 $
+ * $Date: 2008-07-02 10:35:05 -0700 (Wed, 02 Jul 2008) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.protocol;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.Header;
+import org.apache.http.HttpException;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestInterceptor;
+import org.apache.http.ProtocolException;
+import org.apache.http.client.CookieStore;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.client.params.HttpClientParams;
+import org.apache.http.conn.ManagedClientConnection;
+import org.apache.http.cookie.Cookie;
+import org.apache.http.cookie.CookieOrigin;
+import org.apache.http.cookie.CookieSpec;
+import org.apache.http.cookie.CookieSpecRegistry;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.ExecutionContext;
+
+/**
+ * Request interceptor that matches cookies available in the current
+ * {@link CookieStore} to the request being executed and generates
+ * corresponding cookierequest headers.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision: 673450 $
+ *
+ * @since 4.0
+ */
+public class RequestAddCookies implements HttpRequestInterceptor {
+
+ private final Log log = LogFactory.getLog(getClass());
+
+ public RequestAddCookies() {
+ super();
+ }
+
+ public void process(final HttpRequest request, final HttpContext context)
+ throws HttpException, IOException {
+ if (request == null) {
+ throw new IllegalArgumentException("HTTP request may not be null");
+ }
+ if (context == null) {
+ throw new IllegalArgumentException("HTTP context may not be null");
+ }
+
+ // Obtain cookie store
+ CookieStore cookieStore = (CookieStore) context.getAttribute(
+ ClientContext.COOKIE_STORE);
+ if (cookieStore == null) {
+ 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);
+ if (registry == null) {
+ 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);
+ if (conn == null) {
+ throw new IllegalStateException("Client connection not specified in HTTP context");
+ }
+
+ String policy = HttpClientParams.getCookiePolicy(request.getParams());
+ if (this.log.isDebugEnabled()) {
+ this.log.debug("CookieSpec selected: " + policy);
+ }
+
+ URI requestURI;
+ if (request instanceof HttpUriRequest) {
+ requestURI = ((HttpUriRequest) request).getURI();
+ } else {
+ try {
+ requestURI = new URI(request.getRequestLine().getUri());
+ } catch (URISyntaxException ex) {
+ throw new ProtocolException("Invalid request URI: " +
+ request.getRequestLine().getUri(), ex);
+ }
+ }
+
+ String hostName = targetHost.getHostName();
+ int port = targetHost.getPort();
+ if (port < 0) {
+ port = conn.getRemotePort();
+ }
+
+ CookieOrigin cookieOrigin = new CookieOrigin(
+ 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
+ List<Cookie> cookies = new ArrayList<Cookie>(cookieStore.getCookies());
+ // Find cookies matching the given origin
+ List<Cookie> matchedCookies = new ArrayList<Cookie>();
+ for (Cookie cookie : cookies) {
+ if (cookieSpec.match(cookie, cookieOrigin)) {
+ if (this.log.isDebugEnabled()) {
+ this.log.debug("Cookie " + cookie + " match " + cookieOrigin);
+ }
+ matchedCookies.add(cookie);
+ }
+ }
+ // Generate Cookie request headers
+ if (!matchedCookies.isEmpty()) {
+ List<Header> headers = cookieSpec.formatCookies(matchedCookies);
+ for (Header header : headers) {
+ request.addHeader(header);
+ }
+ }
+
+ int ver = cookieSpec.getVersion();
+ if (ver > 0) {
+ boolean needVersionHeader = false;
+ for (Cookie cookie : matchedCookies) {
+ if (ver != cookie.getVersion()) {
+ needVersionHeader = true;
+ }
+ }
+
+ if (needVersionHeader) {
+ Header header = cookieSpec.getVersionHeader();
+ if (header != null) {
+ // Advertise cookie version support
+ request.addHeader(header);
+ }
+ }
+ }
+
+ // 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);
+ }
+
+}
diff --git a/src/org/apache/http/client/protocol/RequestDefaultHeaders.java b/src/org/apache/http/client/protocol/RequestDefaultHeaders.java
new file mode 100644
index 0000000..27d5cc7
--- /dev/null
+++ b/src/org/apache/http/client/protocol/RequestDefaultHeaders.java
@@ -0,0 +1,74 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestDefaultHeaders.java $
+ * $Revision: 653041 $
+ * $Date: 2008-05-03 03:39:28 -0700 (Sat, 03 May 2008) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.protocol;
+
+import java.io.IOException;
+import java.util.Collection;
+
+import org.apache.http.Header;
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestInterceptor;
+import org.apache.http.client.params.ClientPNames;
+import org.apache.http.protocol.HttpContext;
+
+/**
+ * Request interceptor that adds default request headers.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision: 653041 $
+ *
+ * @since 4.0
+ */
+public class RequestDefaultHeaders implements HttpRequestInterceptor {
+
+ public RequestDefaultHeaders() {
+ super();
+ }
+
+ public void process(final HttpRequest request, final HttpContext context)
+ throws HttpException, IOException {
+ if (request == null) {
+ throw new IllegalArgumentException("HTTP request may not be null");
+ }
+ // Add default headers
+ Collection<?> defHeaders = (Collection<?>) request.getParams().getParameter(
+ ClientPNames.DEFAULT_HEADERS);
+ if (defHeaders != null) {
+ for (Object defHeader : defHeaders) {
+ request.addHeader((Header) defHeader);
+ }
+ }
+ }
+
+}
diff --git a/src/org/apache/http/client/protocol/RequestProxyAuthentication.java b/src/org/apache/http/client/protocol/RequestProxyAuthentication.java
new file mode 100644
index 0000000..b4dfe76
--- /dev/null
+++ b/src/org/apache/http/client/protocol/RequestProxyAuthentication.java
@@ -0,0 +1,104 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestProxyAuthentication.java $
+ * $Revision: 673450 $
+ * $Date: 2008-07-02 10:35:05 -0700 (Wed, 02 Jul 2008) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.protocol;
+
+import java.io.IOException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestInterceptor;
+import org.apache.http.auth.AUTH;
+import org.apache.http.auth.AuthScheme;
+import org.apache.http.auth.AuthState;
+import org.apache.http.auth.AuthenticationException;
+import org.apache.http.auth.Credentials;
+import org.apache.http.protocol.HttpContext;
+
+/**
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision: 673450 $
+ *
+ * @since 4.0
+ */
+public class RequestProxyAuthentication implements HttpRequestInterceptor {
+
+ private final Log log = LogFactory.getLog(getClass());
+
+ public RequestProxyAuthentication() {
+ super();
+ }
+
+ public void process(final HttpRequest request, final HttpContext context)
+ throws HttpException, IOException {
+ if (request == null) {
+ throw new IllegalArgumentException("HTTP request may not be null");
+ }
+ if (context == null) {
+ throw new IllegalArgumentException("HTTP context may not be null");
+ }
+
+ if (request.containsHeader(AUTH.PROXY_AUTH_RESP)) {
+ return;
+ }
+
+ // Obtain authentication state
+ AuthState authState = (AuthState) context.getAttribute(
+ ClientContext.PROXY_AUTH_STATE);
+ if (authState == null) {
+ return;
+ }
+
+ AuthScheme authScheme = authState.getAuthScheme();
+ if (authScheme == null) {
+ return;
+ }
+
+ Credentials creds = authState.getCredentials();
+ if (creds == null) {
+ this.log.debug("User credentials not available");
+ return;
+ }
+ if (authState.getAuthScope() != null || !authScheme.isConnectionBased()) {
+ try {
+ request.addHeader(authScheme.authenticate(creds, request));
+ } catch (AuthenticationException ex) {
+ if (this.log.isErrorEnabled()) {
+ this.log.error("Proxy authentication error: " + ex.getMessage());
+ }
+ }
+ }
+ }
+
+}
diff --git a/src/org/apache/http/client/protocol/RequestTargetAuthentication.java b/src/org/apache/http/client/protocol/RequestTargetAuthentication.java
new file mode 100644
index 0000000..c140183
--- /dev/null
+++ b/src/org/apache/http/client/protocol/RequestTargetAuthentication.java
@@ -0,0 +1,105 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestTargetAuthentication.java $
+ * $Revision: 673450 $
+ * $Date: 2008-07-02 10:35:05 -0700 (Wed, 02 Jul 2008) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.protocol;
+
+import java.io.IOException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestInterceptor;
+import org.apache.http.auth.AUTH;
+import org.apache.http.auth.AuthScheme;
+import org.apache.http.auth.AuthState;
+import org.apache.http.auth.AuthenticationException;
+import org.apache.http.auth.Credentials;
+import org.apache.http.protocol.HttpContext;
+
+/**
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision: 673450 $
+ *
+ * @since 4.0
+ */
+public class RequestTargetAuthentication implements HttpRequestInterceptor {
+
+ private final Log log = LogFactory.getLog(getClass());
+
+ public RequestTargetAuthentication() {
+ super();
+ }
+
+ public void process(final HttpRequest request, final HttpContext context)
+ throws HttpException, IOException {
+ if (request == null) {
+ throw new IllegalArgumentException("HTTP request may not be null");
+ }
+ if (context == null) {
+ throw new IllegalArgumentException("HTTP context may not be null");
+ }
+
+ if (request.containsHeader(AUTH.WWW_AUTH_RESP)) {
+ return;
+ }
+
+ // Obtain authentication state
+ AuthState authState = (AuthState) context.getAttribute(
+ ClientContext.TARGET_AUTH_STATE);
+ if (authState == null) {
+ return;
+ }
+
+ AuthScheme authScheme = authState.getAuthScheme();
+ if (authScheme == null) {
+ return;
+ }
+
+ Credentials creds = authState.getCredentials();
+ if (creds == null) {
+ this.log.debug("User credentials not available");
+ return;
+ }
+
+ if (authState.getAuthScope() != null || !authScheme.isConnectionBased()) {
+ try {
+ request.addHeader(authScheme.authenticate(creds, request));
+ } catch (AuthenticationException ex) {
+ if (this.log.isErrorEnabled()) {
+ this.log.error("Authentication error: " + ex.getMessage());
+ }
+ }
+ }
+ }
+
+}
diff --git a/src/org/apache/http/client/protocol/ResponseProcessCookies.java b/src/org/apache/http/client/protocol/ResponseProcessCookies.java
new file mode 100644
index 0000000..0689e93
--- /dev/null
+++ b/src/org/apache/http/client/protocol/ResponseProcessCookies.java
@@ -0,0 +1,146 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java $
+ * $Revision: 673450 $
+ * $Date: 2008-07-02 10:35:05 -0700 (Wed, 02 Jul 2008) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.protocol;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.Header;
+import org.apache.http.HeaderIterator;
+import org.apache.http.HttpException;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpResponseInterceptor;
+import org.apache.http.client.CookieStore;
+import org.apache.http.cookie.Cookie;
+import org.apache.http.cookie.CookieOrigin;
+import org.apache.http.cookie.CookieSpec;
+import org.apache.http.cookie.MalformedCookieException;
+import org.apache.http.cookie.SM;
+import org.apache.http.protocol.HttpContext;
+
+/**
+ * Response interceptor that populates the current {@link CookieStore} with data
+ * contained in response cookies received in the given the HTTP response.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision: 673450 $
+ *
+ * @since 4.0
+ */
+public class ResponseProcessCookies implements HttpResponseInterceptor {
+
+ private final Log log = LogFactory.getLog(getClass());
+
+ public ResponseProcessCookies() {
+ super();
+ }
+
+ public void process(final HttpResponse response, final HttpContext context)
+ throws HttpException, IOException {
+ if (response == null) {
+ throw new IllegalArgumentException("HTTP request may not be null");
+ }
+ if (context == null) {
+ throw new IllegalArgumentException("HTTP context may not be null");
+ }
+
+ // Obtain cookie store
+ CookieStore cookieStore = (CookieStore) context.getAttribute(
+ ClientContext.COOKIE_STORE);
+ if (cookieStore == null) {
+ this.log.info("Cookie store not available in HTTP context");
+ return;
+ }
+ // Obtain actual CookieSpec instance
+ CookieSpec cookieSpec = (CookieSpec) context.getAttribute(
+ ClientContext.COOKIE_SPEC);
+ if (cookieSpec == null) {
+ this.log.info("CookieSpec not available in HTTP context");
+ return;
+ }
+ // Obtain actual CookieOrigin instance
+ CookieOrigin cookieOrigin = (CookieOrigin) context.getAttribute(
+ ClientContext.COOKIE_ORIGIN);
+ if (cookieOrigin == null) {
+ this.log.info("CookieOrigin not available in HTTP context");
+ return;
+ }
+ 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.
+ // Cookie2 will replace equivalent Cookie instances
+ it = response.headerIterator(SM.SET_COOKIE2);
+ processCookies(it, cookieSpec, cookieOrigin, cookieStore);
+ }
+ }
+
+ private void processCookies(
+ final HeaderIterator iterator,
+ final CookieSpec cookieSpec,
+ final CookieOrigin cookieOrigin,
+ final CookieStore cookieStore) {
+ while (iterator.hasNext()) {
+ Header header = iterator.nextHeader();
+ try {
+ List<Cookie> cookies = cookieSpec.parse(header, cookieOrigin);
+ for (Cookie cookie : cookies) {
+ try {
+ cookieSpec.validate(cookie, cookieOrigin);
+ cookieStore.addCookie(cookie);
+
+ if (this.log.isDebugEnabled()) {
+ this.log.debug("Cookie accepted: \""
+ + cookie + "\". ");
+ }
+ } catch (MalformedCookieException ex) {
+ if (this.log.isWarnEnabled()) {
+ this.log.warn("Cookie rejected: \""
+ + cookie + "\". " + ex.getMessage());
+ }
+ }
+ }
+ } catch (MalformedCookieException ex) {
+ if (this.log.isWarnEnabled()) {
+ this.log.warn("Invalid cookie header: \""
+ + header + "\". " + ex.getMessage());
+ }
+ }
+ }
+ }
+
+}
diff --git a/src/org/apache/http/client/protocol/package.html b/src/org/apache/http/client/protocol/package.html
new file mode 100644
index 0000000..43dd0d6
--- /dev/null
+++ b/src/org/apache/http/client/protocol/package.html
@@ -0,0 +1,40 @@
+<html>
+<head>
+<!--
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/package.html $
+ * $Revision: 555193 $
+ * $Date: 2007-07-11 00:36:47 -0700 (Wed, 11 Jul 2007) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+-->
+</head>
+<body>
+Additional request and response interceptors.
+
+</body>
+</html>
diff --git a/src/org/apache/http/client/utils/CloneUtils.java b/src/org/apache/http/client/utils/CloneUtils.java
new file mode 100644
index 0000000..fec534b
--- /dev/null
+++ b/src/org/apache/http/client/utils/CloneUtils.java
@@ -0,0 +1,75 @@
+/*
+ * $HeadURL:$
+ * $Revision:$
+ * $Date:$
+ *
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.client.utils;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * A collection of utilities to workaround limitations of Java clone framework.
+ */
+public class CloneUtils {
+
+ public static Object clone(final Object obj) throws CloneNotSupportedException {
+ if (obj == null) {
+ return null;
+ }
+ if (obj instanceof Cloneable) {
+ Class<?> clazz = obj.getClass ();
+ Method m;
+ try {
+ m = clazz.getMethod("clone", (Class[]) null);
+ } catch (NoSuchMethodException ex) {
+ throw new NoSuchMethodError(ex.getMessage());
+ }
+ try {
+ return m.invoke(obj, (Object []) null);
+ } catch (InvocationTargetException ex) {
+ Throwable cause = ex.getCause();
+ if (cause instanceof CloneNotSupportedException) {
+ throw ((CloneNotSupportedException) cause);
+ } else {
+ throw new Error("Unexpected exception", cause);
+ }
+ } catch (IllegalAccessException ex) {
+ throw new IllegalAccessError(ex.getMessage());
+ }
+ } else {
+ throw new CloneNotSupportedException();
+ }
+ }
+
+ /**
+ * This class should not be instantiated.
+ */
+ private CloneUtils() {
+ }
+
+}
diff --git a/src/org/apache/http/client/utils/URIUtils.java b/src/org/apache/http/client/utils/URIUtils.java
new file mode 100644
index 0000000..1cbb9af
--- /dev/null
+++ b/src/org/apache/http/client/utils/URIUtils.java
@@ -0,0 +1,209 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/utils/URIUtils.java $
+ * $Revision: 653041 $
+ * $Date: 2008-05-03 03:39:28 -0700 (Sat, 03 May 2008) $
+ *
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.client.utils;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.http.HttpHost;
+
+/**
+ * A collection of utilities for {@link URI URIs}, to workaround
+ * bugs within the class or for ease-of-use features.
+ */
+public class URIUtils {
+
+ /**
+ * Constructs a {@link URI} using all the parameters. This should be
+ * used instead of
+ * {@link URI#URI(String, String, String, int, String, String, String)}
+ * or any of the other URI multi-argument URI constructors.
+ *
+ * See <a
+ * href="https://issues.apache.org/jira/browse/HTTPCLIENT-730">HTTPCLIENT-730</a>
+ * for more information.
+ *
+ * @param scheme
+ * Scheme name
+ * @param host
+ * Host name
+ * @param port
+ * Port number
+ * @param path
+ * Path
+ * @param query
+ * 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
+ * components violates RFC&nbsp;2396, or if the authority
+ * component of the string is present but cannot be parsed
+ * as a server-based authority
+ */
+ public static URI createURI(
+ final String scheme,
+ final String host,
+ int port,
+ final String path,
+ final String query,
+ final String fragment) throws URISyntaxException {
+
+ StringBuilder buffer = new StringBuilder();
+ if (host != null) {
+ if (scheme != null) {
+ buffer.append(scheme);
+ buffer.append("://");
+ }
+ buffer.append(host);
+ if (port > 0) {
+ buffer.append(':');
+ buffer.append(port);
+ }
+ }
+ if (path == null || !path.startsWith("/")) {
+ buffer.append('/');
+ }
+ if (path != null) {
+ buffer.append(path);
+ }
+ if (query != null) {
+ buffer.append('?');
+ buffer.append(query);
+ }
+ if (fragment != null) {
+ buffer.append('#');
+ buffer.append(fragment);
+ }
+ return new URI(buffer.toString());
+ }
+
+ /**
+ * A convenience method for creating a new {@link URI} whose scheme, host
+ * 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 HttpHost target,
+ boolean dropFragment) throws URISyntaxException {
+ if (uri == null) {
+ throw new IllegalArgumentException("URI may nor be null");
+ }
+ if (target != null) {
+ return URIUtils.createURI(
+ target.getSchemeName(),
+ target.getHostName(),
+ target.getPort(),
+ uri.getRawPath(),
+ uri.getRawQuery(),
+ dropFragment ? null : uri.getRawFragment());
+ } else {
+ return URIUtils.createURI(
+ null,
+ null,
+ -1,
+ uri.getRawPath(),
+ uri.getRawQuery(),
+ dropFragment ? null : uri.getRawFragment());
+ }
+ }
+
+ /**
+ * A convenience method for
+ * {@link URIUtils#rewriteURI(URI, HttpHost, boolean)} that always keeps the
+ * fragment.
+ */
+ public static URI rewriteURI(
+ 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>)
+ *
+ * @param baseURI the base URI
+ * @param reference the URI reference
+ * @return the resulting URI
+ */
+ public static URI resolve(final URI baseURI, final String reference) {
+ return URIUtils.resolve(baseURI, URI.create(reference));
+ }
+
+ /**
+ * 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>)
+ *
+ * @param baseURI the base URI
+ * @param reference the URI reference
+ * @return the resulting URI
+ */
+ public static URI resolve(final URI baseURI, URI reference){
+ if (baseURI == null) {
+ throw new IllegalArgumentException("Base URI may nor be null");
+ }
+ if (reference == null) {
+ throw new IllegalArgumentException("Reference URI may nor be null");
+ }
+ boolean emptyReference = reference.toString().length() == 0;
+ if (emptyReference) {
+ reference = URI.create("#");
+ }
+ URI resolved = baseURI.resolve(reference);
+ if (emptyReference) {
+ String resolvedString = resolved.toString();
+ resolved = URI.create(resolvedString.substring(0,
+ resolvedString.indexOf('#')));
+ }
+ return resolved;
+ }
+
+ /**
+ * This class should not be instantiated.
+ */
+ private URIUtils() {
+ }
+
+}
diff --git a/src/org/apache/http/client/utils/URLEncodedUtils.java b/src/org/apache/http/client/utils/URLEncodedUtils.java
new file mode 100644
index 0000000..8b08f90
--- /dev/null
+++ b/src/org/apache/http/client/utils/URLEncodedUtils.java
@@ -0,0 +1,191 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/utils/URLEncodedUtils.java $
+ * $Revision: 655107 $
+ * $Date: 2008-05-10 08:20:42 -0700 (Sat, 10 May 2008) $
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.utils;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Scanner;
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.NameValuePair;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.protocol.HTTP;
+import org.apache.http.util.EntityUtils;
+
+/**
+ * A collection of utilities for encoding URLs.
+ */
+public class URLEncodedUtils {
+
+ public static final String CONTENT_TYPE = "application/x-www-form-urlencoded";
+ private static final String PARAMETER_SEPARATOR = "&";
+ private static final String NAME_VALUE_SEPARATOR = "=";
+
+ /**
+ * Returns a list of {@link NameValuePair NameValuePairs} as built from the
+ * URI's query portion. For example, a URI of
+ * http://example.org/path/to/file?a=1&b=2&c=3 would return a list of three
+ * 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
+ * encoding to use while parsing the query
+ */
+ public static List <NameValuePair> parse (final URI uri, final String encoding) {
+ List <NameValuePair> result = Collections.emptyList();
+ final String query = uri.getRawQuery();
+ if (query != null && query.length() > 0) {
+ result = new ArrayList <NameValuePair>();
+ parse(result, new Scanner(query), encoding);
+ }
+ return result;
+ }
+
+ /**
+ * Returns a list of {@link NameValuePair NameValuePairs} as parsed from an
+ * {@link HttpEntity}. The encoding is taken from the entity's
+ * Content-Encoding header.
+ * <p>
+ * This is typically used while parsing an HTTP POST.
+ *
+ * @param entity
+ * The entity to parse
+ * @throws IOException
+ * If there was an exception getting the entity's data.
+ */
+ public static List <NameValuePair> parse (
+ final HttpEntity entity) throws IOException {
+ List <NameValuePair> result = Collections.emptyList();
+ if (isEncoded(entity)) {
+ final String content = EntityUtils.toString(entity);
+ final Header encoding = entity.getContentEncoding();
+ if (content != null && content.length() > 0) {
+ result = new ArrayList <NameValuePair>();
+ parse(result, new Scanner(content),
+ encoding != null ? encoding.getValue() : null);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Returns true if the entity's Content-Type header is
+ * <code>application/x-www-form-urlencoded</code>.
+ */
+ public static boolean isEncoded (final HttpEntity entity) {
+ final Header contentType = entity.getContentType();
+ return (contentType != null && contentType.getValue().equalsIgnoreCase(CONTENT_TYPE));
+ }
+
+ /**
+ * Adds all parameters within the Scanner to the list of
+ * <code>parameters</code>, as encoded by <code>encoding</code>. For
+ * 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
+ * Input that contains the parameters to parse.
+ * @param encoding
+ * Encoding to use when decoding the parameters.
+ */
+ public static void parse (
+ final List <NameValuePair> parameters,
+ final Scanner scanner,
+ final String encoding) {
+ scanner.useDelimiter(PARAMETER_SEPARATOR);
+ while (scanner.hasNext()) {
+ final String[] nameValue = scanner.next().split(NAME_VALUE_SEPARATOR);
+ if (nameValue.length == 0 || nameValue.length > 2)
+ throw new IllegalArgumentException("bad parameter");
+
+ final String name = decode(nameValue[0], encoding);
+ String value = null;
+ if (nameValue.length == 2)
+ value = decode(nameValue[1], encoding);
+ parameters.add(new BasicNameValuePair(name, value));
+ }
+ }
+
+ /**
+ * 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 String encoding) {
+ final StringBuilder result = new StringBuilder();
+ for (final NameValuePair parameter : parameters) {
+ final String encodedName = encode(parameter.getName(), encoding);
+ final String value = parameter.getValue();
+ final String encodedValue = value != null ? encode(value, encoding) : "";
+ if (result.length() > 0)
+ result.append(PARAMETER_SEPARATOR);
+ result.append(encodedName);
+ result.append(NAME_VALUE_SEPARATOR);
+ result.append(encodedValue);
+ }
+ return result.toString();
+ }
+
+ private static String decode (final String content, final String encoding) {
+ try {
+ return URLDecoder.decode(content,
+ encoding != null ? encoding : HTTP.DEFAULT_CONTENT_CHARSET);
+ } catch (UnsupportedEncodingException problem) {
+ throw new IllegalArgumentException(problem);
+ }
+ }
+
+ private static String encode (final String content, final String encoding) {
+ try {
+ return URLEncoder.encode(content,
+ encoding != null ? encoding : HTTP.DEFAULT_CONTENT_CHARSET);
+ } catch (UnsupportedEncodingException problem) {
+ throw new IllegalArgumentException(problem);
+ }
+ }
+
+}
diff --git a/src/org/apache/http/client/utils/package.html b/src/org/apache/http/client/utils/package.html
new file mode 100644
index 0000000..7abeb93
--- /dev/null
+++ b/src/org/apache/http/client/utils/package.html
@@ -0,0 +1,40 @@
+<html>
+<head>
+<!--
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/utils/package.html $
+ * $Revision: 555193 $
+ * $Date: 2007-07-11 00:36:47 -0700 (Wed, 11 Jul 2007) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+-->
+</head>
+<body>
+Helpers and utility classes for <i>HttpClient</i>.
+
+</body>
+</html>