首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

hessian——客户端动态署理

2013-03-06 
hessian——客户端动态代理客户端代码:String urlString http://localhost/hessian/testServiceHessian

hessian——客户端动态代理

客户端代码:

String urlString = "http://localhost/hessian/testService";HessianProxyFactory factory = new HessianProxyFactory();TestService testService = (TestService)factory.create(TestService.class,urlString);

?

 public Object create(Class<?> api, URL url, ClassLoader loader)  {    if (api == null)      throw new NullPointerException("api must not be null for HessianProxyFactory.create()");    InvocationHandler handler = null;    handler = new HessianProxy(url, this, api);    return Proxy.newProxyInstance(loader,                                  new Class[] { api,                                                HessianRemoteObject.class },                                  handler);  }

?handler = new HessianProxy(url, this, api);是关键,利用java动态代理,创建了一个HessianProxy对象来代理对Service对象的方法调用,具体HessianProxy的代理方式就是通过网络连接,调用远程的方法(见

hessian——源码分析(二)------ HessianProxy《转》)

热点排行