Adding Service Metadata
Introduction
Web services may have various metadata associated with them (e.g. the WSDL for the service or a set of Topic Space documents). The WS-MEXWS-Metadata Exchange specification (defined by Microsoft and other industry contributors) defines operations that can be provided by services to allow clients to retrieve these metadata documents.
Define the Operations
The metadata data operations are defined in your service's WSDL. If you used the INSTALL_DIR/template/_TEMPLATE_.wsdl file to create your WSDL, you simply need to uncomment these operations in the portType and binding sections.
<portType name="MyPortType"> ... <operation name="GetMetadata" > <input message="mex:GetMetadataMsg" wsa04:Action="http://schemas.xmlsoap.org/ws/2004/09/mex/GetMetadata/Request" /> <output message="mex:GetMetadataResponseMsg" wsa04:Action="http://schemas.xmlsoap.org/ws/2004/09/mex/GetMetadata/Response" /> </operation> <operation name="Get" > <input message="mex:GetMsg" wsa04:Action="http://schemas.xmlsoap.org/ws/2004/09/mex/Get/Request" /> <output message="mex:GetResponseMsg" wsa04:Action="http://schemas.xmlsoap.org/ws/2004/09/mex/Get/Response" /> </operation> </portype> <binding name="MySoapHttpBinding"> ... <operation name="GetMetadata" > <soap:operation style="document"/> <input> <soap:body use="literal"/> </input> <output> <soap:body use="literal"/> </output> </operation> <operation name="Get" > <soap:operation style="document"/> <input> <soap:body use="literal"/> </input> <output> <soap:body use="literal"/> </output> </operation> </binding>
Modify the JNDI Configuration File
The JNDI configuration file must be modified to include a metadata resource for your service as well as configurations that define where your metadata files are located.
To update the JNDI configuration file to include metadata information:
- Using a text editor, open jndi-config.xml in the WEB-INF/classes directory.
- Add the following JNDI resource block to the service, for which you would like to associate metadata:
<service name="myService"> <resource name="metadata" type="org.apache.ws.util.jndi.tools.MetadataConfigImpl">
The org.apache.ws.util.jndi.tools.MetadataConfigImpl object containing the metadata is available via JNDI using a Context lookup of wsrf/services/{service_name}/metadata - i.e. ctx.lookup("wsrf/services/sushi/metadata");
- In the metadata resource block, add a metadataConfig element that contains metadata configurations. The configuration includes a dialect
attribute that defines the type of the data (xsd, wsdl, etc...) and an identifier attribute that uniquely identifies a particular document and is typically a targetNamespace. The
following examples demonstrate five different methods of configuring where your metadata files are located. The files should be "reachable" at the configured locations.
<resource name="metadata" type="org.apache.ws.util.jndi.tools.MetadataConfigImpl"> <metadataConfig> <!-- classpath --> <metadata dialect="http://www.w3.org/2001/XMLSchema" identifier="http://ws.apache.org/resource/properties/test/sushi_classpath"> <location>org/apache/ws/resource/properties/SushiProperties.xsd</location> </metadata> <!-- file --> <metadata dialect="http://schemas.xmlsoap.org/wsdl/" identifier="http://ws.apache.org/resource/properties/test/sushi_wsdl"> <location>C:/Projects/apache/wsrf/trunk/src/test/org/apache/ws/resource/properties/SushiProperties.wsdl</location> </metadata> <!-- http url --> <metadata dialect="http://www.w3.org/2001/XMLSchema" identifier="http://ws.apache.org/resource/properties/test/sushi_url"> <location>http://localhost:8080/wsrf/SushiProperties.xsd</location> </metadata> <!-- file url --> <metadata dialect="http://www.w3.org/2001/XMLSchema" identifier="http://ws.apache.org/resource/properties/test/sushi_fileurl"> <location>file://C:/Projects/apache/wsrf/trunk/src/test/org/apache/ws/resource/properties/SushiProperties.xsd</location> </metadata> <!-- EndpointReference --> <metadata dialect="http://schemas.xmlsoap.org/ws/2004/08/addressing" identifier="http://ws.apache.org/resource/properties/test/sushi_epr"> <reference xmlns:wsa04="http://schemas.xmlsoap.org/ws/2004/08/addressing"> <wsa04:Address>http://localhost:8080/wsrf/services/sushi</wsa04:Address> <wsa04:ReferenceProperties> <sushi:ResourceIdentifier xmlns:sushi="http://ws.apache.org/resource/properties/test/sushi">1</sushi:ResourceIdentifier> </wsa04:ReferenceProperties> </reference> </metadata> </metadataConfig> </resource>
- Save and close jndi-config.xml.
- Restart Tomcat if it is already started.