我正在使用 Apache CXF (v2.7.3) 通过 HTTPS 调用 SOAP 服务。我可以从文件加载信任库,但不能从类路径加载 - 我收到“无效的密钥库格式”错误。
我的 cfx.xml 文件中有这个配置:
<http:conduit name="*.http-conduit">
<http:tlsClientParameters>
<sec:trustManagers>
<!-- For some reason, when I use the resource field, I get a "Invalid keystore format" exception -->
<sec:keyStore type="JKS" password="MYPASSWORD"
resource="truststore.jks" />
<!-- THIS WORKS FINE: <sec:keyStore type="JKS" password="MYPASSWORD"
file="/fullPathToMyTrustStore/truststore.jks" /> -->
</sec:trustManagers>
</http:tlsClientParameters>
</http:conduit>
我可以从文件加载信任库,但不能从类路径加载。我可以从异常中看出正在找到 truststore.jks 文件,但它是无效的。这是抛出异常的堆栈跟踪。
Caused by: java.io.IOException: Invalid keystore format
at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:633)
at sun.security.provider.JavaKeyStore$JKS.engineLoad(JavaKeyStore.java:38)
at java.security.KeyStore.load(KeyStore.java:1185)
at org.apache.cxf.configuration.jsse.TLSParameterJaxBUtils.getKeyStore(TLSParameterJaxBUtils.java:142)
at org.apache.cxf.configuration.jsse.TLSParameterJaxBUtils.getTrustManagers(TLSParameterJaxBUtils.java:292)
at org.apache.cxf.configuration.jsse.TLSClientParametersConfig.createTLSClientParametersFromType(TLSClientParametersConfig.java:114)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:149)