Hi,
I enhanced the HttpClient by a proxy property. First set the proxy
host and port, then call any of the startSession methods. I also
improved the documentation a tiny little bit. Hopefully you find this
useful and apply it to the CVS. Thanks!
Best regards
Rainer Klute
Rainer Klute IT-Consulting GmbH i. Gr.
Dipl.-Inform.
Rainer Klute E-Mail: [EMAIL PROTECTED]
K�rner Grund 24 Telefon: +49 172 2324824
D-44143 Dortmund Telefax: +49 231 5349423
? xdocs/stylesheets/site.vsl
Index: src/java/org/apache/commons/httpclient/HttpClient.java
===================================================================
RCS file:
/home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v
retrieving revision 1.45
diff -u -r1.45 HttpClient.java
--- src/java/org/apache/commons/httpclient/HttpClient.java 17 Feb 2002 11:47:52
-0000 1.45
+++ src/java/org/apache/commons/httpclient/HttpClient.java 22 Apr 2002 09:36:57
+-0000
@@ -71,17 +71,17 @@
import org.apache.commons.httpclient.log.*;
/**
- * <p>
- * An HTTP "user-agent", containing an {@link HttpState} and
- * one or more {@link HttpConnection}s, to which
- * {@link HttpMethod}s can be applied.
- * </p>
+ * <p>An HTTP "user-agent", containing an {@link HttpState} and one or
+ * more {@link HttpConnection}s, to which {@link HttpMethod}s can be
+ * applied. Before the {@link HttpClient} can execute an {@link
+ * HttpMethod} a session must be started with one of the {@link
+ * #startSession} methods.</p>
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Rodney Waldhoff</a>
* @author Sean C. Sullivan
* @author <a href="mailto:[EMAIL PROTECTED]">dIon Gillard</a>
- * @version $Revision: 1.45 $ $Date: 2002/02/17 11:47:52 $
- */
+ * @version $Revision: 1.45 $ $Date: 2002/02/17 11:47:52 $ */
public class HttpClient {
@@ -110,6 +110,16 @@
*/
private HttpState state;
+ /**
+ * <p>The proxy host this HTTP client should use.</p>
+ */
+ private String proxyHost;
+
+ /**
+ * <p>The proxy port this HTTP client should use.</p>
+ */
+ private int proxyPort;
+
// ------------------------------------------------------------- Properties
/**
@@ -135,6 +145,68 @@
this.state = state;
}
+ /**
+ * <p>Returns this HTTP client's proxy host name or IP address.</p>
+ *
+ * @see #setProxyHost
+ * @see #getProxyPort
+ * @see #setProxyPort
+ *
+ */
+ public String getProxyHost()
+ {
+ return proxyHost;
+ }
+
+ /**
+ * <p>Sets this HTTP client's proxy host.</p>
+ *
+ * @param proxyHost The proxy's host name or IP address
+ *
+ * @see #getProxyHost
+ * @see #getProxyPort
+ * @see #setProxyPort
+ *
+ */
+ public void setProxyHost(String proxyHost)
+ {
+ if (connection != null)
+ throw new IllegalStateException
+ ("Can't change proxy for an open session.");
+ this.proxyHost = proxyHost;
+ }
+
+ /**
+ * <p>Returns this HTTP client's proxy port number.</p>
+ *
+ * @see #setProxyPort
+ * @see #getProxyHost
+ * @see #setProxyHost
+ *
+ */
+ public int getProxyPort()
+ {
+ return proxyPort;
+ }
+
+ /**
+ * <p>Sets this HTTP client's proxy port number.</p>
+ *
+ * @param proxyPort The proxy's port number
+ *
+ * @see #getProxyPort
+ * @see #getProxyHost
+ * @see #setProxyHost
+ *
+ */
+ public void setProxyPort(int proxyPort)
+ {
+ if (connection != null)
+ throw new IllegalStateException
+ ("Can't change proxy for an open session.");
+ this.proxyPort = proxyPort;
+ }
+
// --------------------------------------------------------- Public Methods
/**
@@ -165,7 +237,14 @@
log.debug("HttpClient.startSession(String,int,boolean): Host:" +
host + " Port:" + port + " HTTPS:" + https);
}
- connection = new HttpConnection(host,port,https);
+ if (connection != null)
+ throw new IllegalStateException
+ ("Cannot start an already started session.");
+ if (proxyHost == null)
+ connection = new HttpConnection(host, port, https);
+ else
+ connection = new HttpConnection(proxyHost, proxyPort, host, port,
+ https);
}
/**
@@ -198,24 +277,18 @@
*/
public void startSession(String host, int port, Credentials creds,
boolean https) {
- if (log.isDebugEnabled()) {
- log.debug(
- "HttpClient.startSession(String,int,Credentials,boolean): Host:"
- + host + " Port:" + port + " Credentials:" + creds +
- " HTTPS:" + https);
- }
getState().setCredentials(null,creds);
- connection = new HttpConnection(host,port,https);
+ startSession(host, port, https);
}
/**
- * Start an HTTP or HTTPS session with the server specified
+ * <p>Start an HTTP or HTTPS session with the server specified
* by the protocol, host and port of the given
- * <i>url</i>.
- * <p>
- * Note that everything but the protocol, host and port of the
- * given <i>url</i> is ignored.
- * </p>
+ * <i>url</i>.</p>
+ *
+ * <p>Note that everything but the protocol, host and port of the
+ * given <i>url</i> is ignored.</p>
+ *
* @param url the {@link URL URL} from which the protocol, host,
* and port of the session are determined
*
@@ -270,7 +343,9 @@
*/
public void startSession(String host, int port,
String proxyhost, int proxyport) {
- connection = new HttpConnection(proxyhost,proxyport,host,port,false);
+ this.proxyHost = proxyhost;
+ this.proxyPort = proxyport;
+ startSession(host, port, false);
}
/**
@@ -319,6 +394,9 @@
if (log.isDebugEnabled()) {
log.debug("HttpClient.endSession()");
}
+ if (connection == null)
+ throw new IllegalStateException
+ ("Cannot end a closed session.");
if (null != connection) {
connection.close();
connection = null;
Index: src/java/org/apache/commons/httpclient/HttpMethodBase.java
===================================================================
RCS file:
/home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
retrieving revision 1.28
diff -u -r1.28 HttpMethodBase.java
--- src/java/org/apache/commons/httpclient/HttpMethodBase.java 16 Apr 2002 14:30:42
-0000 1.28
+++ src/java/org/apache/commons/httpclient/HttpMethodBase.java 22 Apr 2002 09:37:04
+-0000
@@ -1261,7 +1261,7 @@
/**
* Throws an {@link IllegalStateException} if
- * used by not recycled.
+ * used but not recycled.
*/
protected void checkNotUsed() {
if (used) {
Index: src/java/org/apache/commons/httpclient/package.html
===================================================================
RCS file:
/home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/package.html,v
retrieving revision 1.4
diff -u -r1.4 package.html
--- src/java/org/apache/commons/httpclient/package.html 6 Oct 2001 00:32:44 -0000
1.4
+++ src/java/org/apache/commons/httpclient/package.html 22 Apr 2002 09:37:05 -0000
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0//EN//">
<!-- $Id: package.html,v 1.4 2001/10/06 00:32:44 rwaldhoff Exp $ -->
<html>
<head>
@@ -18,7 +19,7 @@
<p>
The basis for the abstraction is provided by three types:
</p>
- <ul><dl>
+ <dl>
<dt>{@link org.apache.commons.httpclient.HttpConnection}</dt>
<dd>
represents a network connection to some HTTP host.
@@ -35,11 +36,11 @@
request to request, such as cookies and authentication
credentials.
</dd>
- </dl></ul>
+ </dl>
<p>
and several simple bean-style classes:
</p>
- <ul><dl>
+ <dl>
<dt>{@link org.apache.commons.httpclient.Cookie}</dt>
<dd>
represents HTTP cookie.
@@ -60,7 +61,7 @@
<dd>
a username and password pair.
</dd>
- </dl></ul>
+ </dl>
<p>
{@link org.apache.commons.httpclient.HttpClient} provides a
simple "user-agent" implementation that will suffice for many
@@ -70,7 +71,7 @@
<em>HTTP Client</em> also provides several utilities that may be
useful when extending the framework:
</p>
- <ul><dl>
+ <dl>
<dt>{@link org.apache.commons.httpclient.HttpMethodBase}</dt>
<dd>
an abstract base implementation of <tt>HttpMethod</tt>,
@@ -96,6 +97,6 @@
provides utilities for encoding and decoding URI's in the
<tt>%HH</tt> format.
</dd>
- </dl></ul>
+ </dl>
</body>
</html>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>