java - 为单个服务配置多个端点
问题描述
我cxf-spring-boot-starter-jaxws
用来编写一个简单的 SOAP 服务。WSDL 有一个服务和几个端口,看起来像这样
<wsdl:port name="myServiceSoap11Endpoint" binding="ns:myServiceSoap11Binding">
<soap:address location="http://example.com/services/myService.myServiceSoap11Endpoint/"/>
</wsdl:port>
<wsdl:port name="myServiceSoap12Endpoint" binding="ns:myServiceSoap12Binding">
<soap12:address location="http://example.com/services/myService.myServiceSoap12Endpoint/"/>
</wsdl:port>
两个绑定几乎相同,并指向相同的 PortType。
在我的 java 代码中,我使用 spring boot@Configuration
机制配置端点。我为每个端口创建一个单独的端点。
// The class MyService was auto-generated by wsdl2java
@Bean
public Endpoint endpointMyServiceSoap11() {
EndpointImpl endpoint = new EndpointImpl(springBus, new MyServiceImplementor());
endpoint.setWsdlLocation(MyService.WSDL_LOCATION.toString());
endpoint.setServiceName(MyService.SERVICE);
endpoint.setEndpointName(MyService.MyServiceSoap11Endpoint);
endpoint.publish("/myService.myServiceSoap11Endpoint");
return endpoint;
}
@Bean
public Endpoint endpointMyServiceSoap12() {
EndpointImpl endpoint = new EndpointImpl(springBus, new MyServiceImplementor());
endpoint.setWsdlLocation(MyService.WSDL_LOCATION.toString());
endpoint.setServiceName(MyService.SERVICE);
endpoint.setEndpointName(MyService.MyServiceSoap12Endpoint);
endpoint.publish("/myService.myServiceSoap12Endpoint");
return endpoint;
}
这有点工作,但是当我想要获取 WSDL 文件时问题就开始了。两个端点都作为单独的服务发布,并且它们都提供自己的 WSDL 版本,每个端点只有一个端口是正确的。
有没有办法将两个端点作为公共服务的一部分发布,以便/myService?WSDL
返回一个正确的 WSDL 与两个端点?
解决方案
经过一番干预,我发现不可能做我想做的事。不过,至少有一种方法可以获取正确的 WSDL 文件。您可以通过使用 autoRewriteSoapAddressForAllServices 属性来做到这一点,例如像这样
endpoint.setProperties(Map.of(WSDLGetUtils.AUTO_REWRITE_ADDRESS_ALL, true))
但是,此属性不起作用cxf.path
,您需要将所有内容放入server.servlet.contextPath
中,因为 WSDL 中的结果路径基本上是通过将 contextPath 与端点发布路径结合起来创建的。
推荐阅读
- rust - Rust - 将 const 设置为环境变量的值,具有备用值
- flutter - Flutter 网址路由
- azure-ad-b2c - Azure B2C SAML 元数据错误 AADB2C90020
- laravel - Laravel Jetstream Fortify 强制 SSL 或 HTTPS
- types - Agda:通常/花括号相对于彼此和“:”符号的使用方式
- extjs - 如何在不触发 ExtJS7 中的任何事件的情况下暂停和恢复路由器?
- android - 任务 ':app:packageRelease' 执行失败。- 反应原生安卓
- c++ - 在碰撞OpenGL时改变物体的颜色
- c - 从 C 中的音频流服务器读取
- javascript - 覆盖 console.log 等以在 HTML 视图中显示