【发布时间】:2015-04-30 09:25:28
【问题描述】:
我的项目使用 xfire 作为 Web 服务客户端 api。我的项目在旧版 Servlet/JSP 中。我们使用 XFire eclipse 插件来生成客户端存根。
Web 服务已迁移到 SLL (HTTPS)。有什么简单的方法可以在 XFire 中通过 SSL 使用 Webservice。
我在http://docs.codehaus.org/display/XFIRE/HTTP+Transport 找到了一些代码。
我也有一些困惑。它鼓励使用 Alpha 中的not-so-common-ssl,我不知道它是否足够稳定以用于生产。
// Technique similar to http://juliusdavies.ca/commons- ssl/TrustExample.java.html
HttpSecureProtocol protocolSocketFactory = new HttpSecureProtocol();
// "/thecertificate.cer" can be PEM or DER (raw ASN.1). Can even be several PEM certificates in one file.
TrustMaterial trustMaterial = new TrustMaterial(getClass().getResource("/thecertificate.cer"));
// We can use setTrustMaterial() instead of addTrustMaterial() if we want to remove
// HttpSecureProtocol's default trust of TrustMaterial.CACERTS.
protocolSocketFactory.addTrustMaterial(trustMaterial);
// Maybe we want to turn off CN validation (not recommended!):
protocolSocketFactory.setCheckHostname(false);
Protocol protocol = new Protocol("https", (ProtocolSocketFactory) protocolSocketFactory, 8443);
Protocol.registerProtocol("https", protocol);
现在上面是一种创建协议工厂并将其注册到 Apache HTTPclient api 的方法。但 id 并没有说明如何处理生成的存根。
如有更多信息,请随时询问。
我们无法迁移到其他 Web 服务客户端 api,因此这不是一个选项。
【问题讨论】:
标签: java ssl https webservice-client xfire