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

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

Introduction

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

Prototype

int SC_CREATED

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

Click Source Link

Document

<tt>201 Created</tt> (HTTP/1.0 - RFC 1945)

Usage

From source file:org.wso2.ei.businessprocess.integration.common.clients.bpmn.ActivitiRestClient.java

/**
 * Method is used to acquire deployment details using the deployment ID
 *
 * @param deploymentID Deployment ID of the BPMN Package
 * @throws java.io.IOException/*from   w w  w .ja  v a  2s. c  o m*/
 * @throws org.json.JSONException
 * @returns String Array with status, deploymentID and Name
 */
public String[] getDeploymentInfoById(String deploymentID)
        throws RestClientException, IOException, JSONException {
    String url = serviceURL + "repository/deployments/" + deploymentID;
    DefaultHttpClient httpClient = getHttpClient();
    HttpGet httpget = new HttpGet(url);
    HttpResponse response = httpClient.execute(httpget);
    String status = response.getStatusLine().toString();
    String responseData = EntityUtils.toString(response.getEntity());
    JSONObject jsonResponseObject = new JSONObject(responseData);
    if (status.contains(Integer.toString(HttpStatus.SC_CREATED))
            || status.contains(Integer.toString(HttpStatus.SC_OK))) {
        String depID = jsonResponseObject.getString(ID);
        String name = jsonResponseObject.getString(NAME);
        return new String[] { status, depID, name };
    } else if (status.contains(Integer.toString(HttpStatus.SC_NOT_FOUND))) {
        throw new RestClientException(NOT_AVAILABLE);
    } else {
        throw new RestClientException("Cannot find deployment");
    }
}

From source file:org.wso2.ei.businessprocess.integration.common.clients.bpmn.ActivitiRestClient.java

/**
 * Method use to instantiate a process instance using the definition ID
 *
 * @param processDefintionID used to start a processInstance
 * @throws IOException/*from  w  w w.  j av a  2 s  . c  o m*/
 * @throws JSONException
 * @returns String Array which contains status and processInstanceID
 */
public String[] startProcessInstanceByDefintionID(String processDefintionID)
        throws IOException, JSONException, RestClientException {
    String url = serviceURL + "runtime/process-instances";
    DefaultHttpClient httpClient = getHttpClient();
    HttpPost httpPost = new HttpPost(url);
    StringEntity params = new StringEntity("{\"processDefinitionId\":\"" + processDefintionID + "\"}",
            ContentType.APPLICATION_JSON);
    httpPost.setEntity(params);
    HttpResponse response = httpClient.execute(httpPost);
    String status = response.getStatusLine().toString();
    String responseData = EntityUtils.toString(response.getEntity());
    JSONObject jsonResponseObject = new JSONObject(responseData);
    if (status.contains(Integer.toString(HttpStatus.SC_CREATED))
            || status.contains(Integer.toString(HttpStatus.SC_OK))) {
        String processInstanceID = jsonResponseObject.getString(ID);
        return new String[] { status, processInstanceID };
    }
    throw new RestClientException("Cannot Find Process Instance");
}

From source file:org.wso2.ei.businessprocess.integration.common.clients.bpmn.ActivitiRestClient.java

/**
 * Method used to suspend a process instance
 *
 * @param processInstanceID used to identify the process instance to suspend
 * @return String array containing the status and the current state
 * @throws IOException/*w  w  w  .ja v  a  2  s.  c  o  m*/
 * @throws JSONException
 */
public String[] suspendProcessInstanceById(String processInstanceID)
        throws IOException, JSONException, RestClientException {
    String url = serviceURL + "runtime/process-instances/" + processInstanceID;
    DefaultHttpClient httpClient = getHttpClient();
    HttpPut httpPut = new HttpPut(url);
    StringEntity params = new StringEntity("{\"action\":\"suspend\"}", ContentType.APPLICATION_JSON);
    httpPut.setEntity(params);
    HttpResponse response = httpClient.execute(httpPut);
    String status = response.getStatusLine().toString();
    String responseData = EntityUtils.toString(response.getEntity());
    JSONObject jsonResponseObject = new JSONObject(responseData);
    if (status.contains(Integer.toString(HttpStatus.SC_CREATED))
            || status.contains(Integer.toString(HttpStatus.SC_OK))) {
        String state = jsonResponseObject.getString("suspended");
        return new String[] { status, state };
    }
    throw new RestClientException("Cannot Suspend Process");
}

From source file:org.wso2.ei.businessprocess.integration.common.clients.bpmn.ActivitiRestClient.java

/**
 * Method used to add a new comment to a task
 *
 * @param taskID  used to identify the task
 * @param comment comment to be added//w w  w.j  a v a2s . com
 * @return String Array containing status and the message
 * @throws IOException
 * @throws JSONException
 */
