我正在使用 Mule Community Edition 3.4.0,在设置/获取流之间的会话变量时遇到问题。我有一个流程,其中有一个直到成功的组件;当发生异常时,我使用拦截器将异常名称保存在会话变量中,以便在另一个流程中读取它。问题是当我尝试重试会话变量时,我得到一个空值。我真的不知道为什么。在下面,您可以看到 mule 配置文件:
<spring:beans>
<spring:bean id="OS_Bean_id" name="OS_Bean" class="org.mule.util.store.QueuePersistenceObjectStore"/>
<spring:bean id="myExceptionHandler_id" class="it.aizoon.prova.ManageException" name="myExceptionHandler"/>
<spring:bean id="handleException_id" name="handleException" class="it.aizoon.prova.exception.CustomSoapFaultInInterceptor"/>
<spring:bean id="handleSysError_id" name="handleSysError" class="it.aizoon.prova.exception.CustomInInterceptor"/>
<spring:bean id="BeanCheckProperty_id" name="BeanCheckProperty" class="it.aizoon.prova.utilities.CheckProperty"/>
</spring:beans>
<http:endpoint exchange-pattern="request-response" host="localhost" port="8081" path="service/prova" method="POST" name="HTTP" doc:name="HTTP"/>
<vm:endpoint exchange-pattern="one-way" path="myQueue" name="myQueue" doc:name="VM"/>
<queued-asynchronous-processing-strategy name="Queued_Asynchronous_Processing_Strategy" doc:name="Queued Asynchronous Processing Strategy">
<file-queue-store/>
</queued-asynchronous-processing-strategy>
<flow name="myFlow" doc:name="myFlow" processingStrategy="Queued_Asynchronous_Processing_Strategy">
<vm:inbound-endpoint exchange-pattern="one-way" doc:name="VM" ref="myQueue"/>
<logger level="INFO" doc:name="Logger" message="EEEEE: #[exception]"/>
<processor ref="BeanCheckProperty"/>
<set-payload value="The request cannot be processed, the error is #[payload]" doc:name="Set Payload"/>
<set-property propertyName="http.status" value="500" doc:name="Property"/>
<logger message="PAYLOAD_VM: #[payload]" level="INFO" doc:name="Logger"/>
</flow>
<flow name="ProvaRepeatFlow1" doc:name="ProvaRepeatFlow1" processingStrategy="Queued_Asynchronous_Processing_Strategy">
<quartz:inbound-endpoint jobName="TalendJob" repeatInterval="5000" repeatCount="0" responseTimeout="10000" doc:name="Quartz">
<quartz:event-generator-job>
<quartz:payload>error</quartz:payload>
</quartz:event-generator-job>
</quartz:inbound-endpoint>
<object-to-string-transformer doc:name="Object to String"/>
<until-successful objectStore-ref="OS_Bean" maxRetries="2" secondsBetweenRetries="2" doc:name="Until Successful" >
<flow-ref name="CallWebService" doc:name="Flow Reference"/>
</until-successful>
<catch-exception-strategy doc:name="Catch Exception Strategy">
<processor-chain doc:name="Processor Chain">
<logger level="INFO" doc:name="Logger"/>
<vm:outbound-endpoint exchange-pattern="one-way" path="myQueue" doc:name="VM"/>
</processor-chain>
</catch-exception-strategy>
</flow>
<sub-flow name="CallWebService" doc:name="CallWebService">
<processor-chain doc:name="Processor Chain">
<cxf:jaxws-client operation="getCode" clientClass="it.aizoon.prova.client.ProvaService" port="ProvaPort" enableMuleSoapHeaders="true" doc:name="SOAP">
<cxf:inInterceptors>
<!-- <spring:ref bean="handleSysError"/> -->
</cxf:inInterceptors>
<cxf:inFaultInterceptors>
<spring:ref bean="handleException"/>
</cxf:inFaultInterceptors>
<cxf:outInterceptors/>
<cxf:outFaultInterceptors/>
</cxf:jaxws-client>
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8088" path="mockProvaServiceSoapBinding" method="POST" doc:name="HTTP"/>
</processor-chain>
</sub-flow>
如您所见,我有一个 SOAP 组件。如果存在 SOAP 错误,我可以拦截它并将其名称保存在名为 EXCEPTION 的会话变量中。这里有拦截器代码:
public class CustomSoapFaultInInterceptor extends AbstractPhaseInterceptor{
public CustomSoapFaultInInterceptor() {
// TODO Auto-generated constructor stub
super(Phase.INVOKE);
//getAfter().add(Soap11FaultInInterceptor.class.getName());
}
@Override
public void handleMessage(Message message) throws Fault {
// TODO Auto-generated method stub
System.out.println("InFaultInterceptor_CONTENUTO ECCEZIONE: " + message.getContent(Exception.class));
System.out.println("InFaultInterceptor_CONTENUTO EVENTO MULE: " + message.getExchange().get(CxfConstants.MULE_EVENT));
MuleEvent muleEvent = (MuleEvent) message.getExchange().get(CxfConstants.MULE_EVENT);
MuleMessage muleMessage = muleEvent.getMessage();
if((message.getContent(Exception.class)) instanceof ParideExec_Exception){
ParideExec_Exception parideExec = (ParideExec_Exception) message.getContent(Exception.class);
String exceptionName = message.getContent(Exception.class).getClass().getName();
//context.getRegistry().registerObject("Eccezione", exceptionName);
muleEvent.setSessionVariable("CustomExec", exceptionName);
System.out.println("ID SESSIONE: " + muleEvent.getSession().getId());
}
}
}
这是在另一个流程中读取会话变量的 java 代码。
public class CheckProperty implements MessageProcessor{
@Override
public MuleEvent process(MuleEvent event) throws MuleException {
// TODO Auto-generated method stub
System.out.println("PPPP: " + event.getSessionVariable("CustomExec"));
System.out.println("ID SESSIONE: " + event.getSession().getId());
if(event.getSessionVariable("CustomExec") != null){
System.out.println("EXCEPTION: " + event.getSessionVariable("CustomExec"));
String exceptionName = event.getSessionVariable("CustomExec").toString();
event.getMessage().setPayload(exceptionName);
}
return event;
}
但是这个变量 id 为空。请帮我。我真的不知道为什么骡子有这种行为。