spring的axis axis2 httpinvoker hessian cfx远程调用

阅读更多
实体

package com.micc.entity;
import java.io.Serializable;
import java.util.Date;

public class Finger implements Serializable {

	/** */
	private static final long serialVersionUID = 137535894213747943L;
	
	/** 手头的数据 */
	private byte[] fingerData;
	private float data1;
	private double data2;
	private Date data3;
	
	public Date getData3() {
		return data3;
	}

	public void setData3(Date data3) {
		this.data3 = data3;
	}

	public byte[] getFingerData() {
		return fingerData;
	}

	public void setFingerData(byte[] fingerData) {
		this.fingerData = fingerData;
	}

	public float getData1() {
		return data1;
	}

	public void setData1(float data1) {
		this.data1 = data1;
	}

	public double getData2() {
		return data2;
	}

	public void setData2(double data2) {
		this.data2 = data2;
	}

}

package com.micc.entity;

import java.io.Serializable;

public class Micc implements Serializable {

	/** */
	private static final long serialVersionUID = 6419383801409398601L;
	private long pw;

	public long getPw() {
		return pw;
	}

	public void setPw(long pw) {
		this.pw = pw;
	}

}

package com.micc.entity;

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

public class Person implements Serializable {

	/** */
	private static final long serialVersionUID = 3677113821106894243L;
	/** 手指 */
	private Finger finger;
	/** 年龄 */
	private int age;
	/** 账户 */
	private List account;
	/** 姓名 */
	private String name;
	/** 时间 */
	private Date date;

	public Finger getFinger() {
		return finger;
	}

	public void setFinger(Finger finger) {
		this.finger = finger;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public List getAccount() {
		return account;
	}

	public void setAccount(List account) {
		this.account = account;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

}

接口及实现

package com.micc.service;

import java.util.List;

import com.micc.entity.Finger;
import com.micc.entity.Micc;

public interface ITestService {
	
	/**
	 * @param p
	 * @return
	 */
	Finger getPersonFinger(String p);
	
	/**
	 * 
	 * 
	 * @param id
	 * @return
	 */
	List getPersonAccount(String id);

}

package com.micc.service.spring;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.micc.entity.Finger;
import com.micc.entity.Micc;
import com.micc.entity.Person;
import com.micc.service.ITestService;

public class SpringTestService implements ITestService {

	/**
	 * @see com.micc.axisserver.ITestService.ITestAxisService#getPersonFinger(java.lang.String)
	 */
	@Override
	public Finger getPersonFinger(String id) {
		Person p = new Person();
		
		Finger f= new Finger();
		f.setData1(2.0f);
		f.setData2(2.0D);
		byte[] b= new byte[1];
		b[0] = 1;
		f.setFingerData(b);
		f.setData3(new Date());
		p.setFinger(f);
		return p.getFinger();
	}

	/**
	 * @see com.micc.axisserver.ITestService.ITestAxisService#getPersonAccount(java.lang.String)
	 */
	@Override
	public List getPersonAccount(String id) {
		Person p = new Person();
		
		List l= new ArrayList();
		Micc m1 = new Micc();
		m1.setPw(10l);
		l.add(m1);
		
		Micc m2 = new Micc();
		m2.setPw(11l);
		l.add(m2);
		
		p.setAccount(l);
		return p.getAccount();
	}

}


(一)axis

1服务端
package com.micc.axisserver.webservice;

import java.util.List;

import org.springframework.remoting.jaxrpc.ServletEndpointSupport;

import com.micc.entity.Finger;
import com.micc.entity.Micc;
import com.micc.service.ITestService;

public class TestAxisService extends ServletEndpointSupport implements
		ITestService {

	private ITestService axisService;

	/**
	 * @see org.springframework.remoting.jaxrpc.ServletEndpointSupport#onInit()
	 */
	protected void onInit() {
		this.axisService = (ITestService) getWebApplicationContext()
				.getBean("axisService");
	}

	/**
	 * @see com.micc.axisserver.ITestService.ITestAxisService#getPersonFinger(java.lang.String)
	 */
	@Override
	public Finger getPersonFinger(String id) {
		return this.axisService.getPersonFinger(id);
	}

	/**
	 * @see com.micc.axisserver.ITestService.ITestAxisService#getPersonAccount(java.lang.String)
	 */
	@Override
	public List getPersonAccount(String id) {
		return this.axisService.getPersonAccount(id);
	}

}



	

	
		
		

		
		

		
		

		
		

	

	
		
			
		
	

 org.apache.axis.transport.http.AxisHTTPSessionListener 

 Apache-Axis Servlet AxisServlet 
		org.apache.axis.transport.http.AxisServlet 
		  AxisServlet /servlet/AxisServlet 
		  AxisServlet 
		*.jws   AxisServlet 
		/services/* 
 30  
		 wsdl text/xml 
		  xsd text/xml 
		

2客户端
package test;

import java.util.List;

import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;

import org.apache.axis.Constants;
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 com.micc.entity.Finger;
import com.micc.entity.Micc;

public class TestAxisWs {

	/**
	 * @param args
	 */
	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		try {
			String wsdlUrl = "http://localhost:8080/webservice/services/TAxisWebService?wsdl";
			String nameSpaceUri = "http://localhost:8080/webservice/services/TAxisWebService";
			// 创建调用对象
			Service service = new Service();
			Call call = null;
			call = (Call) service.createCall();

			System.out.println(">>>getPersonFinger");
			call.setOperationName(new QName(nameSpaceUri, "getPersonFinger"));
			call.setTargetEndpointAddress(new java.net.URL(wsdlUrl));
			QName qn1 = new QName("TAxisWebService", "Finger");
			call.registerTypeMapping(Finger.class, qn1,
					new BeanSerializerFactory(Finger.class, qn1),
					new BeanDeserializerFactory(Finger.class, qn1));
			call.addParameter("p", Constants.XSD_STRING, ParameterMode.IN);
			call.setReturnType(new QName(nameSpaceUri), Finger.class);
			call.setReturnClass(Finger.class);
			Finger ret1 = (Finger) call.invoke(new Object[] { "ABC" });
			System.out.println("return value is " + ret1);

			System.out.println(">>>getPersonAccount");
			call.setOperationName(new QName(nameSpaceUri, "getPersonAccount"));
			call.setTargetEndpointAddress(new java.net.URL(wsdlUrl));
			QName qn2 = new QName("TAxisWebService", "Micc");
			call.registerTypeMapping(Micc.class, qn2,
					new BeanSerializerFactory(Micc.class, qn2),
					new BeanDeserializerFactory(Micc.class, qn2));
			call.setReturnType(new QName(nameSpaceUri), List.class);
			call.setReturnClass(List.class);
			List ret2 = (List) call.invoke(new Object[] { "ABC" });
			System.out.println("return value is " + ret2);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}

(二)httpinvoker

1服务端


    
        
        
        
        
    


		spring
		/remoting/*
	

2客户端



	
		
		
		
		
		
		
			
		
	

package test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.micc.service.ITestService;

public class TestHttpInvoker {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext("/httpinvoker.cfg.xml");
		
		ITestService test = (ITestService) context.getBean("testService");
		
		System.out.println(">>>getPersonFinger");
		System.out.println("return value is " + test.getPersonFinger("11"));
		
		System.out.println(">>>getPersonAccount");
		System.out.println("return value is " + test.getPersonAccount("11"));
		
	}

}

你可能感兴趣的:(Spring,WebService,应用服务器,Tomcat,Apache)