HttpClient use Proxy Server with Basic Auth

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

HttpClient use Proxy Server with Basic Auth

vngarla
Hi,

I'm trying to get URLs via a Proxy Server.  No matter what I try, i get
an SC 407 - Proxy Authorization Required.  Can somebody send me an example
of using HttpClient with a Proxy Server which requires Basic Auth?

This is what I'm doing:
        String _proxyHost = System.getProperty("http.proxyHost");
        if(_proxyHost != null) {
            HostConfiguration _hc = HostConfiguration();
            _hc.setProxy(_proxyHost, Integer.parseInt(System.getProperty("http.proxyPort")));
            _client.setHostConfiguration(_hc);
            Credentials _creds = new UsernamePasswordCredentials(System.getProperty("http.proxyUser"),
System.getProperty("http.proxyPassword"));
            _client.getState().setProxyCredentials(null, _proxyHost, _creds);

        }
        GetMethod get = new GetMethod(aURL);
        int _status = _client.executeMethod(get);
        //this doesn't work either: int _status = _client.executeMethod(_client.getHostConfiguration(),
get, _client.getState());


TIA,

Vijay Garla

__________________________________________________________________
Das Italien-Gewinnspiel
Jetzt bei der Italien-Reise mitspielen und einen von 30 Preisen gewinnen.
http://spielmanege.tiscali.de/italienreise/italien.php




---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

AW: HttpClient use Proxy Server with Basic Auth

vngarla
A bit more information: The proxy sends the following Proxy-Authenticate
Headers back:

Proxy-Authenticate: NTLM
Proxy-Authenticate: Basic realm="s991057.suvanet.ch"
Proxy-Authenticate: Kerberos
Proxy-Authenticate: Negotiate
...

I just tried this with the good old HTTPClient.HttpClient, and I got the
exception that Negotiate wasn't supported:
HTTPClient.AuthSchemeNotImplException: Negotiate
        at HTTPClient.DefaultAuthHandler.getAuthorization(DefaultAuthHandler.java:150)
        at HTTPClient.AuthorizationInfo.queryAuthHandler(AuthorizationInfo.java:335)
        at HTTPClient.AuthorizationModule.setAuthHeaders(AuthorizationModule.java:572)

Could it be that jakarta HttpClient proxy auth doesn't work when multiple
authentication schemes are allowed?  I'm using 2.0 rc1 at the moment.

TIA,

Vijay



>-- Urspr√ľngliche Nachricht --
>Reply-To: "Jakarta Commons Users List" <[hidden email]>
>Date: Fri, 3 Jun 2005 17:36:42 +0200
>From: [hidden email]
>Subject: HttpClient use Proxy Server with Basic Auth
>To: [hidden email]
>
>
>Hi,

I'm trying to get URLs via a Proxy Server.  No matter what I try, i get
an SC 407 - Proxy Authorization Required.  Can somebody send me an example
of using HttpClient with a Proxy Server which requires Basic Auth?

This is what I'm doing:

>      String _proxyHost = System.getProperty("http.proxyHost");
        if(_proxyHost != null) {
            HostConfiguration _hc = HostConfiguration();
            _hc.setProxy(_proxyHost, Integer.parseInt(System.getProperty("http.proxyPort")));

>           _client.setHostConfiguration(_hc);
            Credentials _creds = new UsernamePasswordCredentials(System.getProperty("http.proxyUser"),
System.getProperty("http.proxyPassword"));
            _client.getState().setProxyCredentials(null,
>proxyHost, _creds);

        }
        GetMethod get = new GetMethod(aURL);
        int _status = _client.executeMethod(get);
        //this doesn't work either: int _status = _client.executeMethod(_client.getHostConfiguration(),
get, _client.get
>tate());


TIA,

Vijay Garla

__________________________________________________________________
Das Italien-Gewinnspiel
Jetzt bei der Italien-Reise mitspielen und einen von 30 Preisen gewinnen.
http://spielmanege.tiscali.de/italienreise/ital
>en.php




---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]




__________________________________________________________________
Das Italien-Gewinnspiel
Jetzt bei der Italien-Reise mitspielen und einen von 30 Preisen gewinnen.
http://spielmanege.tiscali.de/italienreise/italien.php




---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: AW: HttpClient use Proxy Server with Basic Auth

olegk
Vijay,

It is not humanly possible for us to support every single release of
HttpClient out there. Please upgrade to the latest stable version (2.0.2
or 3.0-rc3), retest and if the problem persists, follow the instructions
of the troubleshooting guide

