apache > ws.apache
WSRF
 

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-Metadata Exchange (WS-MEx) specification (defined by Microsoft and other industry contributors) defines operations that can be provided by services to allow clients to retrieve these metadata documents.

Note
Pubscribe will handle the GetMetadata operation for you if your WSDL supports the portType. The Get operation, however will be generated as an abstract method which you will need to implement in your Service class. If you do not wish to support/implement the Get operation, you may delegate the operation to the org.apache.ws.resource.metadataexchange.v2004_09.porttype.impl.MetadataExchangePortTypeImpl.get() operation which will in turn throw a fault.

Define the Operations

The metadata 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 Configuration File

The WSRF configuration file must be modified to include a metadata bean for your service that defines your metadata documents and where they are located.

To update the WSRF configuration file to include metadata information:

  1. Using a text editor, open wsrf-config.xml in the WEB-INF/classes directory.
  2. Add the following property to the ResourceHome bean, with which you would like to associate metadata:
        <property name="metadataConfig">
        <bean class="org.apache.ws.metadata.MetadataConfiguration">
    	  <constructor-arg>
    	    <list>		  
    		<bean class="org.apache.ws.metadata.MetadataEntry">     
    		  <property name="dialect">    
    		    <value>http://schemas.xmlsoap.org/wsdl/</value>    
    		  </property>  
    		  <property name="identifier">  
    		    <value>http://ws.apache.org/notification/base/service/SubscriptionManager.wsdl</value>
    		  </property>   
    		  <property name="location"> 
    		    <value>wsdl/SubscriptionManager.wsdl</value>
    		  </property>	    
    		</bean>	 
    	    </list>
    	  </constructor-arg>	    
    	</bean> 
        </property>	 

    The org.apache.ws.metadata.MetadataConfiguration object containing the metadata is available via the ResourceHome interface, which is available via the ResourceContext - i.e. getResourceContext().getResourceHome().getMetadataConfig()

  3. The MetadataConfiguration contains a set of MetadataEntry objects. Each MetadataEntry includes a dialect property that defines the type of the data (xsd, wsdl, etc...) , an identifier property that uniquely identifies a particular document (e.g. a WSDL targetNamespace), and a location which is either a file URL, http URL or a resource path (which would be loaded via the current class loader). The following example shows the SubscriptionManager service's metadata configuration. Notice it has a single metadata entry which describes its WSDL.
      <bean id="SubscriptionHome" class="org.apache.ws.notification.base.v2004_06.impl.SubscriptionHome" init-method="init">
        <property name="portComponentName">
          <value>SubscriptionManager</value>
        </property>
        <property name="serviceClass">
          <value>org.apache.ws.notification.base.v2004_06.impl.SubscriptionService</value>
        </property>
        <property name="resourceClass">
          <value>org.apache.ws.notification.base.v2004_06.impl.SubscriptionResource</value>
        </property>
        <property name="resourceIdentifierReferenceParameterName">
          <value>{http://ws.apache.org/notification/base/service/SubscriptionManager}ResourceIdentifier</value>
        </property>
        <property name="metadataConfig">
    	<bean class="org.apache.ws.metadata.MetadataConfiguration" singleton="true">
    	  <constructor-arg>
    	    <list>		  
    		<bean class="org.apache.ws.metadata.MetadataEntry">     
    		  <property name="dialect">    
    		    <value>http://schemas.xmlsoap.org/wsdl/</value>    
    		  </property>  
    		  <property name="identifier">  
    		    <value>http://ws.apache.org/notification/base/service/SubscriptionManager.wsdl</value>
    		  </property>   
    		  <property name="location"> 
    		    <value>wsdl/SubscriptionManager.wsdl</value>
    		  </property>	    
    		</bean>	 
    	    </list>
    	  </constructor-arg>	    
    	</bean> 
        </property>	 
      </bean>
  4. Save and close wsrf-config.xml.
  5. Restart Tomcat if it is already started.