cancel
Showing results for 
Search instead for 
Did you mean: 

NPE with REST and Camel

mallux
Champ in-the-making
Champ in-the-making
Hi

When starting a camel process instance from a rest post, I'm getting a Null Pointer Exception on the receive - so the instance gets stuck waiting for a receive which never arrives.  I can invoke the same process from explorer and it completes fine.

I've reproduced this using the async Camel example (https://github.com/Activiti/Activiti/blob/activiti-5.13/modules/activiti-camel/src/test/resources/pr...) - the stack trace is below.  Am I doing something daft?

thanks
Chris


03:28:27,515 [Camel (camelContext) thread #3 - seda://asyncQueue2] DEBUG org.apache.camel.processor.SendProcessor  - >>>> Endpoint[seda://receiveQueue] Exchange[Message: [Body is null]]
03:28:27,515 [Camel (camelContext) thread #2 - seda://asyncQueue] DEBUG org.apache.camel.processor.SendProcessor  - >>>> Endpoint[seda://receiveQueue] Exchange[Message: [Body is null]]
03:28:27,521 [Camel (camelContext) thread #4 - seda://receiveQueue] DEBUG org.apache.camel.impl.DefaultComponent  - Creating endpoint uri=[activiti://asyncCamelProcess:receive2], path=[asyncCamelProcess:receive2]
03:28:27,525 [Camel (camelContext) thread #4 - seda://receiveQueue] DEBUG org.apache.camel.spring.SpringCamelContext  - activiti://asyncCamelProcess:receive2 converted to endpoint: Endpoint[activiti://asyncCamelProcess:receive2] by component: org.activiti.camel.ActivitiComponent@10bcc8f4
03:28:27,526 [Camel (camelContext) thread #4 - seda://receiveQueue] DEBUG org.apache.camel.impl.ProducerCache  - Adding to producer cache with key: Endpoint[activiti://asyncCamelProcess:receive2] for producer: Producer[activiti://asyncCamelProcess:receive2]
03:28:27,533 [Camel (camelContext) thread #4 - seda://receiveQueue] DEBUG org.apache.camel.processor.DefaultErrorHandler  - Redelivery enabled: false on error handler: DefaultErrorHandler[Producer[activiti://asyncCamelProcess:receive2]]
03:28:27,546 [Camel (camelContext) thread #4 - seda://receiveQueue] DEBUG org.apache.camel.processor.DefaultErrorHandler  - Failed delivery for (MessageId: ID-activapp-2ed77445-eb8c-4f6a-86e3-b6ef5923d024-34620-1372260329571-0-4 on ExchangeId: ID-activapp-2ed77445-eb8c-4f6a-86e3-b6ef5923d024-34620-1372260329571-0-8). On delivery attempt: 0 caught: java.lang.NullPointerException
03:28:27,550 [Camel (camelContext) thread #4 - seda://receiveQueue] ERROR org.apache.camel.processor.DefaultErrorHandler  - Failed delivery for (MessageId: ID-activapp-2ed77445-eb8c-4f6a-86e3-b6ef5923d024-34620-1372260329571-0-4 on ExchangeId: ID-activapp-2ed77445-eb8c-4f6a-86e3-b6ef5923d024-34620-1372260329571-0-8). Exhausted after delivery attempt: 1 caught: java.lang.NullPointerException
java.lang.NullPointerException
   at org.activiti.camel.ActivitiProducer.signal(ActivitiProducer.java:59)
   at org.activiti.camel.ActivitiProducer.process(ActivitiProducer.java:49)
   at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
   at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
   at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:390)
   at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:273)
   at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:46)
   at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
   at org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:150)
   at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:117)
   at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
   at org.apache.camel.processor.MulticastProcessor.doProcessSequential(MulticastProcessor.java:571)
   at org.apache.camel.processor.MulticastProcessor.doProcessSequential(MulticastProcessor.java:504)
   at org.apache.camel.processor.MulticastProcessor.process(MulticastProcessor.java:213)
   at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
   at org.apache.camel.processor.RecipientList.sendToRecipientList(RecipientList.java:151)
   at org.apache.camel.processor.RecipientList.process(RecipientList.java:112)
   at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
   at org.apache.camel.processor.Pipeline.process(Pipeline.java:117)
   at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
   at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
   at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
   at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
   at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
   at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
   at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
   at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
   at org.apache.camel.processor.interceptor.BacklogTracerInterceptor.process(BacklogTracerInterceptor.java:84)
   at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
   at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
   at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
   at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:91)
   at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
   at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:390)
   at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:273)
   at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:46)
   at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
   at org.apache.camel.processor.interceptor.DefaultChannel.process(DefaultChannel.java:335)
   at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:46)
   at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
   at org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:150)
   at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:117)
   at org.apache.camel.processor.RouteInflightRepositoryProcessor.processNext(RouteInflightRepositoryProcessor.java:48)
   at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
   at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
   at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
   at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
   at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
   at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
   at org.apache.camel.component.seda.SedaConsumer.sendToConsumers(SedaConsumer.java:275)
   at org.apache.camel.component.seda.SedaConsumer.doRun(SedaConsumer.java:183)
   at org.apache.camel.component.seda.SedaConsumer.run(SedaConsumer.java:139)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
   at java.lang.Thread.run(Thread.java:679)


camel context:


    <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
        <packageScan>
            <package>org.activiti.camel.route</package>
        </packageScan>
    </camelContext>

    <bean id="sleepBean" class="org.activiti.camel.util.SleepBean"/>


route:


    from("activiti:asyncCamelProcess:serviceTaskAsync1").setHeader("destination", constant("activiti:asyncCamelProcess:receive1")).to("seda:asyncQueue");
    from("seda:asyncQueue").to("bean:sleepBean?method=sleep").to("seda:receiveQueue");

    from("activiti:asyncCamelProcess:serviceTaskAsync2").setHeader("destination", constant("activiti:asyncCamelProcess:receive2")).to("seda:asyncQueue2");
    from("seda:asyncQueue2").to("bean:sleepBean?method=sleep").to("seda:receiveQueue");

    from("seda:receiveQueue").recipientList(header("destination"));


POST body:

{
   "processDefinitionKey":"asyncCamelProcess",
   
   "variables" : [ ]
}
3 REPLIES 3

trademak
Star Contributor
Star Contributor
Hi Chris,

Did you add the camel context definition to the activiti-context.xml file in the Activiti REST application?

Best regards,

mallux
Champ in-the-making
Champ in-the-making
Hi Tijs

Yes I added this to the activit-context.xml:

<import resource="activiti-camel-context.xml" />

and that file contains:

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

    <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
        <packageScan>
            <package>org.activiti.camel.route</package>
        </packageScan>
    </camelContext>
    <bean id="sleepBean" class="org.activiti.camel.util.SleepBean"/>
</beans>

The routes seem to be being loaded ok during startup, and I can see the bean executing if I add some debug statements, which would seem to indicate that there is nothing fundamentally wrong with the camel part.

I'll see if I can put together a unit test which demonstrates the problem.

Chris

smirzai
Champ on-the-rise
Champ on-the-rise
This might be the cure.
https://github.com/Activiti/Activiti/pull/126

Could you test if it fixes your problem ?

– Saeid