使用java向远程服务发送xml请求

时间:2017-06-02 11:04:13

标签: java xml web-services esb

我想使用java将以下xml请求发送到ESB端点http://abc.co.za:8000/service/abcdefg。我不是很熟悉Web服务和ESB,因为我来自前端。

任何帮助或建议都将不胜感激。

Server Time: 11:02:58:028 / Workstation Time: Monday, 22 February 2016 - 11:02:57:703
[DEBUG] SENDING SOAP REQUEST
MethodID: ID_getSubmitRequest; UID=-4820428854312736237
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns2:getSubmitRequest xmlns:ns2="urn:AC_IDM_SUBMITREQUESTVi" xmlns="urn:com.virsa.ae.ejbutil">
<ns2:requestDetails>
<application/>
<company>STACK OVERFLOW</company>
<customField>
<CustomFieldsDTO>
<name>Users ID Number</name>
<value>6303066107089</value>
</CustomFieldsDTO>
</customField>
<department xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<emailAddress>ronny.ronny@stack.co.za</emailAddress>
<employeeType>STACK</employeeType>
<firstName>RONNY</firstName>
<functionalArea xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<lastName>RONNY</lastName>
<locale xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<location xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<managerTelephone xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<mgrEmailAddress xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<mgrFirstName xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<mgrId xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<mgrLastName xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<priority>HIGH</priority>
<requestReason xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<requestType>SYSTEM</requestType>
<requestorEmailAddress>None</requestorEmailAddress>
<requestorFirstName>None</requestorFirstName>
<requestorId>BP5151</requestorId>
<requestorLastName>None</requestorLastName>
<requestorTelephone>None</requestorTelephone>
<roles>
<RoleData>
<action>ADD</action>
<comments xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<company xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<roleId>ZCB_STACK</roleId>
<sysId/>
<validFrom>2016-02-22T11:02:57+02:00</validFrom>
<validTo>9999-02-22T11:02:57+02:00</validTo>
</RoleData>
</roles>
<sNCName xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<telephone>0123456789</telephone>
<unsecureLogon>false</unsecureLogon>
<userId>BP111</userId>
<validFrom>2016-02-22T11:02:57+02:00</validFrom>
<validTo>9999-02-22T11:02:57+02:00</validTo>
</ns2:requestDetails>
</ns2:getSubmitRequest>
</soapenv:Body>
</soapenv:Envelope>

1 个答案:

答案 0 :(得分:1)

有多个库可以帮助您完成此任务。其中一个选项是Apache CXF:http://cxf.apache.org/docs/wsdl-to-java.html

完成此任务的步骤:

  • 使用Apache CXF或其他库创建包含连接到目标SOAP服务的代码的客户端JAR
  • 在Java代码/项目中包含此库
  • 初始化代理以连接到服务(由生成的客户端库提供)
  • 填充您的输入
  • 调用SOAP端点并返回流程输出

证明这一点的好例子:http://cxf.apache.org/docs/developing-a-consumer.html