我用wsdl的cxf和camel创建了一个Web服务。以下是我的bean配置:
@Bean
open fun cxfServlet(): ServletRegistrationBean<CXFServlet> {
val servlet = ServletRegistrationBean(CXFServlet(), "/ws/*")
servlet.setLoadOnStartup(1)
servlet.setName("cxfServlet")
return servlet
}
@Bean
open fun cxf(): Bus {
return BusFactory.newInstance().createBus()
}
@Bean("endpoint")
open fun endpoint(bus: Bus): CxfEndpoint {
val endpoint = CxfEndpoint()
endpoint.address = "/endpoint"
endpoint.serviceClass = IWebService::class.java
endpoint.wsdlURL = "wsdl/mywsdl.wsdl"
endpoint.dataFormat = DataFormat.POJO
endpoint.bindingId = SOAPBinding.SOAP11HTTP_BINDING
endpoint.isLoggingFeatureEnabled = true
endpoint.loggingSizeLimit = -1
return endpoint
}
我也配置了ssl。我使用springBoot,我的属性文件是:
server.port = 8442
security.require-ssl = true
server.ssl.key-store-type = PKCS12
server.ssl.key-store = classpath:keystore.p12
server.ssl.key-store-password = 123456
server.ssl.key-alias = testalias
该服务的wsdl可在以下地址获得:
在我将WSDl与块“ Policy”一起使用之前,它工作正常:
<wsp:Policy wsu:Id="id">
<wsp:ExactlyOne>
<wsp:All>
<sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:TransportToken>
<wsp:Policy>
<sp:HttpsToken RequireClientCertificate="false"/>
</wsp:Policy>
</sp:TransportToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic256/>
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Strict/>
</wsp:Policy>
</sp:Layout>
</wsp:Policy>
</sp:TransportBinding>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
现在该应用可以正常运行,但是当我发送消息时出现异常:
org.apache.cxf.ws.policy.PolicyException:无法满足这些替代策略:
{http://schemas.xmlsoap.org/ws/2005/07/securitypolicy} TransportToken
{http://schemas.xmlsoap.org/ws/2005/07/securitypolicy} HttpsToken
{http://schemas.xmlsoap.org/ws/2005/07/securitypolicy} AlgorithmSuite
{http://schemas.xmlsoap.org/ws/2005/07/securitypolicy} Basic256
{http://schemas.xmlsoap.org/ws/2005/07/securitypolicy}布局
{http://schemas.xmlsoap.org/ws/2005/07/securitypolicy}严格
但是,如果我在soapUI中创建服务器,它就可以正常工作。
我尝试了一些有关创建拦截器的建议,而其他建议则来自stackoverflow,但没有任何变化。
我该如何解决这个问题?
答案 0 :(得分:0)
您的Web服务是否已通过SSL保护?该错误表明WSDL中未满足声明的安全策略。
请注意,WSDL策略声明未设置在请求者和提供者之间的HTTPS传输!当调用具有已定义策略的Web服务时,它们仅确保已声明的机制到位。
对于SoapUI,我不是很清楚,但我认为它会忽略该策略。
答案 1 :(得分:0)
实际上,我发现使用 IgnorablePolicyInterceptorProvider 的某种解决方案。但是据我所知,这只是无视政策,我认为这不是真正的解决方案:
val reg = bus.getExtension(PolicyInterceptorProviderRegistry::class.java)
val set = HashSet<QName>()
set.add(QName("http://schemas.xmlsoap.org/ws/2005/07/securitypolicy", "TransportBinding"))
set.add(QName("http://schemas.xmlsoap.org/ws/2005/07/securitypolicy", "TransportToken"))
set.add(QName("http://schemas.xmlsoap.org/ws/2005/07/securitypolicy", "HttpsToken"))
set.add(QName("http://schemas.xmlsoap.org/ws/2005/07/securitypolicy", "AlgorithmSuite"))
set.add(QName("http://schemas.xmlsoap.org/ws/2005/07/securitypolicy", "Basic256"))
set.add(QName("http://schemas.xmlsoap.org/ws/2005/07/securitypolicy", "Layout"))
set.add(QName("http://schemas.xmlsoap.org/ws/2005/07/securitypolicy", "Strict"))
reg.register(IgnorablePolicyInterceptorProvider(set))