【问题标题】:Configuring several endpoints for a single service为单个服务配置多个端点
【发布时间】:2019-07-30 17:58:16
【问题描述】:

我正在使用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?

【问题讨论】:

    标签: java spring-boot soap wsdl cxf


    【解决方案1】:

    经过一番干预,我发现不可能做我想做的事。不过,至少有一种方法可以获取正确的 WSDL 文件。您可以通过使用 autoRewriteSoapAddressForAllServices 属性来做到这一点,例如像这样

    endpoint.setProperties(Map.of(WSDLGetUtils.AUTO_REWRITE_ADDRESS_ALL, true))
    

    此属性不适用于cxf.path,但是,您需要将所有内容放入server.servlet.contextPath,因为 WSDL 中的结果路径基本上是通过将 contextPath 与端点发布路径相结合来创建的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-18
      • 1970-01-01
      • 1970-01-01
      • 2018-01-04
      • 1970-01-01
      • 2011-09-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多