The WS-MetaDataExchange specification defines protocols that support the dynamic exchange of metadata that is relevant to the service interaction (such as XML Schema WS-policy and WSDL descriptions) between Web services endpoints. WS-MetadataExchange specification [1] provides more information you need to know about it.
WSO2 Mex is the implementation of WS-MetadataExchange version 1.1 (August 2006) for Apache Axis2/Java and WSO2 WSAS. The objective of this KB is to walk you through the basic steps to see how wso2-MEX module is used to retrieve metadata of a web service.
Applies To
| WSO2 WSAS | Version 2.2 or later |
Pre-requisites install WSO2 WSAS [2]
First you need to engage WSO2 MEX module in to a web service deployed on WSO2 WSAS.
Start wso2wsas by running wso2wsas.bat{sh}. Then open a browser and go to https://localhost:9443
Log in to WSAS management console (admin/admin)
Navigate to service and service group management page. Select "version" service. You will be directed to the Version service's service information page.
Select "Manage Module Engagements" link. "Engage modules" page will be displayed. Select WSO2-MEX-2.* from the "Module" drop down and click on engage.
The following page will appear.
Step 2 - Develop a client to retrieve metadata of version service
Next, we need to write a client to get some matadata of version service. Open your favorite ide and create a new class as given below. Here we are going to fetch the schema (xsd) of version service and display it in console.
public class MexTestClient {
public static final String epr = "http://localhost:9762/services/version?wsdl";
public static void main(String[] args)throws AxisFault {
MexClient mc = new MexClient();
Options options = mc.getOptions();
options.setTo(new EndpointReference(epr));
options.setAction(DRConstants.SPEC.Actions.GET_METADATA_REQUEST);
options.setExceptionToBeThrownOnSOAPFault(true);
OMElement request = mc.setupGetMetadataRequest(MexConstants.SPEC.DIALECT_TYPE_SCHEMA, null);
OMElement result = mc.sendReceive(request);
Metadata metadata = new Metadata();
metadata.fromOM(result);
MetadataSection[] metadatSections = metadata.getMetadatSections();
MetadataSection metadataSection;
for (int i = 0; i < metadatSections.length; i++) {
metadataSection = metadatSections[i];
String dialect = metadataSection.getDialect();
if (dialect != null) {
System.out.println("Dialect : " + dialect);
}
OMNode inlineData = metadataSection.getInlineData();
if (inlineData != null) {
System.out.println("InlineData : \n" + inlineData.toString());
continue;
}
Location location = metadataSection.getLocation();
if (location != null)
{
System.out.println("Location : \n" + location.getURI());
continue;
}
}
}
}
Complie and run the client by adding WSAS libraries (WSAS_HOME/lib) in to your class path. The schema metadata of version service will be fetched and deployed in runtime console. In the same way, you can retrieve WSDL metadata and policy as follows.
OMElement request = mc.setupGetMetadataRequest(MexConstants.SPEC.DIALECT_TYPE_WSDL, null); OMElement request = mc.setupGetMetadataRequest(MexConstants.SPEC.DIALECT_TYPE_POLICY, null);
Resources:
[1]http://wso2.org/library/2794 [3]
Author:
Charitha Kankanamge, Manager Software Quality Assurance, charitha AT wso2 dot com