Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JMS JNDI problems

Status
Not open for further replies.

EcEiNeDnA

Programmer
Joined
Jan 10, 2003
Messages
1
Location
SG
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 = &quot;MyQCF&quot;;
public static final String qInLookup = &quot;MyQueue&quot;;

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(&quot;getting jndi context&quot;);
p.put(Context.PROVIDER_URL, &quot;file://c|/Sample/MessageTut/temp&quot;);
p.put(
Context.INITIAL_CONTEXT_FACTORY,
&quot;com.sun.jndi.fscontext.RefFSContextFactory&quot;);

System.out.println(&quot;pass1&quot;);
Context ctx = new InitialContext(p);
System.out.println(&quot;pass2&quot;);

// Obtain the connection factory from JNDI
System.out.println(&quot;Retrieving JMS objects from JNDI&quot;);
factory = (QueueConnectionFactory) ctx.lookup(qcfLookup);
System.out.println(&quot;pass3&quot;);
requestQueue = (Queue) ctx.lookup(qInLookup);
System.out.println(&quot;pass4&quot;);

} catch (NamingException e) {
System.err.println(&quot;Unable to obtain objects from JNDI&quot;);
e.printStackTrace(System.err);
System.exit(0);
}

// Sending a message
try {
System.out.println(
&quot;sending message <&quot; + text + &quot;> to &quot; + 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(&quot;message sent&quot;);

} catch (JMSException e) {
System.out.println(&quot;Unable to send message&quot;);
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(&quot;Error closing connection&quot;);
}
}
}

Could someone pls help me???
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top