Home > Back-end >  How to replace CXF base url in WSDLs
How to replace CXF base url in WSDLs

Time:07-26

I'm using Apache CXF and Spring Boot to expose SOAP endpoints. Here's the config:

@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;
    }
}

You can see that I expose one endpoint. It's accessible at 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>

But this location="https://localhost:8081/daas/activate/activateGateway is not valid because this service is behind api gateway. Is there a way to change the "base url"? For example to this https://localhost:8081/soap/daas/activate/activateGateway (notice the additional /soap prefix).

These files are generated at the start, this is not hardcoded.

CodePudding user response:

I haven't found a solution, but rather a workaround. There's this configuration guide https://cxf.apache.org/docs/jax-ws-configuration.html which mentions publishedEndpointUrl, but sadly it didn't work for me for some reason. The solution I used is combination of server.servlet.context-path=/test and Ambassador's rewrite functionality:

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
  • Related