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 to claim task by a user//from w ww .j av a2s . co m * * @param taskID used to identify the task to be claimed * @return String Array containing status * @throws IOException */ public String claimTaskByTaskId(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\" : \"claim\"," + "\"assignee\" :\"" + userClaim + "\"}", 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
/** * Mehtod to delegate a task to certain user * * @param taskID used to identify the task to be delegated * @return String with the status of the delegation * @throws IOException//w w w. j a va 2 s . co m */ public String delegateTaskByTaskId(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\" : \"delegate\"," + "\"assignee\" :\"" + userDelegate + "\"}", ContentType.APPLICATION_JSON); httpPost.setEntity(params); HttpResponse response; response = httpClient.execute(httpPost); return response.getStatusLine().toString(); }
From source file:org.wso2.bps.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 ww . ja va2 s . com * @return String Array containing status and the message * @throws IOException * @throws JSONException */ public String[] addNewCommentOnTaskByTaskId(String taskID, String comment) throws Exception { String url = serviceURL + "runtime/tasks/" + taskID + "/comments"; 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( "{\"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.bps.integration.common.clients.bpmn.ActivitiRestClient.java
/** * Method to delete a task//w ww . j a va 2 s.co m * * @param taskId used to identify a task * @param cascadeHistory boolean to either delete the task history or not * @param deleteReason reason for deleteing the task * @return String containing the status of the request * @throws IOException */ public String deleteTaskByTaskId(String taskId, boolean cascadeHistory, String deleteReason) throws IOException { String url = serviceURL + "runtime/tasks/" + taskId + "?cascadeHistory=" + cascadeHistory + "&deleteReason=" + deleteReason; 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.ei.businessprocess.integration.common.clients.bpmn.ActivitiRestClient.java
private DefaultHttpClient getHttpClient() { HttpHost target = new HttpHost(hostname, port, "http"); DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getCredentialsProvider().setCredentials(new AuthScope(target.getHostName(), target.getPort()), new UsernamePasswordCredentials(USERNAME, PASSWORD)); return httpClient; }
From source file:rinor.Rest_com.java
@SuppressWarnings("null") public static JSONObject connect(String url, String login, String password) { tracerengine Tracer = null;/* w ww . ja v a 2 s . c o m*/ JSONObject json = null; try { DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.getCredentialsProvider().setCredentials(new AuthScope(null, -1), new UsernamePasswordCredentials(login + ":" + password)); // TODO Set timeout // this doesn't work //httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 10000); HttpGet httpget = new HttpGet(url); HttpResponse response; String result = null; response = httpclient.execute(httpget); if (response.getStatusLine().getStatusCode() == 200) { HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); result = convertStreamToString(instream); json = new JSONObject(result); instream.close(); } } else { Tracer.d(mytag, "Resource not available>"); } } catch (HttpHostConnectException e) { //e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } return json; }