On 19 Jun, Clement, Nathan wrote:
> Hi everyone.
> 
> I am having trouble writing a JMS client program that sends a message to a
> JMS topic.  The source code I am using is very similar to the example in the
> JBoss manual.  It seems that the JNDI lookup is returning an object of the
> type org.jbossmq.distributed.interfaces.DistributedConnectionFactory which
> is not of the required type (javax.jms.TopicConnectionFactory).
> 
> I have looked through the archives of this list but have not found any
> references to a similar problem, so I assume it is just something with my
> configuration.
Have you tried without using  PortableRemoteObject, and doing a normal c
cast instead?

//Peter

> 
> My setup is JBoss 2.2.2 with Tomcat 3.2.1 running on Windows 2000
> Professional under JDK 1.3.  The classpath (as output by my batch file that
> runs the program) is:
> Classpath:
> .\jars\jbossmq.client.jar;.\jars\jndi.jar;.\jars\jms.jar;.\jars\jnp-c
> lient.jar;.\jars\jta-spec1_0_1.jar;.
> 
> The source code I am using is what I consider to be fairly basic JMS code:
> 
> ------------------------------------------ START
> import javax.naming.*;
> import java.util.*;
> import javax.jms.*;
> import javax.rmi.PortableRemoteObject;
> 
> public class JBossTopicPublisher
> {
>     public final static String JNDI_FACTORY =
>         "org.jnp.interfaces.NamingContextFactory";
>     public final static String JNDI_PACKAGE = "org.jboss.naming";
>     public final static String SERVER_URL = "localhost:1099";
> 
>     public static void main(String arg[]) 
>     {
>         try 
>         {
>             System.out.println( new Date() + " Creating JMS stuff... " );
>             // Get access to JNDI
>             Properties env = new Properties();
>             env.setProperty("java.naming.factory.initial", JNDI_FACTORY);
>             env.setProperty("java.naming.provider.url", SERVER_URL);
>             env.setProperty("java.naming.factory.url.pkgs", JNDI_PACKAGE);
>             Context context = new InitialContext( env );
> 
>             // Lookup the managed connection factory for a topic
>             Object objref;
>             objref = context.lookup("TopicConnectionFactory");
>             TopicConnectionFactory topicFactory = 
>                 (TopicConnectionFactory)
>                     PortableRemoteObject.narrow( objref, 
>  
> TopicConnectionFactory.class );
> 
>             // Create a connection to the JMS provider
>             TopicConnection topicConnection = 
>                 topicFactory.createTopicConnection();
> 
>             // Creat a topic session
>             TopicSession session = topicConnection.createTopicSession(
>                                // No transaction
>                                false, 
>                                // Auto ack
>                                Session.AUTO_ACKNOWLEDGE);
> 
>             // Lookup the destination you want to publish to
>             objref = context.lookup("topic/testTopic");
>             System.out.println( objref );
>             Topic topic = 
>                 (Topic)PortableRemoteObject.narrow( objref, Topic.class );
> 
>             // Create a publisher
>             TopicPublisher pub = session.createPublisher(topic);
>             System.out.println( new Date() + " Sending message... " );
> 
>             // Create a message
>             TextMessage message = session.createTextMessage();
>             message.setText("Hello World!");
> 
>             // Publish the message
>             pub.publish(topic, message);
>             System.out.println( new Date() + " Sent message " );
>             System.out.println( new Date() + " Closing JMS stuff... " );
> 
>             // Close the stuff
>             session.close();
>             topicConnection.close();
>             System.out.println( new Date() + " Closed JMS stuff " );
>         }
>         catch (Exception e) 
>         {
>             System.out.println( "I could not send a message :(" );
>             e.printStackTrace();
>         }
>     }
> }
> ------------------------------------------ END
> 
> The program output is:
> 
> ------------------------------------------ START
> Tue Jun 19 17:41:56 GMT+10:00 2001 Creating JMS stuff...
> I could not send a message :(
> java.lang.ClassCastException
>         at
> com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(Porta
> bleRemoteObject.java:296)
>         at
> javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
>         at JBossTopicPublisher.main(JBossTopicPublisher.java:28)
> ------------------------------------------ END
> 
> I would appreciate any help anyone can offer me.
> 
> Thanks,
> 
> Nathan Clement
> Software Engineer
> Metiom Australasia
> http://www.metiom.com.au
> 
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
> http://lists.sourceforge.net/lists/listinfo/jboss-user

-- 
Jobba hos oss: http://www.tim.se/weblab
------------------------------------------------------------
Peter Antman             Technology in Media, Box 34105 100 26 Stockholm
Systems Architect        WWW: http://www.tim.se
Email: [EMAIL PROTECTED]        WWW: http://www.backsource.org
Phone: +46-(0)8-506 381 11 Mobile: 070-675 3942 
------------------------------------------------------------


_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to