EJB client library

Remote EJB components can be invoked through the EJB client library. This library works inside the InitialContext. The library provides a JNDI context factory to invoke the EJBs. You must only configure the value org.jboss.ejb.client.naming for the java.naming.factory.url.pkgs key in your InitialContext instance:

Properties prop = new Properties();
prop.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
Context context = new InitialContext(prop);

With this environment property the IntitalContext has the URL context factory implementation of the EJB client library to handle the JBoss-specific namespaces for the EJB.
Other configuration properties to invoke the EJB must be put in a specific file, the jboss-ejb-client.properties. It's important for this file to be inside the class path. Usually, it is put in the root package of your classes. Following is an example:

remote.connections=default
remote.connection.default.host=127.0.0.1
remote.connection.default.port=8080
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT=false
remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS=${host.auth:JBOSS-LOCAL-USER}
remote.connection.default.username=${username}
remote.connection.default.password=${password}

Following is an example to call the EJB through JNDI:

context.lookup("ejb:/myapp/remoting/machine!it.vige.businesscomponents.businesslogic.remote.Machine");

When you invoke the stateless EJB through JNDI, a proxy is created for the client. There is no server connection until you invoke a method of the EJB. This invocation avoids network problems at the start of the client.

A different achievement is when you must invoke a stateful EJB. The stateful needs a session created server-side, so the invocation will be more sophisticated and a network server connection is mandatory. To invoke a stateful EJB you need to add the extension stateful to your JNDI URL.

The EJB client library supports the clustering too. Load balancing and failover are automatically managed by the lookup according to the chosen configuration.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.218.147