public String[] addNewCommentOnTaskByTaskId(String taskID, String comment)
        throws RestClientException, IOException, JSONException {
    String url = serviceURL + "runtime/tasks/" + taskID + "/comments";
    DefaultHttpClient httpClient = getHttpClient();
    HttpPost httpPost = new HttpPost(url);
    StringEntity params = new StringEntity(
            "{\"message\" : \"" + comment + "\",\"saveProcessInstanceId\" : true}",
            ContentType.APPLICATION_JSON);
    httpPost.setEntity(params);
    HttpResponse response = httpClient.execute(httpPost);
    String status = response.getStatusLine().toString();
    String responseData = EntityUtils.toString(response.getEntity());
    JSONObject jsonResponseObject = new JSONObject(responseData);
    if (status.contains(Integer.toString(HttpStatus.SC_CREATED))
            || status.contains(Integer.toString(HttpStatus.SC_OK))) {
        String message = jsonResponseObject.getString("message");
        String commentID = jsonResponseObject.getString(ID);
        return new String[] { status, message, commentID };
    } else {
        throw new RestClientException("Cannot Add Comment");
    }
}

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

@Test(description = "Test get pending operations", dependsOnMethods = { "testModifyEnrollment" })
public void testGetPendingOperations() throws Exception {
    JsonArray pendingOperationsData = PayloadGenerator.getJsonArray(
            Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME,
            Constants.AndroidEnrollment.GET_PENDING_OPERATIONS_METHOD);
    HttpResponse response = client.put(//from   w  w w .  j ava 2  s.  c o  m
            Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + "/" + deviceId + "/pending-operations",
            pendingOperationsData.toString());
    JsonArray pendingOperations = new JsonParser().parse(response.getData()).getAsJsonArray();
    Assert.assertEquals("Error while getting pending operations for android device with the id " + deviceId,
            HttpStatus.SC_CREATED, response.getResponseCode());
    Assert.assertTrue("Pending operation count is 0. Periodic monitoring tasks are not running.",
            0 < pendingOperations.size());
}

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

@BeforeClass(alwaysRun = true, groups = { Constants.UserManagement.USER_MANAGEMENT_GROUP })
public void initTest() throws Exception {
    super.init(userMode);
    User currentUser = getAutomationContext().getContextTenant().getContextUser();
    byte[] bytesEncoded = Base64
            .encodeBase64((currentUser.getUserName() + ":" + currentUser.getPassword()).getBytes());
    String encoded = new String(bytesEncoded);
    String auth_string = "Basic " + encoded;
    String anaytics_https_url = automationContext.getContextUrls().getWebAppURLHttps()
            .replace("9443", String.valueOf(Constants.HTTPS_ANALYTICS_PORT))
            .replace("/t/" + automationContext.getContextTenant().getDomain(), "") + "/";
    this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString);
    this.analyticsClient = new RestClient(anaytics_https_url, Constants.APPLICATION_JSON, auth_string);
    if (this.userMode == TestUserMode.TENANT_ADMIN) {
        HttpResponse response = client/* www  .  j  a va2 s . c  o m*/
                .post(Constants.AndroidSenseEnrollment.ANALYTICS_ARTIFACTS_DEPLOYMENT_ENDPOINT, "");
        Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
    }
}

From source file:org.wso2.iot.integration.device.operation.AndroidOperation.java

@Test(groups = {
        Constants.AndroidOperations.OPERATIONS_GROUP }, description = "Test Android device lock operation.")
public void testLock() throws MalformedURLException, AutomationFrameworkException {
    HttpResponse response = client.post(
            Constants.AndroidOperations.OPERATION_ENDPOINT + Constants.AndroidOperations.LOCK_ENDPOINT,
            Constants.AndroidOperations.LOCK_OPERATION_PAYLOAD);
    Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
}

From source file:org.wso2.iot.integration.device.operation.AndroidOperation.java

@Test(groups = { Constants.AndroidOperations.OPERATIONS_GROUP }, description = "Test Android device un-lock "
        + "operation.")
public void testUnLock() throws MalformedURLException, AutomationFrameworkException {
    HttpResponse response = client.post(
            Constants.AndroidOperations.OPERATION_ENDPOINT + Constants.AndroidOperations.UNLOCK_ENDPOINT,
            Constants.AndroidOperations.UNLOCK_OPERATION_PAYLOAD);
    Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
}

From source file:org.wso2.iot.integration.device.operation.AndroidOperation.java

@Test(groups = { Constants.AndroidOperations.OPERATIONS_GROUP }, description = "Test Android device location "
        + "operation.")
public void testLocation() throws Exception {
    HttpResponse response = client.post(
            Constants.AndroidOperations.OPERATION_ENDPOINT + Constants.AndroidOperations.LOCATION_ENDPOINT,
            Constants.AndroidOperations.LOCATION_PAYLOAD);
    Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
}

From source file:org.wso2.iot.integration.device.operation.AndroidOperation.java

@Test(groups = {
        Constants.AndroidOperations.OPERATIONS_GROUP }, description = "Test Android device clear password "
                + "operation.")
public void testClearPassword() throws Exception {
    HttpResponse response = client.post(
            Constants.AndroidOperations.OPERATION_ENDPOINT
                    + Constants.AndroidOperations.CLEAR_PASSWORD_ENDPOINT,
            Constants.AndroidOperations.CLEAR_PASSWORD_PAYLOAD);
    Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
}