Fields Summary |
---|
private String | useridThe userid to login with, if automated login is used |
private String | passwordThe password to login with, if automated login is used |
private String | commandThe command to execute |
private String | serverThe server to connect to. |
private int | portThe tcp port to connect to. |
private Vector | rexecTasksThe list of read/write commands for this session |
private boolean | addCarriageReturnIf true, adds a CR to beginning of login script |
private Integer | defaultTimeoutDefault time allowed for waiting for a valid response
for all child reads. A value of 0 means no limit. |
Methods Summary |
---|
public org.apache.tools.ant.taskdefs.optional.net.RExecTask$RExecSubTask | createRead()A string to wait for from the server.
A subTask <read> tag was found. Create the object,
Save it in our list, and return it.
RExecSubTask task = (RExecSubTask) new RExecRead();
rexecTasks.addElement(task);
return task;
|
public org.apache.tools.ant.taskdefs.optional.net.RExecTask$RExecSubTask | createWrite()Add text to send to the server
A subTask <write> tag was found. Create the object,
Save it in our list, and return it.
RExecSubTask task = (RExecSubTask) new RExecWrite();
rexecTasks.addElement(task);
return task;
|
public void | execute()Verify that all parameters are included.
Connect and possibly login.
Iterate through the list of Reads and writes.
/** A server name is required to continue */
if (server == null) {
throw new BuildException("No Server Specified");
}
/** A userid and password must appear together
* if they appear. They are not required.
*/
if (userid == null && password != null) {
throw new BuildException("No Userid Specified");
}
if (password == null && userid != null) {
throw new BuildException("No Password Specified");
}
/** Create the telnet client object */
AntRExecClient rexec = null;
try {
rexec = new AntRExecClient();
try {
rexec.connect(server, port);
} catch (IOException e) {
throw new BuildException("Can't connect to " + server);
}
if (userid != null && password != null && command != null
&& rexecTasks.size() == 0) {
// simple one-shot execution
rexec.rexec(userid, password, command);
} else {
// need nested read/write elements
handleMultipleTasks(rexec);
}
/** Keep reading input stream until end of it or time-out */
rexec.waitForEOF(defaultTimeout);
} catch (IOException e) {
throw new BuildException("Error r-executing command", e);
} finally {
if (rexec != null && rexec.isConnected()) {
try {
rexec.disconnect();
} catch (IOException e) {
throw new BuildException("Error disconnecting from "
+ server);
}
}
}
|
private void | handleMultipleTasks(org.apache.tools.ant.taskdefs.optional.net.RExecTask$AntRExecClient rexec)Deals with multiple read/write calls.
/** Login if userid and password were specified */
if (userid != null && password != null) {
login(rexec);
}
/** Process each sub command */
Enumeration tasksToRun = rexecTasks.elements();
while (tasksToRun != null && tasksToRun.hasMoreElements()) {
RExecSubTask task = (RExecSubTask) tasksToRun.nextElement();
if (task instanceof RExecRead && defaultTimeout != null) {
((RExecRead) task).setDefaultTimeout(defaultTimeout);
}
task.execute(rexec);
}
|
private void | login(org.apache.tools.ant.taskdefs.optional.net.RExecTask$AntRExecClient rexec)Process a 'typical' login. If it differs, use the read
and write tasks explicitely
if (addCarriageReturn) {
rexec.sendString("\n", true);
}
rexec.waitForString("ogin:");
rexec.sendString(userid, true);
rexec.waitForString("assword:");
rexec.sendString(password, false);
|
public void | setCommand(java.lang.String c)Set the the comand to execute on the server;
this.command = c;
|
public void | setInitialCR(boolean b)send a carriage return after connecting; optional, defaults to false.
this.addCarriageReturn = b;
|
public void | setPassword(java.lang.String p)Set the the login password to use
required if userid is set.
this.password = p;
|
public void | setPort(int p)Set the tcp port to connect to; default is 23.
this.port = p;
|
public void | setServer(java.lang.String m)Set the hostname or address of the remote server.
this.server = m;
|
public void | setTimeout(java.lang.Integer i)set a default timeout in seconds to wait for a response,
zero means forever (the default)
this.defaultTimeout = i;
|
public void | setUserid(java.lang.String u)Set the the login id to use on the server;
required if password is set.
this.userid = u;
|