我的项目使用 xfire 作为 Web 服务客户端 api。我的项目在旧版 Servlet/JSP 中。我们使用 XFire eclipse 插件来生成客户端存根。
Web 服务已迁移到 SLL (HTTPS)。有没有简单的方法在 XFire 中通过 SSL 使用 Web 服务。
我在http://docs.codehaus.org/display/XFIRE/HTTP+Transport找到了一些代码。我也有一些困惑。它激发了使用not-so-common-ssl
Alpha 版本的动机,我不知道它是否足够稳定以用于生产。
// 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,所以这不是一个选择。