Ejemplo n.º 1
0
 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());
 }
Ejemplo n.º 2
0
 public JsonRequestBuilder addParam(String key, Object value) {
   if (jsonRequest.params == null) {
     jsonRequest.params = new HashMap<>();
   }
   jsonRequest.params.put(key, value);
   return this;
 }
Ejemplo n.º 3
0
  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);
    }
  }
Ejemplo n.º 4
0
 public JsonRequestBuilder params(Map<String, Object> params) {
   jsonRequest.params = params;
   return this;
 }
Ejemplo n.º 5
0
 public JsonRequestBuilder checkValue(ApiBase2Action action) {
   ApiContext context = jsonRequest.toContext();
   jsonRequest.checkValue = action.getCheckValue(context);
   return this;
 }
Ejemplo n.º 6
0
 public JsonRequestBuilder checkValue(String checkValue) {
   jsonRequest.checkValue = checkValue;
   return this;
 }
Ejemplo n.º 7
0
 public JsonRequestBuilder setCurrentTime() {
   jsonRequest.time = new Date().getTime() / 1000l;
   return this;
 }
Ejemplo n.º 8
0
 public JsonRequestBuilder time(Long time) {
   jsonRequest.time = time;
   return this;
 }
Ejemplo n.º 9
0
 public JsonRequestBuilder method(String method) {
   jsonRequest.method = method;
   return this;
 }
Ejemplo n.º 10
0
 public JsonRequestBuilder machineCode(String machineCode) {
   jsonRequest.machineCode = machineCode;
   return this;
 }
Ejemplo n.º 11
0
 public JsonRequestBuilder appCode(String appCode) {
   jsonRequest.appCode = appCode;
   return this;
 }