Reputation: 1503
I'm trying to do simple if else condition in expression component. After expression component I have logger. My query here is I'm not able to see the test1
but can able to view temp
value in logger component. Why?
Same time, if I print test1
value in system.out.println. Getting the value, but why not in logger?.
<quartz:inbound-endpoint responseTimeout="10000" doc:name="Quartz" connector-ref="Quartz" jobName="Feedjob" repeatInterval="36000000" >
<quartz:event-generator-job groupName="Feedjob" jobGroupName="Feedjob"/>
</quartz:inbound-endpoint>
<s3:list-objects config-ref="Amazon_S3" doc:name="Amazon S3" bucketName="${amazon.BucketName}" prefix="master"/>
<foreach doc:name="For Each">
<set-variable variableName="TestValue" value="#[payload.getKey()]" doc:name="Variable"/>
<expression-component doc:name="Expression"><![CDATA[
sessionVars.temp = message.outboundProperties['MULE_CORRELATION_SEQUENCE'] ;
if ( sessionVars.temp == "2"){
sessionVars.test1 = sessionVars.temp ;
System.out.println(sessionVars.test1);
return message.payload;
}
else{
System.out.println(" No test");
return message.payload;
}
]]></expression-component>
<logger message="Payload**********temp:#[sessionVars.temp] test1: #[sessionVars.test1]" level="INFO" doc:name="Logger"/>
</foreach>
<logger message="Outside For each logger**********temp:#[sessionVars.temp] test1: #[sessionVars.test1]" level="INFO" doc:name="Logger"/>
It seems to be once after payload returning from expression component sessionVars.temp is set, but sessionVars.test1 diaappears. It is strange. Where I'm wrong?
Upvotes: 1
Views: 7419
Reputation: 91
Two ways to fix this:
#[sessionVars['test1']]
instead of #[sessionVars.test1]
while accessing session variables.sessionVars.test1="";
before the if block The issue seems to be with the way variables are accessed with .
operator. It only happens when the variable is declared in a component which doesn't create those variables the first time (in your case, the test1 variable is created only in the second foreach iteration and not in the first). If your condition had been if ( sessionVars.temp == "1")
, you wouldn't face this issue.
Apparently mule had already fixed this in latest versions, 3.7 seems to be working as expected. I had the same issue in 3.5.
Upvotes: 1
Reputation: 8311
I tried to recreate your scenario in following way :-
<set-property propertyName="MULE_CORRELATION_SEQUENCE" value="2" doc:name="Property"/>
<expression-component doc:name="Expression"><![CDATA[
sessionVars.temp = message.outboundProperties['MULE_CORRELATION_SEQUENCE'] ;
if ( sessionVars.temp == "2"){
sessionVars.test1 = sessionVars.temp ;
System.out.println(sessionVars.test1);
return message.payload;
}
else{
System.out.println(" No test");
return message.payload;
}
]]></expression-component>
and I am able to get the value in logger :- INFO 2015-08-06 09:19:48,556 [[testcon].HTTP_Listener_Configuration1.worker.01] org.mule.api.processor.LoggerMessageProcessor: Payload**********temp:2 test1: 2
Make sure your outbound property MULE_CORRELATION_SEQUENCE is not null or contains value
Upvotes: 0