rel=""> 40
    public static IDataset getPushServerListCache() throws Exception {
41

42
        if (null == getBizDataCache().get(PUSH_SERVER_LIST)) {
43

44
            synchronized (BizDataCacheManager.class) {
45
                if (null != getBizDataCache().get(PUSH_SERVER_LIST)) {// 避免时间差
46
                    return (IDataset) getBizDataCache().get(PUSH_SERVER_LIST);
47
                }
48
                initPushServerListCache();
49
            }
50
        }
51
        return (IDataset) getBizDataCache().get(PUSH_SERVER_LIST);
52
    }
53

54
    public static boolean containsPushServer(String serverId) throws Exception {
55
        if (null == serverId) {
56
            throw new IpuBaseException("serverId is null.");
57
        }
58
        IDataset list = getPushServerListCache();
59
        if (list.isEmpty()) {
60
            return false;
61
        }
62
        IData pushServer;
63
        for (int i = 0; i < list.size(); i++) {
64
            pushServer = list.getData(i);
65
            if (serverId.equals(pushServer.getString("serverId"))) {
66
                return true;
67
            }
68
        }
69
        return false;
70
    }
71

72
    /**
73
     * 读取数据库,初始化数据
74
     */
75
    // private static void initPushServerListCache() throws Exception {
76
    // ServerDao dao = new ServerDao(Constant.connName);
77
    // IData param = new DataMap();
78
    // param.put("STATE", Constant.Server.STATE_AVAILABLE);
79
    // IDataset list = dao.getServerList(param);
80
    // if (list == null || list.isEmpty()) {
81
    // IpuLogger.error(log, "tab_server表未找到数据.");
82
    // IpuUtility.error("tab_server表未找到数据.");
83
    // }
84
    // getBizDataCache().put(PUSH_SERVER_LIST, list);
85
    //
86
    // IpuLogger.debug(log, "初始化" + PUSH_SERVER_LIST + "成功.");
87
    // }
88

89
    /**
90
     * 初始化P的列表,应该是主动扫描P的列表
91
     */
92
    private static void initPushServerListCache() throws Exception {
93
        // 待处理。。。
94
        log.debug("待处理,初始化扫描可用的P的列表");
95
        IDataset list = new DatasetList();
96
        getBizDataCache().put(PUSH_SERVER_LIST, list);
97
    }
98

99
    /**
100
     * 主动更改缓存,用于数据库tab_server表变动
101
     */
102
    public static void putPushServerListCache(IDataset list) throws Exception {
103
        getBizDataCache().put(PUSH_SERVER_LIST, list);
104

105
        log.debug("更改" + PUSH_SERVER_LIST + "成功.");
106
    }
107

108
    /**
109
     * 获取指定push_server端的accounts的Set集合
110
     */
111
    @SuppressWarnings("unchecked")
112
    public static Set<String> getPushServerAccountsCache(String serverId) throws Exception {
113
        if (null == getBizDataCache().get(PUSH_SERVER_ACCOUNTS_PREFIX + serverId)) {
114
            return new HashSet<String>();
115
        }
116
        return (Set<String>) getBizDataCache().get(PUSH_SERVER_ACCOUNTS_PREFIX + serverId);
117
    }
118

119
    /**
120
     * 存放accountSet值
121
     */
122
    public static void putPushServerAccountsCache(Set<String> accountSet, String serverId) throws Exception {
123
        getBizDataCache().put(PUSH_SERVER_ACCOUNTS_PREFIX + serverId, accountSet);
124
    }
125

126
    /**
127
     * 初始化或者更改accountSet值
128
     */
129
    public static void addAccountToPushServerAccountsId(String account, String serverId) throws Exception {
130
        Set<String> accountSet = getPushServerAccountsCache(serverId);
131
        log.debug("M add route, put before:key=" + (PUSH_SERVER_ACCOUNTS_PREFIX + serverId) + ",value=" + accountSet.toString());
132
        accountSet.add(account);
133
        putPushServerAccountsCache(accountSet, serverId);
134
        log.debug("M add route, put after:key=" + (PUSH_SERVER_ACCOUNTS_PREFIX + serverId) + ",value=" + accountSet.toString());
135

136
    }
137

138
    /**
139
     * 删除指定serverId的一个account值
140
     */
141
    public static void removeAccountToPushServerAccountsId(String account, String serverId) throws Exception {
142
        Set<String> accountSet = getPushServerAccountsCache(serverId);
143
        if (null == accountSet || !accountSet.contains(account)) {
144
            log.debug("has not this account [" + account + "] on this " + serverId + "server");
145
            return;
146
        }
147
        accountSet.remove(account);
148
        putPushServerAccountsCache(accountSet, serverId);
149
    }
150

151
    public static void addAvailableAccount(String account) throws Exception {
152
        if (getAvailableAccountSet().contains(account)) {
153
            // account已经存在了
154
            log.debug("account[" + account + "] already exists.");
155
        }
156
        Set<String> accountSet = getAvailableAccountSet();
157
        accountSet.add(account);
158
        putAvailableAccountSet(accountSet);
159
    }
160

161
    @SuppressWarnings("unchecked")
162
    public static Set<String> getAvailableAccountSet() throws Exception {
163
        if (null == getBizDataCache().get(AVAILABLE_ACCOUNTS)) {
164
            return new HashSet<String>();
165
        }
166
        return (Set<String>) getBizDataCache().get(AVAILABLE_ACCOUNTS);
167
    }
168

169
    public static void putAvailableAccountSet(Set<String> accountSet) throws Exception {
170
        getBizDataCache().put(AVAILABLE_ACCOUNTS, accountSet);
171
    }
172

173
    public static boolean containsAvailableAccount(String account) throws Exception {
174
        return getAvailableAccountSet().contains(account);
175
    }
176

177
    public static void increasePushServerAccountsSize(String serverId) throws Exception {
178
        int size = getPushServerAccountsSize(serverId);
179
        putPushServerAccountsSize(serverId, size + 1);
180
        log.debug("Number of server connections plus one");
181
    }
182

183
    public static void decreasePushServerAccountsSize(String serverId) throws Exception {
184
        int size = getPushServerAccountsSize(serverId);
185
        if (size < 1) {
186
            throw new IpuBaseException("The number of current connected account is less than one.");
187
        }
188
        putPushServerAccountsSize(serverId, size - 1);
189
        log.debug("Number of server connections minus one");
190
    }
