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 | serverThe server to connect to. |
private int | portThe tcp port to connect to. |
private Vector | telnetTasksThe 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.TelnetTask$TelnetSubTask | 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.
TelnetSubTask task = (TelnetSubTask) new TelnetRead();
telnetTasks.addElement(task);
return task;
|
public org.apache.tools.ant.taskdefs.optional.net.TelnetTask$TelnetSubTask | 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.
TelnetSubTask task = (TelnetSubTask) new TelnetWrite();
telnetTasks.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 */
AntTelnetClient telnet = null;
try {
telnet = new AntTelnetClient();
try {
telnet.connect(server, port);
} catch (IOException e) {
throw new BuildException("Can't connect to " + server);
}
/** Login if userid and password were specified */
if (userid != null && password != null) {
login(telnet);
}
/** Process each sub command */
Enumeration tasksToRun = telnetTasks.elements();
while (tasksToRun != null && tasksToRun.hasMoreElements()) {
TelnetSubTask task = (TelnetSubTask) tasksToRun.nextElement();
if (task instanceof TelnetRead && defaultTimeout != null) {
((TelnetRead) task).setDefaultTimeout(defaultTimeout);
}
task.execute(telnet);
}
} finally {
if (telnet != null && telnet.isConnected()) {
try {
telnet.disconnect();
} catch (IOException e) {
throw new BuildException("Error disconnecting from "
+ server);
}
}
}
|
private void | login(org.apache.tools.ant.taskdefs.optional.net.TelnetTask$AntTelnetClient telnet)Process a 'typical' login. If it differs, use the read
and write tasks explicitely
if (addCarriageReturn) {
telnet.sendString("\n", true);
}
telnet.waitForString("ogin:");
telnet.sendString(userid, true);
telnet.waitForString("assword:");
telnet.sendString(password, false);
|
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;
|