0
我有以下https客戶端,但其中包含已棄用的方法。當我嘗試刪除它們時,我沒有收到回覆。 你可以幫我得到這個客戶端沒有不推薦的方法。爲Apache Camel創建http客戶端以啓用證書啓用web服務
棄用方法: SSLSocketFactory的 SchemeRegistry 方案 getConnectionManager()
我的客戶:
HttpComponent httpComponent = context.getComponent( 「https4」,HttpComponent.class);
KeyStore keystore = KeyStore.getInstance("JKS");
keystore.load(new FileInputStream(new File("XXXXXX")), "XXXXXX".toCharArray());
//keystore.load(new FileInputStream(new File("C:/certificate/ToPankaj/clientcert.jks")), "changeit".toCharArray());
KeyManagerFactory keyFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyFactory.init(keystore, "changeit".toCharArray());
SSLContext sslcontext = SSLContext.getInstance("SSLv3");
sslcontext.init(keyFactory.getKeyManagers(), null, null);
@SuppressWarnings("deprecation")
SSLSocketFactory factory = new SSLSocketFactory(sslcontext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
@SuppressWarnings("deprecation")
SchemeRegistry registry = new SchemeRegistry();
@SuppressWarnings("deprecation")
final Scheme scheme = new Scheme("https4", 443, factory);
//registry.register(scheme);
httpComponent.setHttpClientConfigurer(new HttpClientConfigurer()
{
@SuppressWarnings("deprcecation")
@Override
public void configureHttpClient(HttpClient client) {
client.getConnectionManager().getSchemeRegistry().register(scheme);
}
});
httpComponent.setClientConnectionManager(new ThreadSafeClientConnManager());
//httpComponent.
Endpoint endpoint =httpComponent.createEndpoint(Uri);
return endpoint;
提到其實我看到這個例子....這示例不會創建https客戶端 – bhalkian
'to(「https://mail.google.com/mail/」)'定義客戶端從服務器讀取數據,不是嗎? –
它的確如此。另外,這是我見過的最簡單的例子,因爲它並不要求你自己擺弄HTTP客戶端。只需添加密鑰庫或信任庫就可以滿足許多用例。 – Jaap