Dustin Marx is a software developer who enjoys identifying and using the correct tool for the job. In addition to writing software and writing a blog on software development, Dustin occasionally presents at conferences and writes articles. Dustin is a DZone MVB and is not an employee of DZone and has posted 237 posts at DZone. You can read more from them at their website. View Full User Profile

Browsing the COS Naming Service Namespace with Groovy

04.22.2013
| 2762 views |
  • submit to reddit

There was a time when CORBA was all the rage and was as trendy and popular as any favored technology that has come along since. Although CORBA does not get the attention in blogs and other online media that it would have in those days or that other technologies get today, it still underlies several of the technologies that many of us use. In this post, I look at using Groovy to browse the objects in a hierarchical namespace associated with the CORBA Common Object Services (COS) Naming Service that is provided by Java IDL (which also includes command line tools) and supports GlassFish's EJBs.

The Oracle Java SE Documentation contains a highly useful page called Naming Service that provides Java source code with explanations for adding objects to the namespace, resolving objects from the namespace, and browsing the namespace. In this post, I convert the Java code providing for the third example (browsing the namespace) to Groovy for a script that is easy to use to check objects in the namespace. That script is shown next.

browseNamingService.groovy
#!/usr/bin/env groovy
//
// browseNamingService.groovy <hostname> <port>
//
// Adapted from Example #3 at
// http://docs.oracle.com/javase/7/docs/technotes/guides/idl/jidlNaming.html#example3

if (args.length < 2)
{
   println "\n\nUsage: browseNamingService.groovy <hostname> <port>\n\n"
   System.exit(-1)
}

import java.util.Properties
import org.omg.CORBA.*
import org.omg.CosNaming.*

def properties = new Properties()
properties.put("org.omg.CORBA.ORBInitialPort", args[1])
properties.put("org.omg.CORBA.ORBInitialHost", args[0])
def orb = ORB.init(args, properties)

def namingContext = NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService"))

def bindingList = new BindingListHolder()
def bindingListIterator = new BindingIteratorHolder()
namingContext.list(1000, bindingList, bindingListIterator)
def bindings = bindingList.value

bindings.each
{ binding ->
   def lastIndex = binding.binding_name.length-1;

   // BindingType of ncontext indicates this is a naming context; only other
   // BindingType is nobject.
   if (binding.binding_type == BindingType.ncontext)
   {
      println "Context: ${binding.binding_name[lastIndex].id}"
   }
   else
   {
      println "Object: ${binding.binding_name[lastIndex].id}"
   }
}

For details on what the script above is doing, see the discussion surrounding the Java code from which this was adapted. The script makes it easy to provide a hostname and port and find the objects referenced in the namespace at that host and port. This is shown in the GlassFish (port 3700) in the next screen snapshot.

In this case, I happened to know that my GlassFish installation used the default port of 3700 for this CORBA COS Naming Service, but I also could have found that port in the GlassFish web-based Admin GUI as shown in the next screen snapshot.

When you don't know the appropriate port and the product whose port you are looking for the Naming Service on doesn't indicate the appropriate port, you can use tools to find potential ports such as netstat and TCPView for Windows. Any of these ports run through the above script without a stack trace and that return names are posts on which a CORBA COS Naming Service is hosted.

 

Published at DZone with permission of Dustin Marx, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)