Search code examples
javapythonweblogicweblogic-10.xwlst

Get list of all applications deployed on a weblogic server


Using the following code, I am able to connect to the weblogic server. Now I want to get a list of all the applications deployed on the server.

listapplications() from the command prompt lists the applications, but I am not able to store the output into a variable when I execute interpreter.exec(listapplications()) because interpreter.exec returns a void. Any ideas on how can I store the applications list in a collection/array?

Any other alternative or leads would also help.

import org.python.util.InteractiveInterpreter;
import weblogic.management.scripting.utils.WLSTInterpreter;

public class SampleWLST {

    public static void main(String[] args) {
        SampleWLST wlstObject = new SampleWLST();
        wlstObject.connect();
    }

    public void connect() {
        InteractiveInterpreter interpreter = new WLSTInterpreter();
        interpreter.exec("connect('username', 'password', 't3://localhost:8001')");
    }
}

Solution

  • I solved it. I captured the output of the wlst by redirect to a stream using setOut method of InteractiveInterpreter and wrote a scanner to read the stream in Java.

    Hope this might help someone else.

    ArrayList<String> appList = new ArrayList<String>();
    Writer out = new StringWriter();
    interpreter.setOut(out);
    interpreter.exec("print listApplications()");   
    
    StringBuffer results = new StringBuffer();
    results.append(out.toString());
    
    Scanner scanner = new Scanner(results.toString());
    while(scanner.hasNextLine()){
        String line = scanner.nextLine();
        line = line.trim();
        if(line.equals("None"))
            continue;
        appList.add(line);
    }