07-20-2015 02:57 PM
public static void main(String[] args) throws Exception {
DefaultHttpClient httpclient = new DefaultHttpClient();
try {
HttpGet httpGet = new HttpGet("http://localhost:8080/activiti-rest/service/runtime/tasks/20005");
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("kermit", "kermit");
httpGet.addHeader(new BasicScheme().authenticate(creds, httpGet));
System.out.println("executing request" + httpGet.getRequestLine());
HttpResponse response = httpclient.execute(httpGet);
HttpEntity entity = response.getEntity();
System.out.println("—————————————-");
System.out.println(response.getStatusLine());
if (entity != null) {
System.out.println("Response content length: " + entity.getContentLength());
}
EntityUtils.consume(entity);
} finally {
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
httpclient.getConnectionManager().shutdown();
}
}
public static void main(String[] args) throws Exception {
//crea un httpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
//indica donde se va a conectar
HttpPost httpPost = new HttpPost("http://localhost:8080/activiti-rest/service/runtime/tasks/20005");
//Acepta json
httpPost.setHeader("Accept", "application/json");
//Identificacion para usar rest
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("kermit", "kermit");
httpPost.addHeader(new BasicScheme().authenticate(creds, httpPost));
//Parammetros para enviar por post
List<NameValuePair> arguments = new ArrayList();
BasicNameValuePair action = new BasicNameValuePair("action","complete");
arguments.add(action);
//Envia los parametros
httpPost.setEntity(new UrlEncodedFormEntity(arguments));
//Me muestra el metodo y la url que estoy usando
System.out.println("executing request " + httpPost.getRequestLine());
//Ejecuta todo lo anterior
HttpResponse response = httpClient.execute(httpPost);
//No se
HttpEntity entity = response.getEntity();
//Me muestra el tipo de error o si salio bien
System.out.println("—————————————-");
System.out.println(response.getStatusLine());
if (entity != null) {
System.out.println("Response content length: " + entity.getContentLength());
}
EntityUtils.consume(entity);
} finally {
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
//Cierra la coneccion
httpClient.getConnectionManager().shutdown();
}
}
07-21-2015 01:23 AM
07-21-2015 06:51 AM
07-21-2015 10:00 AM
07-21-2015 04:42 PM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.