Java: get sample request XML from WSDL
Is there a way to get the sample request XML using WSDL (URL) alone?
The following is WSDL: http://www.webservicemart.com/uszip.asmx?WSDL Sample application for:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://webservicemart.com/ws/"> <soapenv:Header/> <soapenv:Body> <ws:ValidateZip> <!--Optional:--> <ws:ZipCode>?</ws:ZipCode> </ws:ValidateZip> </soapenv:Body> </soapenv:Envelope>
I know there are tools like soapUI that can do this However, if you don't use these tools, is there any other way to implement it in Java?
Using wsimport is an option to get java source code, which is more static Is there a dynamic way to do this?
Exception encountered:
18:57:59,677 WARN [SoapUI] Missing folder [D:\TestAutomation\Z_ZZLastResort\.\ext] for external libraries 18:57:59,920 INFO [DefaultSoapUICore] initialized soapui-settings from [C:\Users\mike\soapui-settings.xml] Progress: 1 - Caching DeFinition from url [http://www.webservicemart.com/uszip.asmx?WSDL] 18:58:00,587 INFO [SchemaUtils] Added default schema from file:/C:/Users/mike/Desktop/soapui-4.5.1-SNAPSHOT.jar!/com/eviware/soapui/resources/xsds/xop.xsd with targetNamespace http://www.w3.org/2004/08/xop/include 18:58:00,625 INFO [SchemaUtils] Added default schema from file:/C:/Users/mike/Desktop/soapui-4.5.1-SNAPSHOT.jar!/com/eviware/soapui/resources/xsds/XMLSchema.xsd with targetNamespace http://www.w3.org/2001/XMLSchema 18:58:00,627 INFO [SchemaUtils] Added default schema from file:/C:/Users/mike/Desktop/soapui-4.5.1-SNAPSHOT.jar!/com/eviware/soapui/resources/xsds/xml.xsd with targetNamespace http://www.w3.org/XML/1998/namespace 18:58:00,628 INFO [SchemaUtils] Added default schema from file:/C:/Users/mike/Desktop/soapui-4.5.1-SNAPSHOT.jar!/com/eviware/soapui/resources/xsds/swaref.xsd with targetNamespace http://ws-i.org/profiles/basic/1.1/xsd 18:58:00,629 INFO [SchemaUtils] Added default schema from file:/C:/Users/mike/Desktop/soapui-4.5.1-SNAPSHOT.jar!/com/eviware/soapui/resources/xsds/xmime200505.xsd with targetNamespace http://www.w3.org/2005/05/xmlmime 18:58:00,637 INFO [SchemaUtils] Added default schema from file:/C:/Users/mike/Desktop/soapui-4.5.1-SNAPSHOT.jar!/com/eviware/soapui/resources/xsds/xmime200411.xsd with targetNamespace http://www.w3.org/2004/11/xmlmime 18:58:00,638 INFO [SchemaUtils] Added default schema from file:/C:/Users/mike/Desktop/soapui-4.5.1-SNAPSHOT.jar!/com/eviware/soapui/resources/xsds/soapEnvelope.xsd with targetNamespace http://schemas.xmlsoap.org/soap/envelope/ 18:58:00,641 INFO [SchemaUtils] Added default schema from file:/C:/Users/mike/Desktop/soapui-4.5.1-SNAPSHOT.jar!/com/eviware/soapui/resources/xsds/soapEncoding.xsd with targetNamespace http://schemas.xmlsoap.org/soap/encoding/ 18:58:00,643 INFO [SchemaUtils] Added default schema from file:/C:/Users/mike/Desktop/soapui-4.5.1-SNAPSHOT.jar!/com/eviware/soapui/resources/xsds/soapEnvelope12.xsd with targetNamespace http://www.w3.org/2003/05/soap-envelope 18:58:00,645 INFO [SchemaUtils] Added default schema from file:/C:/Users/mike/Desktop/soapui-4.5.1-SNAPSHOT.jar!/com/eviware/soapui/resources/xsds/soapEncoding12.xsd with targetNamespace http://www.w3.org/2003/05/soap-encoding Progress: 2 - Loading [http://www.webservicemart.com/uszip.asmx?WSDL] 18:58:00,648 DEBUG [WsdlLoader] Getting wsdl component from [http://www.webservicemart.com/uszip.asmx?WSDL] 18:58:01,073 DEBUG [HttpClientSupport$SoapUIHttpClient] Attempt 1 to execute request 18:58:01,074 DEBUG [SoapUIMultiThreadedhttpconnectionManager$SoapUIDefaultClientConnection] Sending request: GET /uszip.asmx?WSDL HTTP/1.1 18:58:01,314 DEBUG [SoapUIMultiThreadedhttpconnectionManager$SoapUIDefaultClientConnection] Connection closed 18:58:01,314 DEBUG [HttpClientSupport$SoapUIHttpClient] Closing the connection. 18:58:01,314 INFO [HttpClientSupport$SoapUIHttpClient] I/O exception (java.net.socketException) caught when processing request: Connection reset 18:58:01,316 DEBUG [HttpClientSupport$SoapUIHttpClient] Connection reset java.net.socketException: Connection reset at java.net.socketInputStream.read(UnkNown Source) at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:149) at org.apache.http.impl.io.socketInputBuffer.fillBuffer(SocketInputBuffer.java:110) at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:264) at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:98) at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:252) at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:281) at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:247) at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:219) at com.eviware.soapui.impl.wsdl.support.http.HttpClientSupport$SoapUIHttpRequestExecutor.doReceiveResponse(HttpClientSupport.java:133) at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125) at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:633) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:454) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754) at com.eviware.soapui.impl.wsdl.support.wsdl.UrlWsdlLoader$LoaderWorker.construct(UrlWsdlLoader.java:226) at com.eviware.soapui.impl.wsdl.support.wsdl.UrlWsdlLoader.load(UrlWsdlLoader.java:138) at com.eviware.soapui.impl.wsdl.support.wsdl.WsdlLoader.loadXmlObject(WsdlLoader.java:121) at com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils.getDeFinitionParts(SchemaUtils.java:535) at com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils.getDeFinitionParts(SchemaUtils.java:524) 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) 18:58:01,319 INFO [HttpClientSupport$SoapUIHttpClient] retrying request 18:58:01,319 DEBUG [HttpClientSupport$SoapUIHttpClient] Reopening the direct connection. 18:58:01,602 DEBUG [HttpClientSupport$SoapUIHttpClient] Attempt 2 to execute request 18:58:01,602 DEBUG [SoapUIMultiThreadedhttpconnectionManager$SoapUIDefaultClientConnection] Sending request: GET /uszip.asmx?WSDL HTTP/1.1 18:58:02,200 DEBUG [SoapUIMultiThreadedhttpconnectionManager$SoapUIDefaultClientConnection] Receiving response: HTTP/1.1 200 OK 18:58:02,210 DEBUG [HttpClientSupport$SoapUIHttpClient] Connection can be kept alive indefinitely Progress: 1 - Loading DeFinition from url 18:58:02,260 DEBUG [AbstractDeFinitionContext] Loading DeFinition... 18:58:02,277 DEBUG [WsdlInterfaceDeFinition] Loading WSDL: http://www.webservicemart.com/uszip.asmx?WSDL 18:58:02,277 DEBUG [AbstractWsdlDeFinitionLoader] Returning baseInputSource [http://www.webservicemart.com/uszip.asmx?WSDL] Retrieving document at 'http://www.webservicemart.com/uszip.asmx?WSDL'. 18:58:02,347 INFO [SchemaUtils] Loading schema types from [http://www.webservicemart.com/uszip.asmx?WSDL] 18:58:02,347 INFO [SchemaUtils] Getting schema http://www.webservicemart.com/uszip.asmx?WSDL 18:58:02,357 ERROR [SoapUI] An error occured [org.apache.xmlbeans.impl.xb.xsdschema.impl.SchemaDocumentImpl],see error log for details java.lang.ArrayStoreException: org.apache.xmlbeans.impl.xb.xsdschema.impl.SchemaDocumentImpl at com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils.getSchemas(SchemaUtils.java:418) at com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils.getSchemas(SchemaUtils.java:327) at com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils.loadSchemaTypes(SchemaUtils.java:192) at com.eviware.soapui.impl.support.deFinition.support.XmlSchemaBasedInterfaceDeFinition.loadSchemaTypes(XmlSchemaBasedInterfaceDeFinition.java:79) at com.eviware.soapui.impl.wsdl.support.wsdl.WsdlInterfaceDeFinition.load(WsdlInterfaceDeFinition.java:61) at com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext.loadDeFinition(WsdlContext.java:66) at com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext.loadDeFinition(WsdlContext.java:30) at com.eviware.soapui.impl.support.deFinition.support.AbstractDeFinitionContext.cacheDeFinition(AbstractDeFinitionContext.java:268) at com.eviware.soapui.impl.support.deFinition.support.AbstractDeFinitionContext.access$400(AbstractDeFinitionContext.java:44) at com.eviware.soapui.impl.support.deFinition.support.AbstractDeFinitionContext$Loader.construct(AbstractDeFinitionContext.java:235) 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) 18:58:02,359 ERROR [SoapUI] An error occured [com.eviware.soapui.impl.wsdl.support.xsd.SchemaException],see error log for details com.eviware.soapui.impl.wsdl.support.xsd.SchemaException at com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils.getSchemas(SchemaUtils.java:512) at com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils.getSchemas(SchemaUtils.java:327) at com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils.loadSchemaTypes(SchemaUtils.java:192) at com.eviware.soapui.impl.support.deFinition.support.XmlSchemaBasedInterfaceDeFinition.loadSchemaTypes(XmlSchemaBasedInterfaceDeFinition.java:79) at com.eviware.soapui.impl.wsdl.support.wsdl.WsdlInterfaceDeFinition.load(WsdlInterfaceDeFinition.java:61) at com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext.loadDeFinition(WsdlContext.java:66) at com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext.loadDeFinition(WsdlContext.java:30) at com.eviware.soapui.impl.support.deFinition.support.AbstractDeFinitionContext.cacheDeFinition(AbstractDeFinitionContext.java:268) at com.eviware.soapui.impl.support.deFinition.support.AbstractDeFinitionContext.access$400(AbstractDeFinitionContext.java:44) at com.eviware.soapui.impl.support.deFinition.support.AbstractDeFinitionContext$Loader.construct(AbstractDeFinitionContext.java:235) 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) 18:58:02,360 ERROR [SoapUI] An error occured [com.eviware.soapui.impl.wsdl.support.xsd.SchemaException],363 ERROR [AbstractDeFinitionContext] Error loading schema types from http://www.webservicemart.com/uszip.asmx?WSDL,see log for details 18:58:35,061 DEBUG [SoapUIMultiThreadedhttpconnectionManager$SoapUIDefaultClientConnection] Connection closed
Solution
Soap UI also provides a Java API for creating requests / responses
public class SOAPInputGenerator { public static void main(String[] args) throws Exception { WsdlProject project = new WsdlProject(); WsdlInterface[] wsdls = WsdlImporter.importWsdl(project,"http://localhost:7000/Solicitud?wsdl"); WsdlInterface wsdl = wsdls[0]; for (Operation operation : wsdl.getOperationList()) { WsdlOperation wsdlOperation = (WsdlOperation) operation; System.out.println("OP:"+wsdlOperation.getName()); System.out.println("Request:"); System.out.println(wsdlOperation.createRequest(true)); System.out.println("Response:"); System.out.println(wsdlOperation.createResponse(true)); } } }
Jar location of soap UI Library
http://www.soapui.org/repository/eviware/jars/
If you don't want to use soap UI directly, you may find reficio very useful A subset of the soapUI library API and examples can be found here
https://github.com/reficio/soap-ws
http://www.reficio.org/projects/
This is an open source project that supports soap in pure XML in Java