【发布时间】:2014-08-18 23:03:42
【问题描述】:
http://www.oracle.com/technetwork/articles/javase/rmi-corba-136641.html 的当前 CORBA 示例
使用不同的 JDK 版本。我正在使用 JDK 1.7
所以问题是我用extends FileInterfacePOA而不是extends _FileInterfaceImplBase扩展了课程
所以现在我在服务器代码中遇到错误,我应该使用什么来代替函数 .connect() 和 .rebind()。
服务器代码是:
import java.io.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
public class StartServer {
public static void main(String args[]) {
try{
// create and initialize the ORB
ORB orb = ORB.init(args, null);
// create the servant and register it with the ORB
FileTransferObj fileRef = new FileTransferObj();
orb.connect(fileRef);
// get the root naming context
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
NamingContext ncRef = NamingContextHelper.narrow(objRef);
// Bind the object reference in naming
NameComponent nc = new NameComponent("FileTransfer", " ");
NameComponent path[] = {nc};
ncRef.rebind(path, fileRef);
System.out.println("Server started....");
// Wait for invocations from clients
java.lang.Object sync = new java.lang.Object();
synchronized(sync){
sync.wait();
}
} catch(Exception e) {
System.err.println("ERROR: " + e.getMessage());
e.printStackTrace(System.out);
}
}
}
接口代码为:
import FileTransferApp.*;``
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;
import java.util.Properties;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
public class FileTransferObj extends FileInterfacePOA {
public byte[] downloadFile(String fileName){
File file = new File(fileName);
byte buffer[] = new byte[(int)file.length()];
try {
BufferedInputStream input = new
BufferedInputStream(new FileInputStream(argv[0]));
input.read(buffer,0,buffer.length);
} catch(Exception e) {
System.out.println("FileServant Error: "+e.getMessage());
e.printStackTrace();
}
return(buffer);
}
}
【问题讨论】:
-
您遇到什么错误?
-
大家好。我解决了错误。错误是因为如您所见,我使用的是 JDK 1.7,因此 StartServer.java 中的整个逻辑发生了变化。我正在更新chage,请看答案部分。
标签: java corba distributed-objects