use of org.openmuc.framework.lib.rest.ToJson in project OpenMUC by isc-konstanz.
the class ChannelResourceServlet method doGet.
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(APPLICATION_JSON);
String[] pathAndQueryString = checkIfItIsACorrectRest(request, response, logger);
if (pathAndQueryString == null) {
return;
}
setConfigAccess();
String pathInfo = pathAndQueryString[0];
String[] pathInfoArray = ServletLib.getPathInfoArray(pathInfo);
response.setStatus(HttpServletResponse.SC_OK);
ToJson json = new ToJson();
if (pathInfo.equals("/")) {
boolean details = Boolean.parseBoolean(request.getParameter("details"));
if (details) {
doGetChannelList(json);
} else {
doGetRecordList(json);
}
} else if (pathInfoArray.length == 1 && pathInfoArray[0].equalsIgnoreCase(Const.RECORDS)) {
doGetRecordList(json);
} else if (pathInfoArray.length == 1 && pathInfoArray[0].equalsIgnoreCase(Const.STATES)) {
doGetStateList(json);
} else if (pathInfoArray.length == 1 && pathInfoArray[0].equalsIgnoreCase(Const.CONFIGS)) {
doGetConfigsList(json);
} else {
doGetChannel(request, response, pathInfoArray, json);
}
sendJson(json, response);
}
use of org.openmuc.framework.lib.rest.ToJson in project OpenMUC by isc-konstanz.
the class ControlsServlet method doGet.
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(APPLICATION_JSON);
String[] pathAndQueryString = checkIfItIsACorrectRest(request, response, logger);
if (pathAndQueryString != null) {
String pathInfo = pathAndQueryString[ServletLib.PATH_ARRAY_NR];
ToJson json = new ToJson();
if (pathInfo.equals("/")) {
} else {
String[] pathInfoArray = ServletLib.getPathInfoArray(pathInfo);
if (pathInfoArray.length == 1) {
} else {
ServletLib.sendHTTPErrorAndLogDebug(response, HttpServletResponse.SC_NOT_FOUND, logger, REQUESTED_REST_PATH_IS_NOT_AVAILABLE, " Path Info = ", request.getPathInfo());
}
}
sendJson(json, response);
}
}
use of org.openmuc.framework.lib.rest.ToJson in project OpenMUC by isc-konstanz.
the class RestChannel method write.
public void write(RestConnection connection) throws ConnectionException {
Record record = getRecord();
ToJson json = new ToJson();
json.addRecord(record, getValueType());
Flag flag = connection.put(uri, json.toString());
setFlag(flag);
}
use of org.openmuc.framework.lib.rest.ToJson in project OpenMUC by isc-konstanz.
the class DeviceResourceServlet method doGet.
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(APPLICATION_JSON);
String[] pathAndQueryString = checkIfItIsACorrectRest(request, response, logger);
if (pathAndQueryString == null) {
return;
}
setConfigAccess();
String pathInfo = pathAndQueryString[0];
String[] pathInfoArray = ServletLib.getPathInfoArray(pathInfo);
response.setStatus(HttpServletResponse.SC_OK);
ToJson json = new ToJson();
if (pathInfo.equals("/")) {
boolean details = Boolean.parseBoolean(request.getParameter("details"));
if (details) {
doGetDeviceList(json);
} else {
doGetDeviceIdList(json);
}
} else if (pathInfoArray.length == 1 && pathInfoArray[0].equalsIgnoreCase(Const.STATES)) {
doGetStateList(json);
} else if (pathInfoArray.length == 1 && pathInfoArray[0].equalsIgnoreCase(Const.CONFIGS)) {
doGetConfigsList(json);
} else {
doGetDevice(request, response, pathInfoArray, json);
}
sendJson(json, response);
}
use of org.openmuc.framework.lib.rest.ToJson in project OpenMUC by isc-konstanz.
the class DriverResourceServlet method doGet.
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(APPLICATION_JSON);
String[] pathAndQueryString = checkIfItIsACorrectRest(request, response, logger);
if (pathAndQueryString != null) {
setConfigAccess();
String pathInfo = pathAndQueryString[ServletLib.PATH_ARRAY_NR];
String[] pathInfoArray = ServletLib.getPathInfoArray(pathInfo);
response.setStatus(HttpServletResponse.SC_OK);
ToJson json = new ToJson();
if (pathInfo.equals("/")) {
boolean details = Boolean.parseBoolean(request.getParameter("details"));
if (details) {
doGetDriverList(json);
} else {
doGetDriverIdList(json);
}
} else if (pathInfoArray.length == 1 && pathInfoArray[0].equalsIgnoreCase(Const.RUNNING)) {
doGetRunningList(json);
} else if (pathInfoArray.length == 1 && pathInfoArray[0].equalsIgnoreCase(Const.CONFIGS)) {
doGetConfigsList(json);
} else if (pathInfoArray.length > 1 && pathInfoArray[1].equalsIgnoreCase(Const.INFOS)) {
doGetInfo(request, response, pathInfoArray, json);
} else {
doGetDriver(request, response, pathInfoArray, json);
}
sendJson(json, response);
}
}
Aggregations