hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From greg_wat...@standardlife.com
Subject Problem with HttpClient & HostConfiguration
Date Wed, 29 Mar 2006 08:41:49 GMT

I had a method which opens up http connections to URLs outside our
firewall, and in order to hide the implementation details of our network, I
make the connection via a proxy server. I've previously used the
java.net.HttpURLConnection class, and specified a proxy by setting the http
proxy settings (http.proxyHost/http.proxyPort/http.proxySet) as system
properties. The code to open the connection itself was fairly
straightforward ('url' in the snippet below is a java.net.URL object);


HttpURLConnection conn = (HttpURLConnection) url.openConnection();


However...another application has deployed into the same JVM that my
application lives in, and due to co-existence issues (insert long story
here) I can no longer set these properties in the JVM. To try to just set
the proxy on a connection-by-connection basis, I've changed my application
code to try to use the HttpClient class to create the connection, and a
HostConfiguration object to set the proxy details;


      HttpClient client = new HttpClient();
      PostMethod postMethod = new PostMethod(url.toString());

      // ---- set various headers ----
      RequestEntity re = new StringRequestEntity(data);
      HostConfiguration hostConfig = new HostConfiguration();

      // the 'proxy' object holds the server name and port
      hostConfig.setProxy(proxy.getProxyServer(), proxy.getProxyPort());

      // do the send
      int status = client.executeMethod(postMethod);


The proxy server/port are identical to the one I used before (when using
HttpURLConnection, but I now get the following error from my server code
when I tried to do the send;


org.apache.commons.httpclient.HttpMethodDirector  I/O exception
(java.net.SocketException) caught when processing request:
Operation timed out: connect:could be due to invalid address
org.apache.commons.httpclient.HttpMethodDirector Retrying request


Any help much appreciated......

This e-mail is confidential, if you are not the intended recipient, do not
retain/disclose it and please return it to us. We virus scan and monitor
all e-mails but are not responsible for any damage caused by a
virus/alteration of our e-mail by a third party after sending.

For more information on Standard Life, visit our website

The Standard Life Assurance Company, Standard Life House, 30 Lothian Road,
Edinburgh EH1 2DH, is registered in Scotland (No. SZ4) and is authorised
and regulated by the Financial Services Authority. Tel: 0131 225 2552 -
calls may be recorded or monitored.

To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org

View raw message