客户端代码:
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的代理方式就是通过网络连接,调用远程的方法(见
本文详细介绍了如何使用HessianProxyFactory类通过Java动态代理创建远程服务代理,重点在于理解handler的新建过程及其实现原理。
441

被折叠的 条评论
为什么被折叠?



