Web Services 如何替换WSDL中的CXF基URL

mftmpeh8  于 2022-11-15  发布在  其他
关注(0)|答案(1)|浏览(156)

我使用Apache CXF和Sping Boot 来公开SOAP端点。

@Slf4j
@Configuration
public class SoapWebServiceConfig {

    @Bean(name = "cxf")
    public SpringBus springBus() {
        var loggingFeature = new LoggingFeature();
        loggingFeature.addSensitiveProtocolHeaderNames(Set.of("Server", "Accept", "Date"));
        loggingFeature.setPrettyLogging(true);

        var springBus = new SpringBus();
        springBus.getFeatures().add(loggingFeature);
        return springBus;
    }

    @Bean
    public ActivateGateway activateGateway() {
        return new ActivateGatewayImpl();
    }

    @Bean
    @SneakyThrows
    public Endpoint activateGatewayEndpoint(Bus bus, ActivateGateway activateGateway) {
        EndpointImpl endpoint = new EndpointImpl(bus, activateGateway);
        endpoint.publish("/activateGateway");
        return endpoint;
    }

    @Primary
    @Bean(name = "cxfServletRegistration")
    public ServletRegistrationBean<CXFServlet> cxfServletRegistration() {
        ServletRegistrationBean<CXFServlet> servletRegistrationBean = new ServletRegistrationBean<>(
            new CXFServlet(), "/daas/activate/*");
        servletRegistrationBean.setLoadOnStartup(1);
        return servletRegistrationBean;
    }
}

您可以看到我公开了一个端点,它可以在https://localhost:8081/daas/activate/activateGateway?wsdl中访问:

...
  <wsdl:import location="https://localhost:8081/daas/activate/activateGateway?wsdl=activateGateway.wsdl" namespace="http://schemas.symantec.com/cda/1.0/activateGateway">
    </wsdl:import>
  <wsdl:binding name="ActivateGatewayServiceSoapBinding" type="ns1:activateGateway">
  ...
  <wsdl:service name="ActivateGatewayService">
    <wsdl:port binding="tns:ActivateGatewayServiceSoapBinding" name="activateGatewayPort">
      <soap:address location="https://localhost:8081/daas/activate/activateGateway"/>
    </wsdl:port>
  </wsdl:service>

但是这个location="https://localhost:8081/daas/activate/activateGateway是无效的,因为这个服务在api网关之后。有没有办法改变“基本url”?例如,改变为这个https://localhost:8081/soap/daas/activate/activateGateway(注意额外的/soap前缀)。
这些文件在开始时生成,这不是硬编码。

neekobn8

neekobn81#

我还没有找到一个解决方案,但是找到了一个变通的方法。有一个配置指南https://cxf.apache.org/docs/jax-ws-configuration.html,其中提到了publishedEndpointUrl,但遗憾的是,由于某些原因,它对我不起作用。我使用的解决方案是server.servlet.context-path=/test和Ambassador的重写功能的组合:

apiVersion: getambassador.io/v2
kind: Mapping
metadata:
  name: {{ include "project.name" . }}
spec:
  prefix: /test
  rewrite: /test # <-- This
  host: {{ .Values.global.host }}
  service: {{ $service }}
  timeout_ms: 10000
  connect_timeout_ms: 10000

相关问题