http://jakarta.apache.org/commons/httpclient/3.0/troubleshooting.html

Oleg


On Fri, 2005-06-03 at 17:54 +0200, [hidden email] wrote:

> A bit more information: The proxy sends the following Proxy-Authenticate
> Headers back:
>
> Proxy-Authenticate: NTLM
> Proxy-Authenticate: Basic realm="s991057.suvanet.ch"
> Proxy-Authenticate: Kerberos
> Proxy-Authenticate: Negotiate
> ...
>
> I just tried this with the good old HTTPClient.HttpClient, and I got the
> exception that Negotiate wasn't supported:
> HTTPClient.AuthSchemeNotImplException: Negotiate
>         at HTTPClient.DefaultAuthHandler.getAuthorization(DefaultAuthHandler.java:150)
>         at HTTPClient.AuthorizationInfo.queryAuthHandler(AuthorizationInfo.java:335)
>         at HTTPClient.AuthorizationModule.setAuthHeaders(AuthorizationModule.java:572)
>
> Could it be that jakarta HttpClient proxy auth doesn't work when multiple
> authentication schemes are allowed?  I'm using 2.0 rc1 at the moment.
>
> TIA,
>
> Vijay
>
>
>
> >-- Urspr?ngliche Nachricht --
> >Reply-To: "Jakarta Commons Users List" <[hidden email]>
> >Date: Fri, 3 Jun 2005 17:36:42 +0200
> >From: [hidden email]
> >Subject: HttpClient use Proxy Server with Basic Auth
> >To: [hidden email]
> >
> >
> >Hi,
>
> I'm trying to get URLs via a Proxy Server.  No matter what I try, i get
> an SC 407 - Proxy Authorization Required.  Can somebody send me an example
> of using HttpClient with a Proxy Server which requires Basic Auth?
>
> This is what I'm doing:
>  
> >      String _proxyHost = System.getProperty("http.proxyHost");
>         if(_proxyHost != null) {
>             HostConfiguration _hc = HostConfiguration();
>             _hc.setProxy(_proxyHost, Integer.parseInt(System.getProperty("http.proxyPort")));
>
> >           _client.setHostConfiguration(_hc);
>             Credentials _creds = new UsernamePasswordCredentials(System.getProperty("http.proxyUser"),
> System.getProperty("http.proxyPassword"));
>             _client.getState().setProxyCredentials(null,
> >proxyHost, _creds);
>
>         }
>         GetMethod get = new GetMethod(aURL);
>         int _status = _client.executeMethod(get);
>         //this doesn't work either: int _status = _client.executeMethod(_client.getHostConfiguration(),
> get, _client.get
> >tate());
>
>
> TIA,
>
> Vijay Garla
>
> __________________________________________________________________
> Das Italien-Gewinnspiel
> Jetzt bei der Italien-Reise mitspielen und einen von 30 Preisen gewinnen.
> http://spielmanege.tiscali.de/italienreise/ital
> >en.php
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
>
>
> __________________________________________________________________
> Das Italien-Gewinnspiel
> Jetzt bei der Italien-Reise mitspielen und einen von 30 Preisen gewinnen.
> http://spielmanege.tiscali.de/italienreise/italien.php
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: AW: HttpClient use Proxy Server with Basic Auth

vngarla
In reply to this post by vngarla
Hello,

Thanks for the troubleshooting link, and sorry for the noise.  HttpClient
did indeed try to use ntlm authentication with the proxy; fortunately it
is possible to override defaults and tell httpclient to use basic authentication
with a proxy.  So, for posterity, if you've got a Proxy Server which allows
mutliple authentication schemes (e.g. MS ISA Server), and you need to use
basic authentication with the proxy, do something like this:

        //httpclient, by default, attempts ntlm authentication to the proxy
server
        //we want to use basic authentication for the proxy server
        //so, we have to set the HttpClientParams accordingly.
        HttpClientParams _clientParams = new HttpClientParams();
        BasicScheme _authScheme = new BasicScheme();
        Vector _vecAuthScheme = new Vector(1);
        _vecAuthScheme.add(_authScheme.getSchemeName());
        _clientParams.setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY,_vecAuthScheme);
        HttpClient _client = new HttpClient(_clientParams);
        //set up the proxy
        HostConfiguration _hc = new HostConfiguration();
        String _proxyHost = System.getProperty("http.proxyHost");
        _hc.setProxy(_proxyHost, Integer.parseInt(System.getProperty("http.proxyPort")));
        _hc.setHost(_url.getHost());
        //_client.getHostConfiguration().setProxy(_proxyHost, Integer.parseInt(System.getProperty("http.proxyPort")));

        _client.setHostConfiguration(_hc);
        Credentials _creds = new UsernamePasswordCredentials(System.getProperty("http.proxyUser"),
System.getProperty("http.proxyPassword"));
        _client.getState().setProxyCredentials(null, _proxyHost, _creds);


It would be nice if the Proxy Server authentication were documented somewhere.
 Googling the commons-user archives brought up only 1 thread with proxy
server authentication.

On a different note, is it possible to set up the HttpClient to not use
the proxy for a set of hosts using wildcards in dns names (e.g. what http.nonProxyHosts
does for the URLConnection)?

Thanks for the troubleshooting pointer!

- vijay

__________________________________________________________________
Das Italien-Gewinnspiel
Jetzt bei der Italien-Reise mitspielen und einen von 30 Preisen gewinnen.
http://spielmanege.tiscali.de/italienreise/italien.php




---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: AW: HttpClient use Proxy Server with Basic Auth

olegk
On Mon, Jun 06, 2005 at 03:48:56PM +0200, [hidden email] wrote:
> Hello,
>
...
> It would be nice if the Proxy Server authentication were documented somewhere.

Usually this guide suffices

http://jakarta.apache.org/commons/httpclient/3.0/authentication.html


>  Googling the commons-user archives brought up only 1 thread with proxy
> server authentication.
>

HttpClient project has its own user and dev lists

http://jakarta.apache.org/commons/httpclient/3.0/mail-lists.html

I still monitor this list just in case, but we tend to get most of the
questions sent to httpclient-user list these days


> On a different note, is it possible to set up the HttpClient to not use
> the proxy for a set of hosts using wildcards in dns names (e.g. what http.nonProxyHosts
> does for the URLConnection)?

One can simply have a different HostConfiguration on a per method / thread /
connection basis

Oleg

>
> Thanks for the troubleshooting pointer!
>
> - vijay
>
> __________________________________________________________________
> Das Italien-Gewinnspiel
> Jetzt bei der Italien-Reise mitspielen und einen von 30 Preisen gewinnen.
> http://spielmanege.tiscali.de/italienreise/italien.php
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: AW: HttpClient use Proxy Server with Basic Auth

Christopher L Merrill
Oleg Kalnichevski wrote:
> HttpClient project has its own user and dev lists
>
> http://jakarta.apache.org/commons/httpclient/3.0/mail-lists.html

FYI, the 'subscribe' links on that page are broken.



--
-------------------------------------------------------------------------
Chris Merrill                  |  http://www.webperformanceinc.com
Web Performance Inc.

Website Load Testing and Stress Testing Software
-------------------------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: AW: HttpClient use Proxy Server with Basic Auth

olegk
For what it's worth this page is auto-generated by Maven

Oleg

On Mon, Jun 06, 2005 at 10:19:46AM -0400, Christopher L Merrill wrote:

> Oleg Kalnichevski wrote:
> >HttpClient project has its own user and dev lists
> >
> >http://jakarta.apache.org/commons/httpclient/3.0/mail-lists.html
>
> FYI, the 'subscribe' links on that page are broken.
>
>
>
> --
> -------------------------------------------------------------------------
> Chris Merrill                  |  http://www.webperformanceinc.com
> Web Performance Inc.
>
> Website Load Testing and Stress Testing Software
> -------------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

AW: Re: AW: HttpClient use Proxy Server with Basic Auth

vngarla
In reply to this post by olegk
Hi,

The thing that IMHO is  missing from the user guide wrt Proxy Servers is
the part about the HostConfiguration.

Regarding http.nonProxyHosts, yes, it is possible to set a hostconfiguration
up as required on a per connection basis.  However, it is a pain to parse
a list of hostnames which possibly include wildcards, and determine if we
should use a proxy server or not.  This is one feature of java.net.HttpURLConnection
which I miss.

Thanks,

/ vijay

>-- Urspr√ľngliche Nachricht --
>Reply-To: "Jakarta Commons Users List" <[hidden email]>
>Date: Mon, 6 Jun 2005 16:14:26 +0200
>From: Oleg Kalnichevski <[hidden email]>
>To: [hidden email]
>Subject: Re: AW: HttpClient use Proxy Server with Basic Auth
>
>
>On Mon, Jun 06, 2005 at 03:48:56PM +0200, [hidden email] wrote:
> Hello,
>
...
> It would be nice if the Proxy Server authentication were documented somewhere.

Usually this guide suffices

http://jakarta.apache.org/commons/httpclient/3.0/a
>thentication.html


>  Googling the commons-user archives brought up only 1 thread with proxy
> server authentication.
>

HttpClient project has its own user and dev lists

http://jakarta.apache.org/commons/httpclient/3.0/mail-lists.html

I
>still monitor this list just in case, but we tend to get most of the
questions sent to httpclient-user list these days


> On a different note, is it possible to set up the HttpClient to not use
> the proxy for a set of hosts using wildcards in d
>s names (e.g. what http.nonProxyHosts
> does for the URLConnection)?

One can simply have a different HostConfiguration on a per method / thread
/
connection basis

Oleg

>
> Thanks for the troubleshooting pointer!
>
> - vijay
>
> _____
>____________________________________________________________
> Das Italien-Gewinnspiel
> Jetzt bei der Italien-Reise mitspielen und einen von 30 Preisen gewinnen.
> http://spielmanege.tiscali.de/italienreise/italien.php
>
>
>
>
> ----------
>----------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

------------------------------------------
>--------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]




__________________________________________________________________
Das Italien-Gewinnspiel
Jetzt bei der Italien-Reise mitspielen und einen von 30 Preisen gewinnen.
http://spielmanege.tiscali.de/italienreise/italien.php




---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Re: AW: HttpClient use Proxy Server with Basic Auth

olegk
Vijay,

There are many things that HttpClient is not. HttpClient is not a
browser, nor is it a dishwasher. Certain things do not belong to a
low level, specialized transport library, like HttpClient. We have
a very difficult task of balancing out two extreme opinions: "HttpClient
is too darn big and has too many dependencies for an HTTP library"
versus "Geeez, HttpClient is useless, coz it does not wash dishes
for me".

Hope this explains it

Oleg


On Mon, Jun 06, 2005 at 04:55:17PM +0200, [hidden email] wrote:

> Hi,
>
> The thing that IMHO is  missing from the user guide wrt Proxy Servers is
> the part about the HostConfiguration.
>
> Regarding http.nonProxyHosts, yes, it is possible to set a hostconfiguration
> up as required on a per connection basis.  However, it is a pain to parse
> a list of hostnames which possibly include wildcards, and determine if we
> should use a proxy server or not.  This is one feature of java.net.HttpURLConnection
> which I miss.
>
> Thanks,
>
> / vijay
>
> >-- Urspr?ngliche Nachricht --
> >Reply-To: "Jakarta Commons Users List" <[hidden email]>
> >Date: Mon, 6 Jun 2005 16:14:26 +0200
> >From: Oleg Kalnichevski <[hidden email]>
> >To: [hidden email]
> >Subject: Re: AW: HttpClient use Proxy Server with Basic Auth
> >
> >
> >On Mon, Jun 06, 2005 at 03:48:56PM +0200, [hidden email] wrote:
> > Hello,
> >
> ...
> > It would be nice if the Proxy Server authentication were documented somewhere.
>
> Usually this guide suffices
>
> http://jakarta.apache.org/commons/httpclient/3.0/a
> >thentication.html
>
>
> >  Googling the commons-user archives brought up only 1 thread with proxy
> > server authentication.
> >
>
> HttpClient project has its own user and dev lists
>
> http://jakarta.apache.org/commons/httpclient/3.0/mail-lists.html
>
> I
> >still monitor this list just in case, but we tend to get most of the
> questions sent to httpclient-user list these days
>
>
> > On a different note, is it possible to set up the HttpClient to not use
> > the proxy for a set of hosts using wildcards in d
> >s names (e.g. what http.nonProxyHosts
> > does for the URLConnection)?
>
> One can simply have a different HostConfiguration on a per method / thread
> /
> connection basis
>
> Oleg
>
> >
> > Thanks for the troubleshooting pointer!
> >
> > - vijay
> >
> > _____
> >____________________________________________________________
> > Das Italien-Gewinnspiel
> > Jetzt bei der Italien-Reise mitspielen und einen von 30 Preisen gewinnen.
> > http://spielmanege.tiscali.de/italienreise/italien.php
> >
> >
> >
> >
> > ----------
> >----------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
>
> ------------------------------------------
> >--------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
>
>
> __________________________________________________________________
> Das Italien-Gewinnspiel
> Jetzt bei der Italien-Reise mitspielen und einen von 30 Preisen gewinnen.
> http://spielmanege.tiscali.de/italienreise/italien.php
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]