Spring :How to generate WSDL at run time if XSD provided as input

8.7k views Asked by At

I have to create simulator where on run time WSDL files can be generated if XSD file is given as input. For this i am using Spring Web Services and JAXB API to generate WSDL from given XSD file.

After all the sample programs , i have understood that java classes can be generated with help of JAXB on running maven file but still we need to manually write the serviceEndpoint class , hence it seems difficult to generate ServiceEndpoint class for the given xsd file.

I want to know is it possible to generate serviceEndpoint class as well for the given xsd on the run time and compiled as well.

In short i want to automate whole process of WSDL generation if XSD file is given as input as runtime.

2

There are 2 answers

0
zygimantus On

Make sure that you use ServletRegistrationBean with defined URL mapping, etc., like this:

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

If your XSD schema is named test.xsd then you can access your WSDL at runtime here: http://localhost:8080/ws/test.wsdl

0
Samantha Catania On

Spring automatically exposes the WSDL generated from your configuration. See section 5.3.1.1 from the official documentation