Parsing WSDL with Java
The Membrane SOA Model makes it easy to parse a WSDL. Listing 1 is an example of parsing a wsdl with almost all the information of it. Over and above that, you can get much more details using many other methods and features of SOA Model. For more information see the java api doc or discuss in SOA Model Forum.
package samples.wsdl;
import com.predic8.schema.*;
import com.predic8.wsdl.*;
public class FullWSDLParser {
public static void main(String[] args) {
WSDLParser parser = new WSDLParser();
Definitions defs = parser.parse("http://www.thomas-bayer.com/axis2/services/BLZService?wsdl");
out("-------------- WSDL Details --------------");
out("TargenNamespace: \t" + defs.getTargetNamespace());
out("Style: \t\t\t" + defs.getStyle());
if (defs.getDocumentation() != null) {
out("Documentation: \t\t" + defs.getDocumentation());
}
out("\n");
/* For detailed schema information see the FullSchemaParser.java sample.*/
out("Schemas: ");
for (Schema schema : defs.getSchemas()) {
out(" TargetNamespace: \t" + schema.getTargetNamespace());
}
out("\n");
out("Messages: ");
for (Message msg : defs.getMessages()) {
out(" Message Name: " + msg.getName());
out(" Message Parts: ");
for (Part part : msg.getParts()) {
out(" Part Name: " + part.getName());
out(" Part Element: " + ((part.getElement() != null) ? part.getElement() : "not available!"));
out(" Part Type: " + ((part.getType() != null) ? part.getType() : "not available!" ));
out("");
}
}
out("");
out("PortTypes: ");
for (PortType pt : defs.getPortTypes()) {
out(" PortType Name: " + pt.getName());
out(" PortType Operations: ");
for (Operation op : pt.getOperations()) {
out(" Operation Name: " + op.getName());
out(" Operation Input Name: "
+ ((op.getInput().getName() != null) ? op.getInput().getName() : "not available!"));
out(" Operation Input Message: "
+ op.getInput().getMessage().getQname());
out(" Operation Output Name: "
+ ((op.getOutput().getName() != null) ? op.getOutput().getName() : "not available!"));
out(" Operation Output Message: "
+ op.getOutput().getMessage().getQname());
out(" Operation Faults: ");
if (op.getFaults().size() > 0) {
for (Fault fault : op.getFaults()) {
out(" Fault Name: " + fault.getName());
out(" Fault Message: " + fault.getMessage().getQname());
}
} else out(" There are no faults available!");
}
out("");
}
out("");
out("Bindings: ");
for (Binding bnd : defs.getBindings()) {
out(" Binding Name: " + bnd.getName());
out(" Binding Type: " + bnd.getPortType().getName());
out(" Binding Protocol: " + bnd.getBinding().getProtocol());
if(bnd.getBinding() instanceof AbstractSOAPBinding) out(" Style: " + (((AbstractSOAPBinding)bnd.getBinding()).getStyle()));
out(" Binding Operations: ");
for (BindingOperation bop : bnd.getOperations()) {
out(" Operation Name: " + bop.getName());
if(bnd.getBinding() instanceof AbstractSOAPBinding) {
out(" Operation SoapAction: " + bop.getOperation().getSoapAction());
out(" SOAP Body Use: " + bop.getInput().getBindingElements().get(0).getUse());
}
}
out("");
}
out("");
out("Services: ");
for (Service service : defs.getServices()) {
out(" Service Name: " + service.getName());
out(" Service Potrs: ");
for (Port port : service.getPorts()) {
out(" Port Name: " + port.getName());
out(" Port Binding: " + port.getBinding().getName());
out(" Port Address Location: " + port.getAddress().getLocation()
+ "\n");
}
}
out("");
}
private static void out(String str) {
System.out.println(str);
}
}
Listing 1: FullWSDLParser.java
In listing 2 you can see the output.
-------------- WSDL Details --------------
TargenNamespace: http://thomas-bayer.com/blz/
Style: Document/Literal-Wrapped
Documentation: BLZService
Schemas:
TargetNamespace: http://thomas-bayer.com/blz/
Messages:
Message Name: getBank
Message Parts:
Part Name: parameters
Part Element: element[name=getBank,type={http://thomas-bayer.com/blz/}getBankType,ref=null,embeddedType=null]
Part Type: not available!
Message Name: getBankResponse
Message Parts:
Part Name: parameters
Part Element: element[name=getBankResponse,type={http://thomas-bayer.com/blz/}getBankResponseType,ref=null,embeddedType=null]
Part Type: not available!
PortTypes:
PortType Name: BLZServicePortType
PortType Operations:
Operation Name: getBank
Operation Input Name: not available!
Operation Input Message: {http://thomas-bayer.com/blz/}getBank
Operation Output Name: not available!
Operation Output Message: {http://thomas-bayer.com/blz/}getBankResponse
Operation Faults:
There are no faults available!
Bindings:
Binding Name: BLZServiceSOAP11Binding
Binding Type: BLZServicePortType
Binding Protocol: SOAP11
Style: document
Binding Operations:
Operation Name: getBank
Operation SoapAction:
SOAP Body Use: literal
Binding Name: BLZServiceSOAP12Binding
Binding Type: BLZServicePortType
Binding Protocol: SOAP12
Style: document
Binding Operations:
Operation Name: getBank
Operation SoapAction:
SOAP Body Use: literal
Binding Name: BLZServiceHttpBinding
Binding Type: BLZServicePortType
Binding Protocol: HTTP
Binding Operations:
Operation Name: getBank
Services:
Service Name: BLZService
Service Potrs:
Port Name: BLZServiceSOAP11port_http
Port Binding: BLZServiceSOAP11Binding
Port Address Location: http://www.thomas-bayer.com:80/axis2/services/BLZService
Port Name: BLZServiceSOAP12port_http
Port Binding: BLZServiceSOAP12Binding
Port Address Location: http://www.thomas-bayer.com:80/axis2/services/BLZService
Port Name: BLZServiceHttpport
Port Binding: BLZServiceHttpBinding
Port Address Location: http://www.thomas-bayer.com:80/axis2/services/BLZService
Listing 2: The List of the operation in the WSDL Document