Access flow variable in java code mule

I saved some information in a variable, but I do not know how to get it in my java code ...

Example:

<sub-flow name="EnrichMessage" doc:name="EnrichMessage"> <component doc:name="Scenario01" class="Class01"/> <set-variable variableName="Parameters" value="#[payload]" doc:name="Variable"/> <flow-ref name="SubFlow01" doc:name="SubFlow01"/> <component doc:name="Scenario02" class="Class02"/> </sub-flow> 

I have already seen some incomplete answers, but still do not know how to do this. Anyone can post the full answer?

Thanks.

+4
source share
2 answers

In java, there are several ways to access variables, depending on the type of java class used:

onCall event class

  public Object onCall(MuleEventContext eventContext, @Payload String payload) throws Exception { String returnPath = eventContext.getMessage().getProperty("myReturnPath", PropertyScope.OUTBOUND); 

If passed MuleMessage:

  public void process(@Payload MuleMessage payload ){ String returnPath = messge.getProperty("myReturnPath", PropertyScope.OUTBOUND); 

Using OutboundHeader Annotation

  public void process(@Payload String payload, @OutboundHeaders Map headers ){ String prop = headers.get("propname"); 
+2
source

Add a new Java component to the stream and create a new Java interface that implements the Callable interface.

 public Object onCall(MuleEventContext eventContext) throws Exception { MuleMessage msg = eventContext.getMessage(); // you can access MuleMessage here return msg; } 

Then you can access your MuleMessage.

 String method = msg.getProperty("http.method", PropertyScope.INBOUND); 

If you want to add a new property

 msg.setProperty("foo", "bar", PropertyScope.INVOCATION); 
+1
source

Source: https://habr.com/ru/post/1498488/


All Articles