191

192
    private static void putPushServerAccountsSize(String serverId, int accountsSize) throws Exception {
193
        getBizDataCache().put(PUSH_SERVER_ACCOUNTS_SIZE_PREFIX + serverId, accountsSize);
194
    }
195

196
    private static int getPushServerAccountsSize(String serverId) throws Exception {
197
        if (null == getBizDataCache().get(PUSH_SERVER_ACCOUNTS_SIZE_PREFIX + serverId)) {
198
            return 0;
199
        }
200
        return (Integer) getBizDataCache().get(PUSH_SERVER_ACCOUNTS_SIZE_PREFIX + serverId);
201
    }
202

203
}

+ 48 - 0
push-server/src/com/ai/server/push/cache/PushRouteCacheManager.java

@ -0,0 +1,48 @@
1
package com.ai.server.push.cache;
2

3
import com.ai.ipu.basic.log.ILogger;
4
import com.ai.ipu.basic.log.IpuLoggerFactory;
5
import com.ai.ipu.basic.util.IpuBaseException;
6
import com.ai.ipu.server.cache.CacheFactory;
7
import com.ai.ipu.server.cache.intf.ICache;
8
import com.ai.server.push.route.Route;
9
import com.ai.server.util.PushConstant;
10

11
/**
12
 * 管理服务端路由关系缓存管理类
13
 */
14
public class PushRouteCacheManager {
15

16
    transient protected static final ILogger log = IpuLoggerFactory.createLogger(PushRouteCacheManager.class);
17

18
    private static final String PUSH_ROUTE_CACHE = PushConstant.PUSH_ROUTE_CACHE;
19

20
    public static ICache getPushRouteCache() throws Exception {
21
        return CacheFactory.getCache(PUSH_ROUTE_CACHE);
22
    }
23

24
    public static Route getRoute(String account) throws Exception {
25
        if (null == getPushRouteCache().get(account)) {
26
            return null;
27
        }
28
        return new Route(getPushRouteCache().get(account).toString());
29
    }
30

31
    public static void putRoute(String account, Route route) throws Exception {
32
        if (null == account || "".equals(account) || null == route) {
33
            throw new IpuBaseException("account or route is null.");
34
        }
35
        getPushRouteCache().put(account, route.toString());
36
        log.debug("set key=[" + account + "] route success.");
37
    }
38

39
    public static void removeRoute(String account) throws Exception {
40
        if (null == getRoute(account)) {
41
            log.debug("this route account [" + account + "] is null.");
42
            return;
43
        }
44
        getPushRouteCache().remove(account);
45
        log.debug("remove key=[" + account + "] route success.");
46
    }
47

48
}

+ 112 - 104
push-server/src/com/ai/server/push/handle/RegisterWithRouteHandler.java

@ -1,14 +1,12 @@
1 1
package com.ai.server.push.handle;
2 2

3 3
import java.net.InetAddress;
4
import java.util.HashMap;
5 4
import java.util.Map;
6 5
import java.util.UUID;
7 6

8 7
import org.apache.log4j.Logger;
9 8

10
import com.ai.ipu.basic.net.http.HttpTool;
11
import com.ai.ipu.basic.util.IpuLogger;
9
import com.ai.ipu.basic.util.IpuBaseException;
12 10
import com.ai.mobile.push.handle.IRequestHandler;
13 11
import com.ai.mobile.push.msg.AbstractMessage;
14 12
import com.ai.mobile.push.msg.RegisterMessage;
@ -17,82 +15,86 @@ import com.ai.mobile.push.session.DefaultSessionManager;
17 15
import com.ai.mobile.push.session.IMSession;
18 16
import com.ai.mobile.push.session.ISessionManager;
19 17
import com.ai.mobile.push.util.IMConstant;
18
import com.ai.server.push.cache.PushRouteCacheManager;
19
import com.ai.server.push.route.IRouteManager;
20 20
import com.ai.server.push.route.Route;
21
import com.ai.server.push.route.impl.RouteManagerImpl;
21 22
import com.ai.server.usermanager.DefaultUserManager;
22 23
import com.ai.server.usermanager.IUserManager;
23 24
import com.ai.server.util.BeanHolder;
24 25
import com.ai.server.util.Constant;
25
import com.ailk.common.data.IData;
26
import com.ailk.common.data.impl.DataMap;
27 26

