Java HttpClient SSL:初始化缺省 SSL 上下文失败



我正在尝试执行http请求。然而,在处决时出现了下面的oshiyuka。我想由于证书问题,不可能创建SSLContentFactory。谁见过这样的事情?.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 ***

清单:

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);

}

解决方案:

private SecureConnectionFactory makeSecureConnectionFactory()
        throws NoSuchAlgorithmException, KeyManagementException {

    return SecureConnectionFactory.getDefault();
}