You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by char li <ch...@gmail.com> on 2005/02/26 18:15:34 UTC
about unable to find valid certification path to requested target
Hi all
I have get an error with https.
Now I use jre 5.0 and Commons HttpClient 3.0 RC1
I have read http://jakarta.apache.org/commons/httpclient/sslguide.html
to test https
It get context with https://www.verisign.com/ by ("
get.getResponseBodyAsString()")
but failed with my test https site.
It thorw the follow error:
-----------------------------------------------------------
Exception in thread "main" javax.net.ssl.SSLHandshakeException:
sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to
find valid certification path to requested target
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:150)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1476)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:174)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:168)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:843)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:106)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:495)
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:433)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:815)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1025)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:619)
at com.sun.net.ssl.internal.ssl.AppOutputStream.write(AppOutputStream.java:59)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
at org.apache.commons.httpclient.HttpConnection.flushRequestOutputStream(HttpConnection.java:825)
at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:1920)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1002)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:382)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:168)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:393)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
at com.demo.http.BasicAuthenticationExample.main(BasicAuthenticationExample.java:45)
Caused by: sun.security.validator.ValidatorException: PKIX path
building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to
find valid certification path to requested target
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:221)
at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:145)
at sun.security.validator.Validator.validate(Validator.java:203)
at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:172)
at com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(SSLContextImpl.java:320)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:836)
... 17 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException:
unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:236)
at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:194)
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:216)
... 22 more
-----------------------------------------------------------
Thanks and regards,
charlse
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
Re: about unable to find valid certification path to requested target
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, Mar 02, 2005 at 11:40:49AM +0800, char li wrote:
> hi,Oleg
> thanks
> ???have fix the error,
> I use keytool -import myCA.cer
> But now I think if It can auto import CA. or it can import CA in
> my program.
> Do you think it OK, and how to do ?
Charlse,
Take a look at the AuthSSLProtocolSocketFactory. The source code comes
with extensive instructions in the java docs. This should help you get
up to the speed.
The AuthSSLProtocolSocketFactory and related files can be found here:
http://svn.apache.org/viewcvs.cgi/jakarta/commons/proper/httpclient/trunk/src/contrib/org/apache/commons/httpclient/contrib/ssl/
Hope this helps
Oleg
> thanks again.
> charlse
>
>
> On Tue, 01 Mar 2005 20:35:19 +0100, Oleg Kalnichevski <ol...@apache.org> wrote:
> > Char Li,
> >
> > I have not worked extensively with JVM 5.0, but most likely this problem
> > occurs because the server certificate is not trusted. You have to
> > configure the trust manager within the SSL context used by your
> > application to trust the server. Please refer to the Sun's documentation
> > on SSL configuration in Java 1.5
> >
> > Hope this helps
> >
> > Oleg
> >
> >
> > On Sun, 2005-02-27 at 12:18 +0800, char li wrote:
> > > Hi all
> > > I have get an error with https.
> > > Now I use jre 5.0 and Commons HttpClient 3.0 RC1
> > > I have read http://jakarta.apache.org/commons/httpclient/sslguide.html
> > > to test https
> > > It get context with https://www.verisign.com/ by ("
> > > get.getResponseBodyAsString()")
> > > but failed with my test https site.
> > > It thorw the follow error:
> > >
> > > -----------------------------------------------------------
> > > Exception in thread "main" javax.net.ssl.SSLHandshakeException:
> > > sun.security.validator.ValidatorException: PKIX path building failed:
> > > sun.security.provider.certpath.SunCertPathBuilderException: unable to
> > > find valid certification path to requested target
> > > at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:150)
> > > at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1476)
> > > at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:174)
> > > at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:168)
> > > at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:843)
> > > at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:106)
> > > at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:495)
> > > at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:433)
> > > at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:815)
> > > at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1025)
> > > at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:619)
> > > at com.sun.net.ssl.internal.ssl.AppOutputStream.write(AppOutputStream.java:59)
> > > at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
> > > at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
> > > at org.apache.commons.httpclient.HttpConnection.flushRequestOutputStream(HttpConnection.java:825)
> > > at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:1920)
> > > at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1002)
> > > at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:382)
> > > at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:168)
> > > at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:393)
> > > at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
> > > at com.demo.http.BasicAuthenticationExample.main(BasicAuthenticationExample.java:45)
> > > Caused by: sun.security.validator.ValidatorException: PKIX path
> > > building failed:
> > > sun.security.provider.certpath.SunCertPathBuilderException: unable to
> > > find valid certification path to requested target
> > > at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:221)
> > > at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:145)
> > > at sun.security.validator.Validator.validate(Validator.java:203)
> > > at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:172)
> > > at com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(SSLContextImpl.java:320)
> > > at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:836)
> > > ... 17 more
> > > Caused by: sun.security.provider.certpath.SunCertPathBuilderException:
> > > unable to find valid certification path to requested target
> > > at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:236)
> > > at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:194)
> > > at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:216)
> > > ... 22 more
> > > -----------------------------------------------------------
> > >
> > > Thanks and regards,
> > >
> > > charlse
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
Re: about unable to find valid certification path to requested target
Posted by char li <ch...@gmail.com>.
hi,Oleg
thanks
Ihave fix the error,
I use keytool -import myCA.cer
But now I think if It can auto import CA. or it can import CA in
my program.
Do you think it OK, and how to do ?
thanks again.
charlse
On Tue, 01 Mar 2005 20:35:19 +0100, Oleg Kalnichevski <ol...@apache.org> wrote:
> Char Li,
>
> I have not worked extensively with JVM 5.0, but most likely this problem
> occurs because the server certificate is not trusted. You have to
> configure the trust manager within the SSL context used by your
> application to trust the server. Please refer to the Sun's documentation
> on SSL configuration in Java 1.5
>
> Hope this helps
>
> Oleg
>
>
> On Sun, 2005-02-27 at 12:18 +0800, char li wrote:
> > Hi all
> > I have get an error with https.
> > Now I use jre 5.0 and Commons HttpClient 3.0 RC1
> > I have read http://jakarta.apache.org/commons/httpclient/sslguide.html
> > to test https
> > It get context with https://www.verisign.com/ by ("
> > get.getResponseBodyAsString()")
> > but failed with my test https site.
> > It thorw the follow error:
> >
> > -----------------------------------------------------------
> > Exception in thread "main" javax.net.ssl.SSLHandshakeException:
> > sun.security.validator.ValidatorException: PKIX path building failed:
> > sun.security.provider.certpath.SunCertPathBuilderException: unable to
> > find valid certification path to requested target
> > at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:150)
> > at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1476)
> > at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:174)
> > at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:168)
> > at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:843)
> > at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:106)
> > at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:495)
> > at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:433)
> > at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:815)
> > at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1025)
> > at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:619)
> > at com.sun.net.ssl.internal.ssl.AppOutputStream.write(AppOutputStream.java:59)
> > at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
> > at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
> > at org.apache.commons.httpclient.HttpConnection.flushRequestOutputStream(HttpConnection.java:825)
> > at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:1920)
> > at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1002)
> > at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:382)
> > at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:168)
> > at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:393)
> > at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
> > at com.demo.http.BasicAuthenticationExample.main(BasicAuthenticationExample.java:45)
> > Caused by: sun.security.validator.ValidatorException: PKIX path
> > building failed:
> > sun.security.provider.certpath.SunCertPathBuilderException: unable to
> > find valid certification path to requested target
> > at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:221)
> > at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:145)
> > at sun.security.validator.Validator.validate(Validator.java:203)
> > at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:172)
> > at com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(SSLContextImpl.java:320)
> > at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:836)
> > ... 17 more
> > Caused by: sun.security.provider.certpath.SunCertPathBuilderException:
> > unable to find valid certification path to requested target
> > at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:236)
> > at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:194)
> > at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:216)
> > ... 22 more
> > -----------------------------------------------------------
> >
> > Thanks and regards,
> >
> > charlse
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
Re: about unable to find valid certification path to requested
target
Posted by Oleg Kalnichevski <ol...@apache.org>.
Char Li,
I have not worked extensively with JVM 5.0, but most likely this problem
occurs because the server certificate is not trusted. You have to
configure the trust manager within the SSL context used by your
application to trust the server. Please refer to the Sun's documentation
on SSL configuration in Java 1.5
Hope this helps
Oleg
On Sun, 2005-02-27 at 12:18 +0800, char li wrote:
> Hi all
> I have get an error with https.
> Now I use jre 5.0 and Commons HttpClient 3.0 RC1
> I have read http://jakarta.apache.org/commons/httpclient/sslguide.html
> to test https
> It get context with https://www.verisign.com/ by ("
> get.getResponseBodyAsString()")
> but failed with my test https site.
> It thorw the follow error:
>
> -----------------------------------------------------------
> Exception in thread "main" javax.net.ssl.SSLHandshakeException:
> sun.security.validator.ValidatorException: PKIX path building failed:
> sun.security.provider.certpath.SunCertPathBuilderException: unable to
> find valid certification path to requested target
> at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:150)
> at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1476)
> at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:174)
> at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:168)
> at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:843)
> at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:106)
> at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:495)
> at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:433)
> at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:815)
> at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1025)
> at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:619)
> at com.sun.net.ssl.internal.ssl.AppOutputStream.write(AppOutputStream.java:59)
> at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
> at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
> at org.apache.commons.httpclient.HttpConnection.flushRequestOutputStream(HttpConnection.java:825)
> at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:1920)
> at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1002)
> at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:382)
> at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:168)
> at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:393)
> at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
> at com.demo.http.BasicAuthenticationExample.main(BasicAuthenticationExample.java:45)
> Caused by: sun.security.validator.ValidatorException: PKIX path
> building failed:
> sun.security.provider.certpath.SunCertPathBuilderException: unable to
> find valid certification path to requested target
> at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:221)
> at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:145)
> at sun.security.validator.Validator.validate(Validator.java:203)
> at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:172)
> at com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(SSLContextImpl.java:320)
> at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:836)
> ... 17 more
> Caused by: sun.security.provider.certpath.SunCertPathBuilderException:
> unable to find valid certification path to requested target
> at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:236)
> at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:194)
> at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:216)
> ... 22 more
> -----------------------------------------------------------
>
> Thanks and regards,
>
> charlse
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
RE: HTTPS redirection with form posting
Posted by Oleg Kalnichevski <ol...@apache.org>.
Veena,
The code you are using is almost a verbatim copy of the form login demo
application that comes with HttpClient. I see nothing wrong with it. If
you expect us to help you, you have to produce a wire/context log of the
HTTP session that exhibits the problem and post it to this list
See the logging guide for details:
<http://jakarta.apache.org/commons/httpclient/logging.html>
Oleg
On Tue, 2005-03-01 at 19:16 +0530, Veena Sarolkar wrote:
> Hi,
>
> I have read the complete documentation of HttpClient.
> I am using it as an application not a web application so can't send the log.
> I am just sending the code I tried...
>
>
> public class PostTry {
>
> /**
> * Constructor for BasicAuthenticatonExample.
> */
> public PostTry() {
> super();
> }
>
> public static void main(String[] args) throws Exception {
> System.setProperty("java.protocol.handler.pkgs",
> "com.sun.net.ssl.internal.www.protocol");
> Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
>
> // create a GET method that reads a file over HTTPS, we're assuming
> // that this file requires basic authentication using the realm above.
> PostMethod post = new PostMethod("https://gna.org/account/login.php");
>
>
> post.setDoAuthentication( true );
> post.setFollowRedirects(false) ;
>
> NameValuePair form_loginname= new NameValuePair("form_loginname",
> "veena");
> NameValuePair form_pw= new NameValuePair("form_pw", "veena");
> NameValuePair stay_in_ssl= new NameValuePair("stay_in_ssl", "1");
> NameValuePair cookie_for_a_year= new NameValuePair("cookie_for_a_year",
> "0");
> NameValuePair login= new NameValuePair("login", "login");
> post.setRequestBody(
> new NameValuePair[] {form_loginname, form_pw, stay_in_ssl,
> cookie_for_a_year,login});
>
> client.executeMethod(post);
> System.out.println("Login form post: " +
> post.getStatusLine().toString());
>
> post.releaseConnection();
> // See if we got any cookies
> // The only way of telling whether logon succeeded is
> // by finding a session cookie
> client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
> CookieSpec cookiespec = CookiePolicy.getDefaultSpec();
> Cookie[] logoncookies = cookiespec.match(
> "gna.org", 443, "/", false, client.getState().getCookies());
> System.out.println("Logon cookies:");
> if (logoncookies.length == 0) {
> System.out.println("None");
> }
> else
> {
> for (int i = 0; i < logoncookies.length; i++) {
>
> System.out.println("- " + logoncookies[i].toString());
> }
> }
>
> int statuscode = post.getStatusCode();
> if ((statuscode == HttpStatus.SC_MOVED_TEMPORARILY) ||
> (statuscode == HttpStatus.SC_MOVED_PERMANENTLY) ||
> (statuscode == HttpStatus.SC_SEE_OTHER) ||
> (statuscode == HttpStatus.SC_TEMPORARY_REDIRECT))
> {
> Header header = post.getResponseHeader("location");
> post.getResponseBodyAsString();
>
> post.releaseConnection();
> if (header != null)
> {
> String newuri = header.getValue();
> if ((newuri == null) || (newuri.equals("")))
> {
> newuri = "/";
> }
> System.out.println("Redirect target: " + newuri);
> GetMethod redirect = new GetMethod(newuri);
>
> logoncookies = cookiespec.match(
> "gna.org", 443, "/my", false, client.getState().getCookies());
>
> System.out.println("Logon cookies:");
> if (logoncookies.length == 0) {
> System.out.println("None");
> }
> else
> {
> for (int i = 0; i < logoncookies.length; i++) {
>
> System.out.println("- " + logoncookies[i].toString());
> }
> }
>
> client.executeMethod(redirect);
>
> System.out.println("response :"+redirect.getStatusLine());
> System.out.println("response :"+redirect.getResponseBodyAsString());
>
> // release any connection resources used by the method
> redirect.releaseConnection();
> }
> else
> {
> System.out.println("Invalid redirect");
> System.exit(1);
> }
> }
> }
> }
>
> It is giving me proper set of cookies for original as well as redirected
> urls.
> But it is not giving the page next to login but still giving the original
> page in the response.
> Am I missing something?
>
> Veena
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
RE: HTTPS redirection with form posting
Posted by Veena Sarolkar <sa...@extenprise.com>.
Hi,
I have read the complete documentation of HttpClient.
I am using it as an application not a web application so can't send the log.
I am just sending the code I tried...
public class PostTry {
/**
* Constructor for BasicAuthenticatonExample.
*/
public PostTry() {
super();
}
public static void main(String[] args) throws Exception {
System.setProperty("java.protocol.handler.pkgs",
"com.sun.net.ssl.internal.www.protocol");
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
// create a GET method that reads a file over HTTPS, we're assuming
// that this file requires basic authentication using the realm above.
PostMethod post = new PostMethod("https://gna.org/account/login.php");
post.setDoAuthentication( true );
post.setFollowRedirects(false) ;
NameValuePair form_loginname= new NameValuePair("form_loginname",
"veena");
NameValuePair form_pw= new NameValuePair("form_pw", "veena");
NameValuePair stay_in_ssl= new NameValuePair("stay_in_ssl", "1");
NameValuePair cookie_for_a_year= new NameValuePair("cookie_for_a_year",
"0");
NameValuePair login= new NameValuePair("login", "login");
post.setRequestBody(
new NameValuePair[] {form_loginname, form_pw, stay_in_ssl,
cookie_for_a_year,login});
client.executeMethod(post);
System.out.println("Login form post: " +
post.getStatusLine().toString());
post.releaseConnection();
// See if we got any cookies
// The only way of telling whether logon succeeded is
// by finding a session cookie
client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
CookieSpec cookiespec = CookiePolicy.getDefaultSpec();
Cookie[] logoncookies = cookiespec.match(
"gna.org", 443, "/", false, client.getState().getCookies());
System.out.println("Logon cookies:");
if (logoncookies.length == 0) {
System.out.println("None");
}
else
{
for (int i = 0; i < logoncookies.length; i++) {
System.out.println("- " + logoncookies[i].toString());
}
}
int statuscode = post.getStatusCode();
if ((statuscode == HttpStatus.SC_MOVED_TEMPORARILY) ||
(statuscode == HttpStatus.SC_MOVED_PERMANENTLY) ||
(statuscode == HttpStatus.SC_SEE_OTHER) ||
(statuscode == HttpStatus.SC_TEMPORARY_REDIRECT))
{
Header header = post.getResponseHeader("location");
post.getResponseBodyAsString();
post.releaseConnection();
if (header != null)
{
String newuri = header.getValue();
if ((newuri == null) || (newuri.equals("")))
{
newuri = "/";
}
System.out.println("Redirect target: " + newuri);
GetMethod redirect = new GetMethod(newuri);
logoncookies = cookiespec.match(
"gna.org", 443, "/my", false, client.getState().getCookies());
System.out.println("Logon cookies:");
if (logoncookies.length == 0) {
System.out.println("None");
}
else
{
for (int i = 0; i < logoncookies.length; i++) {
System.out.println("- " + logoncookies[i].toString());
}
}
client.executeMethod(redirect);
System.out.println("response :"+redirect.getStatusLine());
System.out.println("response :"+redirect.getResponseBodyAsString());
// release any connection resources used by the method
redirect.releaseConnection();
}
else
{
System.out.println("Invalid redirect");
System.exit(1);
}
}
}
}
It is giving me proper set of cookies for original as well as redirected
urls.
But it is not giving the page next to login but still giving the original
page in the response.
Am I missing something?
Veena
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
Re: HTTPS redirection with form posting
Posted by Roland Weber <RO...@de.ibm.com>.
Hello Veena,
you may have to do some preparations before you can
use HTTPS. Please have a look at our SSL Guide for details:
http://jakarta.apache.org/commons/httpclient/sslguide.html
If that is not the problem, please verify that you are using
the same HttpState for both method executions. If you are
using the same HttpClient object and don't do anything
with HttpState, you should be fine.
Finally, you can generate and post a wire log to this list
so we can have a more detailed look at the problem:
http://jakarta.apache.org/commons/httpclient/logging.html
hope that helps,
Roland
"Veena Sarolkar" <sa...@extenprise.com>
01.03.2005 07:11
Please respond to
"HttpClient User Discussion"
To
"HttpClient User Discussion" <ht...@jakarta.apache.org>
cc
Subject
HTTPS redirection with form posting
Hi All,
I am very new to HttpClient.
I am trying to connect to gna.org. I am posting usernam e& password over
it.
Login is succesful & it is giving me some cookies & redirecting to
https://gna.org/my
Then I am creating a get method with this URL. & reading the reasponse
body.
But in response body it still gives me the home page i.e. the page with
NOT
LOGGED IN message.
What can be the reason for this?
Regards,
Veena
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
HTTPS redirection with form posting
Posted by Veena Sarolkar <sa...@extenprise.com>.
Hi All,
I am very new to HttpClient.
I am trying to connect to gna.org. I am posting usernam e& password over it.
Login is succesful & it is giving me some cookies & redirecting to
https://gna.org/my
Then I am creating a get method with this URL. & reading the reasponse body.
But in response body it still gives me the home page i.e. the page with NOT
LOGGED IN message.
What can be the reason for this?
Regards,
Veena
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
RE: about unable to find valid certification path to requested target
Posted by Veena Sarolkar <sa...@extenprise.com>.
Hi,
I am using HTTPClient to connect to site over https.
I am behind a proxy. I am specifying proxy details(host,port).
But when I call getMethod's exceute, I am getting following exception
javax.net.ssl.SSLHandshakeException:
java.security.cert.CertificateException: CA certificate does not include
basic constraints extension at
com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.a(DashoA6275) at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275) at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275) at
com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275) at
com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275) at
com.sun.net.ssl.internal.ssl.SunJSSE_ax.a(DashoA6275) at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275) at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.j(DashoA6275) at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275) at
com.sun.net.ssl.internal.ssl.AppOutputStream.write(DashoA6275) at
java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:69) at
java.io.BufferedOutputStream.flush(BufferedOutputStream.java:127) at
org.apache.commons.httpclient.HttpConnection.flushRequestOutputStream(HttpCo
nnection.java:825) at
org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.jav
a:1920) at
org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:100
2) at
org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethod
Director.java:382) at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDir
ector.java:168) at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:394)
at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
at BasicAuthenticationExample.main(BasicAuthenticationExample.java:79)
For proxy I m writing client.getHostConfiguration().setProxy("192.168.0.1",
3128);
Even I am notable to run sample examples for https like
"BasicAuthenticationExample.java".
Can somebody help me.
Regards,
Veena
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
about unable to find valid certification path to requested target
Posted by char li <ch...@gmail.com>.
Hi all
I have get an error with https.
Now I use jre 5.0 and Commons HttpClient 3.0 RC1
I have read http://jakarta.apache.org/commons/httpclient/sslguide.html
to test https
It get context with https://www.verisign.com/ by ("
get.getResponseBodyAsString()")
but failed with my test https site.
It thorw the follow error:
-----------------------------------------------------------
Exception in thread "main" javax.net.ssl.SSLHandshakeException:
sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to
find valid certification path to requested target
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:150)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1476)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:174)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:168)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:843)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:106)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:495)
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:433)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:815)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1025)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:619)
at com.sun.net.ssl.internal.ssl.AppOutputStream.write(AppOutputStream.java:59)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
at org.apache.commons.httpclient.HttpConnection.flushRequestOutputStream(HttpConnection.java:825)
at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:1920)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1002)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:382)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:168)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:393)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
at com.demo.http.BasicAuthenticationExample.main(BasicAuthenticationExample.java:45)
Caused by: sun.security.validator.ValidatorException: PKIX path
building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to
find valid certification path to requested target
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:221)
at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:145)
at sun.security.validator.Validator.validate(Validator.java:203)
at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:172)
at com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(SSLContextImpl.java:320)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:836)
... 17 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException:
unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:236)
at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:194)
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:216)
... 22 more
-----------------------------------------------------------
Thanks and regards,
charlse
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org