use of org.openmuc.framework.lib.rest.exceptions.MissingJsonObjectException in project OpenMUC by isc-konstanz.
the class FromJson method setChannelConfig.
public void setChannelConfig(ChannelConfig channelConfig, String id) throws JsonSyntaxException, IdCollisionException, RestConfigIsNotCorrectException, MissingJsonObjectException {
JsonElement jse = jsonObject.get(Const.CONFIGS);
if (jse.isJsonNull()) {
throw new MissingJsonObjectException();
}
RestChannelMapper.setChannelConfig(channelConfig, gson.fromJson(jse, RestChannelConfig.class), id);
}
use of org.openmuc.framework.lib.rest.exceptions.MissingJsonObjectException in project OpenMUC by isc-konstanz.
the class DriverResourceServlet method doSetConfigs.
private synchronized boolean doSetConfigs(String driverId, HttpServletResponse response, String json) {
boolean ok = false;
try {
DriverConfig driverConfig = rootConfig.getDriver(driverId);
if (driverConfig != null) {
try {
FromJson fromJson = new FromJson(json);
fromJson.setDriverConfig(driverConfig, driverId);
} catch (IdCollisionException e) {
}
configService.setConfig(rootConfig);
configService.writeConfigToFile();
response.setStatus(HttpServletResponse.SC_OK);
ok = true;
} else {
ServletLib.sendHTTPErrorAndLogErr(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, logger, "Not able to access to driver ", driverId);
}
} catch (JsonSyntaxException e) {
ServletLib.sendHTTPErrorAndLogDebug(response, HttpServletResponse.SC_CONFLICT, logger, "JSON syntax is wrong.");
} catch (MissingJsonObjectException e) {
ServletLib.sendHTTPErrorAndLogDebug(response, HttpServletResponse.SC_NOT_FOUND, logger, e.getMessage());
} catch (ConfigWriteException e) {
ServletLib.sendHTTPErrorAndLogErr(response, HttpServletResponse.SC_CONFLICT, logger, "Could not write driver \"", driverId, "\".");
logger.debug(e.getMessage());
} catch (RestConfigIsNotCorrectException e) {
ServletLib.sendHTTPErrorAndLogDebug(response, HttpServletResponse.SC_NOT_ACCEPTABLE, logger, "Not correct formed driver config json.", " JSON = ", json);
} catch (IllegalStateException e) {
ServletLib.sendHTTPErrorAndLogDebug(response, HttpServletResponse.SC_CONFLICT, logger, e.getMessage());
}
return ok;
}
Aggregations