Use WebSphere bindings to define EJB local reference JNDI names

The JBoss-specific deployment descriptor for EJBs, jboss.xml, might contain JNDI names for EJB local references defined in ejb-jar.xml. These references map an EJB local reference to its JNDI name. For these references to work correctly on WebSphere Application Server, information must be moved to the WebSphere Application Server bindings file.

This rule flags EJB local references found in the jboss.xml file, when the automated fix becomes available, the JBoss XML is marked with a comment indicating it has been migrated. This is used to determine whether to run the automated fix, and it can be used at the end of migration to indicate how much of the XML file has been migrated.

When the automated fix becomes available, the JNDI name will be copied from the jboss.xml file to the WebSphere EJB bindings file. For example, the following example shows MyBean2 defining a reference to MyBean. First, the <ejb-local-ref> is defined in the ejb-jar.xml file:

<ejb-jar>
<enterprise-beans>
<session>
<display-name>MyBean</display-name>
<ejb-name>MyBean</ejb-name>
<home>com.ibm.ejb.MyBeanHome</home>
<remote>com.ibm.ejb.MyBean</remote>
<ejb-class>com.ibm.ejb.MyBeanBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<jndi-name>ejb.MyBean</ejb-name>
...
</session>
<session>
<display-name>MyBean2</display-name>
<ejb-name>MyBean2</ejb-name>
<home>com.ibm.ejb.MyBean2Home</home>
<remote>com.ibm.ejb.MyBean2</remote>
<ejb-class>com.ibm.ejb.MyBean2Bean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<ejb-local-ref>
<description></description>
<ejb-ref-name>ejb/MyBean</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>com.ibm.ejb.MyBeanHome</local-home>
<local>com.ibm.ejb.MyBean</local>
</ejb-local-ref>
<jndi-name>ejb.MyBean2</ejb-name>
...
</session>
<enterprise-beans>
<ejb-jar>

Then, the corresponding <ejb-local-ref> JNDI name is defined in the jboss.xml file:


<jboss>
<enterprise-beans>
<session>
<ejb-name>MyBean</ejb-name>
<jndi-name>ejb.MyBean</jndi-name>
</session>
<session>
<ejb-name>MyBean2</ejb-name>
<jndi-name>ejb.MyBean2</jndi-name>
<ejb-local-ref>
<ejb-ref-name>ejb/MyBean</ejb-ref-name>
<local-jndi-name>ejb.MyBean</jndi-name>
</ejb-local-ref>
</session>
</enterprise-beans>
</jboss>

The automated fix will add the ejb.MyBean JNDI name to the bindings file and associates it with the ejb/MyBean local reference for MyBean2. If the binding file does not exist, one is created.

Within Java code, the naming context can be referenced as in the following example:

javax.naming.Context ctx = new javax.naming.InitialContext();
Object beanRef = ctx.lookup("java:comp/env/ejb/MyBean");