Interface client TestCode, Including FTP operations and WebService client operations. Used to provide testing.
Memo.
----------
Package test;
Import sun.net. FTP. ftpclient;
Import java. Io. randomaccessfile;
Import java. Io. dataoutputstream;
Import sun.net. telnetoutputstream;
Public class clienttest {
Public clienttest (){
}
Public static void save (){
String ftpserveraddr = "11.165.21.209 ";
String ftpusername = "user ";
String ftppassword = "password ";
Ftpclient FTP = NULL;
String filename = "C:/test .doc"; // file to be uploaded (including path)
String newfilename = "newtest .doc"; // The name of the uploaded file.
Telnetoutputstream touts = NULL;
Dataoutputstream douts = NULL;
Int readint;
// Link to the FTP service
Try {
FTP = new ftpclient (ftpserveraddr );
FTP. login (ftpusername, ftppassword );
FTP. Binary ();
}
Catch (exception ex ){
System. Out. println ("the user or password may be incorrect. You have no permission to connect to the Host:" + ftpserveraddr +! ");
}
// Transfer a file
Try {
FTP. Cd ("OA"); // enter the OA directory of the specified FTP service
Randomaccessfile sendfile = new randomaccessfile (filename, "R ");
Sendfile. Seek (0 );
Touts = ftp. Put (newfilename); // name of the File Uploaded by FTP
Douts = new dataoutputstream (touts );
While (sendfile. getfilepointer () <sendfile. Length ()){
Readint = sendfile. Read ();
Douts. Write (readint );
}
}
Catch (exception e ){
System. Out. println ("FTP file transmission exception! ");
Return;
}
Finally {
// Close the link and release the resource
Try {
If (douts! = NULL ){
Douts. Close ();
}
If (touts! = NULL ){
Touts. Close ();
}
If (ftp. serverisopen ()){
FTP. closeserver ();
}
If (FTP! = NULL ){
FTP = NULL;
}
}
Catch (exception ex ){
Return;
}
}
// Call the WebService Service to save data
Try {
Oafileservice service = new oafileservicelocator ();
Oafile aoafile = service. getoafile ();
If (aoafile. saveoafile ("2006 ",
"Test .doc", // original file name
// "Newtest .doc", // name of the uploaded file
"File type ",
"Document No ",
"File title ",
"Organization name ",
"2006-08-26 ",
"Subject ",
"2006 ",
"Text Unit ",
100,
"Remarks ")){
System. Out. println ("success:" + aoafile. getsysmsg ());
}
Else {
System. Out. println ("failed:" + aoafile. getsysmsg ());
}
}
Catch (exception e ){
System. Err. println ("execution failed. Exception:" + E );
}
}
Public static void main (string [] ARGs ){
Save ();
}
}