参考地址:https://www.cnblogs.com/garfieldcgf/p/5966317.html
相关资料地址推荐:
https://blog.csdn.net/myblogzz/article/details/80311038
方式一:本文介绍两种方式:
1.适合发送单个参数
2.适合发送很多的list,复杂的数据,但是会有点夸张,各位往下看就知道了
3.文章最末尾有完整的import和Maven
@CrossOrigin(origins = "*", maxAge = 3600)
@PostMapping(value = "/select")
public Object[] 方法名(String ropeModel) {
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("http://你的地址?wsdl");
QName name = new QName("这里好像是什么固定的地址,问对方要", "方法名");
Object[] objects = new Object[0];
try {
objects = client.invoke(name, ropeModel);
return objects;
} catch (Exception e) {
e.printStackTrace();
}
return objects;
}
方式二:原理就是把完整的xml变成字符串发过去
好处:直接发送,容易看懂
坏处:字符串太多了,显得很多
注意看完:推荐一个软件,很牛逼,根据webService的地址就能显示所有的接口,并生成相应的xml模板,这样你就不用懂xml了
1.先分享软件。2.贴上java代码。3.截图使用软件获取xml格式
软件名:SoapUI5.6.0
链接:https://pan.baidu.com/s/1Aibfpd1bVoUF_rbsQ8hXig
提取码:ks4b
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
public class TestWebService {
public static void main(String[] args) throws Exception {
Map map = new HashMap();
//拼接xml请求,带有请求头
String params = "5 ";//随手举个例子,类似...
String soapRequestData = "n" +
" n" +
"tserviceCode n" +
"tuserName n" +
"tauthCoden" +
" n" +
" n" +
" n" +
params +
" n" +
" n" +
" n";
try {
String method = "请求地址";//比如http://192.177.222.222:8888/services/Service_Name/Function_Name
PostMethod postMethod = new PostMethod(method);
byte[] b = soapRequestData.getBytes("utf-8");
InputStream is = new ByteArrayInputStream(b, 0, b.length);
RequestEntity re = new InputStreamRequestEntity(is, b.length, "application/soap+xml; charset=utf-8");
postMethod.setRequestEntity(re);
HttpClient httpClient = new HttpClient();
int statusCode = httpClient.executeMethod(postMethod);
//200说明正常返回数据
if (statusCode != 200) {
//internet error
System.out.println(statusCode);
}
soapRequestData = postMethod.getResponseBodyAsString();
System.out.println(soapRequestData);
} catch (Exception e) {
e.printStackTrace();
}
}
}
软件的使用
请先下载安装SoapUI
然后打开按照下面截图步骤
import cn.hutool.core.util.XmlUtil; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.InputStreamRequestEntity; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.RequestEntity; import org.apache.commons.lang.StringUtils; import org.apache.cxf.endpoint.Client; import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory; import org.json.JSONException; import org.junit.Test; import org.lastools.LASHeader; import org.lastools.LASPoint; import org.lastools.LASReader; import org.lastools.LASlibJNI; import org.springframework.web.bind.annotation.*; import javax.xml.namespace.QName; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import static java.lang.Math.*;
commons-httpclient commons-httpclient 3.1 cn.hutool hutool-all 4.6.1 org.apache.axis axis 1.4 wsdl4j wsdl4j 1.6.3 javax.xml.rpc javax.xml.rpc-api 1.1.2 commons-logging commons-logging 1.2 net.sf.json-lib json-lib 2.4 jdk15 org.apache.cxf cxf-rt-frontend-jaxws 3.1.1 org.apache.cxf cxf-rt-transports-http 3.1.1 org.apache.cxf cxf-rt-frontend-jaxrs 3.1.1 org.apache.cxf cxf-rt-transports-http-jetty 3.1.1 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test com.vaadin.external.google android-json 0.0.20131108.vaadin1 compile net.minidev json-smart cn.torhang.util axis 1.0 cn.torhang.util jaxrpc 1.0 org.apache.ws.commons.axiom axiom-api 1.2.20 junit junit fakepath laslibjni 0.0.1 org.json json 20180130 dom4j dom4j 1.6.1 org.jdom jdom 1.1



