Arun,
Ohh snap! Hmmm... I think I'm going to do a couple of things... First,
I'm going to document this on the Wiki... Second of all, I think the
proxy should be set at run time if the http.proxy* system variables are
utilized. For us, its impossible to hard code our proxy, but for a
temporary fix, I've modified my code to appear as follows:
.
.
String proxyHost = System.getProperty("http.proxyHost");
int proxyPort = Integer.parseInt(System.getProperty("http.proxyPort"));
HttpClient client =
new HttpClient(new MultiThreadedHttpConnectionManager());
client.getHttpConnectionManager().
getParams().setConnectionTimeout(30000);
client.getHostConfiguration().setProxy(proxyHost,proxyPort);
.
.
Lastly, I think I'm going to see about pushing that to a more permanent
change into the repository...
Thanks for that uber fast response!
Joshua Preston.
On Wed, 2006-12-27 at 14:27 -0500, Arunkumar Dubagunta wrote:
>
> The following set of statements helped me to send requests through
> Proxy.
>
> Hope this example can help you.
>
> httpClient.getHostConfiguration().setProxy(proxyHost,proxyPort);
>
> AuthScope as = new AuthScope(proxyHost,proxyPort);
>
> httpClient.getState().setProxyCredentials(as, new
> NTCredentials(proxyUserName,proxyUserPassword,InetAddress.getLocalHost().getHostName(),networkDomainName));
>
> Note: If you have problem with the trusted certificates, you can try
> not-yet-commons-ssl.
>
> Thanks,
> Arun Kumar Dubagunta
>
> -----Original Message-----
> From: Joshua Preston [SMTP:[EMAIL PROTECTED]
> Sent: Wednesday, December 27, 2006 2:08 PM
> To: [email protected]
> Subject: HTTPClient and Proxy problems (Unknown Host)
> even with systemproxy set.
>
> Hey everyone!
>
> I am having problems getting my HTTPClient to connect through
> a proxy.
>
> I have tried setting the system properties http.proxyHost and
> http.proxyPort as well as proxyHost and proxyPort, but neither
> kicks in.
> Am I missing something?
>
> TIA!
>
> Here is the debug trace, it appears that the proxy information
> is never
> set. Perhaps I'm going about it all wrong?
>
>
> 2006/12/27 14:00:51:949 GMT-05:00 [DEBUG] HttpClient - Java
> version: 1.5.0_09
> 2006/12/27 14:00:51:950 GMT-05:00 [DEBUG] HttpClient - Java
> vendor: Sun Microsystems Inc.
> 2006/12/27 14:00:51:951 GMT-05:00 [DEBUG] HttpClient - Java
> class path: ... lots of jars ...
> 2006/12/27 14:00:51:955 GMT-05:00 [DEBUG] HttpClient -
> Operating system name: Linux
> 2006/12/27 14:00:51:957 GMT-05:00 [DEBUG] HttpClient -
> Operating system architecture: i386
> 2006/12/27 14:00:51:957 GMT-05:00 [DEBUG] HttpClient -
> Operating system version: 2.6.15-27-386
> 2006/12/27 14:00:52:086 GMT-05:00 [DEBUG] HttpClient - SUN
> 1.5: SUN (DSA key/parameter generation; DSA signing; SHA-1,
> MD5 digests; SecureRandom; X.509 certificates; JKS keystore;
> PKIX CertPathValidator; PKIX CertPathBuilder; LDAP, Collection
> CertStores)
>
> 2006/12/27 14:00:52:087 GMT-05:00 [DEBUG] HttpClient -
> SunRsaSign 1.5: Sun RSA signature provider
> 2006/12/27 14:00:52:088 GMT-05:00 [DEBUG] HttpClient - SunJSSE
> 1.5: Sun JSSE provider(PKCS12, SunX509 key/trust factories,
> SSLv3, TLSv1)
>
> 2006/12/27 14:00:52:088 GMT-05:00 [DEBUG] HttpClient - SunJCE
> 1.5: SunJCE Provider (implements RSA, DES, Triple DES, AES,
> Blowfish, ARCFOUR, RC2, PBE, Diffie-Hellman, HMAC)
>
> 2006/12/27 14:00:52:088 GMT-05:00 [DEBUG] HttpClient - SunJGSS
> 1.0: Sun (Kerberos v5)
> 2006/12/27 14:00:52:088 GMT-05:00 [DEBUG] HttpClient - SunSASL
> 1.5: Sun SASL provider(implements client mechanisms for:
> DIGEST-MD5, GSSAPI, EXTERNAL, PLAIN, CRAM-MD5; server
> mechanisms for: DIGEST-MD5, GSSAPI, CRAM-MD5)
>
> 2006/12/27 14:00:52:095 GMT-05:00 [DEBUG] DefaultHttpParams -
> Set parameter http.useragent = Jakarta
> Commons-HttpClient/3.0.1
>
> 2006/12/27 14:00:52:098 GMT-05:00 [DEBUG] DefaultHttpParams -
> Set parameter http.protocol.version = HTTP/1.1
> 2006/12/27 14:00:52:099 GMT-05:00 [DEBUG] DefaultHttpParams -
> Set parameter http.connection-manager.class = class
> org.apache.commons.httpclient.SimpleHttpConnectionManager
>
> 2006/12/27 14:00:52:099 GMT-05:00 [DEBUG] DefaultHttpParams -
> Set parameter http.protocol.cookie-policy = rfc2109
> 2006/12/27 14:00:52:099 GMT-05:00 [DEBUG] DefaultHttpParams -
> Set parameter http.protocol.element-charset = US-ASCII
> 2006/12/27 14:00:52:100 GMT-05:00 [DEBUG] DefaultHttpParams -
> Set parameter http.protocol.content-charset = ISO-8859-1
> 2006/12/27 14:00:52:101 GMT-05:00 [DEBUG] DefaultHttpParams -
> Set parameter http.method.retry-handler =
> [EMAIL PROTECTED]
>
> 2006/12/27 14:00:52:102 GMT-05:00 [DEBUG] DefaultHttpParams -
> Set parameter http.dateparser.patterns = [EEE, dd MMM yyyy
> HH:mm:ss zzz, EEEE, dd-MMM-yy HH:mm:ss zzz, EEE MMM d HH:mm:ss
> yyyy, EEE, dd-MMM-yyyy HH:mm:ss z, EEE, dd-MMM-yyyy HH-mm-ss
> z, EEE, dd MMM yy HH:mm:ss z, EEE dd-MMM-yyyy HH:mm:ss z, EEE
> dd MMM yyyy HH:mm:ss z, EEE dd-MMM-yyyy HH-mm-ss z, EEE
> dd-MMM-yy HH:mm:ss z, EEE dd MMM yy HH:mm:ss z, EEE,dd-MMM-yy
> HH:mm:ss z, EEE,dd-MMM-yyyy HH:mm:ss z, EEE, dd-MM-yyyy
> HH:mm:ss z]
>
> 2006/12/27 14:00:52:113 GMT-05:00 [DEBUG] DefaultHttpParams -
> Set parameter http.connection.timeout = 30000
> 2006/12/27 14:00:52:212 GMT-05:00 [DEBUG] HttpConnection -
> Open connection to xoap.weather.com:80
> 2006/12/27 14:00:52:226 GMT-05:00 [DEBUG] HttpMethodDirector -
> Closing the connection.
> 2006/12/27 14:00:52:226 GMT-05:00 [DEBUG] HttpMethodDirector -
> Method retry handler returned false. Automatic recovery will
> not be attempted
>
> 2006/12/27 14:00:52:226 GMT-05:00 [DEBUG] HttpConnection -
> Releasing connection back to connection manager.
> java.net.UnknownHostException: xoap.weather.com
> at
> java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)
> at
> java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
> at java.net.Socket.connect(Socket.java:516)
> at java.net.Socket.connect(Socket.java:466)
> at java.net.Socket.<init>(Socket.java:366)
> at java.net.Socket.<init>(Socket.java:239)
> at
>
> org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:79)
>
> at
>
> org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory$1.doit(ControllerThreadSocketFactory.java:90)
>
> at
>
> org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory$SocketTask.run(ControllerThreadSocketFactory.java:157)
>
> at java.lang.Thread.run(Thread.java:595)
> Exception in thread "main" java.lang.NullPointerException
> at java.io.StringReader.<init>(StringReader.java:33)
> at
> org.apache.xmlbeans.impl.store.Locale.parse(Locale.java:702)
> at
>
> org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:690)
> at
>
> org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:677)
> at
>
> org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:208)
>
> at com.weather.xml.WeatherDocument$Factory.parse(Unknown
> Source) at
> com.tfcc.weatherxml.WeatherXsd.parseXml(WeatherXsd.java:76)
>
> at
> com.tfcc.weatherxml.WeatherXsd.main(WeatherXsd.java:38)
> Java Result: 1
>
>
> --
> Joshua Preston <[EMAIL PROTECTED]>
> Software Engineer
> Twenty First Century Communications
>
>
>
> You are fairminded, just and loving.
>
>
>
>
> ______________________________________________________________________
>
>
>
> This e-mail, including attachments, may include confidential and/or
> proprietary information, and may be used only by the person or
> entity to which it is addressed. If the reader of this e-mail is
> not the intended recipient or his or her authorized agent, the
> reader is hereby notified that any dissemination, distribution or
> copying of this e-mail is prohibited. If you have received this
> e-mail in error, please notify the sender by replying to this
> message and delete this e-mail immediately.
>
--
Joshua Preston <[EMAIL PROTECTED]>
Software Engineer
Twenty First Century Communications
It is so very hard to be an
on-your-own-take-care-of-yourself-because-there-is-no-one-else-to-do-it-for-you
grown-up.