cancel
Showing results for 
Search instead for 
Did you mean: 

Activiti 5.16, Camel -> NullPointerException

markuslauer
Champ in-the-making
Champ in-the-making
Hi,

I'm trying to get this to run:
http://bpmn20inaction.blogspot.de/2013/03/using-camel-routes-in-activiti-made.html

Problem: When a Camel ServiceTask is reached in my process, I get:

13:27:16,075 ERROR [io.undertow.request] (default task-57) UT005023: Exception handling request to /camel_activiti_demo/CompleteTask.jsf: javax.servlet.ServletException
   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:659) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]

Caused by: java.lang.NullPointerException
   at org.activiti.camel.CamelBehavior.setAppropriateCamelContext(CamelBehavior.java:222) [activiti-camel-5.16.4.jar:5.16.4]
   at org.activiti.camel.CamelBehavior.execute(CamelBehavior.java:107) [activiti-camel-5.16.4.jar:5.16.4]


activiti.cfg.xml:

   <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
      <property name="dataSource" ref="dataSource" />
      <property name="transactionManager" ref="transactionManager" />
      <property name="databaseSchemaUpdate" value="true" />
      <property name="jobExecutorActivate" value="true" />
   </bean>

   <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
      <property name="processEngineConfiguration" ref="processEngineConfiguration" />
   </bean>

   <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
      <packageScan>
        <package>info.co_met.experiments.camel_activiti_demo.routes</package> –>
      </packageScan>
   </camelContext>


MyCamelRouteBuilder.java

package info.co_met.experiments.camel_activiti_demo.routes;

import org.apache.camel.builder.RouteBuilder;

public class MyCamelRouteBuilder extends RouteBuilder {

  @Override
  public void configure() throws Exception {   
    from("activiti:demoProcess:ServiceTask_1")
      .to("log:hans?level=INFO&showAll=true&multiline=true");
  }
   
}


Process:

<process id="demoProcess" name="comobile Main Process" isExecutable="true">

<serviceTask id="ServiceTask_1" name="ServiceCall" activiti:type="camel"></serviceTask>

</process>




2 REPLIES 2

smirzai
Champ on-the-rise
Champ on-the-rise
I guess are running activiti with getDefaultProcessEngine or you are running a test case with PluggableActiviti test case.
You have to load spring context yourself as mentioned in user guide:
<b>
First the application context is created with any of the Spring ways to do that. In this example you could use a classpath XML resource to configure our Spring application context:
</b>

or in a test case:
<code>
@ContextConfiguration("classpathSmiley Surprisedrg/activiti/spring/test/transaction/SpringTransactionIntegrationTest-context.xml")
</code>

markuslauer
Champ in-the-making
Champ in-the-making
Few hours before your answer I sneaked a peak into "Activiti In Action" and found the Servlet solution.
But thanks, anyway. Smiley Wink

One can find the @ContextConfiguration solution in the tests of activiti-camel, but nowhere is an example which actually runs on an application server, especially wildfly.

For anyone new to Activiti, Spring, Wildfly and the whole Java EE thingy, I will summarize my solution:

I started with the code from Listing 8.1 (p. 171), noticed chapter 8.2 (programmatically configuration of the process engine).
(Had difficulties to set up the listener from xml (8.2.2), but I guess this should work now, too.)

Finally I got Activiti, Camel and Spring integrated with this solution:

<code>
@WebListener
public class ActivitiServletContextListener implements ServletContextListener {

private Logger log = LoggerFactory.getLogger(ActivitiServletContextListener.class);
private ApplicationContext springApplicationContext;

@Override
public void contextInitialized(ServletContextEvent sce) {
  log.info("contextInitialized: starting");
 
  ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  if ( processEngine == null ) {
   throw new RuntimeException("can not initialize context: activiti ProcessEngine not found");
  }
 
  ProcessEngineConfiguration cfg = processEngine.getProcessEngineConfiguration();
  SpringProcessEngineConfiguration springConfiguration = (SpringProcessEngineConfiguration)cfg;

  springApplicationContext = springConfiguration.getApplicationContext();
 
  if ( springApplicationContext == null ) {
   log.info("springApplicationContext is null. creating it from config.");
   springApplicationContext = new ClassPathXmlApplicationContext("activiti.cfg.xml");
   springConfiguration.setApplicationContext(springApplicationContext);
  }
 
  log.info("contextInitialized: finished");
}

@Override
public void contextDestroyed(ServletContextEvent sce) {
  if ( springApplicationContext == null ) {
   throw new RuntimeException("lost springApplicationContext (can not stop camelContext)");
  }
  
  CamelContext camelContext = (CamelContext)springApplicationContext.getBean("camelContext");
  try {
   camelContext.stop();
  } catch (Exception e) {
   throw new RuntimeException("exception while stopping camelContext: " + e.getMessage());
  }
 
  ProcessEngines.destroy();
  log.info("contextDestroyed: finished");
}

}
</code>

Few important points from the configuration activiti.cfg.xml:

<code>
        …

<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
  <property name="dataSource" ref="dataSource" />
  <property name="transactionManager" ref="transactionManager" />
  <property name="databaseSchemaUpdate" value="true" />
  <property name="jobExecutorActivate" value="true" />
</bean>

<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
  <property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>

  <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService"/>

       <bean id="inBoundRoutes" class="info.co_met.experiments.camel_activiti_demo.routes.InBound"/>

<camel:camelContext id="camelContext">
   <camel:routeBuilder ref="inBoundRoutes" />    

<!–   <camelSmiley Tongueackages> –>
<!–    <camelSmiley Tongueackage>info.co_met.experiments.camel_activiti_demo.routes</camelSmiley Tongueackage> –>
<!–   </camelSmiley Tongueackages> –>

</camel:camelContext>
</beans>
</code>

You must not omit "RuntimeService" and I can't get "packageScan", "packages" nor "ContextScan" to work. Had to define my RouteBuilder has bean and reference that.

Additional dependencies: spring-beans, activiti-spring, camel-spring


Now that I got everything up and running with Spring: Is there a way to use Activiti with Camel in Wildfly without Spring (or at least without a SpringApplicationContext)?