You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by "Suchitha Koneru (sukoneru)" <su...@cisco.com> on 2007/01/19 19:59:27 UTC

active mq and tomcat 5.5

Hello active mq users , 

is there any good tutorial, which will explain configuring active mq on
tomcat 5.5 ? I am running into the following issue.

I have the following configuration on my system 

tomcat 5.5 

java 1.5.09

activemq jars version 4.0

The active MQ broker is started  , from the application . 

the code for it is 

public void contextInitialized(ServletContextEvent arg0) {

try{

System.out.println("Starting ActiveMQ Broker Service...");

broker.addConnector("tcp://localhost:61616?trace=true");

broker.start();

System.out.println("Active MQ Broker Started at local host port 61616");

}catch(Exception e){

System.err.println(e.getMessage());

e.printStackTrace();

throw new RuntimeException(e);

}

}

 

In server.xml , I placed the JNDI resources as follows
<GlobalNamingResources>

<Resource name="jms/TopicConnectionFactory" 

auth="Container" 

type="org.apache.activemq.ActiveMQConnectionFactory" 

description="JMS Connection Factory"

factory="org.apache.activemq.jndi.JNDIReferenceFactory" 

brokerURL="tcp://localhost:61716" 

brokerName="LocalActiveMQBroker"/>

<Resource name="jms/Topic" 

auth="Container" 

type="org.apache.activemq.command.ActiveMQTopic" 

description="sample Topic"

factory="org.apache.activemq.jndi.JNDIReferenceFactory" 

physicalName="FOO.BAR"/> 

</GlobalNamingResources>

I have a web app called UI , I am trying to access these global jndi
recources from this web app, Hence the context.xml for this web app has
the following 

<Context reloadable="true">

<ResourceLink
name="ConnectionFactory"global="jms/TopicConnectionFactory" type=
"org.apache.activemq.ActiveMQConnectionFactory" />

<ResourceLink name="PNMTopic" global="jms/Topic" type=
"org.apache.activemq.command.ActiveMQTopic" />

</Context>

The subsciber class in the UI context is as follows 

