Announcement Announcement Module
Collapse
No announcement yet.
Generate wsdl as part of build process instead of runtime Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Generate wsdl as part of build process instead of runtime

    Hi.
    I have been struggling with the problem of automatically generating wsdl on WebSphere (see issue: http://jira.springframework.org/browse/SWS-166), and have had no luck changin to PARENT_LAST classloading.

    So I'm thinking it should be possible to use
    Code:
    org.springframework.ws.wsdl.wsdl11.DynamicWsdl11Definition
    as a part of the build process. Maybe as a maven plugin so that the wsdl files are generated build time, and then exposed using the
    Code:
    org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition
    in the web application.

    Please let me know if anyone of you have explored this possibility.

    Regards,
    Paul Nyheim

  • #2
    Sounds perfectly reasonable to me.

    Before SWS introduced runtime generation of WSDL, Arjen recommended using an XSLT stylesheet to generate the WSDL at build time. I'm not sure how much the results would differ, but I remember this worked without problems at the time.

    Cheers,
    -Ralph.

    Comment


    • #3
      Creating a WSDL from code is possible, though there is no supplied ant task or similar for it.

      Basically, you would need to reproduce the steps taken in the DynamicWsdlDefinition, i.e. something like:

      Code:
      XsdBasedSoap11Wsdl4jDefinitionBuilder builder = new XsdBasedSoap11Wsdl4jDefinitionBuilder();
      // set builder properties, such as schema, location, etc.
      DynamicWsdl11Definition definition = new DynamicWsdl11Definition();
      definition.setBuilder(builder);
      Transformer transformer = TransformerFactory.newInstance().newTransformer();
      transformer.transfor(definition.getSource(), new StreamResult("service.wsdl");
      I haven't tried it, but it should work.

      Comment


      • #4
        Try this

        Paul,

        The only thing that Arjen left out is that you need to call the afterPropertiesSet method on the beans that would normally be managed by Spring. I found that it was easier to reuse the Spring XML file and implement a BeanPostProcessor to do the generation. Take a look at the included code.

        Here's how it is configured:
        Code:
            <bean id="wsdlGenerator" class="josh.WsdlGenerationPostProcessor">
                <property name="outputDir" value="C:/temp/wsdlgen/wsdl"/>
            </bean>
        Here is some sample code:

        Code:
        package josh;
        import javax.xml.transform.*;
        import javax.xml.transform.stream.StreamResult;
        import java.io.*;
        import org.springframework.beans.BeansException;
        import org.springframework.beans.FatalBeanException;
        import org.springframework.beans.factory.InitializingBean;
        import org.springframework.beans.factory.config.BeanPostProcessor;
        import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition;
        public class WsdlGenerationPostProcessor implements BeanPostProcessor, InitializingBean {
         
            private String outputDir;
            private Transformer transformer; 
            private File outputDirAsFile;
         
            public void setOutputDir(String outputDir) {
                this.outputDir = outputDir;     
            }
            public void afterPropertiesSet() throws Exception {
                this.transformer = TransformerFactory.newInstance().newTransformer();
                this.outputDirAsFile = new File(this.outputDir);
                this.outputDirAsFile.mkdirs();
            }
         
            //Ignore
            public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
                return bean;
            }
         
            public Object postProcessAfterInitialization(Object bean, String beanName)
                    throws BeansException {
                if (bean instanceof Wsdl11Definition) {
                    Wsdl11Definition definition = (Wsdl11Definition)bean;
         
                    //Assume that the beanName will be the wsdl name.  Change appropriately.
                    String wsdlFileName = beanName + ".wsdl";
         
                    File wsdlFile = new File(outputDirAsFile, wsdlFileName);
         
                    try {
                        transformer.transform(definition.getSource(), new StreamResult(wsdlFile));
                    }
                    catch(TransformerException te) {
                        throw new FatalBeanException("Error generating wsdl for bean: " + beanName,te);
                    }                   
                }
         
                return bean;
            }
         
        }
        Regards,

        Joshua

        Comment


        • #5
          Hi Josh,

          I am quite interessted in your solution. But how can I call the afterPropertiesSet method in build/compile time to generate the WSDL file?

          Comment

          Working...
          X