4

I want to develop an app preferbly on servlet environment . I want to trigger alfresco out of box workflow webscripts from my app. Alfresco has provided restful URL for doing that.

can anyone tell me how do i invoke the rest URL to invoke the webscripts from my java code.

can anyone pls give me a sample code or manual for that as I have limited experience in webservice.

I need bit clear and detailed explaination..

Thanks

Padmanabha Vn
  • 624
  • 1
  • 14
  • 33

5 Answers5

8

You could use the Apache HTTP Client library to perform RESTful (JSON requests/posts).

Here is a tutorial how to do a post/get to an Alfresco like server: RESTful Java client

Replace the example url's with the Alfresco urls defined in the Workflow REST API. Furthermore before you do all this, you need to authenticate to Alfresco.

  1. Use the same HTTP Client example to get the ticket with url http://localhost:8080/alfresco/service/api/login?u=admin&pw=admin
  2. You will get a response like: <ticket>TICKET_887add1e01b5c4c0cd58ac11c768f8e54c1eabf4</ticket>
  3. Save the ticket value of the element in a Java variable
  4. Use the ticket with one of the workflow REST API services e.g. http://localhost:8080/alfresco/service/api/workflow-definitions so present the Ticket like following: http://localhost:8080/alfresco/service/api/workflow-definitions?alf_ticket=TICKET_887add1e01b5c4c0cd58ac11c768f8e54c1eabf4
  5. Do whatever you'd like with the result :)
Tahir Malik
  • 6,623
  • 15
  • 22
4

Look here for detailed description of Workflow REST API: http://wiki.alfresco.com/wiki/Workflow_REST_API

Here's for example how to start a workflow: http://wiki.alfresco.com/wiki/Workflow_REST_API#Post_Workflow_Instance

Examples:

Calling alfresco REST services using spring: http://tedwise.com/2010/06/14/accessing-rest-services-from-spring-3/

Matjaz Muhic
  • 5,328
  • 2
  • 16
  • 34
  • thanks for the reply .. I saw the rest url they provide for start workflow etc.. but i need a sample java code to invoke the web service url and get the response.. bit detailed since i have very little exp in web service – Padmanabha Vn Nov 27 '11 at 14:51
  • If you're using spring you can look at this: http://tedwise.com/2010/06/14/accessing-rest-services-from-spring-3/ And here's the quick sample: http://leejava.wordpress.com/2009/09/02/consuming-a-rest-web-service/ – Matjaz Muhic Nov 29 '11 at 09:32
3

Alfresco doesn't expose any SOAP web service related to workflows. The preferred remote interface to workflows is a set of web scripts you can list at http://your.alfresco.url/alfresco/service/index/uri/ as:

/api/workflow/task/end/{taskId}
/api/workflow/task/end/{taskId}/{transitionId}
/api/workflow-definitions
/api/workflow-definitions/{workflow_definition_id}/workflow-instances
/api/workflow-instances
/api/workflow-instances/{workflow_instance_id}
/api/workflow-instances/{workflow_instance_id}/task-instances

Please note that those URLs are much more like families of APIs, and the links will show you more than one effective remote API call per item, possibly responding to different HTTP verbs (e.g. GET, POST, DELETE) or including more input parameters in the URL template.

skuro
  • 13,414
  • 1
  • 48
  • 67
  • thanks skuro.. I need a sample java code to send request and get respose from the alfresco workflow webscripts .. and the libraries i want to include in my classpath.. as I told have very less exp in web service – Padmanabha Vn Nov 27 '11 at 14:48
1

The example with jar you can find below as per Tahir suggestion. It will provide response for home folder and subfolder. You can put your respective url to get jason response.

https://drive.google.com/file/d/0B9B1NsG0lyx6Tno2d1F6RElrTk0/edit?usp=sharing

Tushar Patel
  • 573
  • 3
  • 17
1

Here is a sample Web Script to achieve this. The script can can be invoked using the URL

http://<server>:<port>/alfresco/service/workflows/approveandreview/start/

This will start the Review & Approve workflow on the node specified by the path in the URL (after /start).

You can use Apache HTTPClient to call the URL from Java code.


StartWorkflow.get.desc.xml

<webscript>
  <shortname>Start Review and Approve Workflow</shortname>
  <description>Script to start Review and Approve Workflow on a Node</description>
  <url>/workflows/approveandreview/start/{path}</url>
  <format default="xml">argument</format>
  <authentication>user</authentication>
  <transaction>required</transaction>
</webscript>

StartWorkflow.get.js

// Get the node on which workflow is to be started
var theNode = roothome.childByNamePath(url.extension);

logger.log("theNode=" + theNode);

if (theNode == undefined) {
    status.code = 404;
    status.message = "Node at " + url.extension + " does not exist";
    status.redirect = true;
}
else if (theNode.isContainer) {
    status.code = 404;
    status.message = "Node at " + url.extension + " is not a content node";
    status.redirect = true;
}
else {
    var workflowPackage = workflow.createPackage();
    workflowPackage.addNode(theNode);
    var workflowDef = workflow.getDefinitionByName("activiti$activitiReview");
    var parameters = new Object();
    parameters["bpm:assignee"] = person;
    var workflowPath = workflowDef.startWorkflow(workflowPackage, parameters);

    if (workflowPath == undefined) {
        status.code = 500;
        status.message = "Error starting workflow";
        status.redirect = true;
    }

    status.message = "Done";
}

StartWorkflow.get.xml.ftl

<?xml version="1.0" encoding="UTF-8"?>
<approveandreview>
    <status>${status.code}</status>
    <message>${status.message}</message>
</approveandreview>

Hope this helps. Let me know if any issues.

aniruddhc
  • 320
  • 1
  • 3
  • 15