一个junit正在测试来自模拟服务器的JMS响应。 Junit在maven生成期间无法找到证书路径,但在单独运行时会找到它并且没有例外。
与证书相关的application.yml
:
bridge:
conduit:
keystore:
type: pkcs12
password: ENC(l4/yeZUp8n4v7iArP1H9OWeVHUO5JCM2)
location: src/main/resources/config/certificatessl.p12
jasypt:
encryptor:
password: G;SobWzm9Z;zWOMQuUF
测试类中的junit使用以下模拟服务器:
mockServer.when(HttpRequest.request("/gateway/spec").withSecure(true).withBody(Mockito.anyString()))
.respond(HttpResponse.response(myJsonObject));
上下文将加载模拟服务器:
@Bean(destroyMethod = "stop")
@Lazy
public ClientAndServer mockServer() {
ConfigurationProperties.deleteGeneratedKeyStoreOnExit(true);
ClientAndServer mockServer = ClientAndServer.startClientAndServer(7071);
HttpsURLConnection
.setDefaultSSLSocketFactory(KeyStoreFactory.keyStoreFactory().sslContext().getSocketFactory());
return mockServer;
}
application-cxfconduit.xml
:
<http:conduit name="{/b2b/Services}PreparationPort.http-conduit">
<http:tlsClientParameters disableCNCheck="true" secureSocketProtocol="TLSv1.2">
<sec:keyManagers keyPassword="#{environment['bridge.conduit.keystore.password']}">
<sec:keyStore type="${bridge.conduit.keystore.type}"
password="#{environment['bridge.conduit.keystore.password']}"
file="${bridge.conduit.keystore.location}" />
</sec:keyManagers>
</http:tlsClientParameters>
<http:client Connection="close" ConnectionTimeout="${bridge.conduit.connectionTimeout:30000}"
ReceiveTimeout="${bridge.conduit.receiveTimeout:120000}" ProxyServer="${bridge.conduit.proxy.address:}"
ProxyServerPort="${bridge.conduit.proxy.port:}" ProxyServerType="HTTP" AutoRedirect="true" AllowChunking="false" />
<http:proxyAuthorization>
<sec:UserName>"${bridge.conduit.proxy.username:}"</sec:UserName>
<sec:Password>"${bridge.conduit.proxy.password:}"</sec:Password>
</http:proxyAuthorization>
</http:conduit>
为什么仅在maven构建期间给出sun.security.validator.ValidatorException
,而junit单独成功运行?
在Maven构建过程中抛出的异常是:
sun.security.validator.ValidatorException:PKIX路径构建失败: sun.security.provider.certpath.SunCertPathBuilderException:无法执行 找到到所请求目标的有效认证路径
任何线索都将不胜感激!