2 Replies Latest reply on Jul 15, 2019 7:49 AM by Aman Painuly

    Unable to do JNDI lookup a stateful session bean on JBOSS EAP 7.1

    Aman Painuly Newbie

      I am currently working on an application where I use EJB3.2 to write the business logic. The application is running on jboss EAP7.1 The client is unable to lookup remote stateful bean.

      Below is outline of the structure of the project:

      Gems -- 
              |-- Gems-ejb (project containing the EJB code)
              |
              |---Gems-service (project containing the client and the rest services)

      Here are things I have already done:

      1. Added application user in the server
      2. Created session bean (Gems-ejb):
        1. @Stateful
          @Remote(ActCounterpartUploadBeanRemote.class)
          public class ActCounterpartUploadBean implements ActCounterpartUploadBeanRemote {
            public int getId_counterpartIndex() {
            return id_counterpartIndex;
            }
          }
      3. Created interface for the session bean (Gems-ejb):
        1. public interface ActCounterpartUploadBeanRemote {
            public int getId_counterpartIndex();
          }
      4. Created client (Gems-service-->src --> main --> java):
        1. public class DataSubmissionUtil {
            private static Context initialContext=getInitialContext();
            private static Context getInitialContext() {
            try {
            if(initialContext == null) {
            final Hashtable<String, String> jndiProperties = new Hashtable<>();
            jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
          jndiProperties.put(Context.PROVIDER_URL,"remote+http://localhost:8080");
            initialContext = new InitialContext(jndiProperties);
            }
            }
            catch (NamingException ne) {
            ne.printStackTrace();
            }
            return initialContext;
            }

            ActCounterpartUploadBeanRemote objActCtpUploadBean = lookupActCounterpartUploadBeanRemote();
            public ActCounterpartUploadBeanRemote lookupActCounterpartUploadBeanRemote() {
            try {
            final String appName = "";
            final String moduleName = "Gems-ejb-3.0-SNAPSHOT"; //the jar that is created for Gems-ejb on building the project
            final String beanName = ActCounterpartUploadBean.class.getSimpleName();
            final String viewClassName = ActCounterpartUploadBeanRemote.class.getName();
            context.lookup("ejb:" + moduleName + "/" + beanName + "!" + viewClassName + "?stateful");
            return (ActCounterpartUploadBeanRemote) initialContext.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName + "?stateful");
            }
            catch (NamingException ne) {
            throw new RuntimeException(ne);
            }
            }
          }
      5. Added wildfly-config.xml ( Gems-service -->src --> main --> resources):
        1. <configuration>
            <authentication-client xmlns="urn:elytron:1.0">
            <authentication-rules>
            <rule use-configuration="default" />
            </authentication-rules>
            <authentication-configurations>
            <configuration name="default">
            <sasl-mechanism-selector selector="#ALL" />
            <set-mechanism-properties>
            <property key="wildfly.sasl.local-user.quiet-auth" value="true" />
            </set-mechanism-properties>
            <providers>
            <use-service-loader/>
            </providers>
            </configuration>
            </authentication-configurations>
            </authentication-client>
          </configuration>

      On starting the server the logs shows following JNDI bindings:

      JNDI bindings for session bean named 'ActCounterpartUploadBean' in deployment unit 'deployment "Gems-service.war"' are as follows:  
      java:global/Gems-service/ActCounterpartUploadBean!org.maks.gems.actions.ActCounterpartUploadBeanRemote
      java:app/Gems-service/ActCounterpartUploadBean!org.maks.gems.actions.ActCounterpartUploadBeanRemote
      java:module/ActCounterpartUploadBean!org.maks.gems.actions.ActCounterpartUploadBeanLocal
      java:jboss/exported/Gems-service/ActCounterpartUploadBean!org.maks.gems.actions.ActCounterpartUploadBeanRemote
      java:global/Gems-service/ActCounterpartUploadBean
      java:app/Gems-service/ActCounterpartUploadBean
      java:module/ActCounterpartUploadBean

      I expected the code to run fine however, I get following error:

      Failed to look up "/Gems-ejb-3.0-SNAPSHOT//ActCounterpartUploadBean!org.maks.gems.actions.ActCounterpartUploadBeanRemote?stateful" [Root exception is org.jboss.ejb.client.RequestSendFailedException: EJBCLIENT000409: No more destinations are available]