9 Replies Latest reply on Jul 16, 2018 10:05 AM by ochaloup

    Remote EJB invocations using JNDI not working as Documented in Jboss 7.1.1

    donsenior

      I was trying to configure my client as in https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI with no luck (No EJB receiver available for handling).

       

      Anyway, I've get it working seting the jndi properties as follow:

       

      java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory

      java.naming.provider.url=remote://localhost:4447

      jboss.naming.client.ejb.context=true

      java.naming.factory.url.pkgs=org.jboss.ejb.client.naming

       

      Is this configuration wrong or is just the documentation incomplete?

        • 1. Re: Remote EJB invocations using JNDI not working as Documented in Jboss 7.1.1
          ochaloup

          Hi Pablo,

          the documentation should be complete. I guess that the problem is in the configuration.

          The way of remote client properties definition should be used as it's described in the document. Then you need  jboss-ejb-client.properties file  within your app that has content similar to https://github.com/jbossas/jboss-as/blob/master/testsuite/integration/basic/src/test/resources/jboss-ejb-client.properties

          Otherwise whether you want to use, let's say, obsolete variant of the remote client properties definition then you need to pass it directly to the InintialContext when you are creating it. I think that the answer for your question is covered in the thread https://community.jboss.org/message/748087#748087

          • 2. Re: Remote EJB invocations using JNDI not working as Documented in Jboss 7.1.1
            donsenior

            Hi!

            As I said, I've followed the documentation step by step, I've created the jboss-ejb-client.properties and remove the jndi.properties, but it didn't work.

            I've also looked onto the thread you suggest and I can see that Mike is doing as I do:

             

                 public EJBClient() {

                   // setup 'base' jndi properties - no jboss-ejb-client.properties being picked up from classpath!

                   jndiProps = new Hashtable();

                      jndiProps.put("java.naming.factory.initial","org.jboss.naming.remote.client.InitialContextFactory");

                      jndiProps.put(InitialContext.PROVIDER_URL, "remote://localhost:4447");

                      jndiProps.put("jboss.naming.client.ejb.context", true);

                   

                      // needed for remote access - remember to run add-user.bat

                      jndiProps.put(Context.SECURITY_PRINCIPAL, "client");

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

                 }

             

            I am missing something?

             

            Thanks for your reply!

            • 3. Re: Remote EJB invocations using JNDI not working as Documented in Jboss 7.1.1
              ochaloup

              When you omit the solution described in the forum thread and you defines just jboss-ejb-client.properties and you define InitialContext in way like this:

              Properties properties = new Properties();

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

              return new InitialContext(properties);

              What exception do you get?

              • 4. Re: Remote EJB invocations using JNDI not working as Documented in Jboss 7.1.1
                donsenior

                Using:

                 

                jboss-ejb-client.properties

                remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false

                 

                remote.connections=default

                 

                remote.connection.default.host=192.168.215.30

                remote.connection.default.port=4447

                remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=true

                remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT=false

                 

                Context:



                Properties props = new Properties();

                 

                 



                props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
                //
                props.put(Context.SECURITY_PRINCIPAL, user);
                //
                props.put(Context.SECURITY_CREDENTIALS, pass);


                props.put("remote.connection.default.username", user);


                props.put("remote.connection.default.password", pass);

                 

                 



                Context context = new InitialContext(props);

                 

                Error:

                Exception in thread "main" javax.ejb.EJBAccessException: JBAS014502: Invocation on method: public abstract void com.package.mybeans.MyInteface.myMethod() of bean: MyBean is not allowed

                 

                With:

                 

                jboss-ejb-client.properties

                remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false

                 

                remote.connections=default

                 

                remote.connection.default.host=192.168.215.30

                remote.connection.default.port=4447

                remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=true

                remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT=true

                 

                Error:

                ERROR connection - JBREM000200: Remote connection failed: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed

                WARN  ConfigBasedEJBClientContextSelector - Could not register a EJB receiver for connection to remote://192.168.215.30:4447

                ERROR connection - JBREM000200: Remote connection failed: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed

                Exception in thread "main" java.lang.IllegalStateException: No EJB receiver available for handling [appName:myapp,modulename:mymodule,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@d2368df


                Same error if I use:

                 



                props.put(Context.SECURITY_PRINCIPAL, user);


                props.put(Context.SECURITY_CREDENTIALS, pass);
                //
                props.put("remote.connection.default.username", user);
                //
                props.put("remote.connection.default.password", pass);

                 

                My EJB is annotated with:

                 

                @SecurityDomain("other")

                @RolesAllowed({ "admin" })

                 

                And I have one user with that rol (the user and pass that I'm using to connect).

                 

                Removing the jboss-ejb-client.properties and using the mentioned jndi.properties works just fine!

                • 5. Re: Remote EJB invocations using JNDI not working as Documented in Jboss 7.1.1
                  donsenior

                  Well, the problem is that it doesn't like setting the user and pass in the initial context, by putting those properties in the jboss-ejb-client.properties works!!

                   

                  The problem is that I don't know that values until runtime (I'm using masked input from standard input)...

                   

                  Is there a proper way to achive this?

                  • 6. Re: Remote EJB invocations using JNDI not working as Documented in Jboss 7.1.1
                    ochaloup

                    Maybe you could try to check the following wiki page where is more detailed info about remoting:

                    https://docs.jboss.org/author/display/AS71/Remote+EJB+invocations+via+JNDI+-+EJB+client+API+or+remote-naming+project

                     

                    And then to your problem. Try to check this thread:

                    https://community.jboss.org/thread/177302

                    You'll need to use EJBClientContext.setSelector method which redefines currently defined InitialContext. It should be something like:

                     

                    ... creating InitialContext ...

                    Properties initProperties = new Properties();

                    properties.put(Context.URL_PKG_PREFIXES, PKG_INTERFACES);

                    initialContext = new InitialContext(initProperties);

                     

                    ...define props...

                    final EJBClientConfiguration ejbClientConfiguration = new PropertiesBasedEJBClientConfiguration(props);

                    final ConfigBasedEJBClientContextSelector selector = new ConfigBasedEJBClientContextSelector(ejbClientConfiguration);

                    ContextSelector<EJBClientContext> previousSelector = EJBClientContext.setSelector(selector);

                    • 7. Re: Remote EJB invocations using JNDI not working as Documented in Jboss 7.1.1
                      donsenior

                      Great! That do the trick, this is my final code:

                       

                      {code}

                      Properties jndiProperties = new Properties();

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

                       

                      Context context = new InitialContext(jndiProperties);

                       

                      Properties jbossProperties = new Properties();

                      jbossProperties.load(LoaderMain.class.getResourceAsStream("/jboss-ejb-client.properties"));

                      jbossProperties.put("remote.connection.default.username", user);

                      jbossProperties.put("remote.connection.default.password", pass);

                       

                      final EJBClientConfiguration ejbClientConfiguration = new PropertiesBasedEJBClientConfiguration(jbossProperties);

                       

                      // EJB client context selection is based on selectors. So let's create a ConfigBasedEJBClientContextSelector which uses our EJBClientConfiguration created in previous step

                      final ContextSelector<EJBClientContext> ejbClientContextSelector = new ConfigBasedEJBClientContextSelector(ejbClientConfiguration);

                       

                      // Now let's setup the EJBClientContext to use this selector

                      EJBClientContext.setSelector(ejbClientContextSelector);

                       

                      {code}

                       

                      I was trying to avoid the use of jboss propietary classes, but I think that's not posible if I want to use EJB Client API, and dynamically configurate properties.

                       

                      Thanks!

                      • 8. Re: Remote EJB invocations using JNDI not working as Documented in Jboss 7.1.1
                        chamzz

                        I also have the same problem and this is my initialContext  getting way.I can;t figureout why it shows error as

                        Exception in thread "main" java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:EmployeeModule,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@10f6d3

                         

                        public static Context getInitialContext() throws NamingException {

                        if (initialContext == null) {

                        Properties properties = new Properties();

                        properties.put(Context.URL_PKG_PREFIXES, PKG_INTERFACES);

                        initialContext = new InitialContext(properties);

                        }

                        return initialContext;

                        }

                        • 9. Re: Remote EJB invocations using JNDI not working as Documented in Jboss 7.1.1
                          ochaloup

                          hi chamzz,

                           

                          the error says in general there is not possible to find the expected bean at the remote point. Do you have correctly set up the jboss-ejb-client.properties (with correct address, port and credentials)? Is the variable PKG_INTERFACES referring to the jboss naming context org.jboss.ejb.client.naming? Do you set up the ejb name to search correctly? Is the searched bean defined with remote interface to be exported for the ejb lookup?