Example usage for org.apache.commons.httpclient HttpStatus SC_INTERNAL_SERVER_ERROR

List of usage examples for org.apache.commons.httpclient HttpStatus SC_INTERNAL_SERVER_ERROR

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpStatus SC_INTERNAL_SERVER_ERROR.

Prototype

int SC_INTERNAL_SERVER_ERROR

To view the source code for org.apache.commons.httpclient HttpStatus SC_INTERNAL_SERVER_ERROR.

Click Source Link

Document

<tt>500 Server Error</tt> (HTTP/1.0 - RFC 1945)

Usage

From source file:org.wso2.carbon.device.mgt.iot.firealarm.api.FireAlarmControllerService.java

@Path("/pushalarmdata")
@POST//w  ww .j av a  2s. c o m
@Consumes(MediaType.APPLICATION_JSON)
public void pushAlarmData(final DeviceJSON dataMsg, @Context HttpServletResponse response) {
    boolean result;
    String sensorValues = dataMsg.value;
    log.info("Recieved Sensor Data Values: " + sensorValues);

    String sensors[] = sensorValues.split(":");
    try {
        if (sensors.length == 3) {
            String temperature = sensors[0];
            String bulb = sensors[1];
            String fan = sensors[2];

            sensorValues = "Temperature:" + temperature + "C\tBulb Status:" + bulb + "\t\tFan Status:" + fan;
            log.info(sensorValues);
            DeviceController deviceController = new DeviceController();
            result = deviceController.pushBamData(dataMsg.owner, FireAlarmConstants.DEVICE_TYPE,
                    dataMsg.deviceId, System.currentTimeMillis(), "DeviceData", temperature, "TEMPERATURE");

            if (!result) {
                response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
                log.error("Error whilst pushing temperature: " + sensorValues);
                return;
            }

            result = deviceController.pushBamData(dataMsg.owner, FireAlarmConstants.DEVICE_TYPE,
                    dataMsg.deviceId, System.currentTimeMillis(), "DeviceData", bulb, "BULB");

            if (!result) {
                response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
                log.error("Error whilst pushing Bulb data: " + sensorValues);
                return;
            }

            result = deviceController.pushBamData(dataMsg.owner, FireAlarmConstants.DEVICE_TYPE,
                    dataMsg.deviceId, System.currentTimeMillis(), "DeviceData", fan, "FAN");

            if (!result) {
                response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
                log.error("Error whilst pushing Fan data: " + sensorValues);
            }

        } else {
            DeviceController deviceController = new DeviceController();
            result = deviceController.pushBamData(dataMsg.owner, FireAlarmConstants.DEVICE_TYPE,
                    dataMsg.deviceId, System.currentTimeMillis(), "DeviceData", dataMsg.value, dataMsg.reply);
            if (!result) {
                response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
                log.error("Error whilst pushing sensor data: " + sensorValues);
            }
        }

    } catch (UnauthorizedException e) {
        response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
        log.error("Data Push Attempt Failed at Publisher: " + e.getMessage());
    }
}

From source file:org.wso2.carbon.device.mgt.iot.sensebot.api.SensebotControllerService.java

@Path("/pushsensordata")
@POST//  w ww.  j ava  2 s  . c  o m
@Consumes(MediaType.APPLICATION_JSON)
public void pushAlarmData(final DeviceJSON dataMsg, @Context HttpServletResponse response) {
    boolean result = false;

    String sensorValues = dataMsg.value; //TEMP-PIR-SONAR-LDR
    log.info("Recieved Sensor Data Values: " + sensorValues);

    String sensors[] = sensorValues.split(":");
    try {
        if (sensors.length == 4) {
            String temperature = sensors[0];
            String motion = sensors[1];
            String sonar = sensors[2];
            String light = sensors[3];

            if (sonar.equals("-1")) {
                sonar = "No Object";
            }

            sensorValues = "Temperature:" + temperature + "C\t\tMotion:" + motion + "\tSonar:" + sonar
                    + "\tLight:" + light;

            if (log.isDebugEnabled())
                log.debug(sensorValues);

            result = DeviceController.pushData(dataMsg.owner, "SenseBot", dataMsg.deviceId,
                    System.currentTimeMillis(), "DeviceData", temperature, "TEMP");

            if (!result) {
                response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
                return;
            }

            result = DeviceController.pushData(dataMsg.owner, "SenseBot", dataMsg.deviceId,
                    System.currentTimeMillis(), "DeviceData", motion, "MOTION");

            if (!result) {
                response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
                return;
            }

            if (!sonar.equals("No Object")) {
                result = DeviceController.pushData(dataMsg.owner, "SenseBot", dataMsg.deviceId,
                        System.currentTimeMillis(), "DeviceData", sonar, "SONAR");

                if (!result) {
                    response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
                    return;
                }

            }

            result = DeviceController.pushData(dataMsg.owner, "SenseBot", dataMsg.deviceId,
                    System.currentTimeMillis(), "DeviceData", light, "LIGHT");

            if (!result) {
                response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
                return;
            }

        } else {
            response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
            return;
        }

    } catch (UnauthorizedException e) {
        response.setStatus(HttpStatus.SC_UNAUTHORIZED);

    }

}

