List of usage examples for org.apache.http.impl.client DefaultHttpClient getCredentialsProvider
public synchronized final CredentialsProvider getCredentialsProvider()
From source file:org.wso2.bps.integration.common.clients.bpmn.ActivitiRestClient.java
/** * Method used to activate a process instance * * @param processDefintionID used to identify the process instance to activate * @throws IOException// w w w .ja v a2 s. co m */ public String activateProcessInstanceById(String processDefintionID) throws IOException { String url = serviceURL + "runtime/process-instances/" + processDefintionID; HttpHost target = new HttpHost(hostname, port, "http"); DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getCredentialsProvider().setCredentials(new AuthScope(target.getHostName(), target.getPort()), new UsernamePasswordCredentials(username, password)); HttpPut httpPut = new HttpPut(url); StringEntity params = new StringEntity("{\"action\":\"activate\"}", ContentType.APPLICATION_JSON); httpPut.setEntity(params); HttpResponse response = httpClient.execute(httpPut); return EntityUtils.toString(response.getEntity()); }
From source file:org.wso2.bps.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 ww . j a v a2 s . c om*/ * @throws JSONException */ public String[] suspendProcessInstanceById(String processInstanceID) throws Exception { String url = serviceURL + "runtime/process-instances/" + processInstanceID; HttpHost target = new HttpHost(hostname, port, "http"); DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getCredentialsProvider().setCredentials(new AuthScope(target.getHostName(), target.getPort()), new UsernamePasswordCredentials(username, password)); 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.bps.integration.common.clients.bpmn.ActivitiRestClient.java
/** * Method is used to find thw suspended state of a process instance * * @param processInstanceID used to identify the process instance * @return String containing the suspended state of the process instance * @throws IOException/*from w w w . j a v a 2 s. co m*/ * @throws JSONException */ public String getSuspendedStateOfProcessInstanceByID(String processInstanceID) throws IOException, JSONException { String url = serviceURL + "runtime/process-instances/" + processInstanceID; String responseData = ""; HttpHost target = new HttpHost(hostname, port, "http"); DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getCredentialsProvider().setCredentials(new AuthScope(target.getHostName(), target.getPort()), new UsernamePasswordCredentials(username, password)); HttpGet httpget = new HttpGet(url); HttpResponse response = httpClient.execute(httpget); responseData = EntityUtils.toString(response.getEntity()); JSONObject resObj = new JSONObject(responseData); return resObj.getString("suspended"); }
From source file:org.wso2.bps.integration.common.clients.bpmn.ActivitiRestClient.java
/** * Method to get the value of a variable in the process instance * * @param processInstanceId To identify the process instance * @param variable to identify the variable name * @return String Array containing status, name and the value of the variable * @throws IOException/*from w ww. ja v a 2 s . co m*/ * @throws JSONException */ public String[] getValueOfVariableOfProcessInstanceById(String processInstanceId, String variable) throws IOException, JSONException { String url = serviceURL + "runtime/process-instances/" + processInstanceId + "/variables/" + variable; String responseData = ""; HttpHost target = new HttpHost(hostname, port, "http"); DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getCredentialsProvider().setCredentials(new AuthScope(target.getHostName(), target.getPort()), new UsernamePasswordCredentials(username, password)); HttpGet httpget = new HttpGet(url); HttpResponse response = httpClient.execute(httpget); responseData = EntityUtils.toString(response.getEntity()); JSONObject resObj = new JSONObject(responseData); String status = response.getStatusLine().toString(); String name = resObj.getString("name"); String value = resObj.getString("value"); return new String[] { status, name, value }; }
From source file:org.wso2.bps.integration.common.clients.bpmn.ActivitiRestClient.java
/** * Method used to remove/delete a process instance * * @param processInstanceId used to identify a process instance * @return String value containing the status of the request. * @throws IOException//from www . j av a 2 s . com */ public String deleteProcessInstanceByID(String processInstanceId) throws IOException { String url = serviceURL + "runtime/process-instances/" + processInstanceId; HttpHost target = new HttpHost(hostname, port, "http"); DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getCredentialsProvider().setCredentials(new AuthScope(target.getHostName(), target.getPort()), new UsernamePasswordCredentials(username, password)); HttpDelete httpDelete = new HttpDelete(url); HttpResponse response = httpClient.execute(httpDelete); return response.getStatusLine().toString(); }
From source file:org.wso2.bps.integration.common.clients.bpmn.ActivitiRestClient.java
/** * Method used to get the delegation state of a task * * @param taskID used to identify the task * @return String which contains the state of the task * @throws IOException/* ww w .j a v a2 s .c o m*/ * @throws JSONException */ public String getDelegationsStateByTaskId(String taskID) throws IOException, JSONException { String url = serviceURL + "runtime/tasks/" + taskID; String responseData = ""; HttpHost target = new HttpHost(hostname, port, "http"); DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getCredentialsProvider().setCredentials(new AuthScope(target.getHostName(), target.getPort()), new UsernamePasswordCredentials(username, password)); HttpGet httpget = new HttpGet(url); HttpResponse response = httpClient.execute(httpget); responseData = EntityUtils.toString(response.getEntity()); JSONObject resObj = new JSONObject(responseData); return resObj.getString("delegationState"); }
From source file:org.wso2.bps.integration.common.clients.bpmn.ActivitiRestClient.java
/** * Method used to resolve a task/*from w ww . j av a2s .c o m*/ * * @param taskID used to identify the task * @return String which contains the status of the request * @throws IOException */ public String resolveTaskByTaskId(String taskID) throws IOException { String url = serviceURL + "runtime/tasks/" + taskID; HttpHost target = new HttpHost(hostname, port, "http"); DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getCredentialsProvider().setCredentials(new AuthScope(target.getHostName(), target.getPort()), new UsernamePasswordCredentials(username, password)); HttpPost httpPost = new HttpPost(url); StringEntity params = new StringEntity("{\"action\" : \"resolve\"}", ContentType.APPLICATION_JSON); httpPost.setEntity(params); HttpResponse response = httpClient.execute(httpPost); return response.getStatusLine().toString(); }
From source file:org.wso2.bps.integration.common.clients.bpmn.ActivitiRestClient.java
/** * Method to get the asignee of a task// w w w .j ava2s.c o m * * @param taskID used to identify the task * @return String containing the Asignee * @throws IOException * @throws JSONException */ public String getAssigneeByTaskId(String taskID) throws IOException, JSONException { String url = serviceURL + "runtime/tasks/" + taskID; String responseData = ""; HttpHost target = new HttpHost(hostname, port, "http"); DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getCredentialsProvider().setCredentials(new AuthScope(target.getHostName(), target.getPort()), new UsernamePasswordCredentials(username, password)); HttpGet httpget = new HttpGet(url); HttpResponse response = httpClient.execute(httpget); responseData = EntityUtils.toString(response.getEntity()); JSONObject resObj = new JSONObject(responseData); return resObj.getString("assignee"); }
From source file:org.wso2.bps.integration.common.clients.bpmn.ActivitiRestClient.java
/** * This method is used to get the comment by comment id and task id * * @param taskID used to identify the task where the comment is made * @param commentID used to identify the comment uniquely * @return String containing the comment * @throws IOException//w w w .j av a 2s . c o m * @throws JSONException */ public String getCommentByTaskIdAndCommentId(String taskID, String commentID) throws IOException, JSONException { String url = serviceURL + "runtime/tasks/" + taskID + "/comments/" + commentID; String responseData = ""; HttpHost target = new HttpHost(hostname, port, "http"); DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getCredentialsProvider().setCredentials(new AuthScope(target.getHostName(), target.getPort()), new UsernamePasswordCredentials(username, password)); HttpGet httpget = new HttpGet(url); HttpResponse response = httpClient.execute(httpget); responseData = EntityUtils.toString(response.getEntity()); JSONObject resObj = new JSONObject(responseData); return resObj.getString("message"); }
From source file:org.wso2.bps.integration.common.clients.bpmn.ActivitiRestClient.java
/** * Method used to find task by using the process instance ID * * @param processInstanceId used to identify task through a process instance * @return String Array containing status and the taskID * @throws IOException/* w w w . j ava 2 s. c om*/ * @throws JSONException */ public String[] findTaskIdByProcessInstanceID(String processInstanceId) throws IOException, JSONException { String url = serviceURL + "runtime/tasks"; String taskId = ""; HttpHost target = new HttpHost(hostname, port, "http"); DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getCredentialsProvider().setCredentials(new AuthScope(target.getHostName(), target.getPort()), new UsernamePasswordCredentials(username, password)); 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); JSONArray data = jsonResponseObject.getJSONArray("data"); int responseObjectSize = Integer.parseInt(jsonResponseObject.get("total").toString()); for (int j = 0; j < responseObjectSize; j++) { if (data.getJSONObject(j).getString("processInstanceId").equals(processInstanceId)) { taskId = data.getJSONObject(j).getString("id"); } } return new String[] { status, taskId }; }