user9361372
user9361372

Reputation: 71

Override entire address in WSDL

I have created a simple spring-boot SOAP webservice using this guide: https://spring.io/guides/gs/producing-web-service/

I am deploying it to a cloud service, but will have an API management layer in front of it.

I would like the WSDL to have the use the URL of the API management layer. (Essentially hardcode the address.)

I have tried two methods:

  1. Use a DefaultWsdl11Definition.setLocationUri()

    @Bean(name = "countries")
    public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) {
    DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
    wsdl11Definition.setPortTypeName("CountriesPort");
    wsdl11Definition.setLocationUri("http://example.com/ws");
    wsdl11Definition.setTargetNamespace("http://spring.io/guides/gs-producing-web-service");
    wsdl11Definition.setSchema(countriesSchema);
    return wsdl11Definition;
    }
    
  2. Use SimpleWsdl11Definition.setWsdl() to point to a hand-edited WSDL

    @Bean(name = "countries")
    public SimpleWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) {
    SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition();
    wsdl11Definition.setWsdl(new ClassPathResource("countries.wsdl")); //this WSDL was edited to have the path I want
    return wsdl11Definition;
    } 
    

I am building with Maven. In both cases, the WSDL hosted by the application replaces the host name with the server it is running on, e.g. http://localhost:8080/ and then uses the rest of the URI.

    <wsdl:service name="CountriesPortService">
    <wsdl:port binding="tns:CountriesPortSoap11" name="CountriesPortSoap11">
    <soap:address location="http://localhost:8080/ws"/>
    </wsdl:port>
    </wsdl:service>

How do I set/override the hostname portion of the

Upvotes: 7

Views: 3169

Answers (2)

Ilmari Tyrkk&#246;
Ilmari Tyrkk&#246;

Reputation: 11

An old question, but I've been struggling with a similar problem just recently. My Spring Boot Web Service was working nice on local on a https port and generating proper .wsdl endpoint addresses, but when moved to a test/prod environment somehow the <soap:address location= had a http protocol and ssl port number after the domain:

<soap:address location="http://test.example.com:443/services/Endpoint" />

should have been

<soap:address location="https://test.example.com/services/Endpoint" />

I managed to overwrite these addresses by creating a class extending WsdlDefinitionHandlerAdapter:

public class MyWsdlDefinitionHandlerAdapter extends WsdlDefinitionHandlerAdapter {

    public MyWsdlDefinitionHandlerAdapter() {}

    @Override
    protected String transformLocation(String location, HttpServletRequest request) {
        String newLocation = super.transformLocation(location, request)
                .replaceFirst("http:", "https:")
                .replaceFirst(":443", "");
        return newLocation;
}
}

And adding this to WebServiceConfig.java (The bean name must be "wsdlDefinitionHandlerAdapter"):

@Bean(name = "wsdlDefinitionHandlerAdapter")
public MyWsdlDefinitionHandlerAdapter myWsdlDefinitionHandlerAdapter() {
    return new MyWsdlDefinitionHandlerAdapter();
}

I hope some one can find this helpful.

Upvotes: 0

user2553467
user2553467

Reputation: 63

I think you are using setTransformWsdlLocations(true) in messageDispatcherServlet method of your Web Service config class. This setting will transform the URLs according to the environment that it is running on. Remove this line so that it will take default setting of fals & it won't override.

Upvotes: 4

Related Questions