【发布时间】:2015-01-31 00:43:04
【问题描述】:
我正在为 Mule ESB 应用程序编写集成测试。 Mule 应用程序通过 HTTPS 连接到第三方 API。当我尝试针对第三方测试 API 端点运行我的应用程序时,一切正常,我不必向 HTTPS 连接器添加任何 client 特定的 SSL 配置。我相信这是因为他们的服务器具有 CA 签名证书,因此他们立即受到信任,例如像这样的 HTTP 连接器
<https:connector
name="my.https.connector"
cookieSpec="netscape"
validateConnections="true"
sendBufferSize="0"
receiveBufferSize="0"
receiveBacklog="0"
clientSoTimeout="10000"
serverSoTimeout="10000"
socketSoLinger="0"
doc:name="HTTPS">
<service-overrides sessionHandler="org.mule.session.NullSessionHandler"/>
</https:connector>
开箱即用。
在编写集成测试时,我对第三方 API 进行存根(或模拟,如果您愿意的话)。但是,为了使 SSL 工作,我必须为嵌入式 HTTPS 服务器生成一个密钥库,并通过添加修改客户端 HTTPS 连接器
<https:tls-client path="keystore" storePassword="psw" />
<https:tls-key-store path="keystore" storePassword="psw" keyPassword="psw" />
正如互联网上提到的那样。
我可以在一个单独的 XML 文件中定义测试 HTTPS 连接器,并在 FunctionalTestCase.getConfigResources() 方法中加载它。然而这并不理想:我真正追求的是一种使 HTTPS 连接器(客户端)信任 一切 - 但仅在运行集成测试时 - 即在执行 Maven 构建。这必须以编程方式进行,以使 Mule 应用程序代码保持不变。
我尝试将以下代码添加到 @BeforeClass 带注释的方法中
http://www.rgagnon.com/javadetails/java-fix-certificate-problem-in-HTTPS.html
但没有运气。运行集成测试时,我仍然遇到以下异常
Exception stack is:
1. unable to find valid certification path to requested target (sun.security.provider.certpath.SunCertPathBuilderException)
sun.security.provider.certpath.SunCertPathBuilder:196 (null)
2. PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target (sun.security.validator.ValidatorException)
sun.security.validator.PKIXValidator:385 (null)
3. sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target (javax.net.ssl.SSLHandshakeException)
sun.security.ssl.Alerts:192 (http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/net/ssl/SSLHandshakeException.html)
有工作解决方案的人吗? :)
【问题讨论】: