轻量级Rpc框架Hessian学习笔记
Posted 写点笔记
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了轻量级Rpc框架Hessian学习笔记相关的知识,希望对你有一定的参考价值。
public interface SayHello {
HelloEntity hello(String name);
}
public class HelloEntity implements Serializable {
private String tian;
public HelloEntity(String tian) {
this.tian = tian;
}
public String getTian() {
return tian;
}
public void setTian(String tian) {
this.tian = tian;
}
public String toString() {
return "HelloEntity{" +
"tian='" + tian + '\'' +
'}';
}
}
public class SayHelloService implements SayHello {
public HelloEntity hello(String name) {
return new HelloEntity("你好!"+name);
}
}
public class MyService {
private SayHelloService sayHelloService;
public HessianServiceExporter exportHelloHessian() {
HessianServiceExporter exporter = new HessianServiceExporter();
exporter.setService(sayHelloService);
exporter.setServiceInterface(SayHello.class);
return exporter;
}
}
public class TestHessian {
public staticT getHessianClientBean(Classclazz,String url) throws Exception{
// 客户端连接工厂,这里只是做了最简单的实例化,还可以设置超时时间,密码等安全参数
HessianProxyFactory factory = new HessianProxyFactory();
return (T)factory.create(clazz,url);
}
public static void main(String[] args) {
// 服务器暴露出的地址
String url = "http://localhost:8081/hello.htm";
// 客户端接口,需与服务端对象一样
try {
SayHello helloHessian =TestHessian.getHessianClientBean(SayHello.class,url);
HelloEntity msg = helloHessian.hello("你好");
System.out.println(msg);
} catch (Exception e) {
e.printStackTrace();
}
}
}
@FunctionalInterface
public interface HttpRequestHandler {
void handleRequest(HttpServletRequest var1, HttpServletResponse var2) throws ServletException, IOException;
}
以上是关于轻量级Rpc框架Hessian学习笔记的主要内容,如果未能解决你的问题,请参考以下文章