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

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

Introduction

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

Prototype

int SC_ACCEPTED

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

Click Source Link

Document

<tt>202 Accepted</tt> (HTTP/1.0 - RFC 1945)

Usage

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

@Path("/pushalarmdata")
@POST/* w  w w  .j a v  a  2  s .com*/
@Consumes(MediaType.APPLICATION_JSON)
public String pushAlarmData(final DeviceJSON dataMsg, @Context HttpServletResponse response) {
    String result = null;

    String sensorValues = dataMsg.value;
    log.info("Recieved Sensor Data Values: " + sensorValues);

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

    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);

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

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

        result = DeviceControllerService.pushData(dataMsg.owner, "FireAlarm", dataMsg.deviceId,
                System.currentTimeMillis(), "DeviceData", bulb, "BULB", response);

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

        result = DeviceControllerService.pushData(dataMsg.owner, "FireAlarm", dataMsg.deviceId,
                System.currentTimeMillis(), "DeviceData", fan, "FAN", response);

    } else {
        result = DeviceControllerService.pushData(dataMsg.owner, "FireAlarm", dataMsg.deviceId,
                System.currentTimeMillis(), "DeviceData", dataMsg.value, dataMsg.reply, response);
        return result;
    }

    return result;
}

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

@Path("/pushsensordata")
@POST//  w w  w .  ja v a 2s .c om
@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.iot.services.sensebot.SenseBotControllerService.java

