Uploaded image for project: 'Aries'
  1. Aries
  2. ARIES-572

NamingException in JMXConnectionFactory.connect() calls with JMX over RMI calls

    XMLWordPrintableJSON

Details

    Description

      I get a NamingException with the following bundle activator if aries-jndi is present (I tried the current 0.4-SNAPSOT and 0.3):

      public class Activator implements BundleActivator {

      @Override
      public void start(BundleContext bundleContext) throws Exception

      { Map<String, Object> env = new HashMap<String, Object>(); env.put("osgi.service.jndi.bundleContext", bundleContext); JMXConnectorFactory.connect(new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1717/jmxrmi"), env); }

      @Override
      public void stop(BundleContext arg0) throws Exception {
      }
      }

      The bundle context in the environment is necessary to work around another issue.

      The NamingException is thrown by com.sun.jndi.url.rmi.rmiURLContextFactory.getObjectInstance() if the first parameter is not an URL. This method is called from org.apache.aries.jndi.ObjectFactoryHelper.getObjectInstanceUsingObjectFactories(). This method iterates over all registered ObjectFactories to check if there is a better implementation than the one provided in the first argument, however if it comes to Sun's object factory the NamingException occurs (and will be propagated upwards) even though the proxy object that is already there is actually fine.

      Therefore I would propose the following change:
      Index: src/main/java/org/apache/aries/jndi/ObjectFactoryHelper.java
      ===================================================================
      — src/main/java/org/apache/aries/jndi/ObjectFactoryHelper.java (revision 1068918)
      +++ src/main/java/org/apache/aries/jndi/ObjectFactoryHelper.java (working copy)
      @@ -115,6 +115,7 @@

      try

      { result = factory.getObjectInstance(obj, name, nameCtx, environment); + }

      catch (NamingException e) {
      } finally

      { callerContext.ungetService(ref); }

      The empty catch block is needed because obviously some ObjectFactories throw a NamingException instead of returning null in some circumstances.

      Attachments

        1. ObjectFactoryHelper.java.patch
          0.6 kB
          Stephan Siano

        Activity

          People

            not Alasdair Nottingham
            siano Stephan Siano
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: