Starting and Stopping Clients by using the Application Interface

The following topic will show you a sample program that allows you to start or stop any client by using the Java Application Interface.

You can use the existing Java code or adjust it according to your requirements.

Use the following command-line parameters in order to call the sample program:

java aeClientGoStop <go/stop> <cp> <port> <client> <user> <dep> <pwd>

  • <go/stop>
    Possible values: go or stop.
    go - Starts the client and stop - Stops the client.
  • <cp> = The IP address or the name of the CP computer.
  • <port> = The port number of the CP.
  • <client> = The four-digit client number.
  • <user> = The name of the AE user.
  • <pwd> = The user password.

To be able to call the program successfully, you will need the Java Application Interface (uc4.jar).

import java.io.IOException;

import com.uc4.communication.Connection;

import com.uc4.communication.requests.CreateSession;

import com.uc4.communication.requests.ResumeClient;

import com.uc4.communication.requests.SuspendClient;

import com.uc4.communication.requests.XMLRequest;

public class aeClientGoStop {

 

public static void main(String[] args) throws IOException {

 

new aeClientGoStop().gostop(args);

}

 

private void gostop(String[] args) throws IOException {

 

 

int count = args.length;

if(count < 6){

System.err.println("not enough arguments: min = 6 -> found only: " + count);

System.exit(1);

}

//System.err.println("arguments passed on: " + count);

String action = null;

String cp = null;

String port = null;

String client = null;

String user = null;

String dep = null;

String pwd = null;

 

if(count < 7){

action = args[0];

cp = args[1];

port = args[2];

client = args[3];

user = args[4];

dep = args[5];

pwd = "";

}else if(count == 7){

action = args[0];

cp = args[1];

port = args[2];

client = args[3];

user = args[4];

dep = args[5];

pwd = args[6];

}

 

//Create a connection to the Automation Engine

Connection uc4 = Connection.open(cp, Integer.parseInt(port));

 

//Login

CreateSession login = uc4.login(Integer.parseInt(client),user,dep,pwd,'E');

 

//Test if the login was successful

if (!login.isLoginSuccessful()) {

System.err.println(login.getMessageBox().getText());

uc4.close();

System.exit(1);

}

 

XMLRequest rqr = null ;

if (action.equals("go")){

rqr = new ResumeClient();

 

} else if (action.equals("stop")){

rqr = new SuspendClient();

 

}

uc4.sendRequestAndWait(rqr);

if (rqr.getMessageBox() != null) {

System.err.println(rqr.getMessageBox().getText());

uc4.close();

System.exit(3);

}

 

uc4.close();

System.out.println("done action: " + action + " client: " + client);

}

};