'Caused by: javax.naming.NamingException: WFLYNAM0027: Failed instantiate InitialContextFactory
I deployed a Java application on a JBoss server which allows to connect to WebSphere MQ server using the ressource adapter provided by WebSphere MQ. During the app start I had the problem Caused by: javax.naming.NamingException: WFLYNAM0027: Failed instantiate InitialContextFactory:
at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:360)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1378)
at java.lang.Thread.run(Thread.java:748)
Caused by: javax.naming.NamingException: WFLYNAM0027: Failed instantiate InitialContextFactory com.ibm.websphere.naming.WsnInitialContextFactory from classloader ModuleClassLoader for Module "JmsTest.war" from Service Module Loader [Root exception is java.lang.ClassNotFoundException: com.ibm.websphere.naming.WsnInitialContextFactory from [Module "deployment.JmsTest.war" from Service Module Loader]]
Here's my java code below :
Properties properties = new Properties();
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS, password);
properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
properties.put(Context.URL_PKG_PREFIXES, "com.ibm.ws.naming");
properties.put(Context.PROVIDER_URL, "remote://192.16.70.10:1234");
namingContext = new InitialContext(properties);
MQConnectionFactory cf = new MQConnectionFactory();
cf.setTransportType(WMQConstants.WMQ_CM_CLIENT);
cf.setHostName(mqHostName);
cf.setPort(Integer.parseInt(mqListenerPort));
cf.setQueueManager(mqQueueManagerName);
cf.setChannel(mqChannelName);
MQConnectionFactory factory = cf;
connection = factory.createConnection(user, password);
connection.start();
sessionConsumer = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
queue = namingContext.lookup(queue);
Can anyone help me? Any suggestion would be appreciated!
Solution 1:[1]
The root cause is:
java.lang.ClassNotFoundException: com.ibm.websphere.naming.WsnInitialContextFactory
This means that the application's classloader can't find this class.
However, one of the main benefits of using a JCA resource adapter is that you don't need to include provider-specific details in your code. In other words, you shouldn't be looking up JNDI resources directly on WebSphere MQ in your application code at all. All that stuff should be configured and bound into JNDI via the JCA resource adapter which you've deployed. Then you can perform a local JNDI lookup to access resources on the remote WebSphere MQ server. Then you're application won't need access to any provider-specific classes or configuration details. It can just use the Java EE APIs as they were designed to be used.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
