2021.12.9 java对接sap接口(soap协议、webservice)
问题:对接sap接口,代码调试
执行:
1、soapui 软件测试是否能正确访问
-
未能正确访问,因为未在本地配置域名映射
-
要在
C:\Windows\System32\drivers\etc
里面配置。-
# localhost name resolution is handled within DNS itself. 127.0.0.1 localhost # ::1 localhost 192.168.2.21 xxx.xxx.com
-
-
配置完后soapui软件访问成功!
2、代码测试
2.1、用axis框架的方式测试连接
package com.ly.utils;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.message.SOAPHeaderElement;
import javax.xml.rpc.ParameterMode;
import java.util.List;
public class SendWebServiceUtil {
/**
*axis 方式
* @param nameSpace 命名空间
* @param endpoint wsdl发布地址
* @param methods 方法名
* @param list 参数列表
* @return 返回值
* @author LY
*/
public String webserviceConn(String userName,String passWord, String nameSpace, String endpoint, String methods, List<String> list) {
String result = null;
Object[] parameter = new Object[list.size()];
try {
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName(new javax.xml.namespace.QName(nameSpace,methods));//WSDL里面描述的接口名称
for(int i=0;i<list.size();i++){
call.addParameter("arg"+i, XMLType.XSD_STRING, ParameterMode.IN);//接口的参数
parameter[i] = list.get(i);
}
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//设置返回类型
call.setUseSOAPAction(true);