Saturday, August 29, 2015

How to Invoke a Shell Script using WSO2 ESB

whats covered: creating a custom mediator to invoke shell scripts for ESB 4.8.1.

1) Create a Mediator Project

Generate a mediator project using WSO2 Developer Studio. Developer Studio Dashboard > Mediator Project.

2) Put in the logic to execute shell scripts

exec() method of the of the current runtime object can be used for this purpose. put the logic inside the mediate method(this method should return true to continue the mediation flow). Find the complete code here[1]

    public String execute()
        StringBuilder output = new StringBuilder();
        Process p;
            p = Runtime.getRuntime().exec(command);
            BufferedReader reader =
                    new BufferedReader(new InputStreamReader(p.getInputStream()));

            String line = "";
            while ((line = reader.readLine())!= null) {
                output.append(line + "\n");
        catch(IOException e)
        catch(InterruptedException e)

        return output.toString();

3) Build and Copy the jar

build the project. Copy the created jar file to <ESB_HOME>/repository/components/lib .

4) Create a proxy service

create a proxy service with the class mediator in the mediation path.

<class name="org.wso2.demo.ShellScriptMediator">
      <property name="scriptname"
      <property name="scriptparam"

[1] -

Find more info on the class mediator here,

Friday, August 28, 2015

How to Run WSO2 BAM 2.5.0 on Cygwin

whats covered: configuring and running BAM 2.5.0 on Win 7 over Cygwin.

1) Install Java

install java using the installer and once thats complete setup JAVA_HOME user variable and add the java bin folder to path system variable.

2) Install Cygwin

download from and install using the wizard.

3) Setup JAVA_HOME in Cygwin.

Open <cygwin_home>/home/<user_name>/.profile and export JAVA_HOME following way,



export JAVA_HOME=/cygdrive/c/Java/jdk1.7.0_45

4) Run the Start Script

open cygwin terminal, navigate to BAM 2.5.0 folder and start the server with script.