2

I'm trying to make a twitter app using mule+drools fusion, but I'm getting a null pointer exception in the rhs of one specific rule, "Tweet a caso sospechoso." I can't figure out.

I think that the drools engine is retracting tweet events early. When I need to use a tweet event in the rhs, the event doesn't exist any more.

import java.util.ArrayList;
import org.mule.MessageExchangePattern;
import clases.*;
global org.mule.module.bpm.MessageService mule;
declare Tweet
    @role ( event )                 
end

declare Gripe
    @role ( event )                 
end

declare Sospechoso
    @role ( event )                 
end

rule "Tweet a Gripe"
    when
        $t:Tweet($us:usuario, texto matches "\.*gripe.*") from entry-point "Flujo Tweets"
        not (Gripe(usuario==$us) from entry-point "Casos Confirmados")
    then
        Sospechoso s = new Sospechoso(TiposSintomas.GRIPE,$t);        
        Gripe g = new Gripe(s);        
        entryPoints["Casos Confirmados"].insert(g);
        mule.generateMessage("mensajes",g, null, MessageExchangePattern.ONE_WAY); 
end


rule "Tweet a caso sospechoso"
    when        
        $t:Tweet(texto not matches "\.*gripe.*",$us:usuario) from entry-point "Flujo Tweets"        
        $s:SintomaGripe($t.texto matches regexp,$tip:tipo)
        not (Sospechoso(usuario==$us,tipo==$tip) from entry-point "Casos Sospechosos")
        not (Gripe(usuario==$us) from entry-point "Casos Confirmados")              
    then
        Sospechoso s = new Sospechoso($s.getTipo(),$t);                     
        entryPoints["Casos Sospechosos"].insert(s); 
        mule.generateMessage("mensajes",s, null, MessageExchangePattern.ONE_WAY);       
end


rule "Sospechosos a Gripe"
    when
        $s:Sospechoso($us:usuario) from entry-point "Casos Sospechosos"
        not(Gripe(usuario==$us) from entry-point "Casos Confirmados")
        $casos:ArrayList(size >= 3)
               from collect (Sospechoso(usuario==$us) from entry-point "Casos Sospechosos")         
    then
        Gripe g = new Gripe($casos);        
        entryPoints["Casos Confirmados"].insert(g); 
        mule.generateMessage("mensajes",g, null, MessageExchangePattern.ONE_WAY);   
end

StackTrace

ERROR 2012-11-24 22:15:09,051 [[ceptwitter].Flujo1.stage2.02] org.mule.exception.DefaultMessagingExceptionStrategy: 
********************************************************************************
Message               : Failed to invoke RulesComponent{Flujo1.commponent.24742184}. Component that caused exception is: RulesComponent{Flujo1.commponent.24742184}. Message payload is of type: Tweet
Type                  : org.mule.component.ComponentException
Code                  : MULE_ERROR--2
Payload               : clases.Tweet@1e5627c
JavaDoc               : http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/component/ComponentException.html
********************************************************************************
Exception stack is:
1. null (java.lang.NullPointerException)
  clases.Tweet:8 (null)
2. java.lang.NullPointerException (org.drools.runtime.rule.ConsequenceException)
  org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler:23 (null)
3. Failed to invoke RulesComponent{Flujo1.commponent.24742184}. Component that caused exception is: RulesComponent{Flujo1.commponent.24742184}. Message payload is of type: Tweet (org.mule.component.ComponentException)
  org.mule.component.AbstractComponent:148 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/component/ComponentException.html)
********************************************************************************
Root Exception stack trace:
java.lang.NullPointerException
    at clases.Tweet.<init>(Tweet.java:8)
    at clases.Sospechoso.<init>(Sospechoso.java:9)
    at defaultpkg.Rule_Tweet_a_caso_sospechoso_0.consequence(Rule_Tweet_a_caso_sospechoso_0.java:7)
    at defaultpkg.Rule_Tweet_a_caso_sospechoso_0ConsequenceInvoker.evaluate(Rule_Tweet_a_caso_sospechoso_0ConsequenceInvoker.java:29)
    at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:934)
    at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:885)
    at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1086)
    at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:660)
    at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:627)
    at org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:183)
    at org.mule.module.drools.Drools.assertEvent(Drools.java:167)
    at org.mule.module.bpm.Rules.handleEvent(Rules.java:131)
    at org.mule.module.bpm.RulesComponent.doInvoke(RulesComponent.java:84)
    at org.mule.component.AbstractComponent.invokeInternal(AbstractComponent.java:126)
    at org.mule.component.AbstractComponent.access$000(AbstractComponent.java:61)
    at org.mule.component.AbstractComponent$1$1.process(AbstractComponent.java:242)
    at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
    at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:43)
    at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:43)
    at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
    at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:43)
    at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:43)
    at org.mule.component.AbstractComponent.process(AbstractComponent.java:160)
    at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
    at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:43)
    at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:43)
    at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
    at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:43)
    at org.mule.interceptor.AbstractEnvelopeInterceptor.process(AbstractEnvelopeInterceptor.java:55)
    at org.mule.processor.AsyncInterceptingMessageProcessor.processNextTimed(AsyncInterceptingMessageProcessor.java:116)
    at org.mule.processor.AsyncInterceptingMessageProcessor$AsyncMessageProcessorWorker$1.process(AsyncInterceptingMessageProcessor.java:171)
    at org.mule.processor.AsyncInterceptingMessageProcessor$AsyncMessageProcessorWorker$1.process(AsyncInterceptingMessageProcessor.java:165)
    at org.mule.execution.ExecuteCallbackInterceptor.execute(ExecuteCallbackInterceptor.java:20)
    at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:34)
    at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:18)
    at org.mule.execution.BeginAndResolveTransactionInterceptor.execute(BeginAndResolveTransactionInterceptor.java:58)
    at org.mule.execution.ResolvePreviousTransactionInterceptor.execute(ResolvePreviousTransactionInterceptor.java:48)
    at org.mule.execution.SuspendXaTransactionInterceptor.execute(SuspendXaTransactionInterceptor.java:54)
    at org.mule.execution.ValidateTransactionalStateInterceptor.execute(ValidateTransactionalStateInterceptor.java:44)
    at org.mule.execution.IsolateCurrentTransactionInterceptor.execute(IsolateCurrentTransactionInterceptor.java:44)
    at org.mule.execution.ExternalTransactionInterceptor.execute(ExternalTransactionInterceptor.java:52)
    at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:32)
    at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:17)
    at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:113)
    at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:34)
    at org.mule.processor.AsyncInterceptingMessageProcessor$AsyncMessageProcessorWorker.doRun(AsyncInterceptingMessageProcessor.java:164)
    at org.mule.work.AbstractMuleEventWork.run(AbstractMuleEventWork.java:43)
    at org.mule.work.WorkerContext.run(WorkerContext.java:311)
    at java.util.concu...
