use of org.codehaus.jackson.map.JsonMappingException in project databus by linkedin.
the class ClusterCheckpointPersistenceProvider method getCheckpoint.
/**
* internal function that fetches contents from Helix property store
*
* @param key
* @return checkpoint or null
*/
private Checkpoint getCheckpoint(String key) {
ZNRecord zn = _propertyStore.get(key, null, AccessOption.PERSISTENT);
if (zn != null) {
String v = zn.getSimpleField(KEY_CHECKPOINT);
try {
Checkpoint cp;
cp = new Checkpoint(v);
return cp;
} catch (JsonParseException e) {
LOG.error("Cannot deserialize value for key=" + key + " value=" + v + " exception=" + e);
} catch (JsonMappingException e) {
LOG.error("Cannot deserialize value for key=" + key + " value=" + v + " exception=" + e);
} catch (IOException e) {
LOG.error("Cannot deserialize value for key=" + key + " value=" + v + " exception=" + e);
}
} else {
LOG.error("No record for key = " + key);
}
return null;
}
use of org.codehaus.jackson.map.JsonMappingException in project databus by linkedin.
the class PhysicalSourceConfigBuilder method build.
@Override
public PhysicalSourceStaticConfig[] build() throws InvalidConfigException {
ObjectMapper mapper = new ObjectMapper();
PhysicalSourceStaticConfig[] list = new PhysicalSourceStaticConfig[null == _fileNames ? 0 : _fileNames.length];
if (_fileNames == null)
return list;
for (int i = 0; i < _fileNames.length; ++i) {
File sourceJson = _fileNames[i];
PhysicalSourceConfig pConfig = null;
Exception e = null;
try {
pConfig = mapper.readValue(sourceJson, PhysicalSourceConfig.class);
} catch (JsonParseException jpe) {
e = jpe;
} catch (JsonMappingException jme) {
e = jme;
} catch (IOException ioe) {
e = ioe;
}
if (e != null || pConfig == null) {
throw new InvalidConfigException(e);
}
pConfig.checkForNulls();
LOG.info("Generated Physical source config: name= " + pConfig.getId());
list[i] = pConfig.build();
}
/*
for(PhysicalSourceStaticConfig pCfg : pConfigs) {
for(LogicalSourceStaticConfig lSC : pCfg.getSources()) {
config.setSourceName("" + lSC.getId(), lSC.getName());
}
}
*/
return list;
}
use of org.codehaus.jackson.map.JsonMappingException 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.map.JsonMappingException 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.map.JsonMappingException 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);
}
}
}
Aggregations