@Path("/pushsonardata")
@POST/* w w w. j  a  va  2  s . c o m*/
@Consumes(MediaType.APPLICATION_JSON)
public String pushSonarData(final DeviceJSON dataMsg, @Context HttpServletResponse response) {
    String result = null;

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

    if (sonar.equals("-1")) {
        log.info("Recieved a 'No Obstacle' Sonar value. (Means there are no abstacles within 30cm)");
    } else {
        log.info("Recieved Sonar Sensor Data Value: " + sonar + " cm");

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

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

    return result;
}

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

@PUT
@Path("{id}/{status}")
public Response updateNotificationStatus(@PathParam("id") int id,
        @PathParam("status") Notification.Status status) {
    ResponsePayload responseMsg = new ResponsePayload();
    try {//  w  ww  . java2  s .com
        DeviceMgtAPIUtils.getNotificationManagementService().updateNotificationStatus(id, status);
        responseMsg.setMessageFromServer("Notification status updated successfully.");
        responseMsg.setStatusCode(HttpStatus.SC_ACCEPTED);
        return Response.status(Response.Status.ACCEPTED).entity(responseMsg).build();
    } catch (NotificationManagementException e) {
        String msg = "Error occurred while updating notification status.";
        log.error(msg, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
    }
}

From source file:org.wso2.carbon.esb.mediator.test.call.ESBJAVA4469CallMediatorWithOutOnlyTestCase.java

@Test(groups = { "wso2.esb" })
public void outOnlyWithoutContentAwareMediatorTest() throws Exception {
    WireMonitorServer wireMonitorServer = new WireMonitorServer(3828);
    Map<String, String> headers = new HashMap<>();

    wireMonitorServer.start();//w  w w . j ava  2s . c  om

    headers.put(HttpHeaders.CONTENT_TYPE, "text/xml");
    headers.put(HTTPConstants.HEADER_SOAP_ACTION, "urn:placeOrder");

    HttpResponse response = HttpRequestUtil.doPost(new URL(getProxyServiceURLHttp("ESBJAVA4469")), messageBody,
            headers);

    Assert.assertEquals(response.getResponseCode(), HttpStatus.SC_ACCEPTED, "Response code should be 202");
    String outGoingMessage = wireMonitorServer.getCapturedMessage();
    Assert.assertTrue(outGoingMessage.contains(">WSO2<"),
            "Outgoing message is empty or invalid content " + outGoingMessage);

}

From source file:org.wso2.carbon.esb.mediator.test.call.ESBJAVA4469CallMediatorWithOutOnlyTestCase.java

@Test(groups = { "wso2.esb" })
public void outOnlyWithContentAwareMediatorTest() throws Exception {
    WireMonitorServer wireMonitorServer = new WireMonitorServer(3829);
    Map<String, String> headers = new HashMap<>();

    wireMonitorServer.start();/*  w  w w  .j  a  va  2  s  .c  o  m*/

    headers.put(HttpHeaders.CONTENT_TYPE, "text/xml");
    headers.put(HTTPConstants.HEADER_SOAP_ACTION, "urn:placeOrder");

    HttpResponse response = HttpRequestUtil
            .doPost(new URL(getProxyServiceURLHttp("ESBJAVA4469WithLogMediator")), messageBody, headers);

    Assert.assertEquals(response.getResponseCode(), HttpStatus.SC_ACCEPTED, "Response code should be 202");
    String outGoingMessage = wireMonitorServer.getCapturedMessage();
    Assert.assertTrue(outGoingMessage.contains(">WSO2<"),
            "Outgoing message is empty or invalid content " + outGoingMessage);

}

From source file:org.wso2.carbon.mdm.api.DeviceNotification.java

@PUT
@Path("{id}/{status}")
public ResponsePayload updateNotificationStatus(@PathParam("id") int id,
        @PathParam("status") Notification.Status status) throws MDMAPIException {
    ResponsePayload responseMsg = new ResponsePayload();
    try {// w  ww  .j  av a  2 s . co  m
        MDMAPIUtils.getNotificationManagementService().updateNotificationStatus(id, status);
        Response.status(HttpStatus.SC_ACCEPTED);
        responseMsg.setMessageFromServer("Notification status updated successfully.");
        responseMsg.setStatusCode(HttpStatus.SC_ACCEPTED);
        return responseMsg;
    } catch (NotificationManagementException e) {
        String msg = "Error occurred while updating notification status.";
        log.error(msg, e);
        throw new MDMAPIException(msg, e);
    }
}

From source file:org.wso2.iot.integration.device.enrollment.AndroidEnrollment.java

@Test(description = "Test update applications", dependsOnMethods = { "testModifyEnrollment" })
public void testUpdateApplications() throws Exception {
    JsonArray updateApplicationData = PayloadGenerator.getJsonArray(
            Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME,
            Constants.AndroidEnrollment.UPDATE_APPLICATION_METHOD);
    HttpResponse response = client.put(/*  w  w w  . ja v a  2s.  co  m*/
            Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + "/" + deviceId + "/applications",
            updateApplicationData.toString());
    Assert.assertEquals("Update of applications for the device id " + deviceId + " failed",
            HttpStatus.SC_ACCEPTED, response.getResponseCode());
    response = client.get(Constants.MobileDeviceManagement.CHANGE_DEVICE_STATUS_ENDPOINT
            + Constants.AndroidEnrollment.ANDROID_DEVICE_TYPE + "/" + deviceId + "/applications");
    Assert.assertEquals(
            "Error while getting application list for the device with the id " + deviceId + " failed",
            HttpStatus.SC_OK, response.getResponseCode());
    JsonArray jsonArray = new JsonParser().parse(response.getData()).getAsJsonArray();
    Assert.assertEquals("Installed applications for the device with the device id " + deviceId
            + " has not been " + "updated yet", 3, jsonArray.size());
}

From source file:org.wso2.iot.integration.device.enrollment.WindowsEnrollment.java

@Test(groups = Constants.WindowsEnrollment.WINDOWS_ENROLLMENT_GROUP, description = "Test Windows MS XCEP post.", dependsOnMethods = "testBST")
public void testMSXCEP() throws Exception {
    String xml = readXML(Constants.WindowsEnrollment.MS_XCEP_FILE, Constants.UTF8);
    String payload = xml.replace(BSD_PLACEHOLDER, bsd);
    client.setHttpHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_SOAP_XML);
    HttpResponse response = client.post(Constants.WindowsEnrollment.MS_EXCEP, payload);
    Assert.assertEquals(response.getResponseCode(), HttpStatus.SC_ACCEPTED);
}

From source file:org.wso2.iot.integration.device.enrollment.WindowsEnrollment.java

@Test(groups = Constants.WindowsEnrollment.WINDOWS_ENROLLMENT_GROUP, description = "Test Windows WSETP post.", dependsOnMethods = "testMSXCEP")
public void testWSETP() throws Exception {
    String xml = readXML(Constants.WindowsEnrollment.WS_STEP_FILE, Constants.UTF8);
    String payload = xml.replace(BSD_PLACEHOLDER, bsd);
    client.setHttpHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_SOAP_XML);
    HttpResponse response = client.post(Constants.WindowsEnrollment.WSTEP_URL, payload);
    Assert.assertEquals(response.getResponseCode(), HttpStatus.SC_ACCEPTED);
}