接口的客户端测试代码,含FTP操作和WebService客户端操作。用来提供测试。
备忘。
----------
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:/测试.doc";???????????? //要上传的文件(含路径)
??? String newFileName = "new测试.doc"; //上传后的新的文件名字
??? TelnetOutputStream touts = null;
??? DataOutputStream douts = null;
??? int readInt;
??? //链接FTP服务
??? try {
????? ftp = new FtpClient(ftpServerAddr);
????? ftp.login(ftpUserName,ftpPassword);
????? ftp.binary();
??? }
??? catch (Exception ex) {
????? System.out.println("用户或者密码可能不对,无权限与主机:" + ftpServerAddr + "连接!");
??? }
??? //传输文件
??? try {
????? ftp.cd("oa"); //进入指定的FTP服务的OA目录
????? RandomAccessFile sendFile = new RandomAccessFile(fileName,"r");
????? sendFile.seek(0);
????? touts = ftp.put(newFileName);????? //FTP上传后文件的名字
????? douts = new DataOutputStream(touts);
????? while (sendFile.getFilePointer() < sendFile.length()) {
??????? readInt = sendFile.read();
??????? douts.write(readInt);
????? }
??? }
??? catch (Exception e) {
????? System.out.println("FTP文件传输异常!");
????? return;
??? }
??? finally {
????? //关闭链接,释放资源
????? 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;
????? }
??? }
??? //调用WebService服务保存数据信息
??? try {
????? OAFileService service = new OAFileServiceLocator();
????? OAFile aOAFile = service.getOAFile();
????? if (aOAFile.saveOAFile("2006",
???????????????????????????? "测试.doc",//原文件名
???????????????????????????? //"new测试.doc",? //上传后的新文件名字
???????????????????????????? "文件种类",
???????????????????????????? "文号",
???????????????????????????? "文件标题",
???????????????????????????? "单位名称",
???????????????????????????? "2006-08-26",
???????????????????????????? "主题词",
???????????????????????????? "2006",
???????????????????????????? "制文单位",
???????????????????????????? 100,
???????????????????????????? "备注内容")) {
??????? System.out.println("成功:" + aOAFile.getSysMsg());
????? }
????? else {
??????? System.out.println("失败:" + aOAFile.getSysMsg());
????? }
??? }
??? catch (Exception e) {
????? System.err.println("Execution failed. Exception: " + e);
??? }
? }
? public static void main(String[] args) {??? save();? }}?