Hi All,
I am not able to run a working Java EE 5 JMS tutorial in jdk1.6.0_25, GF3.1 (bundled with Netbeans 7.0 on Windows XP) despite having re-created the whole project from scratch. Below is the code snippets of various components of the project:
C:\Documents and Settings\jack\JMSEnterpriseProject\JMSEnterpriseProject-ejb\src\java\com\ensode\mdb\MessageReceiverBean.java
@MessageDriven(mappedName = "jms/myQueue", activationConfig = {
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})
public class MessageReceiverBean implements MessageListener {
@Override
public void onMessage(Message message) {
TextMessage textMessage = (TextMessage) message;
try {
System.out.println("Received message:" + textMessage.getText());
} catch (JMSException ex) {
Logger.getLogger(MessageReceiverBean.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
C:\Documents and Settings\jack\JMSEnterpriseProject\JMSEnterpriseProjectApplicationClient\src\java\com\ensode\jms
public class Main {
@Resource(name = "jms/myQueue")
private static Queue myQueue;
@Resource(name = "jms/myQueueConnectionFactory")
private static ConnectionFactory myQueueConnectionFactory;
public static void main(String[] args) throws JMSException {
new Main().sendJMSMessageToMyQueue("NetBeans makes JMS trivial!");
}
private Message createJMSMessageForjmsMyQueue(Session session,
Object messageData) throws JMSException {
TextMessage textMessage = session.createTextMessage();
textMessage.setText((String) messageData);
return textMessage;
}
private void sendJMSMessageToMyQueue(Object messageData) throws
JMSException {
Connection connection = null;
Session session = null;
try {
connection = myQueueConnectionFactory.createConnection();
session = connection.createSession(false,
javax.jms.Session.AUTO_ACKNOWLEDGE);
MessageProducer messageProducer = session.createProducer(myQueue);
messageProducer.send(createJMSMessageForjmsMyQueue(session,
messageData));
} finally {
if (session != null) {
session.close();
}
if (connection != null) {
connection.close();
}
}
}
}
C:\Documents and Settings\jack\JMSEnterpriseProject\JMSEnterpriseProject-ejb\setup\glassfish-resources.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<admin-object-resource enabled="true" jndi-name="jms/myQueue" object-type="user" res-adapter="jmsra" res-type="javax.jms.Queue">
<property name="Name" value="myQueue"/>
</admin-object-resource>
<connector-resource enabled="true" jndi-name="jms/myQueueConnectionFactory" object-type="user" pool-name="jms/myQueueConnectionFactory">
<description/>
</connector-resource>
<connector-connection-pool associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-definition-name="javax.jms.QueueConnectionFactory" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="true" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="jms/myQueueFactoryPool" ping="false" pool-resize-quantity="2" pooling="true" resource-adapter-name="jmsra" steady-pool-size="8" validate-atmost-once-period-in-seconds="0"/>
<connector-resource enabled="true" jndi-name="jms/myQueueFactory" object-type="user" pool-name="jms/myQueueFactoryPool"/>
<connector-connection-pool associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-definition-name="javax.jms.ConnectionFactory" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="true" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="jms/myQueueConnectionFactory" ping="false" pool-resize-quantity="2" pooling="true" resource-adapter-name="jmsra" steady-pool-size="8" validate-atmost-once-period-in-seconds="0"/>
</resources>
Yet it was met with the following exception which appears to be an unsupported deployment descriptor generated by Netbeans 7.0:
_GF3.1 server log_
WARNING: DPL8007: Unsupported deployment descriptors element message-destination value null
_Application Client Outpu
t_10/05/2011 2:59:45 AM com.sun.enterprise.deployment.util.ComponentValidator accept
WARNING: DPL8007: Unsupported deployment descriptors element message-destination value null
com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Unresolved Message-Destination-Ref jms/myQueue@java.lang.String@null into class com.ensode.jms.Main
………
Caused by: javax.naming.NamingException: Lookup failed for 'java:comp/env/jms/myQueue' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NameNotFoundException: No object bound for java:comp/env/jms/myQueue [Root exception is java.lang.NullPointerException]]
glassfish-resources.xml used to reside in C:\Documents and Settings\jack\JMSEnterpriseProject\ setup\ sun-resources.xml back in GF2.1.
Deployment was successful which resulted in the following resources created:
Connector Resources => jms/myQueueConnectionFactory, jms/myQueueFactory.
Connector Connection Pools => jms/myQueueFactoryPool, jms/myQueueConnectionFactory.
Admin Object Resources => jms/myQueue.
Your assistance would be very much appreciated.
Thanks,
Jack