I am looking for some java opensource api for generating soap request xml file by passing wsdl_URL and operation name as parameters. Actually soapUI is doing this and I tried to go through the soapUI source code, but I am not able to understand the whole code to get my task done.
Is there any java api available to do this (apache or something)?
I spent couple of days in the net and didn't see any result.
If any body has any idea please help me.
Thanks in advance.
You can use the open-source Membrane SOA library ([http://www.membrane-soa.org/soa-model-doc/1.4/java-api/create-soap-request-template.htm ]) to generate XMLs for each operation defined in the WSDL:
public void createTemplates(String url){
WSDLParser parser = new WSDLParser();
Definitions wsdl = parser.parse(url);
StringWriter writer = new StringWriter();
SOARequestCreator creator = new SOARequestCreator();
creator.setBuilder(new MarkupBuilder(writer));
creator.setDefinitions(wsdl);
for (Service service : wsdl.getServices()) {
for (Port port : service.getPorts()) {
Binding binding = port.getBinding();
PortType portType = binding.getPortType();
for (Operation op : portType.getOperations()) {
creator.setCreator(new RequestTemplateCreator());
creator.createRequest(port.getName(), op.getName(), binding.getName());
System.out.println(writer);
writer.getBuffer().setLength(0);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With