JNDI properties for JMS in Sun Application server

Hello Everybody,

I am trying to create a simple java application that send message to a JMS Queue which is on Sun Application server 8.1. There is my client's code:

package com.jmstest.client;

import java.util.Properties;

import javax.jms.JMSException;

import javax.jms.Queue;

import javax.jms.QueueConnection;

import javax.jms.QueueConnectionFactory;

import javax.jms.QueueSender;

import javax.jms.QueueSession;

import javax.jms.Session;

import javax.jms.TextMessage;

import javax.naming.Context;

import javax.naming.InitialContext;

import javax.naming.NamingException;

publicclass Jmsclient{

publicstaticvoid main(String[] args){

StringqueueName =null;

ContextjndiContext =null;

QueueConnectionFactory queueConnectionFactory =null;

QueueConnection queueConnection =null;

QueueSessionqueueSession =null;

Queuequeue =null;

QueueSender queueSender =null;

TextMessage message =null;

Propertiesprop =null;

finalintNUM_MSGS;

if ( (args.length < 1) || (args.length > 2) ){

System.out.println("Usage: java Jmsclient " +

"<queue-name> [<number-of-messages>]");

System.exit(1);

}

queueName =new String(args[0]);

System.out.println("Queue name is " + queueName);

if (args.length == 2){

NUM_MSGS = (new Integer(args[1])).intValue();

}else{

NUM_MSGS = 1;

}

try{

prop =new Properties();

prop.put("java.naming.factory.initial","com.sun.jndi.cosnaming.CNCtxFactory");

//prop.put("java.naming.provider.url","mq://ie10dtxphb4zl1s.global.ds.honeywell.com:7676");

jndiContext =new InitialContext(prop);

}catch (NamingException e){

System.out.println("Could not create JNDI API " +

"context: " + e.toString());

System.exit(1);

}

try{

queueConnectionFactory = (QueueConnectionFactory) jndiContext.lookup("QueueConnectionFactory");

queue = (Queue) jndiContext.lookup("MyQueue");

System.out.println("JNDItest found and working!!!");

}catch (NamingException e){

System.out.println("JNDI API lookup failed: " +

e.toString());

System.exit(1);

}

/*

* Create connection.

* Create session from connection; false means session is

* not transacted.

* Create sender and text message.

* Send messages, varying text slightly.

* Send end-of-messages message.

* Finally, close connection.

*/

try{

queueConnection = queueConnectionFactory.createQueueConnection();

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

queueSender = queueSession.createSender(queue);

message = queueSession.createTextMessage();

for (int i = 0; i < NUM_MSGS; i++){

message.setText("This is message " + (i + 1));

System.out.println("Sending message: " +

message.getText());

queueSender.send(message);

}

/*

* Send a non-text control message indicating end of

* messages.

*/

queueSender.send(queueSession.createMessage());

}catch (JMSException e){

System.out.println("Exception occurred: " +

e.toString());

}finally{

if (queueConnection !=null){

try{

queueConnection.close();

}catch (JMSException e){}

}

}

}

}

I am not sure what the JNDI properties should be and how configure to make this application work. Any idea / help would be greatful

Thanks

-- Abdel Olakara

http://olakara.googlepages.com

[6627 byte] By [Olakaraa] at [2007-11-27 2:00:53]
# 1
I have the same code....please give ur j2sdk version..For the same code i get the following exception :javax.naming.NameNotFoundException: jms/QueueConnectionFactorywhere jms/QueueConnectionFactory is the name of my QueueConnectionFactory.
trupti.ka at 2007-7-12 1:40:11 > top of Java-index,Core,Core APIs...