`
zqding
  • 浏览: 96373 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

利用AXIS开发Webservice综合应用

阅读更多

利用AXIS开发WebService综合应用:

因项目需要,通过WebService传递对象及附件,最终返回结果对象。

1、开发服务端参数对象:

派单对象:

 

package com.starit.itsmhd.bean;

import java.io.Serializable;
import java.util.Date;

/**
 * @author zqding
 * @version 1.0
 * @date 2010-11-19
 * @class_displayName ApplyItem *
 */

public class ApplyItem implements Serializable {
	private static final long serialVersionUID = -4997055778736225953L;

	// 事件流水号
	private String applyserial;

	// 事件提出人
	private String submitStaffName;

	// 事件标题
	private String title;

	// 地点
	private String place;

	// 事件发生时间
	private Date occurTime;

	// 事件来源
	private int origin;

	// 事件影响度
	private int incidence;

	// 事件优先级
	private int priority;

	// 事件完成期限
	private Date finishLimit;

	// 所属系统类型
	private int sysType;

	// 事件内容
	private String content;

	// 附件标记
	private boolean attachFlag;

	// 附件数量
	private int fileNum;

	// 附件名称
	private String[] attName;

	public ApplyItem() {

	}

	public String getApplyserial() {
		return applyserial;
	}

	public void setApplyserial(String applyserial) {
		this.applyserial = applyserial;
	}

	public boolean isAttachFlag() {
		return attachFlag;
	}

	public void setAttachFlag(boolean attachFlag) {
		this.attachFlag = attachFlag;
	}

	public String[] getAttName() {
		return attName;
	}

	public void setAttName(String[] attName) {
		this.attName = attName;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public int getFileNum() {
		return fileNum;
	}

	public void setFileNum(int fileNum) {
		this.fileNum = fileNum;
	}

	public Date getFinishLimit() {
		return finishLimit;
	}

	public void setFinishLimit(Date finishLimit) {
		this.finishLimit = finishLimit;
	}

	public int getIncidence() {
		return incidence;
	}

	public void setIncidence(int incidence) {
		this.incidence = incidence;
	}

	public Date getOccurTime() {
		return occurTime;
	}

	public void setOccurTime(Date occurTime) {
		this.occurTime = occurTime;
	}

	public int getOrigin() {
		return origin;
	}

	public void setOrigin(int origin) {
		this.origin = origin;
	}

	public String getPlace() {
		return place;
	}

	public void setPlace(String place) {
		this.place = place;
	}

	public int getPriority() {
		return priority;
	}

	public void setPriority(int priority) {
		this.priority = priority;
	}

	public String getSubmitStaffName() {
		return submitStaffName;
	}

	public void setSubmitStaffName(String submitStaffName) {
		this.submitStaffName = submitStaffName;
	}

	public int getSysType() {
		return sysType;
	}

	public void setSysType(int sysType) {
		this.sysType = sysType;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

}

 

 派单返回对象:

 

package com.starit.itsmhd.bean;

import java.io.Serializable;

/**
 * @author zqding
 * @version 1.0
 * @date 2010-11-21
 * @class_displayName ApplyItemResponse
 */

public class ApplyItemResponse implements Serializable {

	private static final long serialVersionUID = -443142827992526070L;

	// 返回结果
	private int result;

	// 服务保障流程号
	private String fwbzSerial;

	// ITSM流程号
	private String itsmSerial;

	// 返回信息
	private String msg;

	public ApplyItemResponse() {
		
	}

	public String getFwbzSerial() {
		return fwbzSerial;
	}

	public void setFwbzSerial(String fwbzSerial) {
		this.fwbzSerial = fwbzSerial;
	}

	public String getItsmSerial() {
		return itsmSerial;
	}

	public void setItsmSerial(String itsmSerial) {
		this.itsmSerial = itsmSerial;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public int getResult() {
		return result;
	}

	public void setResult(int result) {
		this.result = result;
	}

}
 

 

其它对象略...

 

2、配置wsdd文件:

 

<service name="FwbzService" provider="java:RPC" style="rpc" use="encoded">
	<documentation>接口</documentation>
	<parameter name="allowedMethods" value="*"/>
	<parameter name="wsdlPortType" value="FwbzService"/>
    <parameter name="wsdlServicePort" value="FwbzService"/>
	<parameter name="wsdlServiceElement" value="FwbzService"/>
	<parameter name="className" value="com.starit.itsmhd.service.FwbzService"/>
	<parameter name="wsdlTargetNamespace" value="http://itsmhd.starit.com/service"/>
    <parameter name="wsdlServiceElement" value="FwbzService"/>
    <parameter name="schemaUnqualified" value="http://itsmhd.starit.com/bean,http://itsmhd.starit.com/exception"/>
	<!--派发-->
    <typeMapping
		xmlns:ns="http://itsmhd.starit.com/bean"
		qname="ns:ApplyItem"
		type="java:com.starit.itsmhd.bean.ApplyItem"
		serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
		deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
		encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
    />
	<typeMapping
		xmlns:ns="http://itsmhd.starit.com/bean"
		qname="ns:ApplyItemResponse"
		type="java:com.starit.itsmhd.bean.ApplyItemResponse"
		serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
		deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
		encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
	/>
    <!--查询--> 
	<typeMapping
		xmlns:ns="http://itsmhd.starit.com/bean"
		qname="ns:QueryItem"
		type="java:com.starit.itsmhd.bean.QueryItem"
		serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
		deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
		encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
	/>
	<typeMapping
		xmlns:ns="http://itsmhd.starit.com/bean"
		qname="ns:QueryItemResponse"
		type="java:com.starit.itsmhd.bean.QueryItemResponse"
		serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
		deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
		encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
	/>	
	<!-- 取消--> 
	 <typeMapping
		xmlns:ns="http://itsmhd.starit.com/bean"
		qname="ns:CancelItem"
		type="java:com.starit.itsmhd.bean.CancelItem"
		serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
		deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
		encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
	/>
	<typeMapping
		xmlns:ns="http://itsmhd.starit.com/bean"
		qname="ns:CancelItemResponse"
		type="java:com.starit.itsmhd.bean.CancelItemResponse"
		serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
		deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
		encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
	/>
    <!-- 关闭-->
	<typeMapping
		xmlns:ns="http://itsmhd.starit.com/bean"
		qname="ns:CloseItem"
		type="java:com.starit.itsmhd.bean.CloseItem"
		serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
		deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
		encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
	/>
    <typeMapping
		xmlns:ns="http://itsmhd.starit.com/bean"
		qname="ns:CloseItemResponse"
		type="java:com.starit.itsmhd.bean.CloseItemResponse"
		serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
		deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
		encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
	/>
	<!--催单-->
	<typeMapping
		xmlns:ns="http://itsmhd.starit.com/bean"
		qname="ns:PromptItem"
		type="java:com.starit.itsmhd.bean.PromptItem"
		serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
		deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
		encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
    />
	<typeMapping
		xmlns:ns="http://itsmhd.starit.com/bean"
		qname="ns:PromptItemResponse"
		type="java:com.starit.itsmhd.bean.PromptItemResponse"
		serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
		deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
		encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
    />
	<!--附件-->
	<arrayMapping
		xmlns:ns="http://itsmhd.starit.com/bean"
		qname="ns:ArrayOf_tns1_DataHandler"
		type="java:javax.activation.DataHandler[]"
		innerType="cmp-ns:DataHandler" 
		xmlns:cmp-ns="http://xml.apache.org/xml-soap"
		encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
    />
	<!--异常-->
    <typeMapping
		xmlns:ns="http://itsmhd.starit.com/exception"
		qname="ns:AppException"
		type="java:com.starit.itsmhd.exception.AppException"
		serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
		deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
		encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
    />
 </service>

 

 

3、开发功能接口及实现和业务处理类:

 

package com.starit.itsmhd.interfaces;

import java.rmi.Remote;
import java.rmi.RemoteException;

import javax.activation.DataHandler;

import com.starit.itsmhd.bean.ApplyItem;
import com.starit.itsmhd.bean.ApplyItemResponse;
import com.starit.itsmhd.bean.CancelItem;
import com.starit.itsmhd.bean.CancelItemResponse;
import com.starit.itsmhd.bean.CloseItem;
import com.starit.itsmhd.bean.CloseItemResponse;
import com.starit.itsmhd.bean.PromptItem;
import com.starit.itsmhd.bean.PromptItemResponse;
import com.starit.itsmhd.bean.QueryItem;
import com.starit.itsmhd.bean.QueryItemResponse;
import com.starit.itsmhd.exception.AppException;

/**
 * @author zqding
 * @version 1.0
 * @date 2010-11-22
 * @class_displayName FwbzInter
 */

public interface FwbzInter extends Remote {
	public ApplyItemResponse putEvent(ApplyItem applyItem,
			DataHandler[] attchments) throws RemoteException, AppException;

	public QueryItemResponse queryEvent(QueryItem queryItem)
			throws RemoteException, AppException;

	public CancelItemResponse cancelEvent(CancelItem cancelItem)
			throws RemoteException, AppException;

	public CloseItemResponse closeEvent(CloseItem closeItem,
			DataHandler[] attchments) throws RemoteException, AppException;

	public PromptItemResponse promptEvent(PromptItem promptItem)
			throws RemoteException, AppException;

}

 

 

 

package com.starit.itsmhd.impl;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.rmi.RemoteException;
import java.text.SimpleDateFormat;

import javax.activation.DataHandler;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import com.primeton.tp.common.xml.XmlUtil;
import com.primeton.tp.core.api.BizServiceCallerFactory;
import com.primeton.tp.core.bizservice.ProcessCaller;
import com.starit.itsmhd.bean.ApplyItem;
import com.starit.itsmhd.bean.ApplyItemResponse;
import com.starit.itsmhd.bean.CancelItem;
import com.starit.itsmhd.bean.CancelItemResponse;
import com.starit.itsmhd.bean.CloseItem;
import com.starit.itsmhd.bean.CloseItemResponse;
import com.starit.itsmhd.bean.PromptItem;
import com.starit.itsmhd.bean.PromptItemResponse;
import com.starit.itsmhd.bean.QueryItem;
import com.starit.itsmhd.bean.QueryItemResponse;
import com.starit.itsmhd.exception.AppException;
import com.starit.itsmhd.interfaces.FwbzInter;

/**
 * @author zqding
 * @version 1.0
 * @date 2010-11-22
 * @class_displayName FwbzImpl
 */

public class FwbzImpl implements FwbzInter {

	private static Log logger = LogFactory.getLog(FwbzImpl.class);

	public ApplyItemResponse putEvent(ApplyItem applyItem,	DataHandler[] attchments) throws RemoteException, AppException {
		
		ApplyItemResponse resultObj = new ApplyItemResponse();
		//ApplyItemResponse resultObj = null;
		String resultValue = null;
		String resultXML = "";
		try {
			logger.info("开始处理 ITSM系统的工单派发请求接口<ITSM调服务保障>");
			
			//1、如果有附件,先保存附件。
			logger.info("保存附件");
			String[] fileNames = applyItem.getAttName();
			String[] fNames = {"222.pdf","222.rar"};
			SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
			String inputXML = "";
			
			if(applyItem.isAttachFlag()){
				for(int i =0 ;i < fileNames.length ; i++){
					logger.info("保存文件" + i +":"+ fileNames[i]);
					String fullPath = "C:/" + fNames[i];   
			        File file = new File(fullPath);   
			        int flag = 0;   
			        try {   
			            InputStream input = attchments[i].getInputStream();   
			            FileOutputStream fos = new FileOutputStream(file);   
			            byte[] buffer=new byte[4096];   
			            while((flag=input.read(buffer))!=-1){   
			                fos.write(buffer,0,flag);   
			            }   
			            input.close();   
			            fos.close();   
			        } catch (IOException e) {   
			            e.printStackTrace();   
			        }   
			    }
			}
			
			//2、向保障系统派单
			logger.info("参数列表:");
			logger.info("ITSM事件流水号:" + applyItem.getApplyserial());
			logger.info("事件提出人:" 	  + applyItem.getSubmitStaffName());
			logger.info("事件标题:"       + applyItem.getTitle());
			logger.info("事件发生地址:"   +	applyItem.getPlace());
			logger.info("事件发生时间:"   + df.format(applyItem.getOccurTime()));
			logger.info("事件来源:"       + applyItem.getOrigin());
			logger.info("事件影响度:"     + applyItem.getIncidence());
			logger.info("事件优先级:"     + applyItem.getPriority());
			logger.info("事件完成期限:"   + df.format(applyItem.getFinishLimit()));
			logger.info("所属系统类型:"   + applyItem.getSysType());
			logger.info("事件内容:"       + applyItem.getContent());
			logger.info("附件标记:"       + applyItem.isAttachFlag());
			logger.info("附件数量:"       + applyItem.getFileNum());
			logger.info("附件名称:"       + StringUtils.join(applyItem.getAttName(), ","));
			
			inputXML =  "<?xml version=\"1.0\" encoding=\"GB2312\"?><root><data>"
				+ "<applySerial>" 		+ applyItem.getApplyserial() 					+ "</applySerial>"
				+ "<submitStaffName>"   + applyItem.getSubmitStaffName() 				+ "</submitStaffName>"
				+ "<title>" 			+ applyItem.getTitle() 							+ "</title>"
				+ "<place>" 			+ applyItem.getPlace() 							+ "</place>"
				+ "<occurTime>" 		+ df.format(applyItem.getOccurTime())			+ "</occurTime>"
				+ "<origin>" 			+ applyItem.getOrigin() 						+ "</origin>"
				+ "<incidence>" 		+ applyItem.getIncidence() 						+ "</incidence>"
				+ "<priority>" 			+ applyItem.getPriority() 						+ "</priority>"
				+ "<finishLimit>" 		+ df.format(applyItem.getFinishLimit()) 		+ "</finishLimit>"
				+ "<sysType>" 			+ applyItem.getSysType() 						+ "</sysType>"
				+ "<content>" 			+ applyItem.getContent() 						+ "</content>"
				+ "<attachFlag>"		+ applyItem.isAttachFlag() 						+ "</attachFlag>"
				+ "<fileNum>" 			+ applyItem.getFileNum() 						+ "</fileNum>"
				+ "<attName>" 			+ StringUtils.join(applyItem.getAttName(), ",")	+ "</attName>"
				+ "</data></root>"; 
			
			logger.info("派单输入信息:" + inputXML);
			resultXML = callBiz("spi", "bizITSM_Fault_Interface.bizITSM_BZ_PDintf", inputXML);
			logger.info("派单返回信息:" + resultXML);
			
			
		} catch (Exception e) {
			resultValue = "调用 服务保障系统工单派发接口失败,原因";
			resultValue = resultValue  + e.getMessage();
			logger.info("异常原因:" + resultValue);
			throw new AppException(resultValue, null);
		}
		
		//3、把派单返回信息转成Document对象并赋值给ApplyItemResponse->resultObj对象
		Document doc;
		try {
			doc = stringToDoc(resultXML);
			NodeList nodes = doc.getElementsByTagName("data");
			for (int i = 0; i < nodes.getLength(); i++) {
				Node node = nodes.item(i);
				NodeList childNodes = node.getChildNodes();
				for (int j = 0; j < childNodes.getLength(); j++) {
					Node childNode = childNodes.item(j);
					if (childNode.getNodeType() == Node.ELEMENT_NODE && childNode.getNodeName().equals("result"))
						resultObj.setResult(new Integer(childNode.getFirstChild().getNodeValue()));
					
					if (childNode.getNodeType() == Node.ELEMENT_NODE && childNode.getNodeName().equals("fwbzSerial"))
						resultObj.setFwbzSerial(childNode.getFirstChild().getNodeValue());
					
					if (childNode.getNodeType() == Node.ELEMENT_NODE && childNode.getNodeName().equals("itsmSerial"))
						resultObj.setItsmSerial(childNode.getFirstChild().getNodeValue());
					
					if (childNode.getNodeType() == Node.ELEMENT_NODE && childNode.getNodeName().equals("msg"))
						resultObj.setMsg(childNode.getFirstChild().getNodeValue());
				}
			}
		} catch (Exception e) {
			resultValue = "派单结果转换失败,原因";
			resultValue = resultValue  + e.getMessage();
			logger.info("异常原因:" + resultValue);
			throw new AppException(resultValue, null);
		}
		
		return resultObj;
	}

	......

	/**
	 * String 转 XML org.w3c.dom.Document
	 */
	private static Document stringToDoc(String xmlStr) {
		// 字符串转XML
		Document doc = null;
		try {
			xmlStr = new String(xmlStr.getBytes(), "gb2312");
			StringReader sr = new StringReader(xmlStr);
			InputSource is = new InputSource(sr);
			DocumentBuilderFactory factory = DocumentBuilderFactory
					.newInstance();
			DocumentBuilder builder;
			builder = factory.newDocumentBuilder();
			doc = builder.parse(is);
		} catch (ParserConfigurationException e) {
			System.err.println(xmlStr);
			e.printStackTrace();
		} catch (SAXException e) {
			System.err.println(xmlStr);
			e.printStackTrace();
		} catch (IOException e) {
			System.err.println(xmlStr);
			e.printStackTrace();
		}
		return doc;
	}
	
	/**
	 * XML org.w3c.dom.Document 转 String
	 */
	private static String docToString(Document doc) {
		// XML转字符串
		String xmlStr = "";
		try {
			TransformerFactory tf = TransformerFactory.newInstance();
			Transformer t = tf.newTransformer();
			t.setOutputProperty("encoding", "gb2312");// 解决中文问题,试过用GBK不行UTF-8
			ByteArrayOutputStream bos = new ByteArrayOutputStream();
			t.transform(new DOMSource(doc), new StreamResult(bos));
			xmlStr = bos.toString();
		} catch (TransformerConfigurationException e) {
			e.printStackTrace();
		} catch (TransformerException e) {
			e.printStackTrace();
		}
		return xmlStr;
	}

}

 

 

package com.starit.itsmhd.service;
import java.rmi.RemoteException;

import javax.activation.DataHandler;

import org.w3c.dom.*;

import com.primeton.tp.core.api.BizContext;
import com.starit.itsmhd.bean.ApplyItem;
import com.starit.itsmhd.bean.ApplyItemResponse;
import com.starit.itsmhd.bean.CancelItem;
import com.starit.itsmhd.bean.CancelItemResponse;
import com.starit.itsmhd.bean.CloseItem;
import com.starit.itsmhd.bean.CloseItemResponse;
import com.starit.itsmhd.bean.PromptItem;
import com.starit.itsmhd.bean.PromptItemResponse;
import com.starit.itsmhd.bean.QueryItem;
import com.starit.itsmhd.bean.QueryItemResponse;
import com.starit.itsmhd.exception.AppException;
import com.starit.itsmhd.impl.FwbzImpl;
import com.starit.itsmhd.interfaces.FwbzInter;
/**
 * @author zqding
 * @version 1.0
 * @date 2010-11-22
 * @class_displayName FwbzService
 */

public class FwbzService implements FwbzInter {

	private FwbzInter impl;

	public FwbzService() {
		this.impl = new FwbzImpl();
	}

	public FwbzService(FwbzInter impl) {
		this.impl = impl;
	}

	//派单
	public ApplyItemResponse putEvent(ApplyItem applyItem,	DataHandler[] attchments) throws RemoteException, AppException {
		ApplyItemResponse ret = impl.putEvent(applyItem, attchments);
		return ret;
	}

	//查询工单
	public QueryItemResponse queryEvent(QueryItem queryItem) throws RemoteException, AppException {
		QueryItemResponse ret = impl.queryEvent(queryItem);
		return ret;
	}

	//取消工单
	public CancelItemResponse cancelEvent(CancelItem cancelItem) throws RemoteException, AppException {
		CancelItemResponse ret = impl.cancelEvent(cancelItem);
		return ret;
	}

	//关闭工单
	public CloseItemResponse closeEvent(CloseItem closeItem, DataHandler[] attchments) throws RemoteException, AppException {
		CloseItemResponse ret = impl.closeEvent(closeItem, attchments);
		return ret;
	}

	//催单
	public PromptItemResponse promptEvent(PromptItem promptItem) throws RemoteException, AppException {
		PromptItemResponse ret = impl.promptEvent(promptItem);
		return ret;
	}

}

 

 

4、测试代码:

package com.starit.itsmhd.testcase;

import java.io.File;
import java.rmi.RemoteException;
import java.util.Date;

import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.ser.BeanDeserializerFactory;
import org.apache.axis.encoding.ser.BeanSerializerFactory;
import org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory;
import org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory;

import com.starit.itsmhd.bean.ApplyItem;
import com.starit.itsmhd.bean.ApplyItemResponse;
import com.starit.itsmhd.bean.CancelItem;
import com.starit.itsmhd.bean.CancelItemResponse;
import com.starit.itsmhd.bean.CloseItem;
import com.starit.itsmhd.bean.CloseItemResponse;
import com.starit.itsmhd.bean.PromptItem;
import com.starit.itsmhd.bean.PromptItemResponse;
import com.starit.itsmhd.bean.QueryItem;
import com.starit.itsmhd.bean.QueryItemResponse;
import com.starit.itsmhd.exception.AppException;

/**
 * @author zqding
 * @version 1.0
 * @date 2010-11-22
 * @class_displayName TestCase
 */

public class TestCase {

	public static void main(String[] args) {
		putSheet();
		......
	}

	public static int putSheet() {

		String[] fileNames = { "d:/111.pdf", "d:/111.rar" };

		ApplyItem item = new ApplyItem();
		item.setApplyserial("111111111");
		item.setSubmitStaffName("wangyongq");
		item.setTitle("测试单");
		item.setPlace("xxx");
		item.setOccurTime(new Date());
		item.setOrigin(11);
		item.setIncidence(12);
		item.setPriority(12);
		item.setFinishLimit(new Date());
		item.setSysType(10006);
		item.setContent("xxxx测试单");
		item.setFileNum(2);
		item.setAttName(fileNames);
		item.setAttachFlag(true);

		DataHandler[] dataHandler = new DataHandler[item.getFileNum()];

		for (int i = 0; i < item.getFileNum(); i++) {
			File file = new File(item.getAttName()[i]);
			FileDataSource source = new FileDataSource(file);
			dataHandler[i] = new DataHandler(source);
		}

		ApplyItemResponse response;// = new ApplyItemResponse();
		Call call;
		try {

			String url = "http://127.0.0.1:7001/axis/services/FwbzService";

			Service service = new Service();

			call = (Call) service.createCall();

			call.setTargetEndpointAddress(url);

			// 设定服务方法名
			call.setOperationName(new QName(url, "putEvent"));

			QName qna = new QName("http://itsmhd.starit.com/bean", "ApplyItem");

			QName qnd = new QName("http://itsmhd.starit.com/bean",
					"ArrayOf_tns1_DataHandler");

			QName returnType = new QName("http://itsmhd.starit.com/bean",
					"ApplyItemResponse");
			
			QName ae = new QName("http://itsmhd.starit.com/bean",
			"AppException");

			call.registerTypeMapping(ApplyItem.class, qna,
					new BeanSerializerFactory(ApplyItem.class, qna),
					new BeanDeserializerFactory(ApplyItem.class, qna));

			call.registerTypeMapping(DataHandler.class, qnd,
					JAFDataHandlerSerializerFactory.class,
					JAFDataHandlerDeserializerFactory.class);

			call.registerTypeMapping(ApplyItemResponse.class, returnType,
					new BeanSerializerFactory(ApplyItemResponse.class,returnType), 
					new BeanDeserializerFactory(ApplyItemResponse.class,returnType));
			
			call.registerTypeMapping(AppException.class, ae,
					new BeanSerializerFactory(AppException.class,ae), 
					new BeanDeserializerFactory(AppException.class,ae));

			// 设置参数占位符
			call.addParameter("arg1", qna, ParameterMode.IN);
			call.addParameter("arg2", qnd, ParameterMode.IN);			
			call.setReturnType(returnType);
			// 设置Webservice超时时间
			call.setTimeout(new Integer(10000));
			// 调用服务并获取服务调用返回信息
			response = (ApplyItemResponse) call.invoke(new Object[] { item,	dataHandler });
			System.out.println("调用结果:response>>>>>>>>>>>>>>>>>>>>>>>>" + response.getMsg());
		} catch (ServiceException e) {
			e.printStackTrace();
			System.out.println("service method exception!");
			// 调用Webservice异常时,设置标识值,直接返回
			return 2;
		} catch (AppException e) {
			e.printStackTrace();
			return 2;
		} catch (Exception e) {
			System.out.println("remote mothod exception!");
			e.printStackTrace();
			return 2;
		}

		return 1;

	}	
	.......
}
 
分享到:
评论

相关推荐

    Axis2搭建WebService服务端demo

    在本文中,我们将深入探讨如何使用Spring、Axis2和Maven构建一个基于Java的Web服务(WebService)服务端示例。这些技术的结合为开发人员提供了高效、灵活且可扩展的解决方案来创建和消费Web服务。 首先,让我们了解...

    金蝶EAS_V7.5_WebService开发指南_EASwebservice开发_金蝶开发_

    金蝶EAS(Enterprise Application Suite)是一款针对大型企业级应用的综合管理软件,它提供了全面的企业资源规划(ERP)解决方案。在V7.5版本中,金蝶EAS引入了Web Service技术,允许不同系统之间进行无缝的数据交换...

    Axis2教程和java调用webservice的各种方法总结

    标题“Axis2教程和java调用webservice的各种方法总结”表明了本文档主要聚焦于两个核心内容:一是Axis2框架的使用教程,二是Java语言调用Web服务的不同方法的综合概述。 描述中的“Axis2教程”暗示了会详细讲解Axis...

    webservice 打包 开发工具

    总结,Web服务的开发和打包涉及到多个技术环节和工具,从选择合适的协议和标准,到利用开发工具创建和调试服务,再到最后的打包和部署,每个步骤都至关重要。理解这些概念和技术对于构建高效、可靠的分布式系统具有...

    axis2+EJB整合开发 源代码

    【标题】"Axis2+EJB整合开发 源代码"涉及的是在Java环境中,使用Axis2框架与Enterprise JavaBeans(EJB)技术进行Web服务整合的实践案例。这个标题暗示了我们将深入理解如何将EJB的功能集成到基于Axis2的Web服务中,...

    WebService应用

    WebService应用是一种基于开放标准的互联网通信方式,允许不同的应用程序之间进行数据交换,不受平台或语言限制。它基于SOAP(Simple Object ...开发者需要综合运用这些知识,才能有效地设计、实现和使用WebService。

    Xfire+spring+hiebrnate webService

    综合来看,"Xfire+Spring+Hibernate WebService"项目利用了这些工具和技术的协同工作,实现了高效、灵活的Web服务开发。Xfire提供Web服务的基础框架,Spring为业务逻辑提供了容器和管理,而Hibernate则处理了数据...

    webService汇总整理.rar

    开发WebService时,可以使用多种工具,如Apache Axis、Java的JAX-WS、.NET的WCF(Windows Communication Foundation)等。这些工具提供了自动代码生成、调试和部署等功能。 9. **SOAP与RESTful的集成**: 随着...

    webService4java 必须包

    【标题】"webService4java 必须包" 涉及的核心技术是Web服务,主要依赖于一系列的Java库,这些库对于开发和运行基于Java的Web服务至关重要。Web服务是一种通过网络(通常使用HTTP协议)进行通信的软件组件,它提供了...

    webService五个实现方式

    XFire利用了Spring框架,使得集成到现有应用中变得更加容易。它支持SOAP、RESTful风格的服务,同时也提供了丰富的客户端和服务器端API。XFire的一个关键特性是它的代码生成工具,能够自动生成服务代理类,简化开发...

    webservice资料

    3. Axis2:Axis2是Apache软件基金会开发的一个Web服务框架,它支持SOAP 1.1和1.2,提供了高性能的服务托管和调用机制。Axis2教程.zip文件应该包含了Axis2的安装指南、API使用方法、创建和部署Web服务的步骤,以及...

    webservice系统+文档(自己做的)

    【标题解析】 标题"webservice系统+文档(自己做的)"表明这是一个关于Web Service系统的个人项目,其中包含了...通过阅读源码和文档,可以了解如何在Java中创建和消费Web Service,以及如何利用Axis2进行相关操作。

    Asis2(文档+BIN+WAR+代码+配置)

    通过这个资源,用户可以学习到如何利用Axis2创建、调用和管理Web服务,以及与Asis2框架的集成。 `axis配置.txt`顾名思义,包含了Axis2的配置信息。理解并正确配置Axis2对于充分发挥其功能至关重要。用户可以通过这...

    《移动网络优化中心综合管理平台》

    开发技术平台是Java,WebService平台使用Axis2,GIS服务的具体实现未提及。 整个设计方案的提出,不仅针对了现有移动网络优化工作中的不足,而且提供了一个实现信息化管理的框架,为相关企业的移动网络优化工作提供...

    CTSS:一个综合实训选题系统,采用CS架构,客户端有PC端和Android端。使用AIXS2和KSOAP框架提供webservice服务,解决异构平台访问数据库不统一

    AIXS2(可能是指 Axis2,一个由Apache软件基金会开发的Web服务引擎)是一个成熟的Web服务框架,它支持SOAP 1.1和1.2协议,提供了高效的Web服务处理能力。它包含了完整的Web服务生命周期管理,包括服务发布、发现、...

    banking_system.zip_JAVA银行系统_zip_银行系统

    综合以上信息,这个银行系统项目采用了Java技术栈,利用Spring Security进行安全控制,通过Web服务提供外部接口,用Ant进行构建,可能使用Axis处理Web服务,以及FreeMarker生成前端页面。这样的架构设计有利于模块化...

    发布服务

    【发布服务】是一种在IT行业中常见的技术操作,它涉及到软件应用程序的部署和公开,以便其他系统或用户可以访问和利用所提供的功能。在这个场景中,我们关注的是如何发布Web服务,特别是通过使用源码和工具来实现。...

    Web服务(Sams 24 小时自学图书系列)

    ### Web服务(Sams 24 小时自学图书系列) ...总之,《Web服务(Sams 24 小时自学图书系列)》是一本综合性和实用性极强的教程,对于希望深入理解Web服务并能够在项目中运用相关技术的读者来说,是一本不可多得的好书。

Global site tag (gtag.js) - Google Analytics