Use WebSphere bindings to define EJB local reference JNDI names

The WebLogic-specific deployment descriptor for EJBs, weblogic-ejb-jar.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 weblogic-ejb-jar.xml file. An automated fix will be provided. After the automated fix is applied, the WebLogic XML is marked with a comment indicating it has been migrated. This is used to determine whether to run the automted 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 is applied, the JNDI name is copied from the weblogic-ejb-jar.xml file to the WebSphere traditional and Liberty EJB bindings file. For example, the following example shows MyBean2 defining a reference to MyBean. First, the <ejb-local-ref> is defined 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 weblogic-ejb-jar.xml file:


<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>MyBean</ejb-name>
<jndi-name>ejb.MyBean</jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>MyBean2</ejb-name>
<ejb-local-reference-description>
<ejb-ref-name>ejb/MyBean</ejb-ref-name>
<jndi-name>ejb.MyBean</jndi-name>
</ejb-local-reference-description>
<jndi-name>ejb.MyBean2</jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>

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");