********************************************************************************

And if it helps, the Mule flows:

<mule xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:bpm="http://www.mulesoft.org/schema/mule/bpm" xmlns:twitter="http://www.mulesoft.org/schema/mule/twitter" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd 
http://www.mulesoft.org/schema/mule/twitter http://www.mulesoft.org/schema/mule/twitter/2.4/mule-twitter.xsd 
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd 
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd 
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd 
http://www.mulesoft.org/schema/mule/bpm http://www.mulesoft.org/schema/mule/bpm/3.2/mule-bpm.xsd ">
    <spring:beans>
        <spring:bean id="Eventos2" name="eventos" class="clases.Inicial" factory-method="getVacia"/>
    </spring:beans>
  <twitter:config name="Pablo" accessKey="***" accessSecret="***" consumerKey="***" consumerSecret="***" doc:name="Twitter"/>    
  <bpm:drools/>  
  <vm:endpoint name="alerts" path="stock.alerts" doc:name="VM"/>
    <flow name="Flujo1" doc:name="Flujo1" processingStrategy="thread-per-processor">
        <twitter:filtered-stream config-ref="Pablo" doc:name="Twitter (Streaming)">            
            <twitter:keywords>                           
                //KeyWords                               
            </twitter:keywords>
        </twitter:filtered-stream>
        <expression-transformer expression="return new clases.Tweet(payload.getText(),payload.getUser().getScreenName());" doc:name="Expression"/> 
        <bpm:rules rulesDefinition="reglas.drl" initialFacts-ref="eventos" cepMode="true" entryPoint="Flujo Tweets"/>                                              
    </flow>
    <flow name="ceptwitterFlow1" doc:name="ceptwitterFlow1">
        <vm:inbound-endpoint exchange-pattern="one-way" ref="alerts" doc:name="VM"/>
        <echo-component doc:name="Echo"/>
    </flow>

</mule>

Both constructors involved

public Tweet(Tweet t){texto=t.texto;usuario=t.usuario;}

public Sospechoso(TiposSintomas tip,Tweet t){
        tipo=tip;
        tweet = new Tweet(t);
    }
Pablog1108
  • 87
  • 7
  • Could you share with us the exception stacktrace too? – genjosanzo Nov 24 '12 at 20:40
  • I already edited the post with the stacktrace and mule flows. ;) – Pablog1108 Nov 24 '12 at 21:19
  • According to the stacktrace, the error seems to be inside Sospechoso constructor when instantiating a new Tweet object: ... at clases.Tweet.(Tweet.java:8) at clases.Sospechoso.(Sospechoso.java:9) ... Could you please share with use both constructors (Maybe with the corresponding line number)? – Esteban Aliverti Nov 25 '12 at 21:24
  • @EstebanAliverti, I already added both constructors, thanks. – Pablog1108 Nov 25 '12 at 22:00
  • The constructor you have added for Sospechoso is not the same you are using in the RHS of your rule. This is a little bit "Sospechoso"... ;) – Esteban Aliverti Nov 26 '12 at 12:47
  • @EstebanAliverti Sorry, I added an incorrect and sospechoso .drl, already updated. Thanks – Pablog1108 Nov 26 '12 at 18:03
  • I think I remember an issue similar to this one. Unfortunately I couldn't find it in Drools' jira. By the way: Which version of Drools are you using? In order to get more information you could configure and AgendaEventListener in the session to check whether the Tweet fact is being retracted or not. – Esteban Aliverti Nov 27 '12 at 09:19
  • @EstebanAliverti. The drools version wich comes with Mule 3.3.0 is Drools 5.0.1. How I can configure and AgendaEventListener through Mule?? – Pablog1108 Nov 27 '12 at 11:39

0 Answers0