On Wed, 2006-03-29 at 09:41 +0100, [EMAIL PROTECTED] wrote:
>
>
>
> 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);
> postMethod.setRequestEntity(re);
> HostConfiguration hostConfig = new HostConfiguration();
>
> // the 'proxy' object holds the server name and port
> hostConfig.setProxy(proxy.getProxyServer(), proxy.getProxyPort());
>
> client.setHostConfiguration(hostConfig);
Do not do this. Pass the host configuration as a parameter to the
HttpClient#executeMethod
>
> // do the send
> int status = client.executeMethod(postMethod);
>
int status = client.executeMethod(hostConfig, postMethod);
Hope this helps
Oleg
> --------------------------------------------------------------------------------
>
> 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
> http://www.standardlife.co.uk/
>
> 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]