我想使用jersey客户端(版本1.1.9)连接到https jira服务器。 如何配置安全选项以使用REST-API?
我按照这些说明操作: Accessing secure restful web services using jersey client
但是答案中的第一个链接已被破坏,我不知道如何配置信任库和密钥库。我在哪里可以获得这些文件?
答案 0 :(得分:0)
我切换到jersey-client-2.19并使用keytool配置了密钥库和信任库。
System.setProperty("jsse.enableSNIExtension", "false");
SslConfigurator sslConfig = SslConfigurator.newInstance()
.trustStoreFile("C:/Program Files/Java/jre1.8.0_45/lib/security/cacerts.jks")
.trustStorePassword("somepass")
.keyStoreFile("C:/Program Files/Java/jre1.8.0_45/lib/security/keystore.jks")
.keyPassword("somepass");
SSLContext sslContext = sslConfig.createSSLContext();
Client client = ClientBuilder.newBuilder().sslContext(sslContext)
.build();
HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(
JIRA_ADMIN_USERNAME, JIRA_ADMIN_PASSWORD);
client.register(feature);
WebTarget webTarget = client.target(JIRA_URL);
WebTarget projectWebTarget = webTarget.path("project");
Invocation.Builder invocationBuilder = projectWebTarget
.request(MediaType.APPLICATION_JSON);
Response response = invocationBuilder.get();
System.out.println(response.getStatus());
System.out.println(response.readEntity(String.class));
也许有更好的方法来设置密钥库和信任库的属性。所以请告诉我。