1 15 16 package com.jdon.bussinessproxy.remote; 17 18 19 import java.lang.reflect.Proxy ; 20 import java.util.Hashtable ; 21 import java.util.Map ; 22 23 import com.jdon.bussinessproxy.ServiceClientFactory; 24 import com.jdon.bussinessproxy.TargetMetaDef; 25 import com.jdon.bussinessproxy.meta.POJOTargetMetaDef; 26 import com.jdon.bussinessproxy.remote.auth.AuthException; 27 import com.jdon.bussinessproxy.remote.auth.Authenticator; 28 import com.jdon.bussinessproxy.remote.http.HttpClient; 29 import com.jdon.bussinessproxy.remote.http.HttpServerParam; 30 import com.jdon.util.Debug; 31 32 33 public class ServiceHTTPImp extends ServiceClientFactory { 34 35 private final static String module = ServiceHTTPImp.class.getName(); 36 private final static HttpClient httpClient = HttpClient.getInstance(); 37 private static Map _proxyCache = new Hashtable (); 38 39 public void setHttpServerParam(HttpServerParam httpServerParam) { 40 httpClient.setHttpServerParam(httpServerParam); 41 } 42 43 48 public Object getService(TargetMetaDef targetMetaDef) { 49 50 Debug.logVerbose("[JdonFramework] --> enter getService from dynamicProxy", module); 51 52 Object dynamicProxy = _proxyCache.get(targetMetaDef); 53 if (dynamicProxy == null) { 54 dynamicProxy = getServiceFromProxy(targetMetaDef); 55 _proxyCache.put(targetMetaDef, dynamicProxy); 56 } 57 return dynamicProxy; 58 59 } 60 61 67 public String login(String loginName, String password) throws AuthException{ 68 String loginResult = null; 69 try{ 70 Debug.logVerbose("[JdonFramework] --> enter login", module); 71 72 TargetMetaDef targetMetaDef = new POJOTargetMetaDef("authenticator", 73 "com.jdon.bussinessproxy.remote.auth.Authenticator"); 74 75 Authenticator authenticator = (Authenticator) getService(targetMetaDef); 76 loginResult = authenticator.login(loginName, password); 77 }catch(Exception e){ 78 throw new AuthException(e); 79 } 80 return loginResult; 81 82 } 83 88 public Object getServiceFromProxy(TargetMetaDef targetMetaDef) { 89 90 RemoteInvocationHandler handler = null; 91 Object dynamicProxy = null; 92 93 try { 94 Debug.logVerbose("[JdonFramework] ---> create a new ProxyInstance", module); 95 handler = new RemoteInvocationHandler(targetMetaDef); 96 97 ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 98 Class serviceClass = classLoader.loadClass(targetMetaDef.getClassName()); 99 100 dynamicProxy = 101 Proxy.newProxyInstance( 102 classLoader, 103 new Class [] {serviceClass}, 104 handler); 105 106 } catch (Exception ex) { 107 ex.printStackTrace(); 108 } 109 return dynamicProxy; 110 111 } 112 113 114 } 115
| Popular Tags
|