Do not use JBoss-specific JNDI property values

You must remove or replace JBoss-specific naming properties used when getting the IntialContext in your application. The migration tool scans Java and properties files for the property values: org.jnp.interfaces.NamingContextFactory, jnp://.* and org.jboss.naming.*. For example, if an application specifies the following properties, the tool would flag the red text:

Liberty

Java files

When moving your application to Liberty, do not specify an initial context factory or a provider URL in the properties passed to the InitialContext constructor. Use an empty constructor unless other naming properties are being set.

The following example illustrates application code that this rule will flag when migrating to Liberty:


import java.util.Hashtable;
import javax.naming.InitialContext;
...
void main( String[] args ) {
Hashtable ht = new Hashtable();

ht.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
ht.put("java.naming.provider.url", "jnp://localhost:1099");
ht.put("java.naming.factory.url.pkgs", "org.jboss.naming");

InitialContext ctx = new InitialContext(ht);
}

For Liberty, manually remove the unnecessary properties:


import javax.naming.InitialContext;
...
void main( String[] args ) {
InitialContext ctx = new InitialContext();
}

Property files

In addition to flagging java files, the tool will flag property files for the JBoss specific properties listed earlier. For Liberty, remove these properties from the file.

WebSphere Application Server traditional

Java files

When migrating to WebSphere Application Server traditional, the same JBoss properties mentioned earlier will be flagged. An automated fix will flagged Java files that changes the JBoss naming property values to the values that work in WebSphere Application Server traditional:

The following example illustrates application code that this rule will flag when migrating to WebSphere Application Server traditional:


import java.util.Hashtable;
import javax.naming.InitialContext;
...
void main( String[] args ) {
Hashtable ht = new Hashtable();

ht.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
ht.put("java.naming.provider.url", "jnp://localhost:1099");
ht.put("java.naming.factory.url.pkgs", "org.jboss.naming");

InitialContext ctx = new InitialContext(ht);
}

Using the example shown earlier, the code will be migrated as shown:


import java.util.Hashtable;;
import javax.naming.InitialContext;;

...

void main( String[] args ) {
Hashtable ht = new Hashtable();

ht.put("java.naming.factory.initial", "com.ibm.websphere.naming.WsnInitialContextFactory");
ht.put("java.naming.provider.url", "corbaloc:iiop:localhost:2809");
ht.put("java.naming.factory.url.pkgs", "com.ibm.ws.naming");

InitialContext ctx = new InitialContext(ht);
}

Another option when moving to WebSphere Application Server traditional is removing the properties and using the empty InitialContext() constructor.

When provided the automated fix will only be applied when the org.jboss.naming is specified with no trailing string as shown in the preceding example. If the org.jboss.naming value is followed by an additional string, the rule will flag the value. For example, this property will be flagged: java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces.


Property files

In addition to flagging java files, the tool will flag property files for the JBoss specific properties listed earlier. For WebSphere Application Server traditional, manually remove these properties from the file or change them to the WebSphere naming property values.