You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Bruce McHaffie <br...@entrust.com> on 2004/03/09 17:11:53 UTC

Proxy detection in the Sun plugin

I've seen a couple of threads here about detecting proxy settings in applets
(ex: http://nagoya.apache.org/eyebrowse/ReadMsg?listId=128&msgNo=1884). In
case this helps someone out, Sun actually provided an API in 1.4 to let you
hook into the plugin's proxy detection logic. The code looks like this:

//  Look around for the 1.4.X plugin proxy detection class... Without it,
cannot autodetect...
Class t = Class.forName("com.sun.java.browser.net.ProxyService");
com.sun.java.browser.net.ProxyInfo[] pi =
com.sun.java.browser.net.ProxyService.getProxyInfo(sampleURL);
if (pi == null || pi.length == 0) {
    System.out.println("1.4.X reported NULL proxy (no proxy assumed)"); 
    useProxy = false;
}

This code is from a post in the Sun forums:
http://forum.java.sun.com/thread.jsp?forum=30&thread=364342

I've done a small amount of testing and it appears to work. It even parses
proxy.pac files correctly. 

Bruce.



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


Re: Proxy detection in the Sun plugin

Posted by Adrian Sutton <ad...@intencha.com>.
On 10/3/04 2:36 AM, "Ortwin Glück" <or...@nose.ch> wrote:

> 
> 
> Bruce McHaffie wrote:
>> It even parses
>> proxy.pac files correctly.
> 
> I guess the browser parses the proxy.pac, not the Sun classes. AFAIK
> proxy.pac is written in JavaScript. That's the reason why HttpClient
> does not try to interprete proxy.pac files. Maybe one can use Rhino at
> some point to do that....

No actually Sun's classes parse the pac file.  Unfortunately it really
doesn't do it very well.  Some commonly used functions are effectively
no-ops but it seems to manage to work well enough in most cases.  There is
actually a similar API available in Java 1.3 but it's a different class with
a different interface, another change appears to have been made in 1.4.2
which breaks the method Bruce mentioned (at least, it breaks it sometimes
but not always).

Needless to say, this is a very unsupported feature.

Regards,

Adrian Sutton

=======================================================================
Kangaroo Point MarchFest is an annual festival of music, art, food and
culture, that aims to build community spirit and bring all types of
people together for a time of fun and entertainment.
Sat March 20th, midday till 10pm, at Kangaroo Point Uniting Church.
http://www.soulpurpose.com.au/marchfest
=======================================================================


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


Re: Proxy detection in the Sun plugin

Posted by Ortwin Glück <or...@nose.ch>.

Bruce McHaffie wrote:
> It even parses
> proxy.pac files correctly. 

I guess the browser parses the proxy.pac, not the Sun classes. AFAIK 
proxy.pac is written in JavaScript. That's the reason why HttpClient 
does not try to interprete proxy.pac files. Maybe one can use Rhino at 
some point to do that....

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