AnsweredAssumed Answered

Help REST java

Question asked by leandro1 on Jul 20, 2015
Latest reply on Jul 21, 2015 by leandro1
Hello everyone . I am new to this and have a problem with Activiti Rest.
I show them what I have:

1-

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


This only tells me that works. I would love to know how to get the data from that task and manipulate from java

2-

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


this returns error
HTTP/1.1 415 Media Type Not Supported

thank you!
Sorry for my bad english

Outcomes