9 Replies Latest reply on Nov 26, 2012 5:28 AM by wdfink

    Dynamically changing jboss-ejb-client.properties, again

    veitg

      Hi.

       

      As mentioned in https://issues.jboss.org/browse/EJBCLIENT-12 changing connection parameters is really important to us as well. The ticket is closed, but isn't really a

      satisfying solution to us. The post to the example at the bottom (https://community.jboss.org/message/647202#647202) isn't satisfying as well, because then jboss

      specific client code is needed in our code. Reading the documentation shows, that another option exists: using -Djboss.ejb.client.properties.file.path=/home/me/my-client/custom-jboss-ejb-client.properties as

      a system property. But that means that a) I have to create a properties file on disk with the dynamic settings before invoking the client and b) that this settings will be jvm wide. So no connections

      to two different hosts in the same jvm. Not really a nice solution.

       

      So, why isn't it simply possible to put all keys, that are needed within the jboss-ejb-client.properties, in the jndi.properties or passing them in the constructor for InitialContext() like in the old days ?

      I understand, that these settings shouldn't be bound to JNDI in any way, but one could offer this as an option to the existing mechanisms. This way, our code won't depend on JBoss specific classes

      AND passing the configuration to the EJB client is dynamic enough.

       

      What do you think?

        • 1. Re: Dynamically changing jboss-ejb-client.properties, again
          elvisd

          Hi,

           

          I have managed to connect a client to a jboss instance without using that properties file.

          My code is working in JBoss AS 7.1 and 7.2 alpha 1 (and 6.0.0 EAP cause is based on 7.1)

          The code looks like:

           

          Properties clientProp = new Properties();

          clientProp.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");

          clientProp.put("remote.connections", "default");

          clientProp.put("remote.connection.default.host", "localhost"); // comes from JVM argument

          clientProp.put("remote.connection.default.port", "4447"); // comes from JVM argument

          clientProp.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");

           

          EJBClientConfiguration cc = new PropertiesBasedEJBClientConfiguration(clientProp);

          ContextSelector<EJBClientContext> selector = new ConfigBasedEJBClientContextSelector(cc);

          EJBClientContext.setSelector(selector);

           

          Properties props = new Properties();

          props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming:org.jnp.interfaces");

          // props.put("jboss.naming.client.ejb.context"/**/, true); // check if needed...

          context = new InitialContext(props);

           

          Hope this helps

          • 2. Re: Dynamically changing jboss-ejb-client.properties, again
            veitg

            Yes, but your code depends on JBoss specific client classes now .

            • 3. Re: Dynamically changing jboss-ejb-client.properties, again
              wdfink

              Hi,

               

              looks like that   Elvis D, use my example, just to clarify "jboss.naming.client.ejb.context" must be set if you don't have a jboss-ejb-client.properties file in your classpath, otherwise it will not work.

               

              Veit, for you, yes this is a lot of JBoss specific stuff in there.  But we are working on it, there is an enhancement EJBCLIENT-34 for this to provide a property based solution.

              But it depends on what you need. At the moment jaikiran pai and I are working on this and try to provide examples how to use this.

              The examples will be available via quickstarts, so check that list.

              • 4. Re: Dynamically changing jboss-ejb-client.properties, again
                veitg

                Great news. Thanks! I'll keep an eye on it .

                • 5. Re: Dynamically changing jboss-ejb-client.properties, again
                  fernando46

                  Is there any way to write a EJB independent (jboss-client.jar) from JBoss libraries?

                  • 6. Re: Dynamically changing jboss-ejb-client.properties, again
                    wdfink

                    Hi Fernando,

                     

                    you can use the remote-naming project or the new features of EJBCLIENT-34.

                    For EJBCLIENT-34 you need to have a 7.2 upstream build at the moment.

                    You need to set 'org.jboss.ejb.client.scoped.context' to true in your properties. All other properties are the same as in the example above.

                     

                    A example how to use it is available here.

                     


                    • 7. Re: Dynamically changing jboss-ejb-client.properties, again
                      qtm

                      In order to call bean1 on server1 from bean2 located on server2 without any property files or configurations on the server side it is necessary to write in bean2 something like:

                       

                          final Properties env1 = new Properties();       

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

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

                              env1.put("remote.connections", "Server-1");

                              env1.put("org.jboss.ejb.client.scoped.context", true);

                              env1.put("remote.connection.Server-1.host", "host");

                              env1.put("remote.connection.Server-1.port", "port");

                              env1.put("remote.connection.Server-1.username", "user");

                              env1.put("remote.connection.Server-1.password", "pass");

                           

                              final Context ctx = new InitialContext(env1);

                       

                      I am missing something, since the code above doesn't work. Could somebody point what's wrong?

                       

                      Thank you

                      • 8. Re: Dynamically changing jboss-ejb-client.properties, again
                        sfcoy

                        qtm wrote:

                         

                        In order to call bean1 on server1 from bean2 located on server2 without any property files or configurations ...

                        In my opinion the cleanest solution to this problem has always been to have federated JNDI working. I haven't yet looked into this with AS 7.x, but it was easy to do in previous JBoss versions.

                         

                        Doing it this way means that applications never deal with property files at all.

                        • 9. Re: Dynamically changing jboss-ejb-client.properties, again
                          wdfink

                          qtm schrieb:

                           

                          In order to call bean1 on server1 from bean2 located on server2 without any property files or configurations on the server side it is necessary to write in bean2 something like:

                           

                              final Properties env1 = new Properties();       

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

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

                                  env1.put("remote.connections", "Server-1");

                                  env1.put("org.jboss.ejb.client.scoped.context", true);

                                  env1.put("remote.connection.Server-1.host", "host");

                                  env1.put("remote.connection.Server-1.port", "port");

                                  env1.put("remote.connection.Server-1.username", "user");

                                  env1.put("remote.connection.Server-1.password", "pass");

                               

                                  final Context ctx = new InitialContext(env1);

                           

                          I am missing something, since the code above doesn't work. Could somebody point what's wrong?

                           

                          Thank you

                           

                          This code will not work correct inside the server as the EJBClientContext is global. With EJBCLIENT-34 a new feature is introduced that will resolve this.

                          I've implement an example here for the multi-server quickstart, but remember that this will only work if you have a AS7.2 (nightly build ATM)