Search code examples
soapspring-bootspring-ws

Spring WS remove flexible URL, Restricting WSDL URL and service URL


I'm trying to make a Spring Boot Soap WebService application, and was following the Get Started (https://spring.io/guides/gs/producing-web-service/) example to learn how to do this.

I've created what I want, but I have two URL problems with this setup and I could not find what configuration should I change to fix this :

  • WSDL URL basic is localhost:8080/ws/countries.wsdl but anything like localhost:8080/ws/whatever/countries.wsdl is correct
  • service URL for SoapUI request is localhost:8080/ws but anything like localhost:8080/ws/whatever is correct

I know that this is a feature for Spring WS, but I want a fixed URL (without 'whatever' in both cases) and could not find what to change for this


Solution

  • There is no straight forward way to restrict the way you want.

    1. SOAP service is not URL based.
    2. SOAP message body describe the endpoint.

    The thing you wanted is possible following way.

    Changing URL mapping in ServletRegistrationBean to restrict URL access

    1. Existing /ws/* mapping is the reason why all the /ws/whatever url successfully responded.
    2. Change as new ServletRegistrationBean(servlet, "/ws");
    3. Effect will be you can not request other than /ws URL
    4. Now the problem is, you can not get WSDL by this mapping.

    Solution to get WSDL

    1. The DefaultWsdl11Definition is actually generating WSDL from XSD on every request.
    2. Save countries.wsdl to resource folder as static WSDL file.
    3. Remove DefaultWsdl11Definition bean.
    4. Create a new SimpleWsdl11Definition bean as like

      @Bean(name = "countries") public SimpleWsdl11Definition orders() { SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition(); wsdl11Definition.setWsdl(new ClassPathResource("countries.wsdl")); return wsdl11Definition; }

    5. Now add another static URL mapping in ServletRegistrationBean. As it will be finally look like new ServletRegistrationBean(servlet, "/ws", "/ws/countries.wsdl");

    6. This practice is good for development phase as you can publish easily the changed definition. But it is recommended to use static-wsdl for production environment. Details ** here