Folks,
I've found some weird stuff that Java 1.5 does when using HTTP proxies,
and I don't know how to stop it.
To start out I'm using the pretty standard way to specify a proxy to
Java. IE:
Properties p = System.getProperties();
p.setProperty("proxySet", "true");
p.setProperty("proxyHost", "123.123.123.123");
p.setProperty("proxyPort", "8080");
System.setProperties(p);
I'm using a URLConnection and its InputStream to read from a webpage,
say http://www.google.com.
I'm also setting a Timeout for the URLConnection, and catching the
exception.
The problem is that if you specify a proxy that either doesn't exist or
is refusing connections, Java will make the URLConnection *directly* for
you. It doesn't throw an exception or in anyway tell you "oh, BTW, I'm
not using the proxy"
Using Ethereal I could see what happens.
-Send a SYN to the proxy that doesn't work
-Wait about .5 seconds
-Send another SYN to proxy that doesn't work
-wait number of seconds specified by connectionTimeout for URLConnection.
-Send SYN directly to target website (http://www.google.com)
-makes connection and does download directly between google and my computer
So my question is, does anyone know how to force java to use a proxy,
and only the proxy? Is there another way to get java to use proxies? Am
I screwed and have to send HTTP headers myself?
Thanks,
Acidus
--
Most Significant Bit Labs
www.msblabs.org
Chris Smith - 18 Jul 2005 05:45 GMT
> So my question is, does anyone know how to force java to use a proxy,
> and only the proxy? Is there another way to get java to use proxies? Am
> I screwed and have to send HTTP headers myself?
I'm not aware of a way to do this using URLConnection. By using
URLConnection, you are giving up a measure of control and asking Java to
figure out the right thing for you. If you don't like it's choices,
then you need a different API.
See Jakarta Commons HttpClient, which provides that lower level of
control.

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation