0

We do have sub flows shared between many flows. I would like find within my subflow which Flow is the call one...

MEL:-

#[flow.name]

is working only in Logger.

I couldn't even pass this value into Session/Anyother property (by set property connector), so I can access using message.getProperty method.

Thanks in advance.

sanssan
  • 305
  • 1
  • 3
  • 12

4 Answers4

1

Try making your component org.mule.api.construct.FlowConstructAware. You should then be able to get its name.

HTH

afelisatti
  • 2,770
  • 1
  • 13
  • 21
  • Well, you ask how to get it in a Java component so I assume you have a custom class of your own where you are trying to get that value. In that case you can make your class implement the interface I mentioned and you'll get a reference to the flow to which you can ask its name. – afelisatti May 09 '16 at 17:03
1

I my case I created other flow for logging which has VM inbound. Then I called it via Java component. See sample codes below.

public class TestCallVm implements Callable{

    @Override
    public Object onCall(MuleEventContext eventContext) throws Exception {
        MuleMessage message = eventContext.getMessage();
        String tid = message.getProperty("tid", PropertyScope.SESSION).toString();

        MuleClient client = new MuleClient(eventContext.getMuleContext());
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("tid", message.getProperty("tid", PropertyScope.SESSION).toString());
        message.setPayload("Hello");
        client.sendNoReceive("vm://vmLogger", "Hello", map);
        client.send("vm://vmLogger", "Hello", map);
        client.send("vm://vmLogger", message, null);
        MuleMessage response = client.send("vm://vmLogger", "Ross", null);
        System.out.println("response = ");
        return null;
    }

}

Hope this will helps :)

Arden Vallente
  • 216
  • 1
  • 1
1

You can use following code for getting flow name in java component

import org.mule.api.MuleEventContext;
import org.mule.api.construct.FlowConstruct;
import org.mule.api.construct.FlowConstructAware;
import org.mule.api.lifecycle.Callable;

public class LogFlowName implements Callable, FlowConstructAware {
    private FlowConstruct flowConstruct;
    @Override
    public void setFlowConstruct(FlowConstruct flowConstruct) {
         this.flowConstruct = flowConstruct;

    }
    @Override
    public Object onCall(MuleEventContext eventContext) throws Exception {
        //TODO  your code goes here
        System.out.println("Flow Name is : " +flowConstruct.getName());
        //TODO  your code goes here
        return eventContext.getMessage().getPayload();
    }
}

Hope this helps.

AnupamBhusari
  • 2,395
  • 2
  • 14
  • 22
0

Another easy way, set it as variable and then access that variable in java component.

AnupamBhusari
  • 2,395
  • 2
  • 14
  • 22
  • I already tried that. Same error with Variables also...org.mule.mvel2.UnresolveablePropertyException: unable to resolve token: unable to resolve variable 'flow' – sanssan May 09 '16 at 15:44
  • Change the name of the variable to something other than 'flow'. Dont use default words available in schema – tortoise May 10 '16 at 10:34
  • I have observed #[flow.name] does NOT appear to be standard MEL, but a logger specific extension. you can you the FlowConstructAware for getting flow name. – AnupamBhusari May 11 '16 at 07:52