NanoContainer
  1. NanoContainer
  2. NANO-19

NanoMXContainer doesn't work under WebSphere 5

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0-beta-1
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      WebSphere version 5.02
    • Number of attachments :
      1

      Description

      MBean registration fails for components without domain specification.
      To figure out what went wrong I updated NanoMxRegistrationException so it has all constructors from its super class and updated both NanoMxContainer:
      public synchronized void registerComponentInstance(Object key, Object component)
      throws PicoRegistrationException {
      ObjectName name = null;
      try

      { name = NanoMXComponentAdapter.asObjectName(key); super.registerComponentInstance(key, component); Object mbean = NanoMXComponentAdapter.asMBean(component); mbeanServer.registerMBean(mbean, name); }

      catch (InstanceAlreadyExistsException e)

      { throw new NanoMXRegistrationException("Failed to register MBean '" + name + "' for component '" + key + "', due to " + e.getMessage(), e); }

      catch (MBeanRegistrationException e)

      { throw new NanoMXRegistrationException("Failed to register MBean '" + name + "' for component '" + key + "', due to " + e.getMessage(), e); } catch (NotCompliantMBeanException e) { throw new NanoMXRegistrationException("Failed to register MBean '" + name + "' for component '" + key + "', due to " + e.getMessage(), e); }

      catch (MalformedObjectNameException e)

      { throw new NanoMXRegistrationException("Failed to register MBean '" + name + "' for component '" + key + "', due to " + e.getMessage(), e); } catch (PicoRegistrationException e) { throw new NanoMXRegistrationException("Failed to register MBean '" + name + "' for component '" + key + "', due to " + e.getMessage(), e); }

      }

      and updated NanoMxComponentAdapter:
      public Object getComponentInstance(MutablePicoContainer picoContainer) throws PicoInitializationException, PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException {
      if (componentInstance == null) {
      componentInstance = super.getComponentInstance(picoContainer);

      ObjectName name = null;
      try

      { name = asObjectName(getComponentKey()); Object mbean = asMBean(componentInstance); mbeanServer.registerMBean(mbean, name); }

      catch (MalformedObjectNameException e)

      { throw new NanoMXInitializationException("Failed to register MBean '" + name + "' for component '" + getComponentKey() + "', due to " + e.getMessage(), e); } catch (MBeanRegistrationException e) { throw new NanoMXInitializationException("Failed to register MBean '" + name + "' for component '" + getComponentKey() + "', due to " + e.getMessage(), e); }

      catch (NotCompliantMBeanException e)

      { throw new NanoMXInitializationException("Failed to register MBean '" + name + "' for component '" + getComponentKey() + "', due to " + e.getMessage(), e); } catch (InstanceAlreadyExistsException e) { throw new NanoMXInitializationException("Failed to register MBean '" + name + "' for component '" + getComponentKey() + "', due to " + e.getMessage(), e); }

      return componentInstance;
      }
      return componentInstance;
      }

      so they throw more detailed exception messages.
      When it was clear what was wrong, I also updated the NanoMxComponentAdapter' asObjectName() to the following:

      public static ObjectName asObjectName(Object key) throws MalformedObjectNameException {
      if (key == null)

      { throw new NullPointerException("key cannot be null"); }

      if (key instanceof ObjectName)

      { return (ObjectName) key; }

      if (key instanceof Class)

      { Class clazz = (Class) key; return new ObjectName("nanomx:type=" + clazz.getName()); }

      else {
      String text = key.toString();
      // Fix, so it works under WebSphere ver. 5
      if (text.indexOf(':') == -1)

      { text = "nanomx:type=" + text; }

      return new ObjectName(text);
      }
      }

      /Jeppe

        Activity

        Hide
        Jeppe Cramon added a comment -

        Complete sourcecode for the fixes.

        Show
        Jeppe Cramon added a comment - Complete sourcecode for the fixes.
        Jeppe Cramon made changes -
        Field Original Value New Value
        Attachment NanoMXFix.zip [ 10921 ]
        Hide
        Paul Hammant added a comment -

        Patch applied

        Show
        Paul Hammant added a comment - Patch applied
        Paul Hammant made changes -
        Resolution Fixed [ 1 ]
        Status Unassigned [ 1 ] Closed [ 6 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Jeppe Cramon
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: