Process Variables REST Execution

1,115 views
Skip to first unread message

dinom...@gmail.com

unread,
Mar 24, 2014, 5:55:37 AM3/24/14
to camunda-...@googlegroups.com
Hi

I am starting a process with via a REST request and I am passing the following in Request body

{
"variables": {
"id": {
"value": "201",
"type": "String"
},
"dob": {
"value": "2013-12-27T00: 00",
"type": "Date"
}
}
}

Now the first service task is a JAva Delegate class, and I assume that the execution.getVariables() should return the variables passed in the request body above. Am I right? At the moment the Map returned by execution.getVariables() is empty.

thanks

Christian Lipphardt

unread,
Mar 24, 2014, 3:09:46 PM3/24/14
to camunda-...@googlegroups.com, dinom...@gmail.com
Hi,

Generally you are correct about the variables you can retrieve from the execution via getVariables(), but I could not reproduce your issue, maybe some more code will help.
I was to start a process instance by id / key and both worked. But they only worked after I changed your date into a compatible parser format (2013-12-27T00:00:00 instead of 2013-12-27T00: 00)

Cheers,
Christian

dinom...@gmail.com

unread,
Mar 25, 2014, 4:21:07 AM3/25/14
to camunda-...@googlegroups.com, dinom...@gmail.com
Hi
I changed the date format as you said but still doesn't work. I am now passing the following in the request body

{
"variables":{
"id": {
"value": "201",
"type": "String"
},
"dob": {

"value": "2013-12-27T00:00:00",
"type": "Date"
}
}
}


Also the following is my process definition.

<bpmn2:process id="validationProcess" name="Validation process">

<bpmn2:extensionElements>
<camunda:executionListener delegateExpression="${validationListener}" event="end" />
</bpmn2:extensionElements>

<bpmn2:startEvent id="theStart" />

<bpmn2:sequenceFlow id="flow1" sourceRef="theStart" targetRef="validateDate" />


<bpmn2:serviceTask id="validateDate" name="validate Date is between two months"
camunda:class="com.cif.poc.activiti.process.validation.ValidateDate">
</bpmn2:serviceTask>

<bpmn2:sequenceFlow id="flow2" sourceRef="validateDate" targetRef="updateUser"/>

<bpmn2:serviceTask id="updateUser" name="updateUser"
camunda:expression="#{userService.updateUser()}">
</bpmn2:serviceTask>

<bpmn2:sequenceFlow id="flow3" sourceRef="updateUser" targetRef="theEnd" />



<bpmn2:endEvent id="theEnd" />

</bpmn2:process>

</bpmn2:definitions>


And the first service task java Delegate is as follows which has the execution.getVariables() empty

public class ValidateDate implements JavaDelegate {

private final static Logger LOGGER = Logger.getLogger(ValidateDate.class.getName());

@Override
public void execute(DelegateExecution execution) throws Exception {
LOGGER.warning("THIS IS A TEST FROM VALIDATION PROCESS" + execution.getId());

Iterator<Map.Entry<String, Object>> it =execution.getVariables().entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, Object> pairs = (Map.Entry<String, Object>)it.next();
System.out.println(pairs.getKey() + " = " + pairs.getValue());
}

execution.setVariable("validationPassed", true);

}

}

Also I noticed that when I try to get the process definitions with /process-definition . I get a list of empty JSON objects as follows

[{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}]

thanks

Christian Lipphardt

unread,
Mar 25, 2014, 4:25:57 AM3/25/14
to camunda-...@googlegroups.com, dinom...@gmail.com
Could you please describe your environment? 

- Which distribution do you use? (prepackaged as in downloaded from our website or vanilla, where you setup the platform yourself).
- What kind of process engine architecture do you use? (Embedded Engine, Shared Engine)
- What kind of process application do you use? (Spring Process Application, CDI, EJB, Servlet)

Cheers,
Christian

dinom...@gmail.com

unread,
Mar 25, 2014, 4:47:58 AM3/25/14
to camunda-...@googlegroups.com, dinom...@gmail.com
I am using a vanilla glassfish and I add the Camunda Rest dependencies.
I am using a CdiStandaloneProcessEngineConfiguration as follows

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="processEngineConfiguration" class="org.camunda.bpm.engine.cdi.CdiStandaloneProcessEngineConfiguration">

<property name="jdbcUrl" value="jdbc:postgresql://localhost:5432/camunda" />
<property name="jdbcDriver" value="org.postgresql.Driver" />
<property name="jdbcUsername" value="camunda" />
<property name="jdbcPassword" value="camunda" />

<property name="databaseSchemaUpdate" value="true" />

<property name="jobExecutorActivate" value="false" />

<property name="mailServerHost" value="mail.my-corp.com" />
<property name="mailServerPort" value="5025" />

<property name="customPostBPMNParseListeners">
<list>
<bean class="org.camunda.bpm.engine.cdi.impl.event.CdiEventSupportBpmnParseListener" />
</list>
</property>
</bean>

</beans>

Also I added the Camunda Rest dependencies to my web application and exposed the services as follows

@ApplicationPath("/engine-rest")
public class MyApplication extends Application {

@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<Class<?>>();

classes.add(org.camunda.bpm.engine.rest.impl.ProcessEngineRestServiceImpl.class);
classes.add(org.camunda.bpm.engine.rest.impl.ProcessDefinitionRestServiceImpl.class);
classes.add(org.camunda.bpm.engine.rest.impl.ProcessInstanceRestServiceImpl.class);
classes.add(org.camunda.bpm.engine.rest.impl.TaskRestServiceImpl.class);
classes.add(org.camunda.bpm.engine.rest.impl.IdentityRestServiceImpl.class);
classes.add(org.camunda.bpm.engine.rest.impl.MessageRestServiceImpl.class);
classes.add(org.camunda.bpm.engine.rest.impl.JobRestServiceImpl.class);
classes.add(org.camunda.bpm.engine.rest.impl.ExecutionRestServiceImpl.class);
classes.add(org.camunda.bpm.engine.rest.impl.VariableInstanceRestServiceImpl.class);
classes.add(org.camunda.bpm.engine.rest.impl.UserRestServiceImpl.class);
classes.add(org.camunda.bpm.engine.rest.impl.GroupRestServiceImpl.class);
classes.add(org.camunda.bpm.engine.rest.impl.AuthorizationRestServiceImpl.class);
classes.add(org.camunda.bpm.engine.rest.impl.history.HistoryRestServiceImpl.class);

classes.add(org.camunda.bpm.engine.rest.mapper.JacksonConfigurator.class);
classes.add(org.camunda.bpm.engine.rest.exception.RestExceptionHandler.class);
classes.add(org.camunda.bpm.engine.rest.exception.ProcessEngineExceptionHandler.class);
return classes;
}
}

Christian Lipphardt

unread,
Mar 25, 2014, 4:57:38 AM3/25/14
to camunda-...@googlegroups.com, dinom...@gmail.com
What version of Glassfish? (3.x / 4.x)


Could you please provide your pom.xml / web.xml ?

Sorry for asking so many questions, but is hard to diagnose without a test project.

Cheers,
Christian

Dino Mifsud

unread,
Mar 25, 2014, 5:07:52 AM3/25/14
to Christian Lipphardt, camunda-...@googlegroups.com
Sure no problem


I am using Glassfish 4.0

The pom.xml dependencies are

    <dependencies>

        <!-- <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-engine</artifactId>
            <version>5.14</version> </dependency> -->

        <!-- Camunda -->
        <dependency>
            <groupId>org.camunda.bpm</groupId>
            <artifactId>camunda-engine</artifactId>
            <version>7.0.0-Final</version>
        </dependency>
        <dependency>
            <groupId>org.camunda.bpm</groupId>
            <artifactId>camunda-engine-cdi</artifactId>
            <version>7.0.0-Final</version>
        </dependency>
        <dependency>
            <groupId>org.camunda.bpm.javaee</groupId>
            <artifactId>camunda-ejb-client</artifactId>
            <version>7.0.0-Final</version>
        </dependency>
        <dependency>
            <groupId>org.camunda.bpm</groupId>
            <artifactId>camunda-engine-rest</artifactId>
            <classifier>classes</classifier>
            <version>7.0.0-Final</version>
        </dependency>


        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-jdk14</artifactId>
            <version>1.7.5</version>
        </dependency>

        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>

        <!-- SHIRO -->
        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-core</artifactId>
            <version>1.2.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-web</artifactId>
            <version>1.2.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-aspectj</artifactId>
            <version>1.2.1</version>
        </dependency>

    </dependencies>

The web.xml is


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  <display-name>POCJEE_SOCKETS</display-name>
  <listener>
    <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
  </listener>
  <filter>
    <filter-name>ShiroFilter</filter-name>
    <filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>ShiroFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    <dispatcher>ERROR</dispatcher>
  </filter-mapping>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>

Then I have the following Servlet context listener to start/deploy/destroy the engine

@WebListener
public class ActivitiServletContextListener implements ServletContextListener {

    private static final Logger logger = Logger
            .getLogger(ActivitiServletContextListener.class.getName());

    @Override
    public void contextDestroyed(ServletContextEvent arg0) {
        logger.log(Level.INFO, "DESTROYING PROCESS ENGINE");
        ProcessEngines.destroy();

    }

    @Override
    public void contextInitialized(ServletContextEvent arg0) {
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        if (processEngine == null) {
            logger.log(Level.SEVERE, "Could not start the Camunda Process Engine");
        } else {

            deployProcess();
        }

    }

    private void deployProcess() {
        logger.log(Level.INFO, "DEPLOYING PROCESS");
        ProcessEngines.getDefaultProcessEngine().getRepositoryService().createDeployment()
                .addClasspathResource("ValidationProcess.bpmn20.xml").deploy();

    }

}

