2 Replies Latest reply on Feb 18, 2016 1:04 PM by tanvir

    JBoss EJB Client handler missing argument?

    tanvir

      I am trying to set a new InitialContext in the following manner (which is pretty standard I believe):


      private static InitialContext getInitialContext() throws NamingException { 

           InitialContext context = null; 

           try {

                Properties properties = new Properties();

                properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

                properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");

                properties.put(Context.PROVIDER_URL, "remote://localhost:4447");

                properties.put(Context.SECURITY_PRINCIPAL, "username");

                properties.put(Context.SECURITY_CREDENTIALS, "password");

                context = new InitialContext(properties);

                System.out.println("\n\tGot initial Context: " + context);

           }

           catch (Exception e) {

                e.printStackTrace();

           }

           return context;

      } 


      public static void sendMessage(RoboticsParameters object_msg) throws Exception { 

           InitialContext context = getInitialContext(); 

           // other code

      }

      The code "fails" at the line where the new InitialContext is created using the properties and i get a java.lang.NullPointerException. I suspect I am missing an argument. Here is the stack trace:

      WARN: EJB client integration will not be available due to a problem setting up the EJB client handler java.lang.NullPointerException

      at org.jboss.naming.remote.client.InitialContextFactory.<clinit>(InitialContextFactory.java:118)

      at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:348)

      at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:72)

      at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:61)

      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:672)

      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)

      at javax.naming.InitialContext.init(InitialContext.java:244)

      at javax.naming.InitialContext.<init>(InitialContext.java:216)

      Any suggestions?

      I am running JBoss EAP 6.4 and using EJB 3. I have jboss-client.jar in the class path.

        • 1. Re: JBoss EJB Client handler missing argument?
          wdfink

          Drop URL_PKG_PREFIXES, you are mixing two different approaches. See Remote EJB invocations via JNDI - EJB client API or remote-naming project .

          But I would recommend to not use this approach as there are some drawbacks, i.e. no cluster support. See the link above for additional onformations.

          If you have a subscrption you can look for an article in the knowledgebase which describe the differences.

          • 2. Re: JBoss EJB Client handler missing argument?
            tanvir

            I checked the source code for:

            jboss-remote-naming/src/main/java/org/jboss/naming/remote/client/InitialContextFactory.java

            and found where the log message was coming from:

            public class InitialContextFactory implements javax.naming.spi.InitialContextFactory {

                 // code

                 private static final String REMOTE_NAMING_EJB_CLIENT_HANDLER_CLASS_NAME = "org.jboss.naming.remote.client.ejb.RemoteNamingStoreEJBClientHandler";

                 // code

                 try {

                      klass = classLoader.loadClass(REMOTE_NAMING_EJB_CLIENT_HANDLER_CLASS_NAME);

                      method = klass.getMethod("setupEJBClientContext", new Class<?>[] {Properties.class, List.class});

                 } catch (Throwable t) {

                      logger.warn("EJB client integration will not be available due to a problem setting up the EJB client handler", t);

                 }

                 // other code

            }

            The class org.jboss.naming.remote.client.ejb.RemoteNamingStoreEJBClientHandler was in the jar that I added to the class path but for some reason there were problems loading the class.

            Then I stumbled upon this small README-EJB-JMS.txt file in the [jboss_home]/bin/client folder which states the following:

            "Maven users should not use this jar, but should use the following BOM dependencies instead

            <dependencies>

                 <dependency>

                      <groupId>org.jboss.as</groupId>

                      <artifactId>jboss-as-ejb-client-bom</artifactId>

                      <type>pom</type>

                 </dependency>

                 <dependency>

                      <groupId>org.jboss.as</groupId>

                      <artifactId>jboss-as-jms-client-bom</artifactId>

                      <type>pom</type>

                 </dependency>

            </dependencies>

            This is because using maven with a shaded jar has a very high chance of causing class version conflicts, which is why we do not publish this jar to the maven repository."

            So, I added the maven dependency instead of having the jar in my class path and VOILA! It works!