当前位置: 首页 > 面试题库 >

Java:从wsdl获取示例请求XML

宰宣
2023-03-14
问题内容

有什么方法可以单独使用wsdl(url)获得样本请求xml?

以下是wsdl示例:http :
//www.webservicemart.com/uszip.asmx?
WSDL 示例请求:

<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>

我知道那里有SOAPUI等工具,其他工具也可以做到这一点。但是,如果不使用这些工具,还有其他方法可以使用Java实现吗?

使用wsimport将是让我获得Java源码的一种选择,这是更静态的。有没有动态的方式来做到这一点?

遇到异常:

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 DEBUG [SoapUIMultiThreadedHttpConnectionManager$SoapUIDefaultClientConnection] Connection closed
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], 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,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

问题答案:

SOAPUI还提供Java API创建请求/响应

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));
    }
}
}

SOAP UI库的JAR位置

http://www.soapui.org/repository/eviware/jars/

如果您不想直接使用SOAPUI,则可能会发现reficio它非常有用。SoapUI库API的子集以及示例可以在这里找到

https://github.com/reficio/soap-ws

http://www.reficio.org/projects/

这是一个开放源代码项目,旨在以Java中的纯XML方式支持SOAP。



 类似资料:
  • 我需要从wsdl(使用wsdl url)为一个操作创建SOAP请求xml。我从一个web服务调用得到一个响应,我需要从这个响应中获取一些值,并将其添加到另一个web服务Soap请求中,然后再次执行一个web服务调用。因此,为了向soap请求添加新值,我需要获得完整的soap请求xml。这就是为什么我问如何从WSDD获得soap请求xml。我不能使用SoapUI,因为它每次都是动态的,所以我需要编写

  • 我已经用soap请求启动了一个新项目,我遵循了一些关于它的教程,但它并没有像它应该做的那样好。 我将这部分代码用于请求: 它给了我这个错误: SoapFault异常:[HTTP]不支持的媒体类型堆栈跟踪: 所有参数的类型都可以根据我得到的留档。和php部分似乎可以对我和我找到的所有教程。 我想知道这是否是头部问题或类似的问题。 WSDL在[这里](https://smarteye.ariadnex

  • 问题内容: 我有一个向我的Java Servlet发送POST请求的javascript库,但是在该方法中,我似乎无法获取请求有效内容。在chrome Developer Tools中,所有内容都位于标头标签的“请求有效负载”部分中,并且内容在那里,而且我知道doPost方法正在接收POST,但它只是空白。 对于 对象,我可以通过什么方式在请求有效负载中获取数据? 这样做 两者最终都没有数据 问题

  • 我正在构建一个Java的grpc服务器,我很难得到请求头。proto文件是使用Pro buf-maven-plugin编译的,基于生成的存根,我无法访问上下文或请求元数据。 我还尝试在消息请求中定义一个键/值列表,希望grpc能够处理头映射,但目前为止没有成功。 知道我怎么能拿到标题吗? 谢谢 我的原型文件内容: 服务器端实现如下所示: 版本请求。getHeadersCount()始终返回0,尽管

  • 问题内容: 我有一个名为“ localhost:3000 / returnStat”的服务,该服务应将文件路径作为参数。例如“ /BackupFolder/toto/tata/titi/myfile.txt”。 如何在浏览器上测试此服务?例如,如何使用Express格式化此请求? 问题答案: 我尚未测试您的代码,但其他方法可行 如果您想从请求网址获取路径信息 1.如果您获取的URL参数仍然无法读取