On Thu, 2006-04-20 at 19:19 +0200, Thierry Sechao wrote:
> ok, there is it.
>
Now that I have spotted the problem it actually looks plain dead simple.
> The main metod just call this method. I get the IOException
>
> java.io.IOException: Connection through proxy could not be opened
> at test.KeepCLient.connect2(KeepCLient.java:254)
> at test.KeepCLient.main(KeepCLient.java:100)
>
>
> private void connect2() throws IOException
> {
> ProxyClient proxyClient = new ProxyClient();
> proxyClient.getParams().setAuthenticationPreemptive(true) ;
>
> HostConfiguration hostConfiguration =
> proxyClient.getHostConfiguration();
>
> //hostConfiguration.setHost("myhost", 443, "https");
> hostConfiguration.setHost("myhost", 443, new Protocol("https", new
> SSLProtocolSocketFactory(), 443));
You are not supposed to use a secure socket factory here, because the
job of ProxyClient is to set up a plain text connection with the proxy,
which can be used to tunnel any _arbitrary_ protocol, not just SSL.
Here's what you are supposed to do
(1) Request a plain connection to the target host via the proxy
hostConfiguration.setHost("myhost", 443);
(2) Establish a connection to the proxy
ProxyClient.ConnectResponse response = proxyClient.connect();
if (response.getSocket() != null) {
// tunnel SSL via the resultant socket
SSLProtocolSocketFactory sslSocketFactory =
new SSLProtocolSocketFactory();
Socket sslsocket = sslSocketFactory.createSocket(
response.getSocket(),
"myhost", 443, true);
} else {
// say oopsie
}
(3) You are done
Oleg
> //hostConfiguration.setHost("myhost", 443);
>
> hostConfiguration.setProxy("myproxy", 8080) ;
>
> Credentials userCredential = new UsernamePasswordCredentials("mylogin",
> "mypassword") ;
> proxyClient.getState().setProxyCredentials(new AuthScope("myproxy",
> 8080, AuthScope.ANY_REALM), userCredential) ;
> //proxyClient.getState().setProxyCredentials(new AuthScope("myproxy",
> 8080, "MYREALM"), userCredential) ;
>
> ProxyClient.ConnectResponse response = proxyClient.connect();
> if (response.getSocket() == null) {
> throw new IOException("Connection through proxy could not be
> opened");
> }
>
> String EOF = "\r\n" ;
> Socket socket = response.getSocket() ;
> String request= "GET / HTTP/1.1" + EOF + EOF ;
>
> PrintWriter out = new PrintWriter( new BufferedWriter(
> new
> OutputStreamWriter(socket.getOutputStream())));
>
> out.println(request);
> out.println();
> out.flush();
>
> BufferedReader din = new BufferedReader(new
> InputStreamReader(socket.getInputStream()));
> String text = din.readLine() ;
> int i = 0 ;
> while(text != null){
> System.out.println(text);
> text = din.readLine() ;
> }
>
> System.out.println("fin.");
> }
>
>
>
> Oleg Kalnichevski wrote:
> > On Thu, 2006-04-20 at 16:48 +0200, Thierry Sechao wrote:
> >
> >>Oleg,
> >>
> >>Thanks for your reply,
> >>
> >>when I execute the test which works fine, that is I just change the ligne
> >>
> >>hostConfiguration.setHost("myhost", 443, new Protocol("https", new
> >>SSLProtocolSocketFactory(), 443));
> >>
> >>by
> >>
> >>hostConfiguration.setHost("myhost", 443);
> >>
> >>I have some log (see below) which looks similar "Required credentials
> >>not available for BASIC <any realm>@myhost:443 ...", but it works!
> >
> >
> > BASIC <any realm>@myhost:443
> >
> > This has nothing to do with proxy authentication.
> >
> >
> >
> >>I notice that this time, the mode preemptive works too. the
> >>Proxy-Authorization header is submitted at the first request whereas in
> >>the failed test, it is never submitted.
> >>
> >>I also try to set the REALM without success.
> >>
> >>proxyClient.getState().setProxyCredentials(new AuthScope("myproxy",
> >>8080, "MYREALM"), userCredential) ;
> >>
> >>thanks again.
> >>
> >
> >
> > Post the *complete* source code of your test app
> >
> > Oleg
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]