Christian Lipphardt

unread,
Mar 25, 2014, 9:13:59 AM3/25/14
to camunda-...@googlegroups.com, Christian Lipphardt, dinom...@gmail.com
Hi Dino,

please add the following class to your MyApplication class

    classes.add(ProcessEngineRestServiceImpl.class);
   classes.add(ProcessDefinitionRestServiceImpl.class);
   classes.add(ProcessInstanceRestServiceImpl.class);
   classes.add(TaskRestServiceImpl.class);
   classes.add(IdentityRestServiceImpl.class);
   classes.add(MessageRestServiceImpl.class);
   classes.add(JobRestServiceImpl.class);
   classes.add(ExecutionRestServiceImpl.class);
   classes.add(VariableInstanceRestServiceImpl.class);
   classes.add(UserRestServiceImpl.class);
   classes.add(GroupRestServiceImpl.class);
   classes.add(AuthorizationRestServiceImpl.class);
   classes.add(HistoryRestServiceImpl.class);

    classes.add(JacksonConfigurator.class);

    classes.add(JacksonJsonProvider.class);
   classes.add(JsonMappingExceptionMapper.class);
   classes.add(JsonParseExceptionMapper.class);

    classes.add(ProcessEngineExceptionHandler.class);
   classes.add(RestExceptionHandler.class);

It seems to me you are missing some classes from the 7.0.0-Final release. Did you get those classes from our documentation?
Beginning with 7.1.0-Final we introduce a class CamundaRestResources in the REST API, which provides all classes for easier setup when you want to embed the REST API into your own application.

Cheers,
Christian

Dino Mifsud

unread,
Mar 26, 2014, 4:12:26 AM3/26/14
to Christian Lipphardt, camunda-...@googlegroups.com
Yes I got that list from the link 

http://docs.camunda.org/latest/api-references/rest/

Dino Mifsud

unread,
Mar 26, 2014, 5:07:11 AM3/26/14
to Christian Lipphardt, camunda-...@googlegroups.com
I added those classes to MyApplication, but still not process variables and no processdefinitions.

thanks

Christian Lipphardt

unread,
Mar 26, 2014, 5:36:11 AM3/26/14
to camunda-...@googlegroups.com
Hi Dino,

Can you provide a test project so I can reproduce the issue?

Cheers,
Christian

Dino Mifsud

unread,
Mar 26, 2014, 5:51:32 AM3/26/14
to camunda-...@googlegroups.com
Hi
I have sent you a pom.xml and src folder. I removed the frontend which was huge because of JAvascript libraries and images. I also commented out the shiro in  the web.xml to remove the security.
Let me know if you need something else

thanks




--
You received this message because you are subscribed to a topic in the Google Groups "camunda BPM users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/camunda-bpm-users/BnUxqnxwo5k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to camunda-bpm-users+unsubscribe@googlegroups.com.
To post to this group, send email to camunda-bpm-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/camunda-bpm-users/53329F8B.9050105%40googlemail.com.
For more options, visit https://groups.google.com/d/optout.

TestProj.zip

Christian Lipphardt

unread,
Mar 26, 2014, 11:05:39 AM3/26/14
to camunda-...@googlegroups.com, dinom...@gmail.com
Hi Dino,

Glassfish 4 uses Moxy as JSON Provider by default and we use Jackson. There seems to be a glitch with Moxy when using it with our REST API as a JSON Provider.
I solved the issue by adding

    <dependency>
     
<groupId>org.glassfish.jersey.media</groupId>
     
<artifactId>jersey-media-json-jackson</artifactId>
     
<version>2.0</version>
     
<scope>provided</scope>
   
</dependency>

to your pom.xml and adding

classes.add(JacksonFeature.class);

to your JAX-RS application class (com.cif.poc.activiti.conf.MyApplication).
Then the REST API worked.

{"variables": 
   
{"user" : {"value" : "myGlassfishUser", "type": "String"},
     
"anotherVariable" : {"value" : true, "type": "Boolean"}},
 
"businessKey" : "myBusinessKey"
}
as request body. The 'PROCESS_DEFINITION_ID' can be retrieved using GET http://localhost:8080/POCJEE_SOCKETS/engine-rest/process-definition/ .
Given variables will be printed out by your java delegate.

Then I ran into a NPE during process execution:
Caused by: java.lang.NullPointerException
at com.cif.poc.activiti.servicetasks.UserService.updateUser(UserService.java:33)

Maybe you can solve it from there?

Cheers,
Christian




Dino Mifsud

unread,
Mar 26, 2014, 11:26:41 AM3/26/14
to Christian Lipphardt, camunda-...@googlegroups.com
Yes Christian,


I know there are other problems...I will continue from there. I will check your solution and let you know

thanks
Dino
Reply all
Reply to author
Forward
0 new messages