cancel
Showing results for 
Search instead for 
Did you mean: 

How to trigger a Process from APS when an E-mail comes to ACS ?

amitkulhari26
Confirmed Champ
Confirmed Champ

I have created a Process for Alfresco Process Service and now I want to trigger it from Alfresco Content Service when, an E-mail comes to Alfresco Content Service, how it's possible?

22 REPLIES 22

afaust
Legendary Innovator
Legendary Innovator

And can you provide more details to your error, i.e. the original exception stacktrace / response?

It shows: package(com.activiti.alfresco.service) does not exist, which I have used in my package. 

afaust
Legendary Innovator
Legendary Innovator

Don't use it then. It sounds like a package that would only be available within APS itself, but now your are writing code inside ACS.

Could you please provide me some guidance or some example, like how I supposed to do this in ACS?

afaust
Legendary Innovator
Legendary Innovator

I haven't accessed APS from ACS myself, so don't have any ready-to-use code samples. But just use any Java-based tooling for doing REST calls and use the APS ReST API. Don't rely on any APS-internal APIs which are not available in ACS. Build your own little REST client abstraction, i.e. backed by libraries like resteasy, jackson or any other in that domain.

Hi again,

now I am trying to start the process by the following code but getting: Caused by: java.lang.RuntimeException: Failed  : HTTP error code : 401

 

private Behaviour onCreateNode;

public void init() {
this.onCreateNode = new JavaBehaviour(this, "onCreateNode", NotificationFrequency.TRANSACTION_COMMIT);

this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateNode"), ContentModel.TYPE_CONTENT, this.onCreateNode);
}

@Override
public void onCreateNode(ChildAssociationRef childasso) {

NodeRef node=childasso.getChildRef();

System.out.println(node);

System.out.println(childasso.getQName());


try {
URL url = new URL("localhost:9090/activiti-app/api/enterprise/process-instances");

HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");

String input = "{\"processDefinitionId\":\"adhoctask:1:13\"}";
OutputStream os = conn.getOutputStream();
os.write(input.getBytes());
os.flush();

if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));

String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
}


conn.disconnect();

}catch (MalformedURLException e) {

e.printStackTrace();

}catch (IOException e) {

e.printStackTrace();

}

could you please correct me?

afaust
Legendary Innovator
Legendary Innovator

Could you please provide the real error? I.e. look into alfresco.log for the details, because the screenshot only shows a wrapped message...

Actually, I am getting two errors in the log while compiling, which are in the following screenshot.

afaust
Legendary Innovator
Legendary Innovator

So there you have it - you are throwing that error yourself because you get a 401 response code... Your custom code isn't handling authentication.

So could you please pointer me where should I suppose to change in my code to trigger the process?