JMS example

Hi

I am new to JMS in Sun One 7 . I want to run the simpleprogram shown below

import javax.naming.*;

import javax.jms.*;

import java.util.*;

publicclass SimpleMessageClient

{

publicstaticvoid main (String a[])

{

try

{

Properties prop =new Properties ();

prop.put (Context.INITIAL_CONTEXT_FACTORY,

"com.sun.enterprise.naming.SerialInitContextFactory");

prop.put (Context.PROVIDER_URL,"localhost:1050");

prop.put (Context.SECURITY_AUTHENTICATION,"simple");

prop.put (Context.SECURITY_PRINCIPAL,"admin");

prop.put (Context.SECURITY_CREDENTIALS,"adminadmin");

Context jndiContext=new InitialContext (prop);

QueueConnectionFactory queueConnectionFactory =

(QueueConnectionFactory)jndiContext.lookup ("java:comp/env/jms/QueueConnectionFactory");

Queue queue =(Queue)jndiContext.lookup ("java:comp/env/jms/Queue");

QueueConnection queueConnection = queueConnectionFactory.createQueueConnection ();

QueueSession queueSession = queueConnection.createQueueSession (false,Session.AUTO_ACKNOWLEDGE);

QueueSender queueSender = queueSession.createSender (queue);

TextMessage message =queueSession.createTextMessage ();

for(int i=0;i<10;i++)

{

message.setText ("Message "+i);

System.out.println ("Sending the message "+message.getText ());

queueSender.send (message);

}

}catch (Exception e)

{

e.printStackTrace ();

}

}

}

I am getting the exception below

javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.SerialInitContextFactory. Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory

at java.net.URLClassLoader$1.run(URLClassLoader.java:198)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:186)

at java.lang.ClassLoader.loadClass(ClassLoader.java:299)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)

at java.lang.ClassLoader.loadClass(ClassLoader.java:255)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:217)

at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)

at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:649)

at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)

at javax.naming.InitialContext.init(InitialContext.java:219)

at javax.naming.InitialContext.<init>(InitialContext.java:195)

at SimpleMessageClient.main(SimpleMessageClient.java:20)

Please help me

I have set jms.jar and imq.jar in the class path. I searched for jndi.jar but not able to find

I have doubt in instantiating the InitialContext

Properties prop = new Properties ();

prop.put (Context.INITIAL_CONTEXT_FACTORY,

"com.sun.enterprise.naming.SerialInitContextFactory");

prop.put (Context.PROVIDER_URL, "localhost:1050");

prop.put (Context.SECURITY_AUTHENTICATION, "simple");

prop.put (Context.SECURITY_PRINCIPAL, "admin");

prop.put (Context.SECURITY_CREDENTIALS, "adminadmin");

Context jndiContext= new InitialContext (prop);

Can any one explain the variable that are set

Thanks and regards

Suneesh VR

[4565 byte] By [suneeshvr] at [2007-11-25 17:10:23]
# 1

I could able to solve the above problem by including appserv-rt.jar and appserv-ext.jar But still I am getting the following exception

java.lang.UnsatisfiedLinkError: no cis in java.library.path

at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1403)

at java.lang.Runtime.loadLibrary0(Runtime.java:788)

at java.lang.System.loadLibrary(System.java:832)

at com.iplanet.ias.cis.connection.EndPoint.<clinit>(EndPoint.java:254)

at com.sun.corba.ee.internal.iiop.GIOPImpl.createListener(GIOPImpl.java:369)

at com.sun.corba.ee.internal.iiop.GIOPImpl.getEndpoint(GIOPImpl.java:316)

at com.sun.corba.ee.internal.iiop.GIOPImpl.initEndpoints(GIOPImpl.java:149)

at com.sun.corba.ee.internal.POA.POAORB.getServerEndpoint(POAORB.java:505)

at com.sun.corba.ee.internal.POA.POAImpl.pre_initialize(POAImpl.java:157)

at com.sun.corba.ee.internal.POA.POAImpl.<init>(POAImpl.java:115)

at com.sun.corba.ee.internal.POA.POAORB.makeRootPOA(POAORB.java:115)

at com.sun.corba.ee.internal.POA.POAORB$1.evaluate(POAORB.java:133)

at com.sun.corba.ee.internal.core.Future.evaluate(Future.java:26)

at com.sun.corba.ee.internal.corba.ORB.resolveInitialReference(ORB.java:3069)

at com.sun.corba.ee.internal.corba.ORB.resolve_initial_references(ORB.java:3004)

at com.sun.jts.CosTransactions.DefaultTransactionService.createPOAs(DefaultTransac tionService.java:309)

at com.sun.jts.CosTransactions.DefaultTransactionService.identify_ORB(DefaultTrans actionService.java:180)

at com.sun.corba.ee.internal.TxPOA.TxPIORB.initServices(TxPIORB.java:134)

at com.sun.enterprise.iiop.POAEJBORB.initServices(POAEJBORB.java:475)

at com.sun.corba.ee.internal.POA.POAORB.initPostProcessing(POAORB.java:355)

at com.sun.corba.ee.internal.Interceptors.PIORB.initPostProcessing(PIORB.java:236)

at com.sun.corba.ee.internal.POA.POAORB.set_parameters(POAORB.java:193)

at com.sun.corba.ee.internal.Interceptors.PIORB.set_parameters(PIORB.java:337)

at org.omg.CORBA.ORB.init(ORB.java:337)

at com.sun.enterprise.util.ORBManager.createORB(ORBManager.java:355)

at com.sun.enterprise.util.ORBManager.init(ORBManager.java:257)

at com.sun.enterprise.naming.SerialInitContextFactory.<init>(SerialInitConte xtFactory.java:31)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessor Impl.java:39)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructor AccessorImpl.java:27)

at java.lang.reflect.Constructor.newInstance(Constructor.java:274)

at java.lang.Class.newInstance0(Class.java:306)

at java.lang.Class.newInstance(Class.java:259)

at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:649)

at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)

at javax.naming.InitialContext.init(InitialContext.java:219)

at javax.naming.InitialContext.<init>(InitialContext.java:175)

at QueueClientSenderReceiver.init(QueueClientSenderReceiver.java:60)

at QueueClientSenderReceiver.<init>(QueueClientSenderReceiver.java:36)

at QueueClientSenderReceiver.main(QueueClientSenderReceiver.java:116)

Exception in thread "main"

suneeshvr at 2007-7-3 1:47:01 > top of Java-index,Application & Integration Servers,Sun Java System Message Queue...
# 2

Hi

I don't think you can use SerialInitContext to look up connections and queue in Appserver 7; the code you posted looked like it would have worked on the J2EE Reference Implementation, but the JMS implementations are not the same. The process you need is not documented in the Application Server manuals, but I think it is documented in the SunONE Message Queue developer's guide. Unfortunately, docs.sun.com is down at the moment so I can't check.

Best wishes

Kevin

k.boone at 2007-7-3 1:47:01 > top of Java-index,Application & Integration Servers,Sun Java System Message Queue...