From source file:org.wso2.carbon.device.mgt.iot.sensebot.api.SensebotControllerService.java

@Path("/pushtempdata")
@POST/*from   w  ww  . j  a  v  a2 s .c  o  m*/
@Consumes(MediaType.APPLICATION_JSON)
public void pushTempData(final DeviceJSON dataMsg, @Context HttpServletResponse response) {

    String temperature = dataMsg.value; //TEMP-PIR-SONAR-LDR
    if (log.isDebugEnabled())
        log.debug("Recieved Tenperature Data Value: " + temperature + " degrees C");
    try {
        boolean result = DeviceController.pushData(dataMsg.owner, "SenseBot", dataMsg.deviceId,
                System.currentTimeMillis(), "DeviceData", temperature, "TEMP");

        if (!result) {
            response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
            return;
        }

    } catch (UnauthorizedException e) {
        response.setStatus(HttpStatus.SC_UNAUTHORIZED);

    }
}

From source file:org.wso2.carbon.device.mgt.iot.sensebot.api.SensebotControllerService.java

@Path("/pushpirdata")
@POST/* w w  w  .ja  va 2  s.  c  o  m*/
@Consumes(MediaType.APPLICATION_JSON)
public void pushPIRData(final DeviceJSON dataMsg, @Context HttpServletResponse response) {

    String motion = dataMsg.value; //TEMP-PIR-SONAR-LDR
    if (log.isDebugEnabled())
        log.debug("Recieved PIR (Motion) Sensor Data Value: " + motion);
    try {
        boolean result = DeviceController.pushData(dataMsg.owner, "SenseBot", dataMsg.deviceId,
                System.currentTimeMillis(), "DeviceData", motion, "MOTION");

        if (!result) {
            response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
            return;
        }

    } catch (UnauthorizedException e) {
        response.setStatus(HttpStatus.SC_UNAUTHORIZED);

    }

}

From source file:org.wso2.carbon.device.mgt.iot.sensebot.api.SensebotControllerService.java

@Path("/pushsonardata")
@POST// w w w .  ja  v a  2 s.co m
@Consumes(MediaType.APPLICATION_JSON)
public void pushSonarData(final DeviceJSON dataMsg, @Context HttpServletResponse response) {

    String sonar = dataMsg.value; //TEMP-PIR-SONAR-LDR

    if (sonar.equals("-1")) {
        if (log.isDebugEnabled())
            log.debug("Recieved a 'No Obstacle' Sonar value. (Means there are no abstacles within 30cm)");
    } else {
        if (log.isDebugEnabled())
            log.debug("Recieved Sonar Sensor Data Value: " + sonar + " cm");
        try {
            boolean result = DeviceController.pushData(dataMsg.owner, "SenseBot", dataMsg.deviceId,
                    System.currentTimeMillis(), "DeviceData", sonar, "SONAR");

            if (!result) {
                response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
                return;
            }

        } catch (UnauthorizedException e) {
            response.setStatus(HttpStatus.SC_UNAUTHORIZED);

        }

    }

}

From source file:org.wso2.carbon.device.mgt.iot.sensebot.api.SensebotControllerService.java