28
public class RegisterWithRouteHandler implements IRequestHandler{
29
	transient protected final Logger logger = Logger.getLogger(RegisterWithRouteHandler.class);
30
	@Override
31
	public ReplyMessage process(IMSession session, AbstractMessage msg) {
32
	    System.out.println("服务端接收到注册消息,处理中。。。。。。");
33
		// TODO Auto-generated method stub
34
		ISessionManager sessionManager= BeanHolder.getBean(DefaultSessionManager.class);
35
		RegisterMessage message = (RegisterMessage)msg;
36
		ReplyMessage reply = new ReplyMessage();
37
		String account = message.getAccount();
38
		Map<String, Object> map = message.getMap();
39
		IUserManager userManager = new DefaultUserManager();
40
		userManager.verify(map.get("account").toString(), map);//用户连接权限验证
41
		try {
42
			reply.setAccount(account);
43
			session.setAccount(account);
44
			session.setDeviceId(message.getDeviceId());
45
			session.setGid(UUID.randomUUID().toString());
46
			session.setHost(InetAddress.getLocalHost().getHostAddress());
47
			session.setDeviceType(message.getDeviceType());
48
			session.setDeviceModel(message.getDeviceModel());
49
			
50
			/*客户端连接断开,服务端无法获知情况,因此重连需要关闭旧的连接*/
51
			IMSession oldSession = sessionManager.getSession(account);
52
			if (oldSession != null) {
53
				// 如果是账号已经在另一台终端登录。则让另一个终端下线
54
				if ((oldSession.getDeviceId() != null
55
						&& !oldSession.getDeviceId().equals(session.getDeviceId()) 
56
						|| !oldSession.equals(session))) {
27
public class RegisterWithRouteHandler implements IRequestHandler {
28
    transient protected final Logger logger = Logger.getLogger(RegisterWithRouteHandler.class);
57 29

58
					//oldSession.removeAttribute(IMConstant.SESSION_KEY);
59
					ReplyMessage oldReply = new ReplyMessage();
60
					oldReply.setCode(Constant.MessageType.TYPE_999);// 强行下线消息类型
61
					oldReply.setAccount(account);
30
    @Override
31
    public ReplyMessage process(IMSession session, AbstractMessage msg) {
32
        System.out.println("服务端接收到注册消息,处理中。。。。。。");
33
        // TODO Auto-generated method stub
34
        ISessionManager sessionManager = BeanHolder.getBean(DefaultSessionManager.class);
35
        RegisterMessage message = (RegisterMessage) msg;
36
        ReplyMessage reply = new ReplyMessage();
37
        String account = message.getAccount();
38
        Map<String, Object> map = message.getMap();
39
        try {
40
            IUserManager userManager = new DefaultUserManager();
41
            boolean checkUserAvalible = userManager.verify(map.get("account").toString());// 用户连接权限验证
42
            if (!checkUserAvalible) {
43
                throw new IpuBaseException("不是有效用户,禁止连接推送服务端。");
44
            }
45
            reply.setAccount(account);
46
            session.setAccount(account);
47
            session.setDeviceId(message.getDeviceId());
48
            session.setGid(UUID.randomUUID().toString());
49
            session.setHost(InetAddress.getLocalHost().getHostAddress());
50
            session.setDeviceType(message.getDeviceType());
51
            session.setDeviceModel(message.getDeviceModel());
52

53
            /* 客户端连接断开,服务端无法获知情况,因此重连需要关闭旧的连接 */
54
            IMSession oldSession = sessionManager.getSession(account);
55
            if (oldSession != null) {
56
                // 如果是账号已经在另一台终端登录。则让另一个终端下线
57
                if ((oldSession.getDeviceId() != null && !oldSession.getDeviceId().equals(session.getDeviceId()) || !oldSession.equals(session))) {
58

59
                    // oldSession.removeAttribute(IMConstant.SESSION_KEY);
60
                    ReplyMessage oldReply = new ReplyMessage();
61
                    oldReply.setCode(Constant.MessageType.TYPE_999);// 强行下线消息类型
62
                    oldReply.setAccount(account);
63

64
                    if (!oldSession.isLocalhost()) {
65
                        /*
66
                         * 判断当前session是否连接于本台服务器,如不是发往目标服务器处理
67
                         * MessageDispatcher.execute(msg, oldSession.getHost());
68
                         */
69
                    } else {
70
                        oldSession.write(oldReply);
71
                        oldSession.close(true);
72
                        sessionManager.removeSession(account);
73
                    }
74
                    oldSession = null;
75
                }
76
            }
77

78
            if (oldSession == null) {
79
                // 第一次设置心跳时间为登录时间
80
                session.setBindTime(System.currentTimeMillis());
81
                session.setHeartbeat(System.currentTimeMillis());
82
                sessionManager.addSession(account, session);
83
                // 发送M,M记录路由关系,并有业务处理
84
                session.setAttribute("port", map.get("port"));
85
                this.addRoute(session, message, false);
86
            }
87

88
            reply.setCode(IMConstant.CODE_200);
89
        }
90
        catch (Exception e) {
91
            reply.setCode(IMConstant.CODE_500);
92
            e.printStackTrace();
93
        }
94
        logger.debug("[register account]:" + account + "|" + reply.getCode());
95
        return reply;
96
    }
62 97

63
					if (!oldSession.isLocalhost()) {
64
						/*
65
						 * 判断当前session是否连接于本台服务器,如不是发往目标服务器处理
66
						 * MessageDispatcher.execute(msg, oldSession.getHost());
67
						 */
68
					} else {
69
						oldSession.write(oldReply);
70
						oldSession.close(true);
71
						sessionManager.removeSession(account);
72
					}
73
					oldSession = null;
74
				}
75
			}
76
			
77
			if (oldSession == null) {
78
				// 第一次设置心跳时间为登录时间
79
				session.setBindTime(System.currentTimeMillis());
80
				session.setHeartbeat(System.currentTimeMillis());
81
				sessionManager.addSession(account, session);
82
				// 发送M,M记录路由关系,并有业务处理
83
				session.setAttribute("port", map.get("port"));
84
				this.addRoute(session, message, false);
85
			}
86
			
87
			reply.setCode(IMConstant.CODE_200);
88
		} catch (Exception e) {
89
			reply.setCode(IMConstant.CODE_500);
90
			e.printStackTrace();
91
		}
92
		logger.debug("[register account]:" + account + "|" + reply.getCode());
93
		return reply;
94
	}
95
	
96 98
    private void addRoute(IMSession session, RegisterMessage message, boolean isEncrypt) throws Exception {
97 99
        Route route = new Route();
98 100
        route.setAccount(session.getAccount());
@ -111,41 +113,47 @@ public class RegisterWithRouteHandler implements IRequestHandler{
111 113
        route.setState("1");
112 114
        route.setWeight("1");
113 115
        route.setServerId(message.getMap().get("serverId").toString());
116

117
        IRouteManager routeManager = new RouteManagerImpl();
118
        routeManager.addRoute(route.getAccount(), route);
114 119
        
115
        // 1.memcache保存对象,因为不能序列化,故不能发送到M端保存,也可以节省网络开销
116
        //RouteCacheUtil.addRouteCache(session.getAccount(), session);
120
        System.out.println(PushRouteCacheManager.getRoute(route.getAccount()).toString());
117 121
        
118
        // 2.M端业务处理(暂时没有业务处理)
119
        IData dataParam = new DataMap();
120
        dataParam.put("key1", "value1");
121
        dataParam.put("route", route.toString());
122
        Map<String, String> postData = new HashMap<String, String>();
123
        if (isEncrypt) {
124
            /* 参数加密处理 */
125
            postData.put("action", "RouteBean.addRoute");
126
            // postData.put("key", MobileSecurity.getDesKey());
127
            String encryptData = "";// 加密后的数据
128
            postData.put("data", encryptData);
129
        } else {
130
            postData.put("action", "RouteBean.addRoute");
131
            postData.put("data", dataParam.toString());
132
        }
133
        String data = HttpTool.toQueryStringWithEncode(postData);
134

135
        String result = HttpTool.httpRequest("http://localhost:8080/push-manager-server/wlwdata", data, "POST");
136
        if (isEncrypt) {
137
            /*解密*/
138
            //result = MobileSecurity.responseDecrypt(result);
139
        }
140
        if(result.endsWith("\r")){
141
            result = result.substring(0, result.lastIndexOf("\r")); // 待测试,之前尾部没有“\r”???????????
142
        }
143
        IData resultData = new DataMap(result);
144
        if ("success".equals(resultData.getString("flag"))) {
145
            IpuLogger.debug(logger, "添加route路由关系成功.");
146
        } else {
147
            IpuLogger.debug(logger, "添加route路由关系失败.");
148
        }
122
        
123
//        // 1.memcache保存对象,因为不能序列化,故不能发送到M端保存,也可以节省网络开销
124
//        // RouteCacheUtil.addRouteCache(session.getAccount(), session);
125
//
126
//        // 2.M端业务处理(暂时没有业务处理)
127
//        IData dataParam = new DataMap();
128
//        dataParam.put("key1", "value1");
129
//        dataParam.put("route", route.toString());
130
//        Map<String, String> postData = new HashMap<String, String>();
131
//        if (isEncrypt) {
132
//            /* 参数加密处理 */
133
//            postData.put("action", "RouteBean.addRoute");
134
//            // postData.put("key", MobileSecurity.getDesKey());
135
//            String encryptData = "";// 加密后的数据
136
//            postData.put("data", encryptData);
137
//        } else {
138
//            postData.put("action", "RouteBean.addRoute");
139
//            postData.put("data", dataParam.toString());
140
//        }
141
//        String data = HttpTool.toQueryStringWithEncode(postData);
142
//
143
//        String result = HttpTool.httpRequest("http://localhost:8080/push-manager-server/wlwdata", data, "POST");
144
//        if (isEncrypt) {
145
//            /* 解密 */
146
//            // result = MobileSecurity.responseDecrypt(result);
147
//        }
148
//        if (result.endsWith("\r")) {
149
//            result = result.substring(0, result.lastIndexOf("\r")); // 待测试,之前尾部没有“\r”???????????
150
//        }
151
//        IData resultData = new DataMap(result);
152
//        if ("success".equals(resultData.getString("flag"))) {
153
//            IpuLogger.debug(logger, "添加route路由关系成功.");
154
//        } else {
155
//            IpuLogger.debug(logger, "添加route路由关系失败.");
156
//        }
149 157
    }
150 158

151 159
}

+ 41 - 39
push-server/src/com/ai/server/push/handle/UnregisterWithRouteHandler.java

@ -1,12 +1,7 @@
1 1
package com.ai.server.push.handle;
2 2

3
import java.util.HashMap;
4
import java.util.Map;
5

6
import org.apache.log4j.Logger;
7

8
import com.ai.ipu.basic.net.http.HttpTool;
9
import com.ai.ipu.basic.util.IpuLogger;
3
import com.ai.ipu.basic.log.ILogger;
4
import com.ai.ipu.basic.log.IpuLoggerFactory;
10 5
import com.ai.mobile.push.handle.IRequestHandler;
11 6
import com.ai.mobile.push.msg.AbstractMessage;
12 7
import com.ai.mobile.push.msg.RegisterMessage;
@ -14,13 +9,14 @@ import com.ai.mobile.push.msg.ReplyMessage;
14 9
import com.ai.mobile.push.session.DefaultSessionManager;
15 10
import com.ai.mobile.push.session.IMSession;
16 11
import com.ai.mobile.push.session.ISessionManager;
12
import com.ai.server.push.route.IRouteManager;
17 13
import com.ai.server.push.route.Route;
14
import com.ai.server.push.route.impl.RouteManagerImpl;
18 15
import com.ai.server.util.BeanHolder;
19
import com.ailk.common.data.IData;
20
import com.ailk.common.data.impl.DataMap;
21 16

22 17
public class UnregisterWithRouteHandler implements IRequestHandler {
23
    transient protected final Logger logger = Logger.getLogger(UnregisterWithRouteHandler.class);
18
    transient protected static final ILogger log = IpuLoggerFactory.createLogger(UnregisterWithRouteHandler.class);
19

24 20
    @Override
25 21
    public ReplyMessage process(IMSession session, AbstractMessage message) {
26 22
        // TODO Auto-generated method stub
@ -58,36 +54,42 @@ public class UnregisterWithRouteHandler implements IRequestHandler {
58 54
        route.setServerName(registerMessage.getMap().get("serverName").toString());
59 55
        route.setServletDataRequestName(registerMessage.getMap().get("servletDataRequestName").toString());
60 56

61
        IData dataParam = new DataMap();
62
        dataParam.put("key1", "value1");
63
        dataParam.put("route", route.toString());
64
        Map<String, String> postData = new HashMap<String, String>();
65
        if (isEncrypt) {
66
            /* 参数加密处理 */
67
            postData.put("action", "RouteBean.removeRoute");
68
            // postData.put("key", MobileSecurity.getDesKey());
69
            String encryptData = "";// 加密后的数据
70
            postData.put("data", encryptData);
71
        } else {
72
            postData.put("action", "RouteBean.removeRoute");
73
            postData.put("data", dataParam.toString());
74
        }
75
        String data = HttpTool.toQueryStringWithEncode(postData);
57
        IRouteManager routeManager = new RouteManagerImpl();
58
        routeManager.removeRoute(route);
76 59

77
        String result = HttpTool.httpRequest("http://localhost:8080/push-manager-server/wlwdata", data, "POST");
78
        if (isEncrypt) {
79
            /* 解密 */
80
            // result = MobileSecurity.responseDecrypt(result);
81
        }
82
        if (result.endsWith("\r")) {
83
            result = result.substring(0, result.lastIndexOf("\r")); // 待测试,之前尾部没有“\r”???????????
84
        }
85
        IData resultData = new DataMap(result);
86
        if ("success".equals(resultData.getString("flag"))) {
87
            IpuLogger.debug(logger, "删除route路由关系成功.");
88
        } else {
89
            IpuLogger.debug(logger, "删除route路由关系成功.");
90
        }
60
        // IData dataParam = new DataMap();
61
        // dataParam.put("key1", "value1");
62
        // dataParam.put("route", route.toString());
63
        // Map<String, String> postData = new HashMap<String, String>();
64
        // if (isEncrypt) {
65
        // /* 参数加密处理 */
66
        // postData.put("action", "RouteBean.removeRoute");
67
        // // postData.put("key", MobileSecurity.getDesKey());
68
        // String encryptData = "";// 加密后的数据
69
        // postData.put("data", encryptData);
70
        // } else {
71
        // postData.put("action", "RouteBean.removeRoute");
72
        // postData.put("data", dataParam.toString());
73
        // }
74
        // String data = HttpTool.toQueryStringWithEncode(postData);
75
        //
76
        // String result =
77
        // HttpTool.httpRequest("http://localhost:8080/push-manager-server/wlwdata",
78
        // data, "POST");
79
        // if (isEncrypt) {
80
        // /* 解密 */
81
        // // result = MobileSecurity.responseDecrypt(result);
82
        // }
83
        // if (result.endsWith("\r")) {
84
        // result = result.substring(0, result.lastIndexOf("\r")); //
85
        // 待测试,之前尾部没有“\r”???????????
86
        // }
87
        // IData resultData = new DataMap(result);
88
        // if ("success".equals(resultData.getString("flag"))) {
89
        // log.debug("删除route路由关系成功.");
90
        // } else {
91
        // log.debug("删除route路由关系成功.");
92
        // }
91 93
    }
92 94

93 95
}

+ 36 - 0
push-server/src/com/ai/server/push/route/IRouteManager.java

@ -0,0 +1,36 @@
1
package com.ai.server.push.route;
2

3
import com.ai.ipu.server.cache.intf.ICache;
4

5
public interface IRouteManager {
6
    /**
7
     * 添加新的路由关系
8
     */
9
    public void addRoute(String account, Route route) throws Exception;
10

11
    /**
12
     * 用账号来获取route
13
     */
14
    Route getRoute(String account) throws Exception;
15

16
    /**
17
     * 获取所有route
18
     */
19
    public ICache getRoutes() throws Exception;
20

21
    /**
22
     * 删除route
23
     */
24
    public void removeRoute(Route route) throws Exception;
25

26
    /**
27
     * 删除route
28
     */
29
    public void removeRoute(String account) throws Exception;
30

31
    /**
32
     * 判断route是否存在
33
     */
34
    public boolean containsRoute(Route route) throws Exception;
35

36
}

+ 2 - 2
push-server/src/com/ai/server/push/route/Route.java

@ -2,7 +2,7 @@ package com.ai.server.push.route;
2 2

3 3
import java.io.Serializable;
4 4

5
import com.ai.ipu.basic.util.IpuLogger;
5
import com.ai.ipu.basic.util.IpuBaseException;
6 6
import com.ailk.common.data.impl.DataMap;
7 7

8 8
/**
@ -210,7 +210,7 @@ public class Route extends DataMap implements Serializable {
210 210
                }
211 211
            }
212 212
        } else {
213
            IpuLogger.debug("无法解析,不是自定义解析格式。");
213
            throw new IpuBaseException("无法解析,不是自定义解析格式。");
214 214
        }
215 215
    }
216 216


+ 55 - 0
push-server/src/com/ai/server/push/route/impl/DefaultRouteManager.java

@ -0,0 +1,55 @@
1
package com.ai.server.push.route.impl;
2

3
import com.ai.ipu.basic.log.ILogger;
4
import com.ai.ipu.basic.log.IpuLoggerFactory;
5
import com.ai.ipu.server.cache.intf.ICache;
6
import com.ai.server.push.cache.BizDataCacheManager;
7
import com.ai.server.push.cache.PushRouteCacheManager;
8
import com.ai.server.push.route.IRouteManager;
9
import com.ai.server.push.route.Route;
10

11
public class DefaultRouteManager implements IRouteManager {
12

13
    transient protected static final ILogger log = IpuLoggerFactory.createLogger(DefaultRouteManager.class);
14

15
    @Override
16
    public void addRoute(String account, Route route) throws Exception {
17
        PushRouteCacheManager.putRoute(account, route);
18
        BizDataCacheManager.addAccountToPushServerAccountsId(account, route.getServerId());
19
    }
20

21
    @Override
22
    public Route getRoute(String account) throws Exception {
23
        return PushRouteCacheManager.getRoute(account);
24
    }
25

26
    @Override
27
    public ICache getRoutes() throws Exception {
28
        return PushRouteCacheManager.getPushRouteCache();
29
    }
30

31
    @Override
32
    public void removeRoute(Route route) throws Exception {
33
        removeRoute(route.getAccount());
34
    }
35

36
    @Override
37
    public void removeRoute(String account) throws Exception {
38
        Route route = PushRouteCacheManager.getRoute(account);
39
        if (null == route) {
40
            log.debug("Not found this designated account of the Route.");
41
            return;
42
        }
43
        BizDataCacheManager.decreasePushServerAccountsSize(route.getServerId());
44
        PushRouteCacheManager.removeRoute(account);
45
    }
46

47
    @Override
48
    public boolean containsRoute(Route route) throws Exception {
49
        if (null != PushRouteCacheManager.getPushRouteCache().get(route.getAccount())) {
50
            return true;
51
        }
52
        return false;
53
    }
54

55
}

+ 58 - 0
push-server/src/com/ai/server/push/route/impl/RouteManagerImpl.java

@ -0,0 +1,58 @@
1
package com.ai.server.push.route.impl;
2

3
import com.ai.ipu.basic.log.ILogger;
4
import com.ai.ipu.basic.log.IpuLoggerFactory;
5
import com.ai.ipu.server.cache.intf.ICache;
6
import com.ai.server.push.cache.BizDataCacheManager;
7
import com.ai.server.push.cache.PushRouteCacheManager;
8
import com.ai.server.push.route.IRouteManager;
9
import com.ai.server.push.route.Route;
10

11
/**
12
 * 路由关系管理实现类。 注:不保存push-server对象的account列表,只保存account的数量。
13
 */
14
public class RouteManagerImpl implements IRouteManager {
15

16
    transient protected static final ILogger log = IpuLoggerFactory.createLogger(RouteManagerImpl.class);
17

18
    @Override
19
    public void addRoute(String account, Route route) throws Exception {
20
        PushRouteCacheManager.putRoute(account, route);
21
        BizDataCacheManager.increasePushServerAccountsSize(route.getServerId());
22
    }
23

24
    @Override
25
    public Route getRoute(String account) throws Exception {
26
        return PushRouteCacheManager.getRoute(account);
27
    }
28

29
    @Override
30
    public ICache getRoutes() throws Exception {
31
        return PushRouteCacheManager.getPushRouteCache();
32
    }
33

34
    @Override
35
    public void removeRoute(Route route) throws Exception {
36
        removeRoute(route.getAccount());
37
    }
38

39
    @Override
40
    public void removeRoute(String account) throws Exception {
41
        Route route = PushRouteCacheManager.getRoute(account);
42
        if (null == route) {
43
            log.debug("Not found this designated account of the Route.");
44
            return;
45
        }
46
        BizDataCacheManager.decreasePushServerAccountsSize(route.getServerId());
47
        PushRouteCacheManager.removeRoute(account);
48
    }
49

50
    @Override
51
    public boolean containsRoute(Route route) throws Exception {
52
        if (null != PushRouteCacheManager.getPushRouteCache().get(route.getAccount())) {
53
            return true;
54
        }
55
        return false;
56
    }
57

58
}

+ 0 - 16
push-server/src/com/ai/server/usermanager/AbstractUserManager.java

@ -1,16 +0,0 @@
1
package com.ai.server.usermanager;
2

3
import java.util.Map;
4

5
import com.ai.ipu.basic.util.IpuUtility;
6

7
public abstract class AbstractUserManager implements IUserManager {
8

9
    @Override
10
    public void verify(String account, Map<String, Object> map) {
11
        if (account == null || "".equals(account)) {
12
            IpuUtility.error("account为空");
13
        }
14
        customVerify(account, map);
15
    }
16
}

+ 4 - 14
push-server/src/com/ai/server/usermanager/DefaultUserManager.java

@ -1,22 +1,12 @@
1 1
package com.ai.server.usermanager;
2 2

3
import java.util.Map;
3
import com.ai.server.push.cache.BizDataCacheManager;
4 4

5
import com.ai.ipu.basic.util.IpuLogger;
6
import com.ai.ipu.basic.util.IpuUtility;
7

8
public class DefaultUserManager extends AbstractUserManager{
5
public class DefaultUserManager implements IUserManager{
9 6

10 7
    @Override
11
    public void customVerify(String account, Map<String, Object> map) {
12
        // 用户名和密码的校验
13
        String user = (String) map.get("userName");
14
        String passwd = (String) map.get("passwd");
15
        if(user!=null&&passwd!=null){
16
            IpuLogger.debug("用户名密码校验未通过.");
17
            IpuUtility.error("User and password validation failed");
18
        }
19
        IpuLogger.debug("用户连接权限校验通过.");
8
    public boolean verify(String account) throws Exception {
9
        return BizDataCacheManager.containsAvailableAccount(account);
20 10
    }
21 11

22 12
}

+ 1 - 14
push-server/src/com/ai/server/usermanager/IUserManager.java

@ -1,24 +1,11 @@
1 1
package com.ai.server.usermanager;
2 2

3
import java.util.Map;
4 3

5 4
public interface IUserManager {
6 5

7 6
    /**
8 7
     * 验证account有效性
9
     * 
10
     * @param account
11
     * @param map
12
     * @throws Exception
13 8
     */
14
    public void verify(String account, Map<String, Object> map);
9
    public boolean verify(String account) throws Exception;
15 10

16
    /**
17
     * 自定义校验map
18
     * 
19
     * @param account
20
     * @param map
21
     * @throws Exception
22
     */
23
    public void customVerify(String account, Map<String, Object> map);
24 11
}

+ 42 - 0
push-server/src/com/ai/server/util/PushConstant.java

@ -0,0 +1,42 @@
1
package com.ai.server.util;
2

3
public class PushConstant {
4

5
    /**
6
     * 业务数据缓存key,memcache.xml的cluster name
7
     */
8
    public static final String BIZ_DATA_CACHE = "biz_data_cache";
9
    
10
    /**
11
     * 业务数据缓存之一,服务端列表缓存,即tab_server表数据
12
     */
13
    public static final String PUSH_SERVER_LIST = "PUSH_SERVER_LIST"; // value:IDataSet
14

15
    /**
16
     * 业务数据缓存之一的前缀,+serverId即key,单个push-server的链接accounts列表
17
     */
18
    public static final String PUSH_SERVER_ACCOUNTS_PREFIX = "PUSH_SERVER_ACCOUNTS_"; // value:Set<String>
19
    
20
    /**
21
     * 业务数据缓存之一的前缀,+serverId即key,单个push-server链接account的数量
22
     */
23
    public static final String PUSH_SERVER_ACCOUNTS_SIZE_PREFIX = "PUSH_SERVER_ACCOUNTS_SIZE_"; // value:int
24
    
25
    /**
26
     * 业务数据缓存之一,是account的Set集合
27
     */
28
    public static final String AVAILABLE_ACCOUNTS = "AVAILABLE_ACCOUNTS"; // value:Set<String>
29

30
    /**
31
     * 路由缓存key,memcache.xml的cluster name
32
     */
33
    public static final String PUSH_ROUTE_CACHE = "push_route_cache"; // value:Route
34

35
    public class Server {
36
        
37
        public static final String STATE_AVAILABLE = "1";// 可用
38

39
        public static final String STATE_UNAVAILABLE = "0";// 不可用
40
    }
41

42
}

@新增:mobile-action.xml中增加插件对应的权限,避免权限问题导致插件用不了(比如自定义相机等) · efbfeabe37 - Nuosi Git Service
Przeglądaj źródła

@新增:mobile-action.xml中增加插件对应的权限,避免权限问题导致插件用不了(比如自定义相机等)

liuyf23 2 lat temu
rodzic
commit
efbfeabe37
1 zmienionych plików z 28 dodań i 33 usunięć
  1. 28 33
      superapp-client/app/src/main/assets/mobile-action.xml

+ 28 - 33
superapp-client/app/src/main/assets/mobile-action.xml

@ -7,9 +7,9 @@
7 7
    <action name="openRemoteURL" class="com.ai.ipu.superapp.func.MobileOpenApp" method="openRemoteURL"/>
8 8
9 9
    <!-- MobileBasic -->
10
	<action name="call" class="com.ai.ipu.mobile.plugin.MobileBasic" method="call"/>
10
	<action name="call" class="com.ai.ipu.mobile.plugin.MobileBasic" method="call" permissions="call_phone"/>
11 11
	<action name="beep" class="com.ai.ipu.mobile.plugin.MobileBasic" method="beep"/>
12
	<action name="sms" class="com.ai.ipu.mobile.plugin.MobileBasic" method = "sms"/>
12
	<action name="sms" class="com.ai.ipu.mobile.plugin.MobileBasic" method = "sms" permissions="send_sms,read_sms"/>
13 13
	<action name="shock" class="com.ai.ipu.mobile.plugin.MobileBasic" method="shock"/>
14 14
	<!-- MobileApp -->
15 15
	<action name="close" class="com.ai.ipu.mobile.plugin.MobileApp" method="close"/>
@ -65,23 +65,23 @@
65 65
	<action name="hideKeyBoard" class="com.ai.ipu.mobile.plugin.SoftKeyBoard" method="hideKeyBoard"/>
66 66
	<action name="toggleKeyBoard" class="com.ai.ipu.mobile.plugin.SoftKeyBoard" method="toggleKeyBoard"/>
67 67
	<!-- MobileCamera -->
68
	<action name="getPhoto" class="com.ai.ipu.mobile.plugin.MobileCamera" method="getPhoto"/>
69
	<action name="getPicture" class="com.ai.ipu.mobile.plugin.MobileCamera" method="getPicture"/>
68
	<action name="getPhoto" class="com.ai.ipu.mobile.plugin.MobileCamera" method="getPhoto" permissions="camera"/>
69
	<action name="getPicture" class="com.ai.ipu.mobile.plugin.MobileCamera" method="getPicture" permissions="read_external_storage"/>
70 70
	<action name="transImageToBase64" class="com.ai.ipu.mobile.plugin.MobileCamera" method="transImageToBase64"/>
71 71
	<action name="compressImage" class="com.ai.ipu.mobile.plugin.MobileCamera" method="compressImage"/>
72 72
	
73 73
	<!-- MobileInfo -->
74 74
	<action name="getTerminalType" class="com.ai.ipu.mobile.plugin.MobileInfo" method="getTerminalType"/>
75
	<action name="getSysInfo" class="com.ai.ipu.mobile.plugin.MobileInfo" method="getSysInfo"/>
76
	<action name="getNetInfo" class="com.ai.ipu.mobile.plugin.MobileInfo" method="getNetInfo"/>
75
	<action name="getSysInfo" class="com.ai.ipu.mobile.plugin.MobileInfo" method="getSysInfo" permissions="read_phone_state"/>
76
	<action name="getNetInfo" class="com.ai.ipu.mobile.plugin.MobileInfo" method="getNetInfo" permissions="read_phone_state"/>
77 77
	<!-- SwitchActivity -->
78 78
	<action name="browserFile" class="com.ailk.mobile.client.func.SwitchActivity" method = "browserFile"/>
79 79
	<action name="openDisplayPage" class="com.ailk.mobile.client.func.SwitchActivity" method = "openDisplayPage"/>
80 80
	<!-- MobileMap -->
81 81
	
82
	<action name="location" class="com.ai.ipu.map.func.MobileMap" method="location"></action>
83
	 <action name="markMap" class="com.ai.ipu.map.func.MobileMap" method="markMap"></action>
84
	 <action name="selectLocation" class="com.ai.ipu.map.func.MobileMap" method="selectLocation"></action> 
82
	<action name="location" class="com.ai.ipu.map.func.MobileMap" method="location" permissions="location"></action>
83
	<action name="markMap" class="com.ai.ipu.map.func.MobileMap" method="markMap" permissions="location"></action>
84
	<action name="selectLocation" class="com.ai.ipu.map.func.MobileMap" method="selectLocation" permissions="location"></action>
85 85
	 
86 86
	<!-- MobileStorage -->
87 87
	<action name="removeMemoryCache" class="com.ai.ipu.mobile.plugin.MobileStorage" method="removeMemoryCache"></action>
@ -103,11 +103,11 @@
103 103
	<action name="getRelativePath" class="com.ai.ipu.mobile.plugin.MobileFile" method="getRelativePath"/>
104 104
105 105
	<!-- audio -->
106
	<action name="audioRecord" class="com.ai.ipu.mobile.plugin.MobileAudio" method="audioRecord"/>
106
	<action name="audioRecord" class="com.ai.ipu.mobile.plugin.MobileAudio" method="audioRecord" permissions="record_audio"/>
107 107
	<action name="audioPlay" class="com.ai.ipu.mobile.plugin.MobileAudio" method="audioPlay"/>
108 108
	
109 109
	<!-- video -->
110
	<action name="recordVideo" class="com.ai.ipu.mobile.plugin.MobileVideo" method="recordVideo"/>
110
	<action name="recordVideo" class="com.ai.ipu.mobile.plugin.MobileVideo" method="recordVideo" permissions="camera"/>
111 111
	<action name="playVideo" class="com.ai.ipu.mobile.plugin.MobileVideo" method="playVideo"/>
112 112
	
113 113
	<action name="openApp" class="com.ai.mobile.func.OpenOtherApp" method="openApp"></action>
@ -137,7 +137,7 @@
137 137
	<action name="getJpushInfo" class="com.ai.ipu.push.func.IpuJPushPlugin" method="getJpushInfo"/>
138 138
	
139 139
    <!-- Contact-->
140
	<action name="getContacts" class="com.ai.ipu.mobile.plugin.MobileContactDetail" method="getContacts"></action>
140
	<action name="getContacts" class="com.ai.ipu.mobile.plugin.MobileContactDetail" method="getContacts" permissions="read_contacts"></action>
141 141
	
142 142
	<!-- keyboard provided by Beijing CMC PSO -->
143 143
	<action name="openKeyboard" class="com.ai.ipu.mobile.plugin.MobileKeyboard" method="openKeyboard"></action>
@ -151,9 +151,9 @@
151 151
	<action name="openNative" class="com.ai.ipu.func.MobileOpenApp" method="openNative"></action>
152 152
	
153 153
	<!--ScanQR -->
154
 	<action name="scanQrCode" class="com.ai.ipu.scan.func.IpuScan" method="scanSingle"></action>
155
	<action name="scanSingle" class="com.ai.ipu.scan.func.IpuScan" method="scanSingle"></action>
156
	<action name="scanMultiple" class="com.ai.ipu.scan.func.IpuScan" method="scanMultiple"></action>
154
 	<action name="scanQrCode" class="com.ai.ipu.scan.func.IpuScan" method="scanSingle" permissions="camera"></action>
155
	<action name="scanSingle" class="com.ai.ipu.scan.func.IpuScan" method="scanSingle" permissions="camera"></action>
156
	<action name="scanMultiple" class="com.ai.ipu.scan.func.IpuScan" method="scanMultiple" permissions="camera"></action>
157 157
	<action name="createQrCode" class="com.ai.ipu.scan.func.IpuScan" method="createQrCode"></action>
158 158
159 159
	<!--<action name="scanQrCode" class="com.ai.ipu.scan.func.IpuScan" method="scanSingle"></action>-->
@ -186,25 +186,21 @@
186 186
	<!-- 邮件 -->
187 187
	<action name="shareImageBymail" class="com.ai.ipu.mail.func.MailSendByApp" method="shareImageBymail"></action>	
188 188
	<!-- BaiduMap -->
189
	<action name="baiduLocation" class="com.ai.ipu.map.bd.func.MobileBaiduMap" method="bdLocation" ></action>
190
	<action name="baiduMapLocation" class="com.ai.ipu.map.bd.func.MobileBaiduMap" method="baiduMapLocation"></action>
191
	<action name="baiduMapPosition" class="com.ai.ipu.map.bd.func.MobileBaiduMap" method = "baiduMapPosition"></action>
192
	<action name="clickBaiduMap" class="com.ai.ipu.map.bd.func.MobileBaiduMap" method="clickBaiduMap"></action>
193
	<action name="addPolygon" class="com.ai.ipu.map.bd.func.MobileBaiduMap" method="addPolygon"></action>
194
	<action name="poiCitySearch" class="com.ai.ipu.map.bd.func.MobileBaiduMap" method="poiCitySearch"></action>
195
	<action name="poiNearbySearch" class="com.ai.ipu.map.bd.func.MobileBaiduMap" method="poiNearbySearch"></action>
196
	<action name="poiBoundsSearch" class="com.ai.ipu.map.bd.func.MobileBaiduMap" method="poiBoundsSearch"></action>
197
	<action name="lbsLocalSearch" class="com.ai.ipu.map.bd.func.MobileBaiduMap" method="lbsLocalSearch"></action>
198
	<action name="lbsNearbySearch" class="com.ai.ipu.map.bd.func.MobileBaiduMap" method="lbsNearbySearch"></action>
199
	<action name="lbsBoundsSearch" class="com.ai.ipu.map.bd.func.MobileBaiduMap" method="lbsBoundsSearch"></action>
200
	
201
	
189
	<action name="baiduLocation" class="com.ai.ipu.map.bd.func.MobileBaiduMap" method="bdLocation" permissions="location"></action>
190
	<action name="baiduMapLocation" class="com.ai.ipu.map.bd.func.MobileBaiduMap" method="baiduMapLocation" permissions="location"></action>
191
	<action name="baiduMapPosition" class="com.ai.ipu.map.bd.func.MobileBaiduMap" method = "baiduMapPosition" permissions="location"></action>
192
	<action name="clickBaiduMap" class="com.ai.ipu.map.bd.func.MobileBaiduMap" method="clickBaiduMap" permissions="location"></action>
193
	<action name="addPolygon" class="com.ai.ipu.map.bd.func.MobileBaiduMap" method="addPolygon" permissions="location"></action>
194
	<action name="poiCitySearch" class="com.ai.ipu.map.bd.func.MobileBaiduMap" method="poiCitySearch" permissions="location"></action>
195
	<action name="poiNearbySearch" class="com.ai.ipu.map.bd.func.MobileBaiduMap" method="poiNearbySearch" permissions="location"></action>
196
	<action name="poiBoundsSearch" class="com.ai.ipu.map.bd.func.MobileBaiduMap" method="poiBoundsSearch" permissions="location"></action>
197
	<action name="lbsLocalSearch" class="com.ai.ipu.map.bd.func.MobileBaiduMap" method="lbsLocalSearch" permissions="location"></action>
198
	<action name="lbsNearbySearch" class="com.ai.ipu.map.bd.func.MobileBaiduMap" method="lbsNearbySearch" permissions="location"></action>
199
	<action name="lbsBoundsSearch" class="com.ai.ipu.map.bd.func.MobileBaiduMap" method="lbsBoundsSearch" permissions="location"></action>
200
202 201
	<!-- 视频压缩 -->
203 202
	<action name="videoCompressor" class="com.ai.ipu.video.compress.func.MobileVideoCompress" method="videoCompressor"></action>
204 203
	<action name="getVideoPath" class="com.ai.ipu.video.compress.func.MobileVideoCompress" method="getVideoPath"/>
205
	
206
	
207
208 204
209 205
    <action name="openActivityFromPlugin" class="com.ai.ipu.func.MobileOpenApp" method="openActivityFromPlugin"></action>
210 206
    <!-- PathMenu -->
@ -221,7 +217,7 @@
221 217
	<action name="clearImageCache" class="com.ai.ipu.mobile.plugin.ImageCache" method="clearImageCache"></action>
222 218
	<action name="saveImageToAlbum" class="com.ai.ipu.mobile.plugin.ImageCache" method="saveImageToAlbum"></action>
223 219
	
224
	<action name="getIdentifyPhoto" class="com.ai.ipu.ipucustomcamera.IpuCustomCamera" method="getIdentifyPhoto"/>
220
	<action name="getIdentifyPhoto" class="com.ai.ipu.ipucustomcamera.IpuCustomCamera" method="getIdentifyPhoto" permissions="camera"/>
225 221
	<action name="openRN" class="com.ai.ipu.mobile.rn.func.OpenRnView" method="openRnActivity" />
226 222
	<!-- 打开外部app -->
227 223
	<action name="openOuterApp" class="com.ai.ipu.func.MobileOpenOuterApp" method="openOuterApp"/>
@ -238,7 +234,6 @@
238 234
	<action name="getAppVersion" class="com.ai.ipu.superapp.func.AppMenuSettingPlugin" method="getAppVersion"></action>
239 235
	<action name="changeTextSize" class="com.ai.ipu.superapp.func.AppMenuSettingPlugin" method="changeTextSize"></action>
240 236
241
242 237
	<!-- 静默加载子应用资源 -->
243 238
	<action name="updateSubIpuAppResourceSilence" class="com.ai.ipu.superapp.func.SubAppPreLoader" method="updateSubIpuAppResourceSilence" />
244 239