"G.C. Miller" wrote:
>
> I am getting the following exception where trying to access a JMS queue
> created by jonas.
>
> Class: javax.naming.Reference
> Reference: org.objectweb.jonas_jms.QueueConnectionFactory
> java.lang.ClassCastException: javax.naming.Reference
> at
>
>com.triforcetech.messagepro.servlet.CImportMasterTargetListServlet.doPost(CImportMasterTargetListServlet.java:63)
>
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> at
> org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
>
> at org.apache.tomcat.core.Handler.service(Handler.java:287)
> at
> org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
> at
> org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:812)
>
> at
> org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
> at
>
>org.apache.tomcat.service.connector.Ajp13ConnectionHandler.processConnection(Ajp13ConnectionHandler.java:160)
>
> at
> org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
>
> at
> org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
>
> at java.lang.Thread.run(Thread.java:484)
>
> Here is the code to produce the error.
>
> import java.io.*;
> import java.util.*;
> import javax.jms.*;
> import javax.naming.*;
> import javax.rmi.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class CImportMasterTargetListServlet extends HttpServlet
> {
> public void doPost(HttpServletRequest inRequest, HttpServletResponse
> ioResponse)
> throws IOException, ServletException
> {
> try
> {
> InitialContext theEJBContext = new InitialContext();
>
> //QueueConnectionFactory theQueueConnectionFactory =
> (QueueConnectionFactory) theEJBContext.lookup("XAQCF1");
>
> Object theObj = theEJBContext.lookup("QCF1");
> if (theObj != null)
> {
> Class theClass = theObj.getClass();
> System.out.println("Class: " + theClass.getName());
> javax.naming.Reference theReference = (javax.naming.Reference)
> theObj;
> System.out.println("Reference: " + theReference.getClassName());
> QueueConnectionFactory theQueueConnectionFactory =
> (QueueConnectionFactory) theObj;
> QueueConnection theQueueConnection =
> theQueueConnectionFactory.createQueueConnection();
> QueueSession theQueueSession =
> theQueueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
> Queue theQueue = (Queue)
> theEJBContext.lookup("importMasterTargetListQueue");
> QueueSender theQueueSender = theQueueSession.createSender(theQueue);
>
> TextMessage theTextMessage =
> theQueueSession.createTextMessage("Test");
> theQueueSender.send(theTextMessage);
> theQueueSession.close();
> theQueueConnection.close();
> }
> else
> {
> System.out.println("Failed to lookup QCF1");
> }
> }
> catch (Exception inException)
> {
> inException.printStackTrace();
> }
>
> ioResponse.sendRedirect("/manager/targetmanager/index.jsp");
> }
> }
>
> Ok now for the wierd part. The above code works fine when turned into
> an application. It also works fine if the EJBServer and the Tomcat
> Server are on the same machine, however when the EJBServer is run on one
> machine and tomcat on another I can access session beans on the
> EJBServer but not the JMS queue! Anyone have any ideas?
>
> Thanks
> G.C. Miller
Hi!
I think your error is normal and I don't think that
the same code in an application is running.
You have a cast error because you are trying to cast
a QueueConnectionFactory to a Reference. But
org.objectweb.jonas_jms.QueueConnectionFactory
doesn't implement the interface Reference but Referenceable.
You will find attached the source code of a Servlet that send a JMS
TextMessage
to a Queue create by the EJBServer. (I think it is very closed to what
you want to do)
For me this servlet is running OK even if Tomcat and JOnAS doesn't run
on the same machine.
(You must set your jonas.jms.queues to sampleQueue
if you want to run TOMCAT in a different machine than JOnAS, don't
forget
to update the jndi.properties seen via TOMCAT by stting
java.naming.provider.url with the name of the machine where registry and
JOnas are running)
Can you confirm that it is the same for you in your environment?
Thank you very much
Best regards
--
Philippe
Philippe Coq Evidian Phone: (33) 04 76 29 78 49
Bull S.A - 1 rue de Provence - 38432 Echirolles Cedex France
Download our EJBServer at http://www.objectweb.org
Title: Sample of Servlet accessing JMS
package samples;
import java.io.*;
import java.util.*;
import javax.jms.*;
import javax.naming.*;
import javax.rmi.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SampleJmsServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
try {
InitialContext ctx = new InitialContext();
QueueConnectionFactory qcf = (QueueConnectionFactory)ctx.lookup("XAQCF1");
Queue queue = (Queue) ctx.lookup("sampleQueue");
QueueConnection qc = qcf.createQueueConnection();
QueueSession qs = qc.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
QueueSender sender = qs.createSender(queue);
TextMessage theTextMessage =
qs.createTextMessage("Test");
sender.send(theTextMessage);
qs.close();
qc.close();
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("");
out.println("");
out.println("");
out.println("Sample of Servlet accessing JMS!!!!!");
out.println("");
}catch (Exception inException){
inException.printStackTrace();
}
}
}
|