我正在尝试使用 mule+drools fusion 制作一个 twitter 应用程序,但是我在一个特定规则“Tweet a caso sospechoso”的 rhs 中得到了一个空指针异常。我想不通。
我认为 drools 引擎正在提早撤回推文事件。当我需要在 rhs 中使用 tweet 事件时,该事件不再存在。
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
堆栈跟踪
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...
********************************************************************************
如果它有帮助,骡子流动:
<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>
涉及的两个构造函数
public Tweet(Tweet t){texto=t.texto;usuario=t.usuario;}
public Sospechoso(TiposSintomas tip,Tweet t){
tipo=tip;
tweet = new Tweet(t);
}