cancel
Showing results for 
Search instead for 
Did you mean: 

Manage Workflows from outside Alfresco

isloat
Champ in-the-making
Champ in-the-making
Hi,
I'm using Alfresco 3.4a, I would know how can I use the WorkflowService to complete tasks and manage workflows from outside Alfresco. In particular from a Java Servlet. How I have to connect to use this functions?
(http://dev.alfresco.com/resource/docs/java/repository/org/alfresco/service/cmr/workflow/WorkflowServ...)

I'm working in Alfresco share. I have an option in the documents of "Document Library" (Download, View in Browser, Edit Metadata,…..,MyOption) that redirect to my Java Servlet. There, I use the "WebServiceFactory.getRepositoryService()" to edit the document. But I want to complete a task of the workflow that the document is attached.

Please I would appreciate if you could show an example in Java. Because I have only found answers saying to use Web Scripts, but no code how to do it in Java.
1 REPLY 1

isloat
Champ in-the-making
Champ in-the-making
I have found one way to edit some properties of workflows. Using Workflow REST API introduced in Alfresco 3.4. Unfortunately only a few operations are implemented.
http://wiki.alfresco.com/wiki/Workflow_REST_API

In a java Servlet you can write this code to use the service: (e.g. Edit properties of a task instace)

// Modify task instance
      URL url = new URL("http://alfrescoserver:8080/alfresco/service/api/task-instances/jbpm$60");

      /* METHOD */
      String method = "PUT";

HttpURLConnection connection = (HttpURLConnection) url.openConnection();
      connection.setRequestMethod(method);

      // write auth header
      BASE64Encoder encoder = new BASE64Encoder();
      String encodedCredential = encoder.encode((username + ":" + password).getBytes());
      connection.setRequestProperty("Authorization", "BASIC " + encodedCredential);

      byte buffer[] = new byte[8192];
      int read = 0;

      // write body if we're doing PUT
      String body = "{ \"bpm_description\": \"New Description\", \"bpm_priority\": 3 }";
      connection.setDoOutput(true);
      OutputStream output = connection.getOutputStream();
      output.write(body.getBytes());

      connection.connect();

      InputStream responseBodyStream = connection.getInputStream();
      StringBuffer responseBody = new StringBuffer();
      while ((read = responseBodyStream.read(buffer)) != -1) {
         responseBody.append(new String(buffer, 0, read));
      }
      connection.disconnect();

      System.out.print(responseBody);
      System.out.flush();

I hope it help. But using that I'm not able to end a Task remotely.

Any other idea?

Thanks