@Path("/pushlightdata")
@POST/*from  w  w  w. ja va2  s  . c om*/
@Consumes(MediaType.APPLICATION_JSON)
public void pushlightData(final DeviceJSON dataMsg, @Context HttpServletResponse response) {

    String light = dataMsg.value; //TEMP-PIR-SONAR-LDR
    if (log.isDebugEnabled())
        log.debug("Recieved LDR (Light) Sensor Data Value: " + light);

    try {
        boolean result = DeviceController.pushData(dataMsg.owner, "SenseBot", dataMsg.deviceId,
                System.currentTimeMillis(), "DeviceData", light, "LIGHT");

        if (!result) {
            response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
            return;
        }

    } catch (UnauthorizedException e) {
        response.setStatus(HttpStatus.SC_UNAUTHORIZED);

    }

}

From source file:org.wso2.carbon.device.mgt.iot.services.DeviceControllerService.java

@Path("/pushdata/{owner}/{type}/{id}/{time}/{key}/{value}")
@POST//from w  ww.jav a  2  s  . c om
// @Produces("application/xml")
public static String pushData(@PathParam("owner") String owner, @PathParam("type") String deviceType,
        @PathParam("id") String deviceId, @PathParam("time") Long time, @PathParam("key") String key,
        @PathParam("value") String value, @HeaderParam("description") String description,
        @Context HttpServletResponse response) {

    HashMap<String, String> deviceDataMap = new HashMap<String, String>();

    deviceDataMap.put("owner", owner);
    deviceDataMap.put("deviceType", deviceType);
    deviceDataMap.put("deviceId", deviceId);
    deviceDataMap.put("time", "" + time);
    deviceDataMap.put("key", key);
    deviceDataMap.put("value", value);
    deviceDataMap.put("description", description);

    //DeviceValidator deviceChecker = new DeviceValidator();

    //DeviceIdentifier dId = new DeviceIdentifier();
    //dId.setId(deviceId);
    //dId.setType(deviceType);

    //      try {
    //         boolean exists = deviceChecker.isExist(owner, dId);
    String result = null;
    //         if (exists) {
    try {
        iotDataStore.publishIoTData(deviceDataMap);
        response.setStatus(HttpStatus.SC_ACCEPTED);
        result = "Data Published Succesfully...";
    } catch (DeviceControllerServiceException e) {
        response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
        result = "Failed to push " + description + " data to dataStore at " + dataStoreConfig.getEndPoint()
                + ":" + dataStoreConfig.getPort();
    }
    //
    //         }
    //
    return result;
    //
    //      } catch (InstantiationException e) {
    //         response.setStatus(500);
    //         return null;
    //      } catch (IllegalAccessException e) {
    //         response.setStatus(500);
    //         return null;
    //      } catch (ConfigurationException e) {
    //         response.setStatus(500);
    //         return null;
    //      } catch (DeviceCloudException e) {
    //         response.setStatus(500);
    //         return null;
    //      }

}

From source file:org.wso2.carbon.device.mgt.iot.services.DeviceControllerService.java

@Path("/setcontrol/{owner}/{type}/{id}/{key}/{value}")
@POST/*from w w  w . ja v a2s  . c  o  m*/
public static String setControl(@PathParam("owner") String owner, @PathParam("type") String deviceType,
        @PathParam("id") String deviceId, @PathParam("key") String key, @PathParam("value") String value,
        @Context HttpServletResponse response) {
    HashMap<String, String> deviceControlsMap = new HashMap<String, String>();

    deviceControlsMap.put("owner", owner);
    deviceControlsMap.put("deviceType", deviceType);
    deviceControlsMap.put("deviceId", deviceId);
    deviceControlsMap.put("key", key);
    deviceControlsMap.put("value", value);

    String result = null;
    try {
        iotControlQueue.enqueueControls(deviceControlsMap);
        response.setStatus(HttpStatus.SC_ACCEPTED);
        result = "Controls added to queue succesfully..";
    } catch (DeviceControllerServiceException e) {
        response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
        result = "Failed to enqueue data to queue at " + controlQueueConfig.getEndPoint() + ":"
                + controlQueueConfig.getPort();
    }
    return result;
}

From source file:org.wso2.carbon.device.mgt.iot.services.sensebot.SenseBotControllerService.java

