Reputation: 640
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')");
}
}
Upvotes: 4
Views: 4686
Reputation: 126
To get all deployed articats which are deployed, you can use:
private void listAllDeployments(WebLogicDeploymentManager deployManager,
Target targets[]) throws TargetException {
if (deployManager != null && targets.length > 0) {
print("Get Domain:" + deployManager.getDomain(), 0);
TargetModuleID targetModuleID[] = deployManager.getAvailableModules(ModuleType.WAR,
targets);
} else {
System.out.print(
"WebLogicDeploymentManager is either empty or targets are empty.Please check",
1);
}
}
For creating deployer manager, you can use :
SessionHelper.getRemoteDeploymentManager(protocol,hostName, portString, adminUser, adminPassword);
Dependencies that you will need :
compile(group: 'com.oracle.weblogic', name: 'wlfullclient', version: '10.3.6.0', transitive: false)
Upvotes: 0
Reputation: 640
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);
}
Upvotes: 3