How to Parse simple wsdl file?
843833Apr 4 2008 — edited Apr 7 2008Hi,
Please help on parsing the simple wsdl file. Here is my sample wsdl file and I need to get the values of methodname, input parameter type, return type. I'm sure there are some inbuilt tools for parsing. Pls help me on this. Thanks.
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://ws.test.com" xmlns:impl="http://ws.test.com" xmlns:intf="http://ws.test.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsi="http://ws-i.org/profiles/basic/1.1/xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<schema targetNamespace="http://ws.test.com" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<element name="isOddorEvenResponse">
<complexType>
<sequence>
<element name="isOddorEvenReturn" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="isOddorEven">
<complexType>
<sequence>
<element name="x" type="xsd:int"/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="isOddorEvenRequest">
<wsdl:part element="intf:isOddorEven" name="parameters"/>
</wsdl:message>
<wsdl:message name="isOddorEvenResponse">
<wsdl:part element="intf:isOddorEvenResponse" name="parameters"/>
</wsdl:message>
<wsdl:portType name="MyWebService">
<wsdl:operation name="isOddorEven">
<wsdl:input message="intf:isOddorEvenRequest" name="isOddorEvenRequest"/>
<wsdl:output message="intf:isOddorEvenResponse" name="isOddorEvenResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="MyWebServiceSoapBinding" type="intf:MyWebService">
<wsaw:UsingAddressing wsdl:required="false" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"/>
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="isOddorEven">
<wsdlsoap:operation soapAction="isOddorEven"/>
<wsdl:input name="isOddorEvenRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="isOddorEvenResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="MyWebServiceService">
<wsdl:port binding="intf:MyWebServiceSoapBinding" name="MyWebService">
<wsdlsoap:address location="http://localhost:9080/TestWS-JUnit/services/MyWebService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
I'm also attaching the sample class which returns the methodName. I need to know how to get the return type, input type and actual webservice name along with wsal URI location path from wsdl file.
package com.test;
import java.util.Map;
import javax.wsdl.Definition;
import javax.wsdl.WSDLException;
import javax.wsdl.factory.WSDLFactory;
import javax.wsdl.xml.WSDLReader;
public class WSDLParserTest {
/**
* @param args
*/
public static void main(String[] args) {
WSDLFactory wsdlFactory = null;
Definition definition = null;
String endpoint = "http://localhost:9080/Test/services/MyWebService?wsdl";
try {
wsdlFactory = WSDLFactory.newInstance();
} catch (WSDLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
try{
definition = wsdlReader.readWSDL(endpoint);
System.out.println("definition ::"+definition.getNamespaces());
Map services = definition.getServices();
String targetNamespace = definition.getTargetNamespace();
System.out.println("definition234 ::"+targetNamespace);
}
}
}
Your help is greatly appreciated.
Thanks,
Rahul