【发布时间】:2011-01-14 12:09:21
【问题描述】:
我有一个使用axis2 创建的“Hello World”网络服务。我想编写一个客户端 api,它可以通过 https 使用该服务并带有自签名证书。我有一个自签名证书myCertificate.cer 和一个包含它的keystore。
这是我的客户端 API:
public class MyApi{
public Object callMyService(){
Axis2TestStub stub = new Axis2TestStub(
"https://localhost:8443/axis2/services/Axis2Test");
System.setProperty("javax.net.ssl.trustStore",
"src/main/resources/myKeystore.jks")
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
Hello request = new Hello();
request.setMot("World");
HelloResponse response = stub.hello(request);
Object mot = response.get_return();
return mot;
它有效,但我想使用 myCertificate.cer 而不是包含它的 keystore。有人知道该怎么做吗?我试图覆盖https 协议但没有成功:
HttpSecureProtocol myHttpsProtocol = new HttpSecureProtocol();
myHttpsProtocol .setCheckHostname(false);
myHttpsProtocol .addTrustMaterial(new TrustMaterial("myCertificate.cer"));
Protocol customHttps = new Protocol("https",
(ProtocolSocketFactory) myHttpsProtocol , 8443);
Protocol.registerProtocol("https", customHttps);
【问题讨论】:
标签: java https certificate web-services self-signed