use of com.google.gson.JsonSyntaxException in project thingsboard by thingsboard.
the class DeviceApiController method postRpcRequest.
@RequestMapping(value = "/{deviceToken}/rpc", method = RequestMethod.POST)
public DeferredResult<ResponseEntity> postRpcRequest(@PathVariable("deviceToken") String deviceToken, @RequestBody String json, HttpServletRequest httpRequest) {
DeferredResult<ResponseEntity> responseWriter = new DeferredResult<ResponseEntity>();
if (quotaExceeded(httpRequest, responseWriter)) {
return responseWriter;
}
HttpSessionCtx ctx = getHttpSessionCtx(responseWriter);
if (ctx.login(new DeviceTokenCredentials(deviceToken))) {
try {
JsonObject request = new JsonParser().parse(json).getAsJsonObject();
process(ctx, new ToServerRpcRequestMsg(0, request.get("method").getAsString(), request.get("params").toString()));
} catch (IllegalStateException | JsonSyntaxException ex) {
responseWriter.setResult(new ResponseEntity<>(HttpStatus.BAD_REQUEST));
}
} else {
responseWriter.setResult(new ResponseEntity<>(HttpStatus.UNAUTHORIZED));
}
return responseWriter;
}
use of com.google.gson.JsonSyntaxException in project thingsboard by thingsboard.
the class DeviceApiController method subscribe.
private DeferredResult<ResponseEntity> subscribe(String deviceToken, long timeout, FromDeviceMsg msg, HttpServletRequest httpRequest) {
DeferredResult<ResponseEntity> responseWriter = new DeferredResult<ResponseEntity>();
if (quotaExceeded(httpRequest, responseWriter)) {
return responseWriter;
}
HttpSessionCtx ctx = getHttpSessionCtx(responseWriter, timeout);
if (ctx.login(new DeviceTokenCredentials(deviceToken))) {
try {
process(ctx, msg);
} catch (IllegalStateException | JsonSyntaxException ex) {
responseWriter.setResult(new ResponseEntity<>(HttpStatus.BAD_REQUEST));
}
} else {
responseWriter.setResult(new ResponseEntity<>(HttpStatus.UNAUTHORIZED));
}
return responseWriter;
}
use of com.google.gson.JsonSyntaxException in project thingsboard by thingsboard.
the class GatewaySessionCtx method onDeviceRpcResponse.
public void onDeviceRpcResponse(MqttPublishMessage mqttMsg) throws AdaptorException {
JsonElement json = validateJsonPayload(gatewaySessionId, mqttMsg.payload());
if (json.isJsonObject()) {
JsonObject jsonObj = json.getAsJsonObject();
String deviceName = checkDeviceConnected(jsonObj.get(DEVICE_PROPERTY).getAsString());
Integer requestId = jsonObj.get("id").getAsInt();
String data = jsonObj.get("data").toString();
GatewayDeviceSessionCtx deviceSessionCtx = devices.get(deviceName);
processor.process(new BasicToDeviceActorSessionMsg(deviceSessionCtx.getDevice(), new BasicAdaptorToSessionActorMsg(deviceSessionCtx, new ToDeviceRpcResponseMsg(requestId, data))));
} else {
throw new JsonSyntaxException(CAN_T_PARSE_VALUE + json);
}
}
use of com.google.gson.JsonSyntaxException in project BuildCraft by BuildCraft.
the class ElementTypeStatementSlot method deserialize0.
@Override
public IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
FunctionContext ctx = createContext(json);
if (!json.properties.containsKey("size[0]")) {
json.properties.put("size[0]", "18");
}
if (!json.properties.containsKey("size[1]")) {
json.properties.put("size[1]", "18");
}
inheritProperty(json, "pos[0]", "area[0]");
inheritProperty(json, "pos[1]", "area[1]");
inheritProperty(json, "size[0]", "area[2]");
inheritProperty(json, "size[1]", "area[3]");
IGuiArea area = resolveArea(json, "area", parent, ctx);
String source;
if (json.properties.containsKey("source")) {
source = json.properties.get("source");
} else {
source = resolveEquation(json, "source_expression", ctx);
if (source == null) {
throw new JsonSyntaxException("Expected either 'source' or 'source_expression' for " + NAME);
}
}
boolean draw = !"false".equals(json.properties.get("draw"));
FullStatement<?> fullStatement = gui.properties.get(source, FullStatement.class);
if (fullStatement == null) {
throw new JsonSyntaxException("Can't find a statement called '" + source + "'");
}
StatementContext<?> context = gui.properties.get(source, StatementContext.class);
return new GuiElementStatement<>(gui, area, fullStatement, context, draw);
}
use of com.google.gson.JsonSyntaxException in project BuildCraft by BuildCraft.
the class ElementTypeSlot method deserialize0.
// pos: the position of the slot
// slot: The slot to be moved
// index: If the slot was an InventorySlotHolder then this is the index of the slot in the list
// visible: If false then the slot won't be visible
@Override
protected IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
FunctionContext ctx = createContext(json);
String slotName = json.properties.get("slot");
IGuiPosition pos = resolvePosition(json, "pos", parent, ctx);
Slot slot = gui.properties.get(slotName, Slot.class);
INodeBoolean visible = getEquationBool(json, "visible", ctx, true);
if (slot != null) {
return new GuiElementSlotMover(gui, pos, visible, slot);
}
InventorySlotHolder holder = gui.properties.get(slotName, InventorySlotHolder.class);
if (holder == null) {
throw new JsonSyntaxException("Unknown slot '" + slotName + "'");
}
int index = resolveEquationInt(json, "index", ctx);
if (index < 0 || index >= holder.slots.length) {
throw new JsonSyntaxException("Invalid slot index! (" + index + ", min = 0, max = " + (holder.slots.length - 1) + ")");
}
return new GuiElementSlotMover(gui, pos, visible, holder.slots[index]);
}
Aggregations