Search in sources :

Example 1 with ToJson

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);
}
Also used : ToJson(org.openmuc.framework.lib.rest.ToJson)

Example 2 with ToJson

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);
    }
}
Also used : ToJson(org.openmuc.framework.lib.rest.ToJson)

Example 3 with ToJson

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);
}
Also used : ToJson(org.openmuc.framework.lib.rest.ToJson) RestRecord(org.openmuc.framework.lib.rest.objects.RestRecord) Record(org.openmuc.framework.data.Record) Flag(org.openmuc.framework.data.Flag)

Example 4 with ToJson

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);
}
Also used : ToJson(org.openmuc.framework.lib.rest.ToJson)

Example 5 with ToJson

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);
    }
}
Also used : ToJson(org.openmuc.framework.lib.rest.ToJson)

Aggregations

ToJson (org.openmuc.framework.lib.rest.ToJson)7 ArrayList (java.util.ArrayList)1 Flag (org.openmuc.framework.data.Flag)1 Record (org.openmuc.framework.data.Record)1 RestRecord (org.openmuc.framework.lib.rest.objects.RestRecord)1 RestUserConfig (org.openmuc.framework.lib.rest.objects.RestUserConfig)1