Interface client test code

Source: Internet
Author: User

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 ();
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.