use of org.codehaus.jackson.JsonParseException in project databus by linkedin.
the class DbusEventSerializable method getErrorEventFromDbusEvent.
public static DbusErrorEvent getErrorEventFromDbusEvent(DbusEventInternalReadable event) {
if (!event.isErrorEvent()) {
throw new RuntimeException("Event is expected to be an error event: " + event);
}
ByteBuffer valueBuffer = event.value();
byte[] valueBytes = new byte[valueBuffer.limit()];
valueBuffer.get(valueBytes);
try {
DbusErrorEvent errorEvent = DbusErrorEvent.createDbusErrorEvent(new String(valueBytes));
return errorEvent;
} catch (JsonParseException e) {
throw new RuntimeException(e);
} catch (JsonMappingException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.codehaus.jackson.JsonParseException in project openhab1-addons by openhab.
the class FritzahaQueryscriptUpdateNumberCallback method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute(int status, String response) {
super.execute(status, response);
if (validRequest) {
logger.debug("Received State response " + response + " for item " + itemName);
String valueType;
if (type == MeterType.VOLTAGE) {
valueType = "MM_Value_Volt";
} else if (type == MeterType.CURRENT) {
valueType = "MM_Value_Amp";
} else if (type == MeterType.POWER) {
valueType = "MM_Value_Power";
} else if (type == MeterType.ENERGY) {
valueType = "";
} else {
return;
}
ObjectMapper jsonReader = new ObjectMapper();
Map<String, String> deviceData;
try {
deviceData = jsonReader.readValue(response, Map.class);
} catch (JsonParseException e) {
logger.error("Error parsing JSON:\n" + response);
return;
} catch (JsonMappingException e) {
logger.error("Error mapping JSON:\n" + response);
return;
} catch (IOException e) {
logger.error("An I/O error occured while decoding JSON:\n" + response);
return;
}
if (type == MeterType.ENERGY) {
String ValIdent = "EnStats_watt_value_";
long valCount = Long.parseLong(deviceData.get("EnStats_count"));
BigDecimal meterValue = new BigDecimal(0);
BigDecimal meterValueScaled;
long tmplong;
BigDecimal tmpBD;
for (int tmpcnt = 1; tmpcnt <= valCount; tmpcnt++) {
tmplong = Long.parseLong(deviceData.get(ValIdent + tmpcnt));
meterValue = meterValue.add(new BigDecimal(tmplong));
}
if (Long.parseLong(deviceData.get("EnStats_timer_type")) == 10) {
// 10 Minute values are given in mWh, so scale to Wh
meterValueScaled = meterValue.scaleByPowerOfTen(-6);
} else {
// Other values are given in Wh, so scale to kWh
meterValueScaled = meterValue.scaleByPowerOfTen(-3);
}
webIface.postUpdate(itemName, new DecimalType(meterValueScaled));
} else if (deviceData.containsKey(valueType)) {
BigDecimal meterValue = new BigDecimal(deviceData.get(valueType));
BigDecimal meterValueScaled;
switch(type) {
case VOLTAGE:
meterValueScaled = meterValue.scaleByPowerOfTen(-3);
break;
case CURRENT:
meterValueScaled = meterValue.scaleByPowerOfTen(-4);
break;
case POWER:
meterValueScaled = meterValue.scaleByPowerOfTen(-2);
break;
default:
meterValueScaled = meterValue;
}
webIface.postUpdate(itemName, new DecimalType(meterValueScaled));
} else {
logger.error("Response did not contain " + valueType);
}
}
}
use of org.codehaus.jackson.JsonParseException in project openhab1-addons by openhab.
the class FritzahaQueryscriptUpdateSwitchCallback method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute(int status, String response) {
super.execute(status, response);
if (validRequest) {
logger.debug("Received State response " + response + " for item " + itemName);
ObjectMapper jsonReader = new ObjectMapper();
Map<String, String> deviceData;
try {
deviceData = jsonReader.readValue(response, Map.class);
} catch (JsonParseException e) {
logger.error("Error parsing JSON:\n" + response);
return;
} catch (JsonMappingException e) {
logger.error("Error mapping JSON:\n" + response);
return;
} catch (IOException e) {
logger.error("An I/O error occured while decoding JSON:\n" + response);
return;
}
if (deviceData.containsKey("DeviceSwitchState")) {
webIface.postUpdate(itemName, "1".equals(deviceData.get("DeviceSwitchState")) ? OnOffType.ON : OnOffType.OFF);
}
}
}
use of org.codehaus.jackson.JsonParseException in project flink by apache.
the class DumpCompiledPlanTest method dump.
private void dump(Plan p) {
p.setExecutionConfig(new ExecutionConfig());
try {
OptimizedPlan op = compileNoStats(p);
PlanJSONDumpGenerator dumper = new PlanJSONDumpGenerator();
String json = dumper.getOptimizerPlanAsJSON(op);
JsonParser parser = new JsonFactory().createJsonParser(json);
while (parser.nextToken() != null) ;
} catch (JsonParseException e) {
e.printStackTrace();
Assert.fail("JSON Generator produced malformatted output: " + e.getMessage());
} catch (Exception e) {
e.printStackTrace();
Assert.fail("An error occurred in the test: " + e.getMessage());
}
}
use of org.codehaus.jackson.JsonParseException in project OpenAttestation by OpenAttestation.
the class DemoPortalDataController method saveNewHostInfo.
public ModelAndView saveNewHostInfo(HttpServletRequest req, HttpServletResponse res) {
log.info("WLMDataController.saveNewHostInfo >>");
ModelAndView responseView = new ModelAndView(new JSONView());
String hostObject = null;
boolean newhost = false;
try {
hostObject = req.getParameter("hostObject");
newhost = Boolean.parseBoolean(req.getParameter("newhost"));
} catch (Exception e1) {
responseView.addObject("result", false);
responseView.addObject("message", e1.getMessage());
}
System.out.println(hostObject);
ObjectMapper mapper = new ObjectMapper();
HostDetailsEntityVO dataVO = new HostDetailsEntityVO();
try {
dataVO = mapper.readValue(hostObject, HostDetailsEntityVO.class);
} catch (JsonParseException e) {
log.error("Error While Parsing request parameters Data. " + e.getMessage());
responseView.addObject("result", false);
responseView.addObject("message", "Error While Parsing request parameters Data.");
return responseView;
} catch (JsonMappingException e) {
log.error("Error While Mapping request parameters to Mle Data Object. " + e.getMessage());
responseView.addObject("result", false);
responseView.addObject("message", "Error While Mapping request parameters to Mle Data Object.");
return responseView;
} catch (IOException e) {
log.error("IO Exception " + e.getMessage());
responseView.addObject("result", false);
responseView.addObject("message", "Error While Mapping request parameters to Mle Data Object.");
return responseView;
}
dataVO.setUpdatedOn(new Date(System.currentTimeMillis()));
try {
if (newhost) {
System.err.println("dataForNew : " + dataVO);
responseView.addObject("result", demoPortalServices.saveNewHostData(dataVO, getAttestationService(req, AttestationService.class)));
} else {
System.err.println("dataForOLD : " + dataVO);
responseView.addObject("result", demoPortalServices.updateHostData(dataVO, getAttestationService(req, AttestationService.class)));
}
} catch (DemoPortalException e) {
log.error(e.getMessage());
responseView.addObject("result", false);
responseView.addObject("message", e.getMessage());
return responseView;
}
log.info("WLMDataController.saveNewHostInfo <<<");
return responseView;
}
Aggregations