Uploaded image for project: 'WildFly'
  1. WildFly
  2. WFLY-794

javax.naming.NameNotFoundException: rmi://127.0.0.1:1090/jmxrmi thrown when creating MBeanServerConnection

    XMLWordPrintable

Details

    • Hide

      Deploy attached jmx-test.jar, or use the attached 'JMXConnectionBean.java' to create one yourself.

      Show
      Deploy attached jmx-test.jar, or use the attached 'JMXConnectionBean.java' to create one yourself.
    • Workaround Exists
    • Hide
      Connector.java
      JMXConnector connector = null;
              MBeanServerConnection connection = null;
              try {
                  String urlString = "service:jmx:rmi:///jndi/rmi://localhost:1090/jmxrmi";
                  JMXServiceURL serviceURL = new JMXServiceURL(urlString);
                  Map<String, String> env = new HashMap<String, String>();
                  env.put(InitialContext.INITIAL_CONTEXT_FACTORY, RMIContextFactory.class.getName());
                  connector = JMXConnectorFactory.connect(serviceURL, env);
                  connection = connector.getMBeanServerConnection();
              } finally {
                  if (connector != null) {
                     connector.close();
                  }
              }
      
      
      
      RMIContextFactory.java
      import java.util.Hashtable;
      
      import javax.naming.Context;
      import javax.naming.NamingException;
      import javax.naming.spi.InitialContextFactory;
      
      import com.sun.jndi.url.rmi.rmiURLContext;
      
      
      public class RMIContextFactory implements InitialContextFactory{
      
          /* (non-Javadoc)
           * @see javax.naming.spi.InitialContextFactory#getInitialContext(java.util.Hashtable)
           */
          @Override
          public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException {
              return new rmiURLContext(environment);
          }
      
      }
      

      Also this will require small modification of sun.jdk module, to export 'com.sun.jndi.url.rmi' path(or you will have to provide your own impl of rmiContext ), since by default this module exports 'com.sun.jndi.url' and 'com.sun.jndi.url.ldap', iirc.
      So, edit: jboss-as/build/src/main/resources/modules/sun/jdk/main/main.xml and one statement: <path name="com/sun/jndi/url/rmi"/>, it should look like this:

      <module xmlns="urn:jboss:module:1.1" name="sun.jdk">
          <resources>
              <!-- currently jboss modules has not way of importing services from
              classes.jar so we duplicate them here -->
              <resource-root path="service-loader-resources"/>
          </resources>
          <dependencies>
              <system export="true">
                  <paths>
                      <path name="com/sun/script/javascript"/>
                      <path name="com/sun/jndi/dns"/>
                      <path name="com/sun/jndi/ldap"/>
                      <path name="com/sun/jndi/url"/>
      		<path name="com/sun/jndi/url/rmi"/>
                      <path name="com/sun/jndi/url/dns"/>
                      <path name="com/sun/security/auth"/>
                      <path name="com/sun/security/auth/login"/>
                      <path name="com/sun/security/auth/module"/>
                      <path name="sun/misc"/>
                      <path name="sun/io"/>
                      <path name="sun/nio"/>
                      <path name="sun/nio/ch"/>
                      <path name="sun/security"/>
                      <path name="sun/security/krb5"/>
                      <path name="sun/util"/>
                      <path name="sun/util/calendar"/>
                      <path name="sun/security/provider"/>
                      <path name="META-INF/services"/>
                  </paths>
                  <exports>
                      <include-set>
                          <path name="META-INF/services"/>
                      </include-set>
                  </exports>
              </system>
          </dependencies>
      </module>
      

      Now NOTE: this will make that initial context to be usable ONLY for RMI lookups.

      Show
      Connector.java JMXConnector connector = null ; MBeanServerConnection connection = null ; try { String urlString = "service:jmx:rmi: ///jndi/rmi://localhost:1090/jmxrmi" ; JMXServiceURL serviceURL = new JMXServiceURL(urlString); Map< String , String > env = new HashMap< String , String >(); env.put(InitialContext.INITIAL_CONTEXT_FACTORY, RMIContextFactory. class. getName()); connector = JMXConnectorFactory.connect(serviceURL, env); connection = connector.getMBeanServerConnection(); } finally { if (connector != null ) { connector.close(); } } RMIContextFactory.java import java.util.Hashtable; import javax.naming.Context; import javax.naming.NamingException; import javax.naming.spi.InitialContextFactory; import com.sun.jndi.url.rmi.rmiURLContext; public class RMIContextFactory implements InitialContextFactory{ /* (non-Javadoc) * @see javax.naming.spi.InitialContextFactory#getInitialContext(java.util.Hashtable) */ @Override public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException { return new rmiURLContext(environment); } } Also this will require small modification of sun.jdk module, to export 'com.sun.jndi.url.rmi' path(or you will have to provide your own impl of rmiContext ), since by default this module exports 'com.sun.jndi.url' and 'com.sun.jndi.url.ldap', iirc. So, edit: jboss-as/build/src/main/resources/modules/sun/jdk/main/main.xml and one statement: <path name="com/sun/jndi/url/rmi"/> , it should look like this: <module xmlns= "urn:jboss:module:1.1" name= "sun.jdk" > <resources> <!-- currently jboss modules has not way of importing services from classes.jar so we duplicate them here --> <resource-root path= "service-loader-resources" /> </resources> <dependencies> <system export= "true" > <paths> <path name= "com/sun/script/javascript" /> <path name= "com/sun/jndi/dns" /> <path name= "com/sun/jndi/ldap" /> <path name= "com/sun/jndi/url" /> <path name= "com/sun/jndi/url/rmi" /> <path name= "com/sun/jndi/url/dns" /> <path name= "com/sun/security/auth" /> <path name= "com/sun/security/auth/login" /> <path name= "com/sun/security/auth/module" /> <path name= "sun/misc" /> <path name= "sun/io" /> <path name= "sun/nio" /> <path name= "sun/nio/ch" /> <path name= "sun/security" /> <path name= "sun/security/krb5" /> <path name= "sun/util" /> <path name= "sun/util/calendar" /> <path name= "sun/security/provider" /> <path name= "META-INF/services" /> </paths> <exports> <include-set> <path name= "META-INF/services" /> </include-set> </exports> </system> </dependencies> </module> Now NOTE: this will make that initial context to be usable ONLY for RMI lookups.

    Description

      When trying to create a MBeanServerConnection to a NON-JBoss application from within an EJB a "javax.naming.NameNotFoundException" is thrown.

      Steps to reproduce:

      Set up a stand-alone application that exposes an MBean. (ActiveMQ will work in this case.)
      Modify the attached JMXConnectionBean.java to connect to the ActiveMQ instance.
      Deploy the bean. A NameNotFoundException will be thrown.

      I've seen this behavior in 7.1.1.Final, 7.1.2.Final (EAP), 7.1.3.Final (EAP), EAP 6.1.0.Alpha (7.2.0.Final).

      Note that this behavior is NOT seen when connecting to another JBoss server.

      Full stack trace:

       
      Caused by: java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.NameNotFoundException: rmi://127.0.0.1:1090/jmxrmi -- service jboss.naming.context.java.rmi:."127.0.0.1:1090".jmxrmi
      	at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:340) [:1.6.0_26]
      	at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248) [:1.6.0_26]
      	at com.example.JMXConnectionBean.init(JMXConnectionBean.java:28)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_26]
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_26]
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_26]
      	at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_26]
      	at org.jboss.as.ee.component.ManagedReferenceLifecycleMethodInterceptor.processInvocation(ManagedReferenceLifecycleMethodInterceptor.java:70)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]
      	at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]
      	at org.jboss.as.ee.component.ManagedReferenceInterceptor.processInvocation(ManagedReferenceInterceptor.java:53)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]
      	at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]
      	at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:44)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]
      	at org.jboss.as.ejb3.component.session.SessionInvocationContextInterceptor$CustomSessionInvocationContext.proceed(SessionInvocationContextInterceptor.java:126)
      	at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:211)
      	at org.jboss.as.ejb3.tx.CMTTxInterceptor.requiresNew(CMTTxInterceptor.java:313)
      	at org.jboss.as.ejb3.tx.SingletonLifecycleCMTTxInterceptor.processInvocation(SingletonLifecycleCMTTxInterceptor.java:56)
      	at org.jboss.as.ejb3.tx.SingletonLifecycleCMTTxInterceptor.processInvocation(SingletonLifecycleCMTTxInterceptor.java:42)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]
      	at org.jboss.as.ejb3.component.session.SessionInvocationContextInterceptor.processInvocation(SessionInvocationContextInterceptor.java:71)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]
      	at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]
      	at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]
      	at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:152)
      	... 9 more
      Caused by: javax.naming.NameNotFoundException: rmi://127.0.0.1:1090/jmxrmi -- service jboss.naming.context.java.rmi:."127.0.0.1:1090".jmxrmi
      	at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:87)
      	at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:173)
      	at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:47)
      	at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:209)
      	at javax.naming.InitialContext.lookup(InitialContext.java:392) [:1.6.0_26]
      	at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1888) [:1.6.0_26]
      	at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1858) [:1.6.0_26]
      	at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:257) [:1.6.0_26]
      	... 37 more
      

      Attachments

        1. JmxClient.java
          0.7 kB
        2. JMXConnectionBean.java
          1.0 kB
        3. JmxServer.java
          0.7 kB
        4. jmx-test.jar
          2 kB

        Issue Links

          Activity

            People

              emartins@redhat.com Eduardo Martins
              AlexC099 Alex Corvino (Inactive)
              Votes:
              3 Vote for this issue
              Watchers:
              12 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: