My custom sun.net.spi.nameservice.NameService not respected
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 6.x
- 7.x
Issue
- My custom name service1 is not loaded properly on EAP. It works on standalone Java.
Name services like DNS can be customized by implementing sun.net.spi.nameservice.NameService and specifying it by system property sun.net.spi.nameservice.provider.<n>. See the following documentation for the detail.
Content from docs.oracle.com is not included.Oracle Java SE Documentation | Networking Properties
Resolution
Upgrade to the latest update which includes the fix of WFCORE-19982.
By the fix, 2 module.xml files will be update.
$JBOSS_HOME/modules/system/layers/base/**/org/jboss/as/server/main/module.xml:
<module name="sun.jdk" services="export" export="true"/>
$JBOSS_HOME/modules/system/layers/base/**/sun/jdk/main/module.xml:
<path name="sun/net/spi/nameservice"/>
<path name="sun/net/spi/nameservice/dns"/>
Directly modifying anything under $JBOSS_HOME/modules/system/layers/base/ won't be supported. You can override "sun.jdk:main" module with your own NameService implementation, your_impl.jar, by putting under $JBOSS_HOME/modules/.
$JBOSS_HOME/modules/sun/jdk/main/module.xml:
<resource-root path="your_impl.jar"/>
Root Cause
The custom implementation is looked up and loaded by java.util.ServiceLoader.load(Class) method which uses the thread context class loader (TCCL). And the loading process is activated when java.net.InetAddress has been loaded. On EAP, InetAddress is loaded during the boot process and the TCCL is a module class loader of org.jboss.as.server module.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.