[omniORB] string_to_object question

Warren Brown warren@scully.xfiles.za.org
Fri Mar 7 14:03:02 2003


This is a multi-part message in MIME format.

------=_NextPart_000_0037_01C2E4C2.EDE3C1B0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hi

I implemented a simple python script that takes paths ie /path/to/ior. It's
useful in my work, but may not be useful anywhere else :-/. It runs as a
cgi-script.
To use it in python scripts you would use urllib.
ie
urllib.urlopen('http://corbatst.ns.com/name-cgi/path_on_nameservice/").readl
ine()

regards


----- Original Message -----
From: "Duncan Grisby" <duncan@grisby.org>
To: "Gary Duzan" <gduzan@bbn.com>
Cc: "Lee, Robert C." <RLee@northropgrumman.com>;
<omniorb-list@omniorb-support.com>
Sent: Friday, March 07, 2003 2:35 PM
Subject: Re: [omniORB] string_to_object question


> On Wednesday 5 March, Gary Duzan wrote:
>
> >    Even as recent as the CORBA 3.0.2 spec, only the IOR:, corbaname:,
> > and corbaloc: URLs are standard. file://, ftp://, and http:// URLs are
> > reserved and optional in CORBA 3.0.2, per section 13.6.10.7, so portable
> > code can't rely on them being supported by the ORB.
>
> I don't think it's sensible for omniORB to grow HTTP and FTP client
> capabilities. It's just unnecessary bloat. file:// makes more sense.
> If someone wants to come up with a patch, I'll integrate it. If
> someone does implement it, please use C file handling functions, not
> C++ iostreams, since there must not be a dependency between the
> omniORB libraries and iostreams.
>
> Cheers,
>
> Duncan.
>
> --
>  -- Duncan Grisby         --
>   -- duncan@grisby.org     --
>    -- http://www.grisby.org --
> _______________________________________________
> omniORB-list mailing list
> omniORB-list@omniorb-support.com
> http://www.omniorb-support.com/mailman/listinfo/omniorb-list
>

------=_NextPart_000_0037_01C2E4C2.EDE3C1B0
Content-Type: application/octet-stream;
	name="name-cgi"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="name-cgi"

#!/usr/bin/env python

"""
Warren Brown <warren@scully.xfiles.za.org>

Based on a similar program from orbacus.
Corba-ns script, takes the path info and returns an ior
Query string can be used to hold functions that we can use
example
lynx -d http://corba.test.com/path/in/nameservice/agent_name
or
lynx -d http://corba.test.com/path/in/nameservice?cmd=3Dloadbalance
"""

import sys, cgi,string, random
from omniORB import CORBA
import CosNaming


def ns_iterator():
	bl =3D CosNaming.BindingList
	it =3D CosNaming.BindingIterator
        bl,it =3D obj.list(100) # should get the stuff from the =
nameservice
	return bl=09

def convert(thingy):
	try:
		arr =3D string.split(thingy,"/")
		dict=3D[]
		for x in range(1,len(arr)):
			dict.append(CosNaming.NameComponent(arr[x],''))
		obj =3D rootContext.resolve(dict)
		return obj
	except:
		raise("Problem finding reference in NameService, maybe it is wrong or =
your nameservice config file is pointing to the wrong nameservice")

print "content-type: text/html"
print ""
random.seed()  # used for load balancing
try:
	a =3D cgi.os.environ
	commands=3D""
	if(a.has_key('QUERY_STRING') and len(a['QUERY_STRING']) > 0):
		commands =3D string.split(a['QUERY_STRING'],'=3D')[1]
	if(a.has_key('PATH_INFO')):
		thingy =3D a['PATH_INFO']
#initialise the corba crap
	orb =3D CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
	obj =3D orb.resolve_initial_references("NameService")
	rootContext =3D obj._narrow(CosNaming.NamingContext)
	if rootContext is None:
		raise("Failed to narrow the root naming context")
	else:
		obj =3D convert(thingy)
		if (len(commands) =3D=3D 0):  # i.e no commands on the line
			#Split the path into dictionaries and consult the naming service
			try:
				print orb.object_to_string(obj)
			except:=20
				throw("Name not found %s" % thingy)
		else:
			if (commands =3D=3D "nameservice"): 	#print the nameservice ior=09
				print orb.object_to_string(obj)
	=09
			if (commands =3D=3D "getmappings"): # print the objects under the =
Naming Context
				bl =3D ns_iterator()
				retstr=3D"MAPPINGS:"=20
				for x in range(len(bl)):
					retstr=3Dretstr+thingy+"/"+bl[x].binding_name[0].id
					retstr=3Dstring.strip(retstr)
					retstr=3Dretstr+",";
				retstr =3D retstr[0:len(retstr)-1]
				retstr=3Dretstr+":ENDMAPPINGS"
				print retstr
			=09
			if (commands =3D=3D "loadbalance"): # ie an alteon
				ret=3D1
				retstr=3D[]  # Holds the values it gets from the nameservice
				bl=3Dns_iterator()
				for x in range(len(bl)):
					obj =3D convert(thingy+"/"+bl[x].binding_name[0].id)
					try:
						obj._non_existent() # check if it exists
						retstr.append(obj)
					except(CORBA.COMM_FAILURE):
						rootContext.unbind(thingy+"/"+bl[x].binding_name[0].id) #Remove =
the object from the nameservice=09
						sys.stderr.write("%s unbound!\n" % bl[x].binding_name[0].id)
				if len(retstr) > 0 :
					print orb.object_to_string(random.choice(retstr)) # return a random =
server
except:
	raise("If you got here then there was a real problem.<BR>Try the =
nameservice first, then check if you actually have a valid url.")


------=_NextPart_000_0037_01C2E4C2.EDE3C1B0--