CORBA example uses a different JDK [closed]

本小妞迷上赌 提交于 2019-12-11 08:39:41

问题


Current CORBA example from http://www.oracle.com/technetwork/articles/javase/rmi-corba-136641.html

uses a differet JDK version. I am using JDK 1.7

SO the problem is I have extended the class with extends FileInterfacePOA instead of extends _FileInterfaceImplBase

So now I am getting an error in the server code what do I use instead of function .connect() and .rebind() .

Server code is :

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

Interface code is:

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

回答1:


So since the JDK version is different form the example I followed . The following changes will solve the problem.

import org.omg.CORBA.ORB;
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContext;
import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContextExtHelper;
import org.omg.CosNaming.NamingContextHelper;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAHelper;

import FileTransferApp.*;

public class StartServer {
   public static void main(String args[]) {
      try{
         // create and initialize the ORB
         ORB orb = ORB.init(args, null);
         POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
         rootpoa.the_POAManager().activate();

         // create the servant and register it with the ORB
         FileTransferObj fileRef = new FileTransferObj();
         fileRef.setORB(orb);

         //get Object reference from servant
         org.omg.CORBA.Object ref =  rootpoa.servant_to_reference(fileRef);
         FileInterface href = FileInterfaceHelper.narrow(ref);

         // get the root naming context
         org.omg.CORBA.Object objRef =
            orb.resolve_initial_references("NameService");
         NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

         //
         NameComponent path[] = ncRef.to_name("ABC");
         ncRef.rebind(path, href);

         System.out.println("Server started....");
         // Wait for invocations from clients
         for(;;){
            orb.run();
         }
      } catch(Exception e) {
         System.err.println("ERROR: " + e.getMessage());
         e.printStackTrace(System.out);
      }
   }
}


来源:https://stackoverflow.com/questions/25373385/corba-example-uses-a-different-jdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!