package com.jiuqi.mobile.nigo.comeclose.ws.client; import java.lang.reflect.Proxy; import java.util.UUID; import java.util.logging.Handler; import com.google.gson.internal.bind.ObjectTypeAdapter; import com.jiuqi.mobile.nigo.comeclose.bean.base.UserBean; import com.jiuqi.mobile.nigo.comeclose.bean.message.LoginMessageBean; import com.jiuqi.mobile.nigo.comeclose.exception.LoginException; import com.jiuqi.mobile.nigo.comeclose.exception.NiGoException; import com.jiuqi.mobile.nigo.comeclose.manager.base.ILoginManager; import com.jiuqi.mobile.nigo.comeclose.ws.server.Session; /** * 客户端与服务端交互的上下文,负责连接、数据传输等操作 * <pre> * 示例: * ... * ClientContext context = ClientContext.getContext("http://127.0.0.1:8080/saas", "/orderservice"); * IOrderService service = context.getService(IOrderService.class); * service.removeOrder("orderid"); * ... * </pre> * * @author liuhongbin */ public class LBSClientContext { /** * [MMC]webservice的服务相对地址 */ public final static String WS_URI_NJT = "/lbs"; private String serverURL = null; private String serviceURI = null; /** * 获得MMC当前交互上下文的实例 * * @param serverURL * 服务端的地址 * @return */ public static LBSClientContext getClientContext(String serverURL ) throws LoginException { return getClientContext(serverURL , 10 * 1000); } public static LBSClientContext getClientContext(String serverURL, int timeout) throws LoginException { LBSClientContext context = new LBSClientContext(serverURL, WS_URI_NJT); return context; } /** * 根据对应的接口名获取响应的服务(返回的object为传入接口)</br> * * android端实现时异常处理问题,所有返回异常可能会被UndeclaredThrowableException包装。</br> * 请这样使用</br> } catch (Throwable e) {</br> if(e instanceof * UndeclaredThrowableException){</br> e.getCause();</br> }</br> * e.printStackTrace();</br> }</br> </br> * * @param intf * 服务代理接口 * @return 返回的object为传入接口 */ @SuppressWarnings("unchecked") public <T> T getManager(Class<T> intf) { LBSClientInvocationHandler handler = new LBSClientInvocationHandler(serverURL, serviceURI, intf); T manager = (T) Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[] { intf }, handler); return manager; } // /** // * 仅登录使用无session登录 // * @param intf // * @param timeout // * @return // */ // @SuppressWarnings("unchecked") // public <T> T getManager(Class<T> intf, int timeout) { // return (T) Proxy.newProxyInstance(getClass().getClassLoader(), // new Class<?>[]{intf}, // new LBSClientInvocationHandler(serverURL, serviceURI, intf)); // } private LBSClientContext(String serverURL, String serviceURI) { this.serverURL = serverURL; this.serviceURI = serviceURI; } }