Alfresco WebScript and Activiti API

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Established Member

Alfresco WebScript and Activiti API

I would like to use activiti API in an Alfresco JAVA Webscript to query some process variables (runtime and historical). I use Spring ApplicationContextAware interface to get instanciate ActivitiUtil class like this:

ActivitiUtil getActivitiUtilInstance (){
     try {
         ProcessEngine processEngine = (ProcessEngine) this.applicationContext.getBean("activitiProcessEngine");
         if (processEngine == null){
          logger.error ("processEngine is null !");
          return null;
         }else{
          return (new ActivitiUtil(processEngine, this.deployWorkflowsInTenant));
         }
     }catch(Exception e){
      e.printStackTrace();
      return null;
     }
    }

This is OK but when calling any method (eg: activitiUtil.getRuntimeService().getVariables(activitiProcessInstance)), following exception is thrown:

A valid SecureContext was not provided in the RequestContext

Same issue when enforcing user context using 'AuthenticationUtil.runAs'

Any idea ?

4 Replies
Highlighted
Master

Re: Alfresco WebScript and Activiti API

You should (typically) not be calling the low-level Activiti APIs directly, instead using the Alfresco WorkflowService as an abstraction over the workflow engine. Additionally, you may be facing such issues because your web script may not be marked as requiring an authentication context and so you do not have a fully logged-in user. AuthenticationUtil.runAs should be a fix to that in most cases, but should generally be considered a dirty cludge unless you have a specific business requirement to execute code in the context of a specific user. Also note that AuthenticationUtil.runAs will not help you for any functionality that may trigger transaction-level behaviour because such "semi-asynch" logic will be run outside of the runAs-context and as a result continue to result in the same error if that async-logic needs to have a valid security context.

Highlighted
Established Member

Re: Alfresco WebScript and Activiti API

Webscript controllers are defined with: <authentication>user</authentication>, which should require and authentication context. Am I wrong ?

Something that's unclear for me: my webscript is calling WorkflowService which is instantiating ActivitiUtil helper class, getting actitivi API services and to call API methods , without any user context Exception.

Why instantiating ActivitiUtil directly in my WS and calling activiti API should be an issue ?

Thanks for your help

Highlighted
Master

Re: Alfresco WebScript and Activiti API

Keep in mind that Alfresco services also add AOP handling, i.e. transaction/security management. It is generally not a good idea to work around them unless you really understand the technical details.

Highlighted
Established Member

Re: Alfresco WebScript and Activiti API

OK Thanks for your advise.

I'm facing a simple business need: I want to query worklows on process variables (not task) during its whole lifecycle.

Then using workflow service, I can:

- get start task properties to get 'static' view of process variables set at startup

- get path properies to get execution and parent process variables (at run time)

- but how to access these process variables after runtime (historical data) ?

Thanks.