public class PNMSubscriber {

TopicConnection tConn ;

TopicConnectionFactory tFactory ;

Topic pnmTopic;

ActiveMQTopicSession pnmSession ;

public PNMSubscriber(){

try{

InitialContext initialContext = new InitialContext();

Context envContext = (Context) initialContext.lookup("java:comp/env");

tFactory
=(TopicConnectionFactory)envContext.lookup("ConnectionFactory");

tConn = tFactory.createTopicConnection();

pnmSession = (ActiveMQTopicSession) tConn.createTopicSession(true,
Session.AUTO_ACKNOWLEDGE); 

pnmTopic = (Topic)envContext.lookup("PNMTopic");

pnmSubscriber = pnmSession.createSubscriber(pnmTopic);

}catch(Exception e){

e.printStackTrace();

}

}

I get a class cast exception as follows 

java.lang.ClassCastException:
org.apache.activemq.ActiveMQConnectionFactory

at
com.cpnm.common.messaging.PNMSubscriber.<init>(PNMSubscriber.java:40)

The exception is raised , at the following line , in the code above.

tFactory =
(TopicConnectionFactory)envContext.lookup("ConnectionFactory");

I tried casting the object to "ActiveMQConnectionFactory" , I still get
the same exception.

I think, Iam missing something in the configuration, please let me know,
if I need to add anything else.

thank you,

Suchitha.


RE: active mq and tomcat 5.5

Posted by to...@jpmchase.com.
Hi Suchitha,

I've seen this sort of error when there is more than one ActiveMQ JAR in 
the classpath. This can happen if there is one version in 
$CATALINA_HOME/shared/lib, and different version included with your WAR 
file. In this situation the resource in JNDI will have been created using 
the shared JAR, but your application is expecting an object created using 
the JAR bundled with your web application. Even though they share the same 
package name Java will complain with a ClassCastException. This may not be 
what's happening here, but it's a possible explanation.

Hope this helps,

- Tony




"Suchitha Koneru \(sukoneru\)" <su...@cisco.com> 
01/19/2007 02:36 PM
Please respond to
activemq-users@geronimo.apache.org


To
<ac...@geronimo.apache.org>
cc

Subject
RE: active mq and tomcat 5.5






Thanks for your response , I tried using the latest version of activemq
jars (i.e 4.1)
The class of the object being returned 
Is 
org.apache.activemq.ActiveMQConnectionFactory.
I tried casting it to this type as well, but still I get the class cast
exception 

java.lang.ClassCastException:
org.apache.activemq.ActiveMQConnectionFactory
        at
com.cpnm.common.messaging.PNMSubscriber.<init>(PNMSubscriber.java:45)

I am not sure , as to what is going worng. 



-----Original Message-----
From: Adrian Co [mailto:aco@exist.com] 
Sent: Friday, January 19, 2007 11:11 AM
To: activemq-users@geronimo.apache.org
Subject: Re: active mq and tomcat 5.5

Have you tried using the 4.1 jars?

What is the class of the object being returned?

Suchitha Koneru (sukoneru) wrote:
> Hello active mq users ,
>
> is there any good tutorial, which will explain configuring active mq 
> on tomcat 5.5 ? I am running into the following issue.
>
> I have the following configuration on my system
>
> tomcat 5.5
>
> java 1.5.09
>
> activemq jars version 4.0
>
> The active MQ broker is started  , from the application . 
>
> the code for it is
>
> public void contextInitialized(ServletContextEvent arg0) {
>
> try{
>
> System.out.println("Starting ActiveMQ Broker Service...");
>
> broker.addConnector("tcp://localhost:61616?trace=true");
>
> broker.start();
>
> System.out.println("Active MQ Broker Started at local host port 
> 61616");
>
> }catch(Exception e){
>
> System.err.println(e.getMessage());
>
> e.printStackTrace();
>
> throw new RuntimeException(e);
>
> }
>
> }
>
> 
>
> In server.xml , I placed the JNDI resources as follows 
> <GlobalNamingResources>
>
> <Resource name="jms/TopicConnectionFactory" 
>
> auth="Container" 
>
> type="org.apache.activemq.ActiveMQConnectionFactory" 
>
> description="JMS Connection Factory"
>
> factory="org.apache.activemq.jndi.JNDIReferenceFactory" 
>
> brokerURL="tcp://localhost:61716" 
>
> brokerName="LocalActiveMQBroker"/>
>
> <Resource name="jms/Topic" 
>
> auth="Container" 
>
> type="org.apache.activemq.command.ActiveMQTopic" 
>
> description="sample Topic"
>
> factory="org.apache.activemq.jndi.JNDIReferenceFactory" 
>
> physicalName="FOO.BAR"/>
>
> </GlobalNamingResources>
>
> I have a web app called UI , I am trying to access these global jndi 
> recources from this web app, Hence the context.xml for this web app 
> has the following
>
> <Context reloadable="true">
>
> <ResourceLink
> name="ConnectionFactory"global="jms/TopicConnectionFactory" type= 
> "org.apache.activemq.ActiveMQConnectionFactory" />
>
> <ResourceLink name="PNMTopic" global="jms/Topic" type= 
> "org.apache.activemq.command.ActiveMQTopic" />
>
> </Context>
>
> The subsciber class in the UI context is as follows
>
> public class PNMSubscriber {
>
> TopicConnection tConn ;
>
> TopicConnectionFactory tFactory ;
>
> Topic pnmTopic;
>
> ActiveMQTopicSession pnmSession ;
>
> public PNMSubscriber(){
>
> try{
>
> InitialContext initialContext = new InitialContext();
>
> Context envContext = (Context) initialContext.lookup("java:comp/env");
>
> tFactory
> =(TopicConnectionFactory)envContext.lookup("ConnectionFactory");
>
> tConn = tFactory.createTopicConnection();
>
> pnmSession = (ActiveMQTopicSession) tConn.createTopicSession(true, 
> Session.AUTO_ACKNOWLEDGE);
>
> pnmTopic = (Topic)envContext.lookup("PNMTopic");
>
> pnmSubscriber = pnmSession.createSubscriber(pnmTopic);
>
> }catch(Exception e){
>
> e.printStackTrace();
>
> }
>
> }
>
> I get a class cast exception as follows
>
> java.lang.ClassCastException:
> org.apache.activemq.ActiveMQConnectionFactory
>
> at
> com.cpnm.common.messaging.PNMSubscriber.<init>(PNMSubscriber.java:40)
>
> The exception is raised , at the following line , in the code above.
>
> tFactory =
> (TopicConnectionFactory)envContext.lookup("ConnectionFactory");
>
> I tried casting the object to "ActiveMQConnectionFactory" , I still 
> get the same exception.
>
> I think, Iam missing something in the configuration, please let me 
> know, if I need to add anything else.
>
> thank you,
>
> Suchitha.
>
>
> 




-----------------------------------------
This transmission may contain information that is privileged,
confidential, legally privileged, and/or exempt from disclosure
under applicable law.  If you are not the intended recipient, you
are hereby notified that any disclosure, copying, distribution, or
use of the information contained herein (including any reliance
thereon) is STRICTLY PROHIBITED.  Although this transmission and
any attachments are believed to be free of any virus or other
defect that might affect any computer system into which it is
received and opened, it is the responsibility of the recipient to
ensure that it is virus free and no responsibility is accepted by
JPMorgan Chase & Co., its subsidiaries and affiliates, as
applicable, for any loss or damage arising in any way from its use.
If you received this transmission in error, please immediately
contact the sender and destroy the material in its entirety,
whether in electronic or hard copy format. Thank you.

RE: active mq and tomcat 5.5

Posted by "Suchitha Koneru (sukoneru)" <su...@cisco.com>.
Thanks for your response , I tried using the latest version of activemq
jars (i.e 4.1)
The class of the object being returned 
Is 
org.apache.activemq.ActiveMQConnectionFactory.
I tried casting it to this type as well, but still I get the class cast
exception 

java.lang.ClassCastException:
org.apache.activemq.ActiveMQConnectionFactory
        at
com.cpnm.common.messaging.PNMSubscriber.<init>(PNMSubscriber.java:45)

I am not sure , as to what is going worng. 



-----Original Message-----
From: Adrian Co [mailto:aco@exist.com] 
Sent: Friday, January 19, 2007 11:11 AM
To: activemq-users@geronimo.apache.org
Subject: Re: active mq and tomcat 5.5

Have you tried using the 4.1 jars?

What is the class of the object being returned?

Suchitha Koneru (sukoneru) wrote:
> Hello active mq users ,
>
> is there any good tutorial, which will explain configuring active mq 
> on tomcat 5.5 ? I am running into the following issue.
>
> I have the following configuration on my system
>
> tomcat 5.5
>
> java 1.5.09
>
> activemq jars version 4.0
>
> The active MQ broker is started  , from the application . 
>
> the code for it is
>
> public void contextInitialized(ServletContextEvent arg0) {
>
> try{
>
> System.out.println("Starting ActiveMQ Broker Service...");
>
> broker.addConnector("tcp://localhost:61616?trace=true");
>
> broker.start();
>
> System.out.println("Active MQ Broker Started at local host port 
> 61616");
>
> }catch(Exception e){
>
> System.err.println(e.getMessage());
>
> e.printStackTrace();
>
> throw new RuntimeException(e);
>
> }
>
> }
>
>  
>
> In server.xml , I placed the JNDI resources as follows 
> <GlobalNamingResources>
>
> <Resource name="jms/TopicConnectionFactory" 
>
> auth="Container" 
>
> type="org.apache.activemq.ActiveMQConnectionFactory" 
>
> description="JMS Connection Factory"
>
> factory="org.apache.activemq.jndi.JNDIReferenceFactory" 
>
> brokerURL="tcp://localhost:61716" 
>
> brokerName="LocalActiveMQBroker"/>
>
> <Resource name="jms/Topic" 
>
> auth="Container" 
>
> type="org.apache.activemq.command.ActiveMQTopic" 
>
> description="sample Topic"
>
> factory="org.apache.activemq.jndi.JNDIReferenceFactory" 
>
> physicalName="FOO.BAR"/>
>
> </GlobalNamingResources>
>
> I have a web app called UI , I am trying to access these global jndi 
> recources from this web app, Hence the context.xml for this web app 
> has the following
>
> <Context reloadable="true">
>
> <ResourceLink
> name="ConnectionFactory"global="jms/TopicConnectionFactory" type= 
> "org.apache.activemq.ActiveMQConnectionFactory" />
>
> <ResourceLink name="PNMTopic" global="jms/Topic" type= 
> "org.apache.activemq.command.ActiveMQTopic" />
>
> </Context>
>
> The subsciber class in the UI context is as follows
>
> public class PNMSubscriber {
>
> TopicConnection tConn ;
>
> TopicConnectionFactory tFactory ;
>
> Topic pnmTopic;
>
> ActiveMQTopicSession pnmSession ;
>
> public PNMSubscriber(){
>
> try{
>
> InitialContext initialContext = new InitialContext();
>
> Context envContext = (Context) initialContext.lookup("java:comp/env");
>
> tFactory
> =(TopicConnectionFactory)envContext.lookup("ConnectionFactory");
>
> tConn = tFactory.createTopicConnection();
>
> pnmSession = (ActiveMQTopicSession) tConn.createTopicSession(true, 
> Session.AUTO_ACKNOWLEDGE);
>
> pnmTopic = (Topic)envContext.lookup("PNMTopic");
>
> pnmSubscriber = pnmSession.createSubscriber(pnmTopic);
>
> }catch(Exception e){
>
> e.printStackTrace();
>
> }
>
> }
>
> I get a class cast exception as follows
>
> java.lang.ClassCastException:
> org.apache.activemq.ActiveMQConnectionFactory
>
> at
> com.cpnm.common.messaging.PNMSubscriber.<init>(PNMSubscriber.java:40)
>
> The exception is raised , at the following line , in the code above.
>
> tFactory =
> (TopicConnectionFactory)envContext.lookup("ConnectionFactory");
>
> I tried casting the object to "ActiveMQConnectionFactory" , I still 
> get the same exception.
>
> I think, Iam missing something in the configuration, please let me 
> know, if I need to add anything else.
>
> thank you,
>
> Suchitha.
>
>
>   

Re: active mq and tomcat 5.5

Posted by Adrian Co <ac...@exist.com>.
Have you tried using the 4.1 jars?

What is the class of the object being returned?

Suchitha Koneru (sukoneru) wrote:
> Hello active mq users , 
>
> is there any good tutorial, which will explain configuring active mq on
> tomcat 5.5 ? I am running into the following issue.
>
> I have the following configuration on my system 
>
> tomcat 5.5 
>
> java 1.5.09
>
> activemq jars version 4.0
>
> The active MQ broker is started  , from the application . 
>
> the code for it is 
>
> public void contextInitialized(ServletContextEvent arg0) {
>
> try{
>
> System.out.println("Starting ActiveMQ Broker Service...");
>
> broker.addConnector("tcp://localhost:61616?trace=true");
>
> broker.start();
>
> System.out.println("Active MQ Broker Started at local host port 61616");
>
> }catch(Exception e){
>
> System.err.println(e.getMessage());
>
> e.printStackTrace();
>
> throw new RuntimeException(e);
>
> }
>
> }
>
>  
>
> In server.xml , I placed the JNDI resources as follows
> <GlobalNamingResources>
>
> <Resource name="jms/TopicConnectionFactory" 
>
> auth="Container" 
>
> type="org.apache.activemq.ActiveMQConnectionFactory" 
>
> description="JMS Connection Factory"
>
> factory="org.apache.activemq.jndi.JNDIReferenceFactory" 
>
> brokerURL="tcp://localhost:61716" 
>
> brokerName="LocalActiveMQBroker"/>
>
> <Resource name="jms/Topic" 
>
> auth="Container" 
>
> type="org.apache.activemq.command.ActiveMQTopic" 
>
> description="sample Topic"
>
> factory="org.apache.activemq.jndi.JNDIReferenceFactory" 
>
> physicalName="FOO.BAR"/> 
>
> </GlobalNamingResources>
>
> I have a web app called UI , I am trying to access these global jndi
> recources from this web app, Hence the context.xml for this web app has
> the following 
>
> <Context reloadable="true">
>
> <ResourceLink
> name="ConnectionFactory"global="jms/TopicConnectionFactory" type=
> "org.apache.activemq.ActiveMQConnectionFactory" />
>
> <ResourceLink name="PNMTopic" global="jms/Topic" type=
> "org.apache.activemq.command.ActiveMQTopic" />
>
> </Context>
>
> The subsciber class in the UI context is as follows 
>
> public class PNMSubscriber {
>
> TopicConnection tConn ;
>
> TopicConnectionFactory tFactory ;
>
> Topic pnmTopic;
>
> ActiveMQTopicSession pnmSession ;
>
> public PNMSubscriber(){
>
> try{
>
> InitialContext initialContext = new InitialContext();
>
> Context envContext = (Context) initialContext.lookup("java:comp/env");
>
> tFactory
> =(TopicConnectionFactory)envContext.lookup("ConnectionFactory");
>
> tConn = tFactory.createTopicConnection();
>
> pnmSession = (ActiveMQTopicSession) tConn.createTopicSession(true,
> Session.AUTO_ACKNOWLEDGE); 
>
> pnmTopic = (Topic)envContext.lookup("PNMTopic");
>
> pnmSubscriber = pnmSession.createSubscriber(pnmTopic);
>
> }catch(Exception e){
>
> e.printStackTrace();
>
> }
>
> }
>
> I get a class cast exception as follows 
>
> java.lang.ClassCastException:
> org.apache.activemq.ActiveMQConnectionFactory
>
> at
> com.cpnm.common.messaging.PNMSubscriber.<init>(PNMSubscriber.java:40)
>
> The exception is raised , at the following line , in the code above.
>
> tFactory =
> (TopicConnectionFactory)envContext.lookup("ConnectionFactory");
>
> I tried casting the object to "ActiveMQConnectionFactory" , I still get
> the same exception.
>
> I think, Iam missing something in the configuration, please let me know,
> if I need to add anything else.
>
> thank you,
>
> Suchitha.
>
>
>