You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Rob Terpilowski <rt...@yahoo.com> on 2007/06/15 03:41:45 UTC
ClassCastException w/ tomcat & JNDI
Hello active mq users ,
I am running into the following issue that was posted on the mailing list in January, but for which no
response was posted.
I have the following configuration on my system
tomcat 5.5
java 1.5.09
activemq jars version 4.1.1
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.
The active MQ jars are located in <catalina-home>/server/lib and I tried putting them
under <catalina-home>/shared/lib as well with no difference
thank you,
-rob
____________________________________________________________________________________
Don't get soaked. Take a quick peak at the forecast
with the Yahoo! Search weather shortcut.
http://tools.search.yahoo.com/shortcuts/#loc_weather
Re: ClassCastException w/ tomcat & JND
Posted by James Strachan <ja...@gmail.com>.
Sounds like you've multiple jms API jars causing the
ClassCastException (ActiveMQConnectionFactory definitely is-a
ConnectionFactory :)
On 6/15/07, Rob Terpilowski <rt...@yahoo.com> wrote:
> Hello active mq users ,
> I am running into the following issue that was posted on the mailing list in January, but for which no
> response was posted.
>
> I have the following configuration on my system
>
> tomcat 5.5
>
> java 1.5.09
>
> activemq jars version 4.1.1
>
> 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.
>
> The active MQ jars are located in <catalina-home>/server/lib and I tried putting them
> under <catalina-home>/shared/lib as well with no difference
>
> thank you,
> -rob
>
>
>
>
>
> ____________________________________________________________________________________
> Don't get soaked. Take a quick peak at the forecast
> with the Yahoo! Search weather shortcut.
> http://tools.search.yahoo.com/shortcuts/#loc_weather
--
James
-------
http://macstrac.blogspot.com/