spring的axis axis2 httpinvoker hessian cfx远程调用

[align=left][size=large][color=darkred]实体[/color][/size][/align]
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<Micc> 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<Micc> getAccount() {
return account;
}

public void setAccount(List<Micc> 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;
}

}

[align=left][size=large][color=darkred]接口及实现[/color][/size][/align]
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<Micc> 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<Micc> getPersonAccount(String id) {
Person p = new Person();

List<Micc> l= new ArrayList<Micc>();
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();
}

}


[align=left][size=large][color=darkred](一)axis
[/color][/size][/align]
[color=red]1服务端[/color]
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<Micc> getPersonAccount(String id) {
return this.axisService.getPersonAccount(id);
}

}

<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"
xmlns="http://xml.apache.org/axis/wsdd/">
<handler type="java:org.apache.axis.handlers.http.URLMapper"
name="URLMapper" />

<service name="TAxisWebService" provider="java:RPC">
<parameter name="allowedMethods" value="getPersonFinger,getPersonAccount" />
<parameter name="className"
value="com.micc.axisserver.webservice.TestAxisService" />

<beanMapping qname="myNS:Finger" xmlns:myNS="TAxisWebService"
languageSpecificType="java:com.micc.entity.Finger"
encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/"
serializer=" org.apache.axis.encoding.ser.BeanSerializerFactory"
deserializer=" org.apache.axis.encoding.ser.BeanDeserializerFactory">
</beanMapping>

<beanMapping qname="myNS:Micc" xmlns:myNS="TAxisWebService"
encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/"
serializer=" org.apache.axis.encoding.ser.BeanSerializerFactory"
deserializer=" org.apache.axis.encoding.ser.BeanDeserializerFactory"
languageSpecificType="java:com.micc.entity.Micc">
</beanMapping>

<beanMapping qname="myNS:Person" xmlns:myNS="TAxisWebService"
encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/"
serializer=" org.apache.axis.encoding.ser.BeanSerializerFactory"
deserializer=" org.apache.axis.encoding.ser.BeanDeserializerFactory"
languageSpecificType="java:com.micc.entity.Person">
</beanMapping>

</service>

<transport name="http">
<requestFlow>
<handler type="URLMapper" />
</requestFlow>
</transport>
</deployment>

<listener> <listener-class>org.apache.axis.transport.http.AxisHTTPSessionListener</listener-class> 
</listener>
<servlet> <display-name>Apache-Axis Servlet</display-name> <servlet-name>AxisServlet</servlet-name>
<servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
</servlet> <servlet-mapping> <servlet-name>AxisServlet</servlet-name> <url-pattern>/servlet/AxisServlet</url-pattern>
</servlet-mapping> <servlet-mapping> <servlet-name>AxisServlet</servlet-name>
<url-pattern>*.jws</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern> </servlet-mapping>
<session-config> <session-timeout>30</session-timeout> </session-config>
<mime-mapping> <extension>wsdl</extension> <mime-type>text/xml</mime-type>
</mime-mapping> <mime-mapping> <extension>xsd</extension> <mime-type>text/xml</mime-type>
</mime-mapping>

[color=red]2客户端[/color]
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<Micc> ret2 = (List<Micc>) call.invoke(new Object[] { "ABC" });
System.out.println("return value is " + ret2);
} catch (Exception e) {
e.printStackTrace();
}
}

}

[align=left][size=large][color=darkred](二)httpinvoker[/color][/size][/align]
[align=left][size=large][color=darkred]1服务端[/color][/size][/align]
<!-- 将业务服务bean暴露成远程服务 -->
<bean name="/TestService"
class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<!-- 指定需要暴露的业务服务bean -->
<property name="service" ref="testService" />
<!-- 指定暴露的远程服务实现的接口 -->
<property name="serviceInterface" value="com.micc.service.ITestService" />
</bean>

<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/remoting/*</url-pattern>
</servlet-mapping>

[align=left][size=large][color=darkred]2客户端[/color][/size][/align]
<!-- 配置连接远程服务的bean -->

<bean id="testService"
class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<!-- 远程服务的url -->
<property name="serviceUrl"
value="http://localhost:8080/webservice/remoting/TestService" />
<!-- 远程服务所实现的接口 -->
<property name="serviceInterface" value="com.micc.service.ITestService" />
<!-- 指定使用Commons HttpClient功能 -->
<property name="httpInvokerRequestExecutor">
<bean class="org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor" />
</property>
</bean>

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"));

}

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值