Search code examples
jarwso2esbwso2-esb

How do I can call a jar file from wso2


I am new to esb WSO2 and I need to call a .jar with WSO2 parameters. I think I need to create a endpoint and call the jar file. Is it right?

Thanks for all.


Solution

  • I have done this using the Script Mediator (Groovy language). So from within the Groovy script I called my custom method by passing it the payload as JSON and saved the return value of that method as the payload. I used JSON for the payload, but feel free to leave it to default XML. You can also pass parameters, not just the payload, to your custom method.

    <script language="groovy">
        println "---------- start java call -----------"
        mc.setPayloadJSON(new my.own.package.MyClass().myMethod(mc.getPayloadJSON()))
        println "----------- end java call ----------"
    </script>
    

    Added my custom jar, JSON and Groovy jars under {ESB_ROOT}/repository/components/lib and bounced the WSO2 ESB.

    There are probably other ways to achieve what you need.