axis接用web services接口

import java.io.StringReader;
import java.net.MalformedURLException;

import javax.xml.namespace.QName;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;
@SuppressWarnings("unchecked")
public class AxisService extends BaseUtil{
	//private static String  endpoint = "http://60.216.97.120:8081/AnyOfficeService/AnyOfficeWbS.asmx";
	private static String  namespace = "http://tempuri.org/";
	/**
	 * 获取返回的xml
	 * @param method 调用方法名
	 * @param params 输入参数名
	 * @param values 输入参数值
	 * @return
	 */
	public String getReturnXml(String method,String[] params,Object[] values){
		String obj = "";
		Service service = new Service();
		try {
			String endpoint = SysPara.getValue("jnrd_webservice");
			Call call = (Call)service.createCall();
			call.setOperationName(new QName(namespace,method));
			call.setTargetEndpointAddress(new java.net.URL(endpoint));
			//System.out.println("params = " + params.length);
			//System.out.println("values = " + values.length);
			for(int i=0;i<params.length;i++){
				call.addParameter(new QName(namespace,params[i]), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
			}
			call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
			call.setUseSOAPAction(true);
			call.setSOAPActionURI(namespace+method);
			obj = (String)call.invoke(values);
		} catch (Exception e) {
			e.printStackTrace();
		} 
		return obj;
	}
	/**
	 * 将xml转化为document
	 * @param xmlDoc
	 * @return
	 * @throws MalformedURLException
	 * @throws DocumentException
	 */
	public Document read(String xmlDoc)throws MalformedURLException, DocumentException{
		SAXReader reader = new SAXReader();
		xmlDoc = xmlDoc.replaceAll(" "," ");
		xmlDoc = xmlDoc.replaceAll("“", "“").replaceAll("”", "”");
		xmlDoc = xmlDoc.replaceAll("—", "--");
		xmlDoc = xmlDoc.replaceAll("…", "...");
        Document document = reader.read(new StringReader(xmlDoc));
        return document;
	}
	/**
	 * 获取列表xml
	 * @param method 方法名
	 * @param username 用户名称
	 * @param pagesize 每页显示记录数
	 * @param pagecur 第几页
	 * @return
	 */
	public String getListsXml(String method,String username,String pagesize,String pagecur){
		String[] params = {"username","pagesize","pagecur"};
		Object[] values = new Object[]{username,pagesize,pagecur};
		return getReturnXml(method, params, values);
	}
	/**
	 * 根据businessid获取明细
	 * @param method 调用方法
	 * @param username 用户名
	 * @param businessid 模块Id
	 * @return
	 */
	public String getItemXml(String method,String username,String businessid){
		String[] params = {"username","businessid"};
		Object[] values = new Object[]{username,businessid};
		return getReturnXml(method, params, values);
	}
	/**
	 * 根据businessid获取明细
	 * @param method
	 * @param businessid
	 * @return
	 */
	public String getItemXml(String method,String businessid){
		String[] params = {"businessid"};
		Object[] values = new Object[]{businessid};
		return getReturnXml(method, params, values);
	}
	/**
	 * 根据prcsid获取流程相关数据
	 * @param method
	 * @param username
	 * @param businessid
	 * @param prcsid
	 * @return
	 */
	public String getItemXml(String method,String username,String businessid,String prcsid){
		String[] params = {"username","businessid","PrcsId"};
		Object[] values = new Object[]{username,businessid,prcsid};
		return getReturnXml(method, params, values);
	}
	/**
	 * 获取登录xml
	 * @param username
	 * @param password
	 * @return
	 */
	public String getLoginXml(String username,String password){
		String[] params = {"username","password"};
		Object[] values = new Object[]{username,password};
		return getReturnXml("LogInSys", params, values);
	}
	/**
	 * 获取用户权限
	 * @param username
	 * @return
	 */
	public String getUserAuthXml(String username){
		String[] params = {"username"};
		Object[] values = new Object[]{username};
		return getReturnXml("UserprivateList", params, values);
	}
	/**
	 * 获取部门列表xml
	 * @param DetpId
	 * @return
	 */
	public String getDepartmentXml(String DetpId){
		String[] params = {"DetpId"};
		Object[] values = new Object[]{DetpId};
		return getReturnXml("DepartmentList", params, values);
	}
	/**
	 * 获取用户列表xml
	 * @param flag
	 * @param name
	 * @return
	 */
	public String getUsersListXml(String flag,String name){
		String[] params = {"flag","name"};
		Object[] values = new Object[]{flag,name};
		return getReturnXml("UsersList", params, values);
	}
	/**
	 * 获取经办人列表xml
	 * @param runid
	 * @param flowprcsid
	 * @return
	 */
	public String getPrcsUsersListXml(String method,String runid,String flowprcsid){
		String[] params = {"RunId","FlowPrcsId"};
		Object[] values = new Object[]{runid,flowprcsid};
		return getReturnXml(method, params, values);
	}
	/**
	 * 获取虚拟设备参数xml
	 * @param vequipmentID
	 * @return
	 */
	public String getVequParamXml(String vequipmentID){
		String[] params = {"vequipmentID"};
		Object[] values = new Object[]{vequipmentID};
		return getReturnXml("SeeEquParmData", params, values);
	}
	/**
	 * 获取公告通知保存页面
	 * @param username
	 * @return
	 */
	public String getNotifyPageXml(String username){
		String[] params = {"username"};
		Object[] values = new Object[]{username};
		return getReturnXml("NotifyPageFrame", params, values);
	}
	/**
	 * 邮件回复保存,返回的xml
	 * @param username
	 * @return
	 */
	public String EmailReplyPage(String FromId,String ToId,String CopyToId, 
			String SecretToId,String Subject,String Content, String Important, String IsSms,String IsMobile){
		String[] params = {"FromId","ToId","CopyToId","SecretToId","Subject","Content","Important","IsSms","IsMobile"};
		Object[] values = new Object[]{FromId, ToId, CopyToId, SecretToId, Subject, Content, Important, IsSms, IsMobile};
		//Object[] values = new Object[]{"admin", "admin,", "admin,", "admin,", "邮件回复:转发", "1111111", "0", "1", "0"};
		return getReturnXml("SaveReplyEmail", params, values);
	}
	/**
	 * 邮件转发保存,返回的xml
	 * @param username
	 * @return
	 */
	public String SaveTransmitEmail(String FromId,String ToId,String CopyToId, 
			String SecretToId,String Subject,String Content, String Important, String AttachmentId,String IsSms,String IsMobile){
		String[] params = {"FromId","ToId","CopyToId","SecretToId","Subject","Content","Important","AttachmentId","IsSms","IsMobile"};
		Object[] values = new Object[]{FromId, ToId, CopyToId, SecretToId, Subject, Content, Important, AttachmentId, IsSms, IsMobile};
		return getReturnXml("SaveTransmitEmail", params, values);
	}
	
	/**
	 * 虚拟设备层级显示接口,返回的xml
	 * @param username
	 * @return
	 */
	public String EquLayerList(String username, String equipmentid){
		String[] params = {"username","equipmentid"};
		Object[] values = new Object[]{username, equipmentid};
		return getReturnXml("EquLayerList", params, values);
	}
	
	/**
	 * 虚拟设备模糊搜索返回类型接口,返回的xml
	 * @param username
	 * @return
	 */
	public String EquSearchType(String username, String equname){
		String[] params = {"username","equname"};
		Object[] values = new Object[]{username, equname};
		return getReturnXml("EquSearchType", params, values);
	}
	
	/**
	 * 运行参数模糊搜索,返回的xml
	 * @param username
	 * @return
	 */
	public String EquParmSearchList(String username, String equname){
		String[] params = {"username","equname"};
		Object[] values = new Object[]{username, equname};
		return getReturnXml("EquParmSearchList", params, values);
	}
	
	/**
	 * 虚拟投备模糊搜索,返回的xml
	 * @param username
	 * @return
	 */
	public String EquSearchList(String username, String equname){
		String[] params = {"username","equname"};
		Object[] values = new Object[]{username, equname};
		return getReturnXml("EquSearchList", params, values);
	}
	
	/**
	 * 虚拟设备树形展示接口,返回xml
	 * @param username
	 * @return
	 */
	public String EquTreeList(String username){
		String[] params = {"username"};
		Object[] values = new Object[]{username};
		return getReturnXml("EquTreeList", params, values);
	}
}

你可能感兴趣的:(axis接用web services接口)