1. 通过soapui新建一个soapui project并填上项目一个地址类似这样:http://127.0.0.1:8888/EsbBusService.asmx?WSDL
2.输入请求xml 类似这样:需要在body外加上:<![CDATA[ ]]>
<soap:Envelope xmlns:soap="" xmlns:tem="/">
<soap:Header/>
<soap:Body>
<tem:Process>
<tem:XmlString>
<![CDATA[
<body>
<head>
<test>123456</test>
</head>
<resquest>
<test2></test2>
</resquest>
</body>
]]>
</tem:XmlString>
</tem:Process>
</soap:Body>
</soap:Envelope>
3.用定义一个和xml对应的实体类
@Data
@XStreamAlias("request")
public class TestBean{
@XStreamAlias("test2")
private String test2;
}
4.使用xstream将实体类转换为xml
XStream xStream = new XStream(new Xpp3Driver(new NoNameCoder()));
xStream.processAnnotations(new Class[]{TestBean.class});
xStream.autodetectAnnotations(true);
5.xstream发起请求方法:
public static Object getResponse(String xml) {
Object[] results = new Object[2];
try {
JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
Client client = factory.createClient("http://127.0.0.1:8888/EsbBusService.asmx?WSDL");
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); // 策略
httpClientPolicy.setConnectionTimeout( 18000 ); //连接超时
httpClientPolicy.setAllowChunking( false );
httpClientPolicy.setReceiveTimeout( 10000 ); //接收超时
HTTPConduit http = (HTTPConduit) client.getConduit();
http.setClient(httpClientPolicy);
// "Process" 为方法名 xml为整个body请求体
results = client.invoke("Process", xml);
}catch (Exception e){
e.printStackTrace();
}
return results[0];
}
"Process"方法名来源:
xml为请求体body部分xml,只包括body部分xml。
5.获取结果后将结果xml解析为实体类:
@XStreamImplicit 用于集合