【问题标题】:Converting xml SOAPUI response to Java Object将 xml SOAPUI 响应转换为 Java 对象
【发布时间】:2014-09-12 09:20:10
【问题描述】:

我是 web 服务的初学者,我正在从一个作为服务器的合作伙伴 API 使用 web 服务,我开发了一个网关应用程序,它将请求推送到作为客户端的我的 API。我这样做是因为我的 API 中的方法与合作伙伴的 API 不匹配。我已经探索了合作伙伴在 SOAPUI 上的 API 并确定了我需要的方法,我将其粘贴在下面:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hub="http://hub4api.cellulant.com/">
<soapenv:Header/>
<soapenv:Body>
  <hub:validateAccount>
     <credentials>
        <username>?</username>
        <password>?</password>
     </credentials>
     <packet>
        <!--1 or more repetitions:-->
        <Item>
           <serviceID>?</serviceID>
           <serviceCode>?</serviceCode>
           <accountNumber>?</accountNumber>
           <requestExtraData>?</requestExtraData>
        </Item>
     </packet>
  </hub:validateAccount>
</soapenv:Body>
</soapenv:Envelope>

向指定的端点 URL 提交请求后,我得到以下响应

<S:<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
Body>
  <ns2:validateAccountResponse xmlns:ns2="http://hub4api.cellulant.com/">
     <return>
        <authStatus>
           <authStatusCode>131</authStatusCode>
           <authStatusDescription>Authentication was a success</authStatusDescription>
        </authStatus>
        <results>
           <Item>
              <statusCode>307</statusCode>
              <statusDescription>Account number provided is valid</statusDescription>
              <serviceID>130</serviceID>
              <serviceCode/>
              <accountNumber>XXXXXXXX</accountNumber>
              <active>yes</active>
              <responseExtraData>{"Currency":"XXX","VALUE":"33.54","DueDate":"2014-09-12T00:00:00+07:00"}</responseExtraData>
           </Item>
        </results>
     </return>
  </ns2:validateAccountResponse>
</S:Body>
</S:Envelope>

我想将响应转换为 java 对象并在我的 GateWay 中使用它,但我不知道如何去做。有人可以帮助我吗?

【问题讨论】:

    标签: java xml web-services jaxb soapui


    【解决方案1】:

    您可以使用wsimport 为某个(简单)网络服务生成 Java 代码。

    看看http://docs.oracle.com/javase/7/docs/technotes/tools/share/wsimport.html

    【讨论】:

    • 为此,您将需要 WSDL 文件。通常是这样发布的:[endpoint]?wsdl。但是,我看到很多使用 SOAP 的 WS 没有发布 WSDL。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多