voliveira89
voliveira89

Reputation: 1294

Create DefaultWsdl11Definition with SimpleXsdSchema

I'm using Spring WS and I'm trying to create a dynamic WSDL trough DefaultWsdl11Definition. Based on Spring WS documentation thw following code should work:

@Bean
public DefaultWsdl11Definition orders() {
    DefaultWsdl11Definition definition = new DefaultWsdl11Definition();
    definition.setPortTypeName("Orders");
    definition.setLocationUri("http://localhost:8080/ordersService/");
    definition.setSchema(new SimpleXsdSchema(new ClassPathResource("echo.xsd")));

    return definition;
}

But the WSDL that is returned doesn't include the operations that are defined in my schema. There is no error in log, the WSDL returned is almost blank, only with the defaults of WSDL generation.

What could be missing?

Upvotes: 0

Views: 2348

Answers (1)

voliveira89
voliveira89

Reputation: 1294

Checking this tutorial from Spring team I finally understand what's wrong. The SimpleXsdSchema has to be a bean.

@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {

    @Bean
    public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean(servlet, "/ws/*");
    }

    @Bean(name = "countries")
    public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("CountriesPort");
        wsdl11Definition.setLocationUri("/ws");
        wsdl11Definition.setTargetNamespace("http://spring.io/guides/gs-producing-web-service");
        wsdl11Definition.setSchema(countriesSchema);
        return wsdl11Definition;
    }

    @Bean
    public XsdSchema countriesSchema() {
        return new SimpleXsdSchema(new ClassPathResource("countries.xsd"));
    }
}

Going deeper, I checked that SimpleXsdSchema implements InitializingBean interface that has afterPropertiesSet() method. It's in the implementation of that method that the schema file is loaded.

So the documentation of Spring WS is wrong. I hope that in the next version this is fixed.

Upvotes: 1

Related Questions