@Path("/pushsensordata")
@POST/*  w  w w  .ja va2  s . com*/
@Consumes(MediaType.APPLICATION_JSON)
public String pushAlarmData(final DeviceJSON dataMsg, @Context HttpServletResponse response) {
    String result = null;

    String sensorValues = dataMsg.value; //TEMP-PIR-SONAR-LDR
    log.info("Recieved Sensor Data Values: " + sensorValues);

    String sensors[] = sensorValues.split(":");

    if (sensors.length == 4) {
        String temperature = sensors[0];
        String motion = sensors[1];
        String sonar = sensors[2];
        String light = sensors[3];

        if (sonar.equals("-1")) {
            sonar = "No Object";
        }

        sensorValues = "Temperature:" + temperature + "C\t\tMotion:" + motion + "\tSonar:" + sonar + "\tLight:"
                + light;
        log.info(sensorValues);

        result = DeviceControllerService.pushData(dataMsg.owner, "SenseBot", dataMsg.deviceId,
                System.currentTimeMillis(), "DeviceData", temperature, "TEMP", response);

        if (response.getStatus() != HttpStatus.SC_ACCEPTED) {
            return result;
        }

        result = DeviceControllerService.pushData(dataMsg.owner, "SenseBot", dataMsg.deviceId,
                System.currentTimeMillis(), "DeviceData", motion, "MOTION", response);

        if (response.getStatus() != HttpStatus.SC_ACCEPTED) {
            return result;
        }

        if (!sonar.equals("No Object")) {
            result = DeviceControllerService.pushData(dataMsg.owner, "SenseBot", dataMsg.deviceId,
                    System.currentTimeMillis(), "DeviceData", sonar, "SONAR", response);

            if (response.getStatus() != HttpStatus.SC_ACCEPTED) {
                return result;
            }
        }

        result = DeviceControllerService.pushData(dataMsg.owner, "SenseBot", dataMsg.deviceId,
                System.currentTimeMillis(), "DeviceData", light, "LIGHT", response);

    } else {
        response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
        return "Invalid data stream format. Needs to be \"TEMP:PIR:SONAR:LDR\"";
    }

    return result;
}

From source file:org.wso2.carbon.device.mgt.jaxrs.api.DashboardImpl.java

@GET
@Path("device-count-overview")
public Response getOverviewDeviceCounts() {
    GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();

    DashboardGadgetDataWrapper dashboardGadgetDataWrapper1 = new DashboardGadgetDataWrapper();

    // getting total device count
    DeviceCountByGroup totalDeviceCount;
    try {//  w w w . ja  v a 2  s .  c o m
        totalDeviceCount = gadgetDataService.getTotalDeviceCount();
    } catch (DataAccessLayerException e) {
        log.error("An internal error occurred while trying to execute relevant data service function "
                + "@ Dashboard API layer to retrieve total device count.", e);
        return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(ERROR_IN_RETRIEVING_REQUESTED_DATA)
                .build();
    }

    List<DeviceCountByGroup> totalDeviceCountInListEntry = new ArrayList<>();
    totalDeviceCountInListEntry.add(totalDeviceCount);

    dashboardGadgetDataWrapper1.setContext("Total-device-count");
    dashboardGadgetDataWrapper1.setGroupingAttribute(null);
    dashboardGadgetDataWrapper1.setData(totalDeviceCountInListEntry);

    // getting device counts by connectivity statuses
    List<DeviceCountByGroup> deviceCountsByConnectivityStatuses;
    try {
        deviceCountsByConnectivityStatuses = gadgetDataService.getDeviceCountsByConnectivityStatuses();
    } catch (DataAccessLayerException e) {
        log.error("An internal error occurred while trying to execute relevant data service function "
                + "@ Dashboard API layer to retrieve device counts by connectivity statuses.", e);
        return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(ERROR_IN_RETRIEVING_REQUESTED_DATA)
                .build();
    }

    DashboardGadgetDataWrapper dashboardGadgetDataWrapper2 = new DashboardGadgetDataWrapper();

    dashboardGadgetDataWrapper2.setContext("Device-counts-by-connectivity-statuses");
    dashboardGadgetDataWrapper2.setGroupingAttribute(CONNECTIVITY_STATUS);
    dashboardGadgetDataWrapper2.setData(deviceCountsByConnectivityStatuses);

    List<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
    responsePayload.add(dashboardGadgetDataWrapper1);
    responsePayload.add(dashboardGadgetDataWrapper2);

    return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
}