java webservice 接收数据_java向webService(java)接口请求并接收数据

import java.net.URL;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import javax.xml.namespace.QName;

import javax.xml.rpc.ParameterMode;

import org.apache.axis.client.Call;

import org.apache.axis.client.Service;

import org.apache.commons.logging.Log;

import org.apache.commons.logging.LogFactory;

import org.dom4j.Document;

import org.dom4j.DocumentHelper;

import org.dom4j.Node;

import com.css.apps.base.dict.service.DictMan;

import com.css.util.StringHelper;

public class sendHttp{

private static Log log = LogFactory.getLog(sendHttpToIssueOa.class);

public static Map> sendHttpTest(String loginName,String flag,String number) {

String namespace = "http://service.cssbaseHomePage.xx.xxx.css.com";

String url="http://xxx.xxx.xxx.x:8080/xxxxx/xxxxx/xxxxxxx?wsdl";

String _xmlInfo=""+loginName+""+flag+""+number+"";

Service service=new Service();

Call call;

String res ="";

Map> issueOa = new HashMap>();

try{

call = (Call)service.createCall();

call.setOperationName(new QName(namespace,"getFileTitle"));

call.setTargetEndpointAddress(new URL(url));

call.addParameter(new QName(namespace,"_xmlInfo"), org.apache.axis.Constants.XSD_STRING, ParameterMode.IN);

call.getParameterTypeByName("_xmlInfo");

res=(String)call.invoke(new Object[] {_xmlInfo});

issueOa = getIssueOa(res,flag);

}catch(Exception e){

e.printStackTrace();

log.error(e.getMessage(), e);

}

return issueOa;

}

//获取到接口返回来的值

@SuppressWarnings({ "unchecked", "null" })

public static Map> getIssueOa(String xml,String flag){

Document doc = null;

Map> map = null;

List errorFlag = null;

if (StringHelper.isEmptyByTrim(xml)) {

map.put("xml为空", errorFlag);

return map;

}

try {

doc = DocumentHelper.parseText(xml);

if (doc != null) {

map = new HashMap>();

List sendPendingName = doc.selectNodes("/result/ColumnName/messageText");

if (sendPendingName == null || sendPendingName.size() < 1) {

map.put("sendColumnName获取失败", errorFlag);

return map;

}

List columnNameList = new ArrayList<>();

for(int i=0;i

String str = sendPendingName.get(i).getStringValue().trim();

columnNameList.add(str);

map.put("columnName", columnNameList);

}

// 此处需要添加逻辑,返回成功的条码号

/*if ("1".equals(code)) {

returnString = "1";

} else {

returnString = "调用接口失败";

}*/

} else {

map.put("解析xml结果为空", errorFlag);

return map;

}

} catch (Exception e) {

log.error(e.getMessage(), e);

}

return map;

}

}

你可能感兴趣的:(java,webservice,接收数据)