Creating WSDL files with comments using Axis Java2WSDL tool
WSDL files produced by Axis Java2WSDL tool have
no <wsdl:documentation>
tags in the generated WSDL. You need these tags to make the WSDL file
self-documenting. Stubs-generating tools, like WSDL2Java,
may include content of the tags as comments into generated
stub classes, making them also documented. Or you can use
WSDLDoc tool to generate a nice Javadoc-style documentation for your
webservice.
This page shows how to add them and also how to use that documented
WSDL file as the file that Axis returns when asked by ?wsdl
parameter.
Suppose that you have a WSDL file named MyService.wsdl
produced by Java2WSDl tool. (If not, see this guide
how to do it.) You may even have Ant build.xml file
that generates it from Java source as needed, so you cannot edit
it by hand to add any documentation tags. So a solution is to
use XSLT transformation to that. Copy this XSLT stylesheet
(source) and change the "documentation"
target so that it adds your comments to your operations.
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/"
>
<xsl:strip-space elements="*"/>
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
<xsl:template match="wsdl:operation">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:call-template name="documentation" />
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<xsl:template name="documentation">
<xsl:choose>
<xsl:when test="@name='getSomething'">
<wsdl:documentation>Returns something</wsdl:documentation>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy>
</xsl:template>
</xsl:stylesheet>
Then do XSLT transformation of the original MyService.wsdl file
with this XSLT stylesheet. I found that the default XSLT transformer
included in SUN JDK 1.4.2 doesn't do a good job in indenting
the result properly, so I recommend to use
SAXON to do that.
If you have an Ant build file that generates the WSDL file,
change it so that it is written to, say, MyService_gen.wsdl
and the use following code to add the documentation:
<java classname="com.icl.saxon.StyleSheet" dir="." fork="yes"
classpathref="some.path" failonerror="true" >
<arg value="-o"/> <arg value="${build}/MyService.wsdl"/>
<arg value="${build}/MyService_gen.wsdl"/>
<arg value="${src}/wsdl.xsl"/>
</java>
Now how to make this file to be the file which is returned by Axis
when /axis/services/MyService?wsdl is called ? Copy the file
MyService.wsdl to $CATALINA_HOME/webapps/axis/WEB-INF/classes. Then edit $CATALINA_HOME/webapps/axis/WEB-INF/server-config.wsdd
and add line
<wsdlFile>/MyService.wsdl</wsdlFile>
to description of your service. That's it.
Sent any comments to Martin Kuba.
Last updated: $Date: 2004/08/20 11:41:29 $
|