Hi,
I am using Websphere Application Developer version 4.0.3 and MQ Series v5.3.
I am currently writing a normal java bean that send message to a Queue. Then i wrap the method sendMessage in my codes as a web service. When i use a test client to test run my web service i got the error as below:
Unable to obtain objects from JNDI
javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.jndi.fscontext.RefFSContextFactory. Root exception is java.lang.ClassNotFoundException: com.sun.jndi.fscontext.RefFSContextFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:325)
at java.lang.ClassLoader.loadClass(ClassLoader.java:257)
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:296)
at java.lang.ClassLoader.loadClass(ClassLoader.java:257)
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:296)
at java.lang.ClassLoader.loadClass(ClassLoader.java:257)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:212)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:46)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:656)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.InitialContext.<init>(InitialContext.java:199)
at com.alert.QSender.produceMessage(QSender.java:60)
at java.lang.reflect.Method.invoke(Native Method)
at org.apache.soap.server.RPCRouter.invoke(RPCRouter.java:146)
at org.apache.soap.providers.RPCJavaProvider.invoke(RPCJavaProvider.java:129)
at org.apache.soap.server.http.RPCRouterServlet.doPost(RPCRouterServlet.java:301)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.servlet.engine.webapp.StrictServletInstance.doService(ServletManager.java:827)
at com.ibm.servlet.engine.webapp.StrictLifecycleServlet._service(StrictLifecycleServlet.java:167)
at com.ibm.servlet.engine.webapp.IdleServletState.service(StrictLifecycleServlet.java:297)
at com.ibm.servlet.engine.webapp.StrictLifecycleServlet.service(StrictLifecycleServlet.java:110)
at com.ibm.servlet.engine.webapp.ServletInstance.service(ServletManager.java:472)
at com.ibm.servlet.engine.webapp.ValidServletReferenceState.dispatch(ServletManager.java:1012)
at com.ibm.servlet.engine.webapp.ServletInstanceReference.dispatch(ServletManager.java:913)
at com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:523)
at com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:282)
at com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:112)
at com.ibm.servlet.engine.srt.WebAppInvoker.doForward(WebAppInvoker.java:91)
at com.ibm.servlet.engine.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:184)
at com.ibm.servlet.engine.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:67)
at com.ibm.servlet.engine.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:122)
at com.ibm.servlet.engine.oselistener.OSEListenerDispatcher.service(OSEListener.java:315)
at com.ibm.servlet.engine.http11.HttpConnection.handleRequest(HttpConnection.java:60)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:323)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:252)
at com.ibm.ws.util.CachedThread.run(ThreadPool.java:122)
However, when i run my bean as a normal java application i did not encouner any problem. i have successfully inserted the message into the queue.
I have use Files system for binding. and Also i have included all the necessary .jars files: com.ibm.mq.jar,com.ibm.mqjms.jar,connector.jar,,fscontext.jar,providerutil.jar in my project.
and also added these jar into my classpath.
com.ibm.mq.jar,com.ibm.mqjms.jar,jms.jar,connector.jar,jndi.jar,ldap.jar,fscontext.jar,providerutil.jar.
Below are my codes....
import javax.naming.*;
import javax.jms.*;
import java.util.*;
public class QSender {
public static final String qcfLookup = "MyQCF";
public static final String qInLookup = "MyQueue";
static Queue requestQueue;
static QueueConnectionFactory factory;
static QueueConnection qCon;
static QueueSession qSession;
public void produceMessage(String text) {
try {
// use the file system JNDI context
Hashtable p = new Hashtable();
System.out.println("getting jndi context"
;
p.put(Context.PROVIDER_URL, "file://c|/Sample/MessageTut/temp"
;
p.put(
Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory"
;
System.out.println("pass1"
;
Context ctx = new InitialContext(p);
System.out.println("pass2"
;
// Obtain the connection factory from JNDI
System.out.println("Retrieving JMS objects from JNDI"
;
factory = (QueueConnectionFactory) ctx.lookup(qcfLookup);
System.out.println("pass3"
;
requestQueue = (Queue) ctx.lookup(qInLookup);
System.out.println("pass4"
;
} catch (NamingException e) {
System.err.println("Unable to obtain objects from JNDI"
;
e.printStackTrace(System.err);
System.exit(0);
}
// Sending a message
try {
System.out.println(
"sending message <" + text + "> to " + requestQueue.getQueueName());
// get a connection and start it
QueueConnection qCon = factory.createQueueConnection();
qCon.start();
// Create a session from from the conection
qSession = qCon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
// Create a sender from the session
QueueSender qSender = qSession.createSender(requestQueue);
// Create a message to send to the queue...
TextMessage message = qSession.createTextMessage(text);
// ...now send the message
qSender.send(message);
System.out.println("message sent"
;
} catch (JMSException e) {
System.out.println("Unable to send message"
;
e.printStackTrace(System.err);
System.exit(0);
// always close the connection when done
} finally {
try {
if (qSession != null) {
qSession.close();
qSession = null;
}
if (qCon != null) {
qCon.close();
qCon = null;
}
} catch (JMSException e) {
System.out.println("Error closing connection"
;
}
}
}
Could someone pls help me???
I am using Websphere Application Developer version 4.0.3 and MQ Series v5.3.
I am currently writing a normal java bean that send message to a Queue. Then i wrap the method sendMessage in my codes as a web service. When i use a test client to test run my web service i got the error as below:
Unable to obtain objects from JNDI
javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.jndi.fscontext.RefFSContextFactory. Root exception is java.lang.ClassNotFoundException: com.sun.jndi.fscontext.RefFSContextFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:325)
at java.lang.ClassLoader.loadClass(ClassLoader.java:257)
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:296)
at java.lang.ClassLoader.loadClass(ClassLoader.java:257)
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:296)
at java.lang.ClassLoader.loadClass(ClassLoader.java:257)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:212)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:46)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:656)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.InitialContext.<init>(InitialContext.java:199)
at com.alert.QSender.produceMessage(QSender.java:60)
at java.lang.reflect.Method.invoke(Native Method)
at org.apache.soap.server.RPCRouter.invoke(RPCRouter.java:146)
at org.apache.soap.providers.RPCJavaProvider.invoke(RPCJavaProvider.java:129)
at org.apache.soap.server.http.RPCRouterServlet.doPost(RPCRouterServlet.java:301)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.servlet.engine.webapp.StrictServletInstance.doService(ServletManager.java:827)
at com.ibm.servlet.engine.webapp.StrictLifecycleServlet._service(StrictLifecycleServlet.java:167)
at com.ibm.servlet.engine.webapp.IdleServletState.service(StrictLifecycleServlet.java:297)
at com.ibm.servlet.engine.webapp.StrictLifecycleServlet.service(StrictLifecycleServlet.java:110)
at com.ibm.servlet.engine.webapp.ServletInstance.service(ServletManager.java:472)
at com.ibm.servlet.engine.webapp.ValidServletReferenceState.dispatch(ServletManager.java:1012)
at com.ibm.servlet.engine.webapp.ServletInstanceReference.dispatch(ServletManager.java:913)
at com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:523)
at com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:282)
at com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:112)
at com.ibm.servlet.engine.srt.WebAppInvoker.doForward(WebAppInvoker.java:91)
at com.ibm.servlet.engine.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:184)
at com.ibm.servlet.engine.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:67)
at com.ibm.servlet.engine.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:122)
at com.ibm.servlet.engine.oselistener.OSEListenerDispatcher.service(OSEListener.java:315)
at com.ibm.servlet.engine.http11.HttpConnection.handleRequest(HttpConnection.java:60)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:323)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:252)
at com.ibm.ws.util.CachedThread.run(ThreadPool.java:122)
However, when i run my bean as a normal java application i did not encouner any problem. i have successfully inserted the message into the queue.
I have use Files system for binding. and Also i have included all the necessary .jars files: com.ibm.mq.jar,com.ibm.mqjms.jar,connector.jar,,fscontext.jar,providerutil.jar in my project.
and also added these jar into my classpath.
com.ibm.mq.jar,com.ibm.mqjms.jar,jms.jar,connector.jar,jndi.jar,ldap.jar,fscontext.jar,providerutil.jar.
Below are my codes....
import javax.naming.*;
import javax.jms.*;
import java.util.*;
public class QSender {
public static final String qcfLookup = "MyQCF";
public static final String qInLookup = "MyQueue";
static Queue requestQueue;
static QueueConnectionFactory factory;
static QueueConnection qCon;
static QueueSession qSession;
public void produceMessage(String text) {
try {
// use the file system JNDI context
Hashtable p = new Hashtable();
System.out.println("getting jndi context"
p.put(Context.PROVIDER_URL, "file://c|/Sample/MessageTut/temp"
p.put(
Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory"
System.out.println("pass1"
Context ctx = new InitialContext(p);
System.out.println("pass2"
// Obtain the connection factory from JNDI
System.out.println("Retrieving JMS objects from JNDI"
factory = (QueueConnectionFactory) ctx.lookup(qcfLookup);
System.out.println("pass3"
requestQueue = (Queue) ctx.lookup(qInLookup);
System.out.println("pass4"
} catch (NamingException e) {
System.err.println("Unable to obtain objects from JNDI"
e.printStackTrace(System.err);
System.exit(0);
}
// Sending a message
try {
System.out.println(
"sending message <" + text + "> to " + requestQueue.getQueueName());
// get a connection and start it
QueueConnection qCon = factory.createQueueConnection();
qCon.start();
// Create a session from from the conection
qSession = qCon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
// Create a sender from the session
QueueSender qSender = qSession.createSender(requestQueue);
// Create a message to send to the queue...
TextMessage message = qSession.createTextMessage(text);
// ...now send the message
qSender.send(message);
System.out.println("message sent"
} catch (JMSException e) {
System.out.println("Unable to send message"
e.printStackTrace(System.err);
System.exit(0);
// always close the connection when done
} finally {
try {
if (qSession != null) {
qSession.close();
qSession = null;
}
if (qCon != null) {
qCon.close();
qCon = null;
}
} catch (JMSException e) {
System.out.println("Error closing connection"
}
}
}
Could someone pls help me???