Hi,
I am developing the SimpleMessage MDB that comes with the JEE 5 tutorial.
I have implemented the projects SimpleMessageMDB and SimpleMessageCient and the corresponding SimpleMessageEAR that I have deployed in GF v2ur2.
For developing and deploying my application I use Eclipse Ganymede RS1. And now I have to setup the JNDI for my “jms/Queue” and “jms/ConnectionFactory” in GF using the Admin Console, but I am doing it wrong because when the client try to instance the ConnectionFactory I get a JMSException that finally exits the application client.
How do I must to do to setup both “jms/Queue” and “jms/ConnectionFactory” in GF?
This is my code,
package simple.message;
import java.util.logging.Logger;
import javax.annotation.Resource;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.ejb.MessageDrivenContext;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
/**
* Message-Driven Bean implementation class for: SimpleMessageMDB
*
*/
@MessageDriven(
activationConfig = { @ActivationConfigProperty(
propertyName = "destinationType", propertyValue = "javax.jms.Queue"
) },
mappedName = "jms/Queue")
public class SimpleMessageMDB implements MessageListener {
static final Logger logger = Logger.getLogger("SimpleMessageMDB");
@Resource
private MessageDrivenContext mdc;
/**
* Default constructor.
*/
public SimpleMessageMDB() {
// TODO Auto-generated constructor stub
}
/**
* @see MessageListener#onMessage(Message)
*/
public void onMessage(Message inMessage) {
// TODO Auto-generated method stub
TextMessage msg = null;
try {
if (inMessage instanceof TextMessage) {
msg = (TextMessage) inMessage;
logger.info("MESSAGE BEAN: Message received: " + msg.getText());
} else {
logger.warning(
"Message of wrong type: "
+ inMessage.getClass().getName());
}
} catch (JMSException e) {
e.printStackTrace();
mdc.setRollbackOnly();
} catch (Throwable te) {
te.printStackTrace();
}
}
}
and the client,
package simple.message;
import javax.jms.ConnectionFactory;
import javax.jms.Queue;
import javax.jms.Connection;
import javax.jms.Session;
import javax.jms.MessageProducer;
import javax.jms.TextMessage;
import javax.jms.JMSException;
import javax.annotation.Resource;
public class SimpleMessageClient {
/**
* @param args
*/
@Resource(mappedName = "jms/ConnectionFactory")
private static ConnectionFactory connectionFactory;
@Resource(mappedName = "jms/Queue")
private static Queue queue;
public static void main(String[] args) {
// TODO Auto-generated method stub
Connection connection = null;
Session session = null;
MessageProducer messageProducer = null;
TextMessage message = null;
final int NUM_MSGS = 3;
try {
connection = connectionFactory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
messageProducer = session.createProducer(queue);
message = session.createTextMessage();
for (int i = 0; i < NUM_MSGS; i++) {
message.setText("This is message " + (i + 1));
System.out.println("Sending message: " + message.getText());
messageProducer.send(message);
}
System.out.println("To see if the bean received the messages,");
System.out.println(
" check <install_dir>/domains/domain1/logs/server.log.");
} catch (JMSException e) {
System.out.println("Exception occurred: " + e.toString());
} finally {
if (connection != null) {
try {
connection.close();
} catch (JMSException e) {
}
} // if
System.exit(0);
} // finally
} // main
} // class
[Message sent by forum member 'josealvarezdelara' (josealvarezdelara)]
http://forums.java.net/jive/thread.jspa?messageID=330339