EasemobChatMessage { public static ObjectNode getChatMessages(ObjectNode queryStrNode) { ObjectNode objectNode = factory.objectNode(); if (!JerseyUtils.match("^(?!-)[0-9a-zA-Z\\-]+#[0-9a-zA-Z]+", APPKEY)) { LOGGER.error("Bad format of Appkey: " + APPKEY); objectNode.put("message", "Bad format of Appkey"); return objectNode; } try { JerseyWebTarget webTarget = EndPoints.CHATMESSAGES_TARGET.resolveTemplate("org_name", APPKEY.split("#")[0]) .resolveTemplate("app_name", APPKEY.split("#")[1]); if (null != queryStrNode && null != queryStrNode.get("ql") && !StringUtils.isEmpty(queryStrNode.get("ql").asText())) { webTarget = webTarget.queryParam("ql", queryStrNode.get("ql").asText()); } if (null != queryStrNode && null != queryStrNode.get("limit") &&!StringUtils.isEmpty(queryStrNode.get("limit").asText())) { webTarget = webTarget.queryParam("limit", queryStrNode.get("limit").asText()); } if (null != queryStrNode && null != queryStrNode.get("cursor") &&!StringUtils.isEmpty(queryStrNode.get("cursor").asText())) { webTarget = webTarget.queryParam("cursor", queryStrNode.get("cursor").asText()); } objectNode = JerseyUtils.sendRequest(webTarget, null, credential, HTTPMethod.METHOD_GET, null); } catch (Exception e) { e.printStackTrace(); } return objectNode; }  static ObjectNode getChatMessages(ObjectNode queryStrNode);  }
@Test public void testGet20ChatMessages() throws Exception { ObjectNode queryStrNode = factory.objectNode(); ObjectNode messages = EasemobChatMessage.getChatMessages(queryStrNode); LOGGER.debug(messages.toString()); }
@Test public void testGet7DChatMessages() throws Exception { String currentTimestamp = String.valueOf(System.currentTimeMillis()); String senvenDayAgo = String.valueOf(System.currentTimeMillis() - 7 * 24 * 60 * 60 * 1000); ObjectNode queryStrNode1 = factory.objectNode(); queryStrNode1.put("ql", "select * where timestamp > " + senvenDayAgo + " and timestamp < " + currentTimestamp); ObjectNode messages1 = EasemobChatMessage.getChatMessages(queryStrNode1); }
@Test public void testGetChatMessagesByPage() throws Exception { ObjectNode queryStrNode2 = factory.objectNode(); queryStrNode2.put("limit", "20"); ObjectNode messages2 = EasemobChatMessage.getChatMessages(queryStrNode2); String cursor = messages2.get("cursor").asText(); queryStrNode2.put("cursor", cursor); ObjectNode messages3 = EasemobChatMessage.getChatMessages(queryStrNode2); }