0

I have a Java class that writes data to a file every time you run the program. The Java class is written in the Mule project, and i would like to use a mule flow to invoke this Java class. So my question is - how can i invoke/start the main method of a class in a Flow in Mule ESB? The whole goal is to automate this process. The flow has other components, and calling the main method of the Java class will be part of the flow.

Thanks

The Georgia
  • 855
  • 6
  • 19
  • 51

3 Answers3

0

You can add a Java component and specify the class that you want to invoke, by keeping one thing in mind if the flow is working on a bean, then the method with bean as a parameter will be called like this

public User process(User user) {
    //call your main method here
    return user;
}
0

I can think of 2 choices --

(1) Make a component and call your any other class from there. Or if you can modify your existing class to be a Callable and implement onCall method and invoke your business method from there.

<component class="com.test.TestClass" />

public class TestClass implements Callable {
public Object onCall(MuleEventContext eventContext) throws Exception {
        //call business method from here.
    }
}

(2) Use groovy to make a java call.

<scripting:component>
            <scripting:script engine="groovy">
                // Your java code here
            </scripting:script>
        </scripting:component>
user1493140
  • 5,056
  • 4
  • 26
  • 48
0

Just use Invoke method (Mule included : https://docs.mulesoft.com/mule-user-guide/v/3.8/invoke-component-reference). While scriping by Groovy does not normally support Spring, and if your class you would like to run is SpringConnected (with all the annotations and so on) you are unable to do it via Groovy (only by using scripting control).

So simple: <invoke object-ref="DirectoryChecker" method="run" doc:name="Invoke DirectoryChecker"/> in totally enough.

Make sure that YouClass is initialized as a bean.

<spring:bean id="YouClass" name="YouClass" class="you.package"/>

That's all.

Checked. It's working.

deyvw
  • 801
  • 7
  • 9