Migrate Applications From Other Platforms to Use Portable JNDI Syntax in Red Hat JBoss Enterprise Application Platform
Summary
Red Hat JBoss Enterprise Application Platform 6 uses standardized portable EJB JNDI namespaces. Applications created on other platforms, for example WebLogic or Websphere, that contain EJBs that use JNDI must be changed to follow the standardized JNDI namespace convention.
Replace JNDI Lookup Code
Applications migrating from other platforms may create a Hashtable
containing environment information, such as provider the URL, context factory, security principal and credentials, and pass this table as a parameter when creating the InitialContext
.
This is an example of how the code might look in WebLogic:
Hashtable<String, String> env = new Hashtable<String, String>();
env.put( Context.PROVIDER_URL, "t3://localhost:7001" );
env.put( Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory" );
env.put( Context.SECURITY_PRINCIPAL, "weblogic" );
env.put( Context.SECURITY_CREDENTIALS, "weblogic" );
Context context = new InitialContext( env );
Service service = (Service)context.lookup( "sample.Service#" + Service.class.getName() );
In JBoss EAP, you instantiate the InitialContext
with no arguments and then look up the Service
using the portable JNDI namespaces:
- java:global
- java:app
- java:module.
This is an example of how the same code would look in JBoss EAP:
Context context = new InitialContext();
Service service = (Service) context.lookup( "java:app/service/" + ServiceImpl.class.getSimpleName() );
Additional Resources
For more information about portable JNDI naming syntax, see the section entitled JNDI Changes in the Migration Guide for JBoss EAP.
Comments