use of com.google.gson.JsonObject in project weixin-java-tools by chanjarster.
the class WxMpServiceImpl method qrCodeCreateTmpTicket.
public WxMpQrCodeTicket qrCodeCreateTmpTicket(int scene_id, Integer expire_seconds) throws WxErrorException {
String url = "https://api.weixin.qq.com/cgi-bin/qrcode/create";
JsonObject json = new JsonObject();
json.addProperty("action_name", "QR_SCENE");
if (expire_seconds != null) {
json.addProperty("expire_seconds", expire_seconds);
}
JsonObject actionInfo = new JsonObject();
JsonObject scene = new JsonObject();
scene.addProperty("scene_id", scene_id);
actionInfo.add("scene", scene);
json.add("action_info", actionInfo);
String responseContent = execute(new SimplePostRequestExecutor(), url, json.toString());
return WxMpQrCodeTicket.fromJson(responseContent);
}
use of com.google.gson.JsonObject in project weixin-java-tools by chanjarster.
the class WxMpServiceImpl method shortUrl.
public String shortUrl(String long_url) throws WxErrorException {
String url = "https://api.weixin.qq.com/cgi-bin/shorturl";
JsonObject o = new JsonObject();
o.addProperty("action", "long2short");
o.addProperty("long_url", long_url);
String responseContent = execute(new SimplePostRequestExecutor(), url, o.toString());
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
return tmpJsonElement.getAsJsonObject().get("short_url").getAsString();
}
use of com.google.gson.JsonObject in project weave by continuuity.
the class YarnWeaveRunnerService method getApplicationId.
/**
* Decodes application ID stored inside the node data.
* @param nodeData The node data to decode from. If it is {@code null}, this method would return {@code null}.
* @return The ApplicationId or {@code null} if failed to decode.
*/
private ApplicationId getApplicationId(NodeData nodeData) {
byte[] data = nodeData == null ? null : nodeData.getData();
if (data == null) {
return null;
}
Gson gson = new Gson();
JsonElement json = gson.fromJson(new String(data, Charsets.UTF_8), JsonElement.class);
if (!json.isJsonObject()) {
LOG.warn("Unable to decode live data node.");
return null;
}
JsonObject jsonObj = json.getAsJsonObject();
json = jsonObj.get("data");
if (!json.isJsonObject()) {
LOG.warn("Property data not found in live data node.");
return null;
}
try {
ApplicationMasterLiveNodeData amLiveNode = gson.fromJson(json, ApplicationMasterLiveNodeData.class);
return YarnUtils.createApplicationId(amLiveNode.getAppIdClusterTime(), amLiveNode.getAppId());
} catch (Exception e) {
LOG.warn("Failed to decode application live node data.", e);
return null;
}
}
use of com.google.gson.JsonObject in project weave by continuuity.
the class LogEntryDecoder method deserialize.
@Override
public LogEntry deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
if (!json.isJsonObject()) {
return null;
}
JsonObject jsonObj = json.getAsJsonObject();
final String name = JsonUtils.getAsString(jsonObj, "name");
final String host = JsonUtils.getAsString(jsonObj, "host");
final long timestamp = JsonUtils.getAsLong(jsonObj, "timestamp", 0);
LogEntry.Level l;
try {
l = LogEntry.Level.valueOf(JsonUtils.getAsString(jsonObj, "level"));
} catch (Exception e) {
l = LogEntry.Level.FATAL;
}
final LogEntry.Level logLevel = l;
final String className = JsonUtils.getAsString(jsonObj, "className");
final String method = JsonUtils.getAsString(jsonObj, "method");
final String file = JsonUtils.getAsString(jsonObj, "file");
final String line = JsonUtils.getAsString(jsonObj, "line");
final String thread = JsonUtils.getAsString(jsonObj, "thread");
final String message = JsonUtils.getAsString(jsonObj, "message");
final StackTraceElement[] stackTraces = context.deserialize(jsonObj.get("stackTraces").getAsJsonArray(), StackTraceElement[].class);
return new LogEntry() {
@Override
public String getLoggerName() {
return name;
}
@Override
public String getHost() {
return host;
}
@Override
public long getTimestamp() {
return timestamp;
}
@Override
public Level getLogLevel() {
return logLevel;
}
@Override
public String getSourceClassName() {
return className;
}
@Override
public String getSourceMethodName() {
return method;
}
@Override
public String getFileName() {
return file;
}
@Override
public int getLineNumber() {
if (line.equals("?")) {
return -1;
} else {
return Integer.parseInt(line);
}
}
@Override
public String getThreadName() {
return thread;
}
@Override
public String getMessage() {
return message;
}
@Override
public StackTraceElement[] getStackTraces() {
return stackTraces;
}
};
}
use of com.google.gson.JsonObject in project weave by continuuity.
the class ZKServiceDecorator method createLiveNode.
private OperationFuture<String> createLiveNode() {
String liveNode = getLiveNodePath();
LOG.info("Create live node {}{}", zkClient.getConnectString(), liveNode);
JsonObject content = new JsonObject();
content.add("data", liveNodeData.get());
return ZKOperations.ignoreError(zkClient.create(liveNode, encodeJson(content), CreateMode.EPHEMERAL), KeeperException.NodeExistsException.class, liveNode);
}
Aggregations