[英]How to consume https RestFul Webservice using jersey client
问题:我想通过球衣客户端使用HTTPS Restful Webservice。
1)我从第三方获得了CARoot证书,并安装在浏览器(Mozilla)上,并且能够从Mozilla浏览器上的RestClient访问这些服务。
i)RootCA.pem ii)SubCA-Client.pem iii)abc_sdsdllkl_p12.pfx
2)我想使用球衣客户端以JAVA代码配置此Web服务。
3)我必须执行哪些步骤才能在Java代码中配置这些证书。
4)我不想在本地JRE中配置它们。
PAttributes pd = new PAttributes();
ClassLoader classLoader = pd.getClass().getClassLoader();
File file = new File(classLoader.getResource("cacerts").getFile());
System.setProperty("javax.net.ssl.trustStore",file.getAbsolutePath());
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
Client client = Client.create();
WebResource webResource = client.resource("https://xyz/abc/getAttributes");
String input = new PAttributes().getRequestBody();
ClientResponse clientResponse = webResource.accept("application/xml").type("application/xml").post(ClientResponse.class, input);
String output = clientResponse.getEntity(String.class);
System.out.println("output"+output);
我已经从浏览器下载了.crt文件,需要进行配置,不知道如何?
在Java安装文件夹中,有一个名为cacerts
的文件。 这是您的JRE的“密钥库”或“信任库”。 它包含您的JRE信任的所有证书。 您可以从信任库中添加/删除证书。 要轻松添加/删除证书,可以使用GUI Programm Keystore Explorer 。
选项1使用Keystore Explorer和默认的Truststore
使用密钥库资源管理器打开信任库。
(信任库应位于<JRE-HOME>/lib/security/cacerts
,默认密码应为“ changeit”或“ changeme”)
将“ .crt”文件拖放到Keystore Explorer中打开的信任库中
单击“导入”,然后保存信任库
现在,您的JRE安装已准备就绪,可以使用Web服务。
选项2使用密钥库资源管理器和单独的信任库
将您的默认信任库复制到您的项目中。 默认信任路径的路径为: <JRE-HOME>/lib/security/cacerts
使用密钥库资源管理器打开复制的信任库。
(默认密码应为“ changeit”或“ changeme”)
将“ .crt”文件拖放到Keystore Explorer中打开的信任库中
使用以下VM参数启动程序:
-Djavax.net.ssl.trustStore [复制到信任库的路径]
-Djavax.net.ssl.trustStorePassword [信任库密码]
选项3使用2个信任库(默认+单独的信任库)
如果要使用默认信任库,并且要为网站使用单独的信任库,请参阅此帖子https://stackoverflow.com/a/24561444/1638059
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.