dcsimg
Problem with message-driven bean in netbeans 6.0 with glassfish v2
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Kamlakar_Bhopatkar
Posted On:   Tuesday, May 11, 2010 12:18 AM

I am using Netbeans 6.0 and GlassFish V2. I want to test a simple example of message-driven bean. When I run the glassfish server, I see the following under JMS Resources - Connection Factories --> jms/queueFactory Desination Resources --> jms/queue I have imported javaee.jar, j2ee.jar, imq.jar, imqutil.jar, jms.jar, appserv-rt.jar, appserv-admin.jar in my console client. The code of the message-driven bean and console client is as follows. Actually it is from j2ee 5 tutorial. In the tutorial, jms/ConnectionFactory is used. But when I use it in my program, I get classnotfoundexception. So I used jms/queueFactory as per t   More>>


I am using Netbeans 6.0 and GlassFish V2. I want to test a simple example
of message-driven bean. When I run the glassfish server, I see the following under JMS Resources -


Connection Factories --> jms/queueFactory
Desination Resources --> jms/queue



I have imported javaee.jar, j2ee.jar, imq.jar, imqutil.jar, jms.jar, appserv-rt.jar,
appserv-admin.jar
in my console client.


The code of the message-driven bean and console client is as follows. Actually it
is from j2ee 5 tutorial. In the tutorial, jms/ConnectionFactory is used. But when
I use it in my program, I get classnotfoundexception. So I used jms/queueFactory
as per the factory name mentioned under jms resources of my glassfish server.
But the program gives runtime error. The program failed when I used annotations
thats why I am using Jndi calls. I even tried QueueConnectionFactory
class but it doesn't work. The program and error is given below.
Can anybody tell what is the problem?


==============

Msg1Bean.java // Message-Driven Bean(Ejb Module)

-----

package EjbMsg2;

import javax.ejb.ActivationConfigProperty;

import javax.ejb.MessageDriven;

import javax.jms.Message;

import javax.jms.MessageListener;

import javax.jms.TextMessage;


@MessageDriven(mappedName = "jms/queue", activationConfig = {
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})


public class Msg1Bean implements MessageListener {


public Msg1Bean() {

}


public void onMessage(Message message) {

TextMessage msg = null;

try

{

if (message instanceof TextMessage)

{

msg = (TextMessage) message;

System.out.println(msg.getText());

}

}

catch(Exception e)

{

System.out.println(e);

}

}

}

======



EjbMsg2Console.java // Console client

=====================


package ejbmsg2console;

import javax.jms.*;

import javax.ejb.*;

import javax.annotation.*;

import javax.naming.*;

import java.util.Hashtable;


public class Main {


// @Resource(mappedName="jms/queueFactory")

// private static ConnectionFactory connectionFactory;

//@Resource(mappedName="jms/queue")

//private static Queue queue;

Context jndiContext = null;

ConnectionFactory connectionFactory = null;

Connection connection = null;

Session session = null;

Queue queue = null;

MessageProducer messageProducer = null;

public void testbean()

{

try

{

Hashtable properties = new Hashtable(2);

properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.appserv.naming.S1ASCtxFactory");

properties.put(Context.PROVIDER_URL, "iiop://192.168.1.3:3700");

System.out.println("in testbean");

jndiContext = new InitialContext(properties);

connectionFactory = (ConnectionFactory)jndiContext.lookup("jms/queueFactory");

queue = (Queue)jndiContext.lookup("jms/queue");

connection = connectionFactory.createConnection();

session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);

messageProducer = session.createProducer(queue);

TextMessage message = session.createTextMessage();

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

{

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

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

messageProducer.send(message);

}

}

catch(Exception e)

{

System.out.println(e);

}

}

public static void main(String[] args)

{


Main ob = new Main();

ob.testbean();

}

}

====
   <<Less
About | Sitemap | Contact