I have a problem using httpclient classes. I need connect through https protocol with 
PostMethod. But, when I execute the method, an Exception ocurred because it doesn't 
find the certificate i've created for this

public class RobotImpl{

    //Init server...    
    public void iniciar() throws ExceptionGlobal{
        try{
                URL u = new URL("https://localhost:8443/Jsp2.jsp";);
                org.apache.commons.httpclient.URI uri=new 
org.apache.commons.httpclient.URI(u);
                HttpClient client = new HttpClient();
                HostConfiguration hc = new HostConfiguration();
                hc.setHost(uri);
                client.setHostConfiguration(hc);
                client.setTimeout(30000);


                PostMethod post = new PostMethod("https://localhost:8443/Jsp2.jsp";);

                int iResultCode = client.executeMethod(post);
        }
        catch................
...
}//end code



Exception Message

javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: Couldn't 
find trusted certificate
 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)...........
....


I tried to create a trust manager that does not validate certificate chains, but it 
doesn't works... this is the code

TrustManager[] trustAllCerts = new TrustManager[]{
    new X509TrustManager() {
    public java.security.cert.X509Certificate[] getAcceptedIssuers() {
        return null;
    }
    public void checkClientTrusted(
            java.security.cert.X509Certificate[] certs, String authType) {
    }
    public void checkServerTrusted(
            java.security.cert.X509Certificate[] certs, String authType) {
    }
    }
};
// Install the all-trusting trust manager
try {
    SSLContext sc = SSLContext.getInstance("SSL");
    sc.init(null, trustAllCerts, new java.security.SecureRandom());
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e) {
}


thanks for advance,
Carlos

Reply via email to