String createRequest(int id, String xsrfKey, String methodName, Collection<Object> args) { JsonRequest msg = new JsonRequest(); msg.method = methodName; if (args != null) { for (Object arg : args) { msg.params.add(arg); } } msg.id = id; msg.xsrfKey = xsrfKey; return gson.toJson(msg, msg.getClass()); }
public JsonRequestBuilder addParam(String key, Object value) { if (jsonRequest.params == null) { jsonRequest.params = new HashMap<>(); } jsonRequest.params.put(key, value); return this; }
public JsonRequestBuilder(String json) { Logger.info("JSON : %s ----", json); jsonRequest = new Gson().fromJson(json, JsonRequest.class); JsonParser parser = new JsonParser(); JsonElement jsonElement = parser.parse(json); JsonObject jsonObject = jsonElement.getAsJsonObject(); JsonElement paramsElement = jsonObject.get("params"); JsonObject paramsObject = paramsElement.getAsJsonObject(); jsonRequest.paramsMap = new HashMap<>(); for (Map.Entry<String, JsonElement> entry : paramsObject.entrySet()) { String key = entry.getKey(); JsonElement element = entry.getValue(); String value = element.getAsString(); Logger.info("===========> %s : %s", key, value); String[] values = new String[] {value}; jsonRequest.paramsMap.put(key, values); } }
public JsonRequestBuilder params(Map<String, Object> params) { jsonRequest.params = params; return this; }
public JsonRequestBuilder checkValue(ApiBase2Action action) { ApiContext context = jsonRequest.toContext(); jsonRequest.checkValue = action.getCheckValue(context); return this; }
public JsonRequestBuilder checkValue(String checkValue) { jsonRequest.checkValue = checkValue; return this; }
public JsonRequestBuilder setCurrentTime() { jsonRequest.time = new Date().getTime() / 1000l; return this; }
public JsonRequestBuilder time(Long time) { jsonRequest.time = time; return this; }
public JsonRequestBuilder method(String method) { jsonRequest.method = method; return this; }
public JsonRequestBuilder machineCode(String machineCode) { jsonRequest.machineCode = machineCode; return this; }
public JsonRequestBuilder appCode(String appCode) { jsonRequest.appCode = appCode; return this; }