Java Springboot项目
如下函数是一个post接口,它用于接收xml格式字符串,并将该串发送至wsdlUrl
@RequestMapping(value="/gggg", method = RequestMethod.POST)
public String test3(@RequestBody String xmlString){
//public String test2(@RequestParam(value ="yy", required = true) String yy){
System.out.println(xmlString);
String wsdlUrl ="https://220.249.107.184/GYSServer/services/btmpSupplierInterface?wsdl";
//看具体响应的WSDL中的namespace
String nameSpaceUri ="http://service.btmp.com/";
Service service = new Service();
Call call;
String returnvalue = "";
try {
call = (Call)service.createCall();
call.setTargetEndpointAddress(wsdlUrl);
//设置operation 名称,
call.setOperationName(new QName(nameSpaceUri, "getDCGH"));
call.addParameter("gysbm", org.apache.axis.Constants.XSD_STRING,ParameterMode.IN);
call.addParameter("authdata",org.apache.axis.Constants.XSD_STRING,ParameterMode.IN);
call.addParameter("xmlString",org.apache.axis.Constants.XSD_STRING,ParameterMode.IN);
//设置返回类型为对象数组
call.setReturnClass(Object[].class);
SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
String pwd = getMd5_16("11"+"11"+sf.format(new Date()));//账户&密码&当天日期
System.out.println(sf.format(new Date()));
System.out.println("pwd=" + pwd);
Object[] objs = (Object[]) call.invoke(new Object[]{"M107530000",pwd, xmlString });//M107530000
//System.out.println("objs="+objs);
System.out.println((String)objs[0]);
System.out.println((String)objs[1]);
returnvalue = (String)objs[0];
String result = (String)objs[2];
System.out.println("result="+result);
} catch (ServiceException e1) {
e1.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
return returnvalue;
}
使用Axis2,需要在springboot中进行如下依赖配置。
//声明:该模块来源于:https://blog.csdn.net/qq_36688143/java/article/details/86527357
1、在当前项目的pom.xml中添加下述依赖
<!-- axis 1.4 jar start -->
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.2</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis-jaxrpc</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis-saaj</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.4</version>
</dependency>
<!-- axis 1.4 jar end -->
另外,可能还需要添加mail和httpclient依赖
<!-- mail.jar和activation.jar依赖 -->
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<!-- 邮件start -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<!-- 邮件end -->
<!-- httpclient 依赖 -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
</dependency>