Forum Discussion

MishkaMishka's avatar
MishkaMishka
New Contributor
9 years ago

Is it possible to generate request template from wsdl using Java code?

Hello. 

Using soapui i can simply paste wsdl url and soapui will generate sample request for me.

I would like to do exactly the same but using java code, get request from wsdl and save / use it as xml for the rest of the program run.

 

I found sample code below but getting errors. Please let me know if it something wrong with the code or it is simply not possible to use soapui api to generate sample request from wsdl?

-------------------------------------------------------------

package com.soupui;

import com.eviware.soapui.impl.wsdl.WsdlInterface;
import com.eviware.soapui.impl.wsdl.WsdlOperation;
import com.eviware.soapui.impl.wsdl.WsdlProject;
import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlImporter;
import com.eviware.soapui.model.iface.Operation;

public class MainSOAPUI {

public static void main(String[] args) {
try {
System.setProperty("java.net.useSystemProxies", "true");

WsdlProject project = new WsdlProject();

WsdlInterface[] wsdls = WsdlImporter.importWsdl(project, "http://ws.cdyne.com/ip2geo/ip2geo.asmx?wsdl");

WsdlInterface wsdl = wsdls[0];

for (Operation operation : wsdl.getOperationList()) {
WsdlOperation op = (WsdlOperation) operation;
System.out.println("OP:"+op.getName());
System.out.println(op.createRequest(true));
System.out.println("Response:");
System.out.println(op.createResponse(true));
}

} catch (Exception e){
e.printStackTrace();
}

}

}

 

------------------------------------------------

16:53:44,748 INFO [DefaultSoapUICore] initialized soapui-settings from [C:\Users\cnt_2170800\soapui-settings.xml]
Progress: 1 - Caching Definition from url [http://ws.cdyne.com/ip2geo/ip2geo.asmx?wsdl]
16:53:45,430 INFO [SchemaUtils] Added default schema from file:/C:/Users/cnt_2170800/Documents/Automation/SOAPUI/lib/soapui-4.0.1.0.jar!/com/eviware/soapui/resources/xsds/xop.xsd with targetNamespace http://www.w3.org/2004/08/xop/include
16:53:45,460 INFO [SchemaUtils] Added default schema from file:/C:/Users/cnt_2170800/Documents/Automation/SOAPUI/lib/soapui-4.0.1.0.jar!/com/eviware/soapui/resources/xsds/XMLSchema.xsd with targetNamespace http://www.w3.org/2001/XMLSchema
16:53:45,462 INFO [SchemaUtils] Added default schema from file:/C:/Users/cnt_2170800/Documents/Automation/SOAPUI/lib/soapui-4.0.1.0.jar!/com/eviware/soapui/resources/xsds/xml.xsd with targetNamespace http://www.w3.org/XML/1998/namespace
16:53:45,464 INFO [SchemaUtils] Added default schema from file:/C:/Users/cnt_2170800/Documents/Automation/SOAPUI/lib/soapui-4.0.1.0.jar!/com/eviware/soapui/resources/xsds/swaref.xsd with targetNamespace http://ws-i.org/profiles/basic/1.1/xsd
16:53:45,466 INFO [SchemaUtils] Added default schema from file:/C:/Users/cnt_2170800/Documents/Automation/SOAPUI/lib/soapui-4.0.1.0.jar!/com/eviware/soapui/resources/xsds/xmime200505.xsd with targetNamespace http://www.w3.org/2005/05/xmlmime
16:53:45,467 INFO [SchemaUtils] Added default schema from file:/C:/Users/cnt_2170800/Documents/Automation/SOAPUI/lib/soapui-4.0.1.0.jar!/com/eviware/soapui/resources/xsds/xmime200411.xsd with targetNamespace http://www.w3.org/2004/11/xmlmime
16:53:45,470 INFO [SchemaUtils] Added default schema from file:/C:/Users/cnt_2170800/Documents/Automation/SOAPUI/lib/soapui-4.0.1.0.jar!/com/eviware/soapui/resources/xsds/soapEnvelope.xsd with targetNamespace http://schemas.xmlsoap.org/soap/envelope/
16:53:45,474 INFO [SchemaUtils] Added default schema from file:/C:/Users/cnt_2170800/Documents/Automation/SOAPUI/lib/soapui-4.0.1.0.jar!/com/eviware/soapui/resources/xsds/soapEncoding.xsd with targetNamespace http://schemas.xmlsoap.org/soap/encoding/
16:53:45,476 INFO [SchemaUtils] Added default schema from file:/C:/Users/cnt_2170800/Documents/Automation/SOAPUI/lib/soapui-4.0.1.0.jar!/com/eviware/soapui/resources/xsds/soapEnvelope12.xsd with targetNamespace http://www.w3.org/2003/05/soap-envelope
16:53:45,481 INFO [SchemaUtils] Added default schema from file:/C:/Users/cnt_2170800/Documents/Automation/SOAPUI/lib/soapui-4.0.1.0.jar!/com/eviware/soapui/resources/xsds/soapEncoding12.xsd with targetNamespace http://www.w3.org/2003/05/soap-encoding
Progress: 2 - Loading [http://ws.cdyne.com/ip2geo/ip2geo.asmx?wsdl]
16:53:45,482 DEBUG [WsdlLoader] Getting wsdl component from [http://ws.cdyne.com/ip2geo/ip2geo.asmx?wsdl]
17:02:05,432 ERROR [WsdlLoader] Failed to load url [http://ws.cdyne.com/ip2geo/ip2geo.asmx?wsdl]
17:02:05,433 ERROR [SoapUI] An error occured [com.eviware.soapui.impl.support.definition.support.InvalidDefinitionException], see error log for details
com.eviware.soapui.impl.support.definition.support.InvalidDefinitionException
at com.eviware.soapui.impl.wsdl.support.wsdl.WsdlLoader.loadXmlObject(WsdlLoader.java:138)
at com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils.getDefinitionParts(SchemaUtils.java:534)
at com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils.getDefinitionParts(SchemaUtils.java:523)
at com.eviware.soapui.impl.support.definition.support.AbstractDefinitionCache.update(AbstractDefinitionCache.java:97)
at com.eviware.soapui.impl.support.definition.support.AbstractDefinitionContext$Loader.construct(AbstractDefinitionContext.java:226)
at com.eviware.soapui.support.swing.SwingWorkerDelegator.construct(SwingWorkerDelegator.java:46)
at com.eviware.soapui.support.swing.SwingWorker$2.run(SwingWorker.java:149)
at java.lang.Thread.run(Unknown Source)
com.eviware.soapui.impl.support.definition.support.InvalidDefinitionException
at com.eviware.soapui.impl.wsdl.support.wsdl.WsdlLoader.loadXmlObject(WsdlLoader.java:138)
at com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils.getDefinitionParts(SchemaUtils.java:534)
at com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils.getDefinitionParts(SchemaUtils.java:523)
at com.eviware.soapui.impl.support.definition.support.AbstractDefinitionCache.update(AbstractDefinitionCache.java:97)
at com.eviware.soapui.impl.support.definition.support.AbstractDefinitionContext$Loader.construct(AbstractDefinitionContext.java:226)
at com.eviware.soapui.support.swing.SwingWorkerDelegator.construct(SwingWorkerDelegator.java:46)
at com.eviware.soapui.support.swing.SwingWorker$2.run(SwingWorker.java:149)
at java.lang.Thread.run(Unknown Source)