1

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?

star
  • 1,493
  • 1
  • 28
  • 61

2 Answers2

1

Two ways to fix this:

  1. use #[sessionVars['test1']] instead of #[sessionVars.test1] while accessing session variables.
  2. declare the session variable 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.

0

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

Anirban Sen Chowdhary
  • 8,233
  • 6
  • 39
  • 81
  • It have value for sure. I'm keeping this expression component inside For each. Is that a problem???. I will edit my question. – star Aug 06 '15 at 03:57
  • Well, it's difficult to say from here.. the config here seems to be fine for now, pls make sure you get the outbound properties value in expression component or it will execute the else part – Anirban Sen Chowdhary Aug 06 '15 at 04:04
  • Edited my question with complete xml. Even If I have hard coded the value for `sessionVars.temp = '2' ` instead of `MULE_Correlation_sequenece( taking from outboundProperties)`. It is not printing the value for sessionVars.temp in logger. – star Aug 06 '15 at 04:05