# -*- coding: utf-8 -*- """ Tester for the CORBA connection """ import sys from omniORB import CORBA import _GlobalIDL import CosNaming class pyCORBATest(): def __init__(self): fileName = "ns.ior" #sys.argv[1] self.IOR = self.getIORString(fileName) #print self.IOR self.RootCon = self.initCORBAObject(self.IOR) print self.RootCon def getIORString(self, fileName): """ Read the IOR file and return the IOR string """ try: return open(fileName, 'r').read() except IOError: print "IO Error in file: %s " % fileName sys.exit(1) def getArgs(self): args = ['-ORBtraceLevel'] args.append('40') #args.append('-ORBacceptMisalignedTcIndirections') #args.append('1') args.append('-ORBuseTypeCodeIndirections') args.append('0') args.append('-ORBstrictIIOP') args.append('0') args.append('-ORBlcdMode') args.append('1') #args.append('-ORBtcAliasExpand') #args.append('1') #args.append('-ORBgiopMaxMsgSize') #args.append('9999998192') print args return args def initCORBAObject(self,IOR): #Initialise the ORB self.orb=CORBA.ORB_init(self.getArgs(),CORBA.ORB_ID) NameSeviceObj = self.orb.string_to_object(IOR) rootContext = NameSeviceObj._narrow(CosNaming.NamingContext) if rootContext is None: print"Failed to narrow the root naming context" sys.exit(1) return rootContext def getObjectReference(self,contextsNames): name =[] #Resolvethename"test.my_context/ExampleEcho.Object" for k in contextsNames: print "%s=%s" % (k, "" ) name.append(CosNaming.NameComponent(k,"")) try: obj=self.RootCon.resolve(name) print obj except CosNaming.NamingContext.NotFound, ex: print"Name not found" sys.exit(1) return obj def DOgetCustomerByID(self): print "==== Start DOgetCustomerByID ======" import CustomerMaintenance_idl #Servant Address names = ["CustomerManager", "Servants", "CustomerManager_11" ] #API Input Hconnect = -1 ExternalId = "bce_2" #get the servant reference servantObject = tester.getObjectReference(names) print servantObject #Invoke the API RC = servantObject.GetCustomerById(Hconnect,ExternalId) #handle Output print RC #Done print "==== End DOgetCustomerByID ======" if __name__ == "__main__": print 'start' tester = pyCORBATest() tester.DOgetCustomerByID() print 'end'