0

I'm trying to perform a http request. However, at the time of execution arises oshiyuka below. I suppose that it is impossible to create SSLContentFactory due to problems with the certificate. Who has ever seen such a thing?. JRE 1.5

Loaded class org.apache.http.conn.scheme.LayeredSchemeSocketFactory
Loaded class org.apache.http.conn.scheme.SocketFactory
Loaded class org.apache.http.conn.scheme.LayeredSocketFactory 
Loaded class org.apache.http.conn.ssl.SSLSocketFactory
Loaded class org.apache.http.conn.ConnectTimeoutException 
Loaded class org.apache.http.conn.ssl.X509HostnameVerifier
Loaded class org.apache.http.conn.ssl.AbstractVerifier 
Loaded class org.apache.http.conn.ssl.AllowAllHostnameVerifier 
Loaded class org.apache.http.conn.ssl.BrowserCompatHostnameVerifier 
Loaded class org.apache.http.conn.ssl.StrictHostnameVerifier
Loaded class org.apache.http.impl.conn.SchemeRegistryFactory 
Loaded class org.apache.http.conn.scheme.SchemeRegistry
Loaded class org.apache.http.conn.scheme.Scheme 
Loaded class org.apache.http.conn.scheme.PlainSocketFactory

*** START APPLICATION TRACE ***

Defaultjava.lang.IllegalStateException: Failure initializing default SSL context

*** END APPLICATION TRACE ***

Listing:

private static DefaultHttpClient createHttpClient()
        throws NoSuchAlgorithmException, KeyManagementException {

    DefaultHttpClient defaultHttpClient = new DefaultHttpClient();

    defaultHttpClient.getParams().setParameter(
            ConnRoutePNames.DEFAULT_PROXY, proxy);

    defaultHttpClient = makeTrustfulHttpClient(defaultHttpClient);
    defaultHttpClient.addRequestInterceptor(
            new DiadocPreemptiveAuthRequestInterceptor(), 0);
    return defaultHttpClient;
}

private static DefaultHttpClient makeTrustfulHttpClient(HttpClient base)
        throws NoSuchAlgorithmException, KeyManagementException {



    SSLSocketFactory ssf = getTrustfulSslSocketFactory();
    ClientConnectionManager ccm = base.getConnectionManager();
    ccm.getSchemeRegistry().register(new Scheme("https", 443, ssf));
    return new DefaultHttpClient(ccm, base.getParams());
}

private static SSLSocketFactory getTrustfulSslSocketFactory()
        throws NoSuchAlgorithmException, KeyManagementException {


    SSLContext ctx = SSLContext.getInstance("TLS");
    X509TrustManager tm = new X509TrustManager() {
        public void checkClientTrusted(X509Certificate[] xcs, String string)
                throws CertificateException {
        }

        public void checkServerTrusted(X509Certificate[] xcs, String string)
                throws CertificateException {
        }

        public X509Certificate[] getAcceptedIssuers() {
            return null;
        }
    };

    ctx.init(null, new TrustManager[] { tm }, null);


    return new SSLSocketFactory(ctx,
            SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);


}
Andre An
  • 9
  • 3
  • Are you asking whether this error message has ever been seen before? http://stackoverflow.com/questions/10063882/failure-initializing-default-ssl-context – Shaymin Gratitude Mar 04 '16 at 04:50
  • I saw this post. That's why I pointed JVM version. The problem is that SAP PI + EJB on a given JVM works fine. Because the built-in data exchange are limited, it was an attempt to create a custom development. Is there still any solution to the problem? For example, by creating your Keystore with selfsigned keys? – Andre An Mar 04 '16 at 08:59
  • To replicate your problem, it would be helpful if you included your main method and imports. I'm not sure what DiadocPreemptiveAuthRequestInterceptor is. Also, I don't know where the variable "proxy" is coming from in the createHttpClient method. Is it a class variable? EDIT: Actually, it would be preferable if you just keep the minimum amount of code in the main method that causes the error rather than posting the whole thing. – Shaymin Gratitude Mar 04 '16 at 14:19
  • This is kind of a stretch, and I doubt it will help, but based on what I read at http://stackoverflow.com/questions/13135230/difference-between-ssl-and-tls-and-their-usage-in-java, maybe you should use SSL instead of TLS. – Shaymin Gratitude Mar 04 '16 at 14:40
  • ))))) This is not my code.... Sorry for my french, shit happened... – Andre An Mar 06 '16 at 14:00
  • No, of course)))) TSL -> SSL don't work. – Andre An Mar 06 '16 at 14:54
  • Look more to stack: Root Cause: java.security.KeyStoreException: problem accessing trust storejava.security.cert.CertificateException: java.security.InvalidKeyException: **PublicKey algorithm not implemented: ECPublicKey** – Andre An Mar 06 '16 at 15:15
  • I don't understand your first comment. Are you saying that the code you posted is not the code that you wrote that causes the exceptions to be thrown? I'm having a difficult time helping you because I don't know how or where your code crashed. What code are you running that makes the program throw an exception? – Shaymin Gratitude Mar 06 '16 at 19:06

1 Answers1

0

Solution:

private SecureConnectionFactory makeSecureConnectionFactory()
        throws NoSuchAlgorithmException, KeyManagementException {


    return SecureConnectionFactory.getDefault();
}
Andre An
  • 9
  • 3