Hello.
I'm developing a simple JMS application, and I have a problem with the JNDI name about it.
I have created two servlets, one for message sender and the other for message reader.
I've done following in the Visual Administrator.(We are in the NetWeaver 2004s SP12).
In the JMS Connector, I created a queue connection factory.
General Tab.
Application Name: sap.com/ShawnTest
Factory name: TCF
Factory Type: QueueConnectionFactory
Provider Type: JNDI based.
Provider Tab
JNDI Path: jmsfactory/default/QueueConnectionFactory
Initial Context Factory: com.sap.engine.services.jndi.InitialContextFactoryImpl
Provider URL: localhost
And I created a Queue in the JMS Provider.
JMS Server Instance: default --> Queues --> ShawnTestQueue (Lookup Name: jmsqueues/default/ShawnTestQueue).
In the Developer Studio,
web.xml
<resource-ref> <res-ref-name>jms/TCF</res-ref-name> <res-type>javax.jms.QueueConnectionFactory</res-type> <res-auth>Container</res-auth> </resource-ref>
web-j2ee-engine.xml
<resource-ref> <res-ref-name>jms/TCF</res-ref-name> <res-link>TCF</res-link> </resource-ref>
MessageSenderServlet.java
jndiContext = new InitialContext();
queueConnectionFactory =
(QueueConnectionFactory) jndiContext.lookup("java:comp/env/jms/TCF");
queue = (Queue) jndiContext.lookup("jmsqueues/default/ShawnTestQueue");
queueConnection = queueConnectionFactory.createQueueConnection();
queueSession =
queueConnection.createQueueSession(
false,
Session.AUTO_ACKNOWLEDGE);
queueSender = queueSession.createSender(queue);
message = queueSession.createTextMessage();
message.setText("This is message sent by me.");
queueSender.send(message);
writer.println("message sent.");
MessageReaderServlet.java is the exact opposite logic to above Sender servlet.
jndiContext = new InitialContext();
queueConnectionFactory =
(QueueConnectionFactory) jndiContext.lookup("java:comp/env/jms/TCF");
queue =
(Queue) jndiContext.lookup("jmsqueues/default/ShawnTestQueue");
queueConnection = queueConnectionFactory.createQueueConnection();
queueSession =
queueConnection.createQueueSession(
false,
Session.AUTO_ACKNOWLEDGE);
queueReceiver = queueSession.createReceiver(queue);
message = (TextMessage)queueReceiver.receiveNoWait();
if (message == null) {
writer.println("No message.");
} else {
writer.println("Got message: " + message.getText());
}
When run, MessageSender shows "message sent.".
But MessageReader shows "No message".
Any idea ? I spent 3 days with this problem.
Actually, my plan was to receive the message from Message Driven Bean, but I can't even solve this problem.
Regards,