8 Replies Latest reply on Mar 18, 2013 12:44 PM by sammie88

    EJB  remote lookup

    sammie88 Newbie

      Hi,

       

      I am using jboss-as-7.1.1.Final 

      When I do want to do an ejb lookup - all I have to do is:

       

      Hashtable env = new Hashtable();

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

      ---

       

      new InitialContext(env).lookup(ejbLookup);

       

      and in jboss-ejb-client.properties:

      I have the ff:

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

      remote.connections=default

      remote.connection.default.host=localhost

      remote.connection.default.port = 4447

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

       

      remote.connection.default.username=xxx

      remote.connection.default.password=xxxxxxx

       

      Everything works fine.  Is there a way though to dynamically/programatically connect to the host and port.  Meaning, the user through the command line will supply the host and port rather than modifying the jboss-ejb-client.properties.  In the previous JBoss,

      we did this by:

       

      env.put(javax.naming.Context.PROVIDER_URL, PortAndIP);


      but it doesnt work anymore. Is this because of the user and password? Are user and password now required? Thank you for any help.

        • 1. Re: EJB  remote lookup
          Jay SenSharma Master

          Hi,

           

           

          Try using "EJBClientConfiguration" to avoid using the "jboss-ejb-clinet.properties"

           

           

          =====================

          JBoss EJB Client API

          =====================

          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.port", "4447");
          clientProp.put("remote.connection.default.host", "localhost");
          clientProp.put("remote.connection.default.username", "ejbUser");
          clientProp.put("remote.connection.default.password", "ejbPassword");
          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");
          Context ctx = new InitialContext(props);
          

           

           

           

          =============================

          JBoss Remoting Based EJB Client

          ============================

              private static void testRemoteNaming() throws Exception 
              {
                  System.out.println("*** Remote Naming API ***");
                  Hashtable<String, String> env = new Hashtable<String, String>();
                  env.put("java.naming.factory.initial", "org.jboss.naming.remote.client.InitialContextFactory");
                  env.put("java.naming.provider.url", "remote://127.0.0.1:4447");
                  env.put("jboss.naming.client.ejb.context", "true");
                  env.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");
                  env.put(Context.SECURITY_PRINCIPAL, "admin");
                  env.put(Context.SECURITY_CREDENTIALS, "testing");
                  InitialContext ctx = new InitialContext(env);
          

           

           

          You can use any of the above techniqueue.   But recommended will be  "JBoss EJB Client API based" EJB invocation.

           

          JBoss AS7.2 provides a method to configure an InitialContext with a Map to enable EJB Clients to access EJBs deployed across multiple servers in a cluster. The method also enables this configuration without dependencies on JBoss specific classes.

          • 2. Re: EJB  remote lookup
            Wolf-Dieter Fink Master

            I agree to Jay,

            additional you can find working examples here, if you will run it you need the multi-server project as well. Both are desinged as quickstarts but not integrated yet.

             

            In the client QS you will find all the different methods (including the new 7.2)

            1 of 1 people found this helpful
            • 3. Re: EJB  remote lookup
              sammie88 Newbie

              Thanks Jay..I tried your suggestion and it  works! Awesome!  Thank you Wolf too coz I was able to view more examples on this. I didnt have to supply the security credentials though ie.

               

              env.put(Context.SECURITY_PRINCIPAL, "admin");
              env.put(Context.SECURITY_CREDENTIALS, "testing");

               

              and I was still able to make an EJB connection.  Could it be because my client is on the same machine as my server? I wanted to be able to access the server from another client machine so I made "public" bound to my IP address (ie.111.1111.1.11) or should I make another interface and leave public alone? If so, could I still use the same ports as the public's?  I wanted to make a connection using the IP address (not localhost) so I can connect from another client machine to the server . Is this the correct way to do it? Sorry, I am really new to this and appreciate all the help.

               

              <interfaces>

                      <interface name="management">

                          <inet-address value="${jboss.bind.address.management:127.0.0.1}"/>

                      </interface>

                      <interface name="public">

                          <inet-address value="${jboss.bind.address:111.111.1.11}"/>

                      </interface>

                      <interface name="unsecure">

                          <inet-address value="${jboss.bind.address.unsecure:127.0.0.1}"/>

                      </interface>

                  </interfaces>

               

               

                  <socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">

                      <socket-binding name="management-native" interface="management" port="${jboss.management.native.port:9999}"/>

                      <socket-binding name="management-http" interface="management" port="${jboss.management.http.port:9990}"/>

                      <socket-binding name="management-https" interface="management" port="${jboss.management.https.port:9443}"/>

                      <socket-binding name="ajp" port="8009"/>

                      <socket-binding name="http" port="8080"/>

                      <socket-binding name="https" port="8443"/>

                      <socket-binding name="osgi-http" interface="management" port="8090"/>

                      <socket-binding name="remoting" port="4447"/>

                      <socket-binding name="txn-recovery-environment" port="4712"/>

                      <socket-binding name="txn-status-manager" port="4713"/>

                      <outbound-socket-binding name="mail-smtp">

                          <remote-destination host="localhost" port="25"/>

                      </outbound-socket-binding>

                  </socket-binding-group>

              • 4. Re: EJB  remote lookup
                Wolf-Dieter Fink Master

                With AS7.1.1 there is no option to change the behaviour how local connections are handled.

                With AS7.1.2 the management section include a local element to control that.

                 

                In your case it is detected that the client, or CLI client, is at the same box and therefore you can access without authentication.

                From AS7.1.2 you can remove the 'local' element to force the authentication. Also you migt set the property 'remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS' = 'JBOSS_LOCAL_USER'

                for the client properties. This will also force the authentication.

                 

                If you set the public interface to the IP address you can access the application from outside, to access the management also you can change the management interface alos.

                The addresses can be set by -b ... and -bmanagement ... via command line in standalone mode.

                • 5. Re: EJB  remote lookup
                  sammie88 Newbie

                  Thanks Wolf! Does this mean though that when you are connecting from another box, you are required to provide  user/passwd? I am porting a Jboss 4.2.3 app and I dont think we supplied credentials even coming from  another box.  Thank you again for your help!

                  • 6. Re: EJB  remote lookup
                    Wolf-Dieter Fink Master

                    You might remove the complete authentication by removing the 'security-realm' from the remoting connector.

                    But in this case you will lost the authorization.

                     

                     

                    <subsystem xmlns="urn:jboss:domain:remoting:1.1">

                       <connector name="remoting-connector" socket-binding="remoting" security-realm="ApplicationRealm"/>

                    </subsystem>

                    1 of 1 people found this helpful
                    • 7. Re: EJB  remote lookup
                      jaikiran pai Master

                      sammie88 wrote:

                       

                      I am porting a Jboss 4.2.3 app and I dont think we supplied credentials even coming from  another box. 

                      AS7 is secured by default http://community.jboss.org/wiki/AS710Beta1-SecurityEnabledByDefault

                      • 8. Re: EJB  remote lookup
                        sammie88 Newbie

                        Thank you wolf for all the info! Yes I tried that and it did remove the security. I appreciate the help! Thank you jaikiran too for the link!