commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@bluewin.ch
Subject Re: [HTTPClient] How to use the cookie JSessionID ... becomes How to pass clien
Date Fri, 19 Mar 2004 14:31:24 GMT
Laurent.
One little detail is missing. HttpClient still does not know you want to
go through the proxy. 

Just add one extra configuration line right after HttpClient instantiation

HttpClient client = new HttpClient();
client.getHostConfiguration().setProxy(PROXY_IP, PROXY_PORT);

In order to be able to see what exactly HttpClient is doing you may want
to turn  the wire/debug log when troubleshooting problems

<http://jakarta.apache.org/commons/httpclient/logging.html>

HTH

Oleg

>-- Original Message --
>Reply-To: "Jakarta Commons Users List" <commons-user@jakarta.apache.org>
>Date: Fri, 19 Mar 2004 15:26:55 +0100
>From: Laurent Forêt <l.foret@clipack.com>
>To: Jakarta Commons Users List <commons-user@jakarta.apache.org>
>Subject: Re: [HTTPClient]  How to use the cookie JSessionID ... becomes
How
> to pass client proxy Authorization through applet.
>
>
>I begin to understand how proxy works, now. And I think now that my previous
>question was stupid.
>
>This morning, I have configured a squid proxy with user authorization and
>a firewall with which the 
>  only possible connection to the web is through this proxy.
>
>I try the simplest program using proxy HttpClient, inspired from cvs example
>:
>
>   static String PROXY_IP = "195.46.214.114";
>   static String PROXY_USER = "squid";
>   static String PROXY_PASSWORD = "squid";
>
>
>    public static void main(String[] args) throws Exception {
>         HttpClient client = new HttpClient();
>	
>	//client.getState().setAuthenticationPreemptive(true);
>	client.getState().setAuthenticationPreemptive(true);
>
>         client.getState().setProxyCredentials(
>	    // IP_PROXY,
>             null,
>             IP_PROXY,
>             new UsernamePasswordCredentials(PROXY_USER, PROXY_PASSWORD)
>         );
>
>	System.out.println(client.getState().toString());
>
>         GetMethod get = new GetMethod("http://www.google.com");
>         get.setDoAuthentication( true );
>         try {
>             int status = client.executeMethod( get );
>             System.out.println(status + "\n" + get.getResponseBodyAsString());
>         } finally {
>             get.releaseConnection();
>         }
>     }
>
>This program ignore the proxyCredentials. And try to connect directly with
>failure (due to the 
>firewall) to www.google.com
>What I have done wrong ?
>
>I am discouraged !!
>
>Laurent F.
>
>PS the output :
>[Authentication domain: '195.46.214.114', authentication realm: 'null'#squid:squidUser
>| 
>Authentication domain: '195.46.214.114', authentication realm: 'null'#squid:squidUser
>| ]
>java.net.SocketException: connect (code=10004)
>         at java.net.PlainSocketImpl.socketConnect(Native Method)
>         at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:320)
>         at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:133)
>         at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:120)
>         at java.net.Socket.<init>(Socket.java:273)
>         at java.net.Socket.<init>(Socket.java:100)
>         at 
>org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:118)
>         at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:683)
>         at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:662)
>         at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:529)
>         at com.clipack.lfo.TestAuthentication.main(TestAuthentication.java:37)
>
>
>
>Laurent Forêt wrote:
>> Ok, thanks a lot. I am sorry, I haven't seen that credentials was also
>
>> for Proxy Authentication.
>> 
>> Another question, I hope it will be the last ;) :
>> 
>> How do we know the values of String parameters for the 
>> UsernamePasswordCredentials constructor ?
>> Is it better to use the default ?
>> 
>> Thanks again for all your help.
>> 
>> Laurent F.
>> 
>> 
>> Oleg Kalnichevski wrote:
>> 
>>> On Thu, 2004-03-18 at 16:49, Laurent Forêt wrote:
>>>
>>>> My problem is now,
>>>>
>>>> how to pass througn proxy Authorization using httpClient.
>>>> Is it managed by HttpClient, or do we have to provide code to manage
>?
>>>> If it is the case , how ?
>>>
>>>
>>>
>>> HttpClient does provide support for transparent proxy authentication.
>>> All you have to do is to add the required proxy credentials to the
>>> HttpState used by HttpClient. Please refer to the javadocs for details
>>>
>>> Oleg
>>>
>>>
>>>
>>>
>>>> Thanks in advance.
>>>>
>>>> Laurent F.
>>>>
>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>>
>>>
>>>
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>> 
>> 
>> 
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>


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


Mime
View raw message