package com.jiuqi.mobile.nigo.comeclose.ws.publish; import java.lang.reflect.Proxy; import com.jiuqi.mobile.nigo.comeclose.bean.base.UserBean; import com.jiuqi.mobile.nigo.comeclose.exception.LoginException; import com.jiuqi.mobile.nigo.comeclose.manager.base.ILoginManager; import com.jiuqi.mobile.nigo.comeclose.ws.client.ClientInvocationHandler; /** * 远程端与服务端交互的上下文,负责连接、数据传输等操作 * @author liuhongbin */ public class WSContext { // // /** // * [MMC]webservice的服务相对地址 // */ // public final static String WS_URI_NJT = "/pub"; // // private String serverURL = null; // private String serviceURI = null; // private String sessionID = null; // private UserBean user; // // /** // * 获得MMC当前交互上下文的实例 // * @param serverURL 服务端的地址 // * @return // */ // public static WSContext getClientContext(String serverURL, String sessionId) throws LoginException { // WSContext context = new WSContext(serverURL, WS_URI_NJT); // if(null != sessionId){ // context.sessionID = sessionId; // context.user = context.getManager(ILoginManager.class).getUser(sessionId); // } // return context; // } // /** // * 获得MMC当前交互上下文的实例 // * @param serverURL 服务端的地址 // * @return // */ // public static WSContext getClientContext(String serverURL, String userAccountOrMobileNumber, String password) throws LoginException { // WSContext context = new WSContext(serverURL, WS_URI_NJT); // context.sessionID = context.getManager(ILoginManager.class).login(userAccountOrMobileNumber, password); // return getClientContext(serverURL, context.sessionID); // } // /** // * 获得MMC当前交互上下文的实例 // * @param serverURL 服务端的地址 // * @return // */ // public static WSContext getClientContext(String serverURL) throws LoginException { // WSContext context = new WSContext(serverURL, WS_URI_NJT); // context.sessionID = context.getManager(ILoginManager.class).login("anonymous", "anonymous"); // return getClientContext(serverURL, context.sessionID); // } // // /** // * 用户注册 // * @param serverURL // * @param userName // * @param mobileNumber // * @param password // * @param roleCode // * @throws LoginException // */ // public static void register(String serverURL,String userName, String mobileNumber, String password, int roleCode) throws LoginException{ // WSContext context = new WSContext(serverURL, WS_URI_NJT); // ILoginManager m = context.getManager(ILoginManager.class); // m.register(userName, mobileNumber, password, roleCode); // } // //// /** //// * 获得当前交互上下文的实例 //// * @param serverURL 服务端的地址 //// * @return //// */ //// public static ClientContext getContext(String serverURL, String serviceURI) { //// return new ClientContext(serverURL, serviceURI); //// } // // /** // * 根据对应的接口名获取响应的服务(返回的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) { // return (T) Proxy.newProxyInstance(getClass().getClassLoader(), // new Class<?>[]{intf}, // new ClientInvocationHandler(serverURL, serviceURI, sessionID, intf)); // } // // private WSContext(String serverURL, String serviceURI) { // this.serverURL = serverURL; // this.serviceURI = serviceURI; // } // // public UserBean getUser() { // return user; // } // public String getSessionID() { // return sessionID; // } // }