在jetty http客户端中,KeyStore API的替代品是什么?

时间:2011-11-01 14:19:09

标签: jetty

所有与密钥库相关的方法在Jetty文档中都被标记为已弃用,但它并未引用替换API。应该使用什么API?

http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/client/HttpClient.html

1 个答案:

答案 0 :(得分:4)

请改用ssl上下文工厂。 e.g。

        SslContextFactory sslContextFactory = new SslContextFactory();
        URL keyStoreUrl = this.getClass().getClassLoader().getResource("XXXXXX.pfx");

        URL trustStoreUrl = this.getClass().getClassLoader().getResource("XXXX.jks");

        sslContextFactory.setKeyStoreType("pkcs12");
        sslContextFactory.setTrustStoreType("jks");
        sslContextFactory.setKeyStore(keyStoreUrl.toString());
        sslContextFactory.setKeyStorePassword(KEY_STORE_PASS);

        sslContextFactory.setNeedClientAuth(true);
        sslContextFactory.setValidateCerts(false);
        sslContextFactory.setTrustStore(trustStoreUrl.toString());
        sslContextFactory.setTrustStorePassword(KEY_STORE_PASS);
        sslContextFactory.setKeyManagerPassword(KEY_STORE_PASS);


        httpClient = new HttpClient(sslContextFactory);