"javax.jms.IllegalStateException: Method setMessageListener not permitted" in WebSphere Application Server V5.0 and later
 Technote (troubleshooting)
 
Problem(Abstract)
Application receives message
javax.jms.IllegalStateException: Method setMessageListener not permitted
when running inside IBM® WebSphere® Application Server EJB or Web container.
 
Cause
While it was permitted in IBM WebSphere Application Server V4.0 to use the method setMessageListener for asynchronous messaging, it is forbidden to use this method inside a WebSphere Application Server V5.0 EJB or Web container due a restriction by the following J2EE™ 1.3 specification:
"Note: A MessageListener can only be used in the client container. (The J2EE specification forbids the use of the JMS MessageListener mechanism for the asynchronous receipt of messages in the EJB and Web containers.)"

The section "J2EE.6.7 Java™ Message Service (JMS) 1.0 Requirements" of the J2EE specification gives a list of methods that must not be called in Web and EJB containers. This is enforced in WebSphere Application Server by throwing a javax.jms.IllegalStateException.

Here is a relevant part from J2EE 1.3 specification:http://java.sun.com/j2ee/j2ee-1_3-fr-spec.pdf section 6.7:

"... Note that the JMS API creates threads to deliver messages to
message listeners. The use of this message listener facility may be
limited by the restrictions on the use of threads in various
containers. In EJB containers, for instance, it is typically not
possible to create threads. The following methods must not be used by
application components executing in containers that prevent them
from creating threads:
.
- javax.jms.Session method setMessageListener
- javax.jms.Session method getMessageListener
- javax.jms.Session method run
- javax.jms.QueueConnection method createConnectionConsumer
- javax.jms.TopicConnection method createConnectionConsumer
- javax.jms.TopicConnection method createDurableConnectionConsumer
- javax.jms.MessageConsumer method getMessageListener
- javax.jms.MessageConsumer method setMessageListener
.
In addition, use of the following methods on javax.jms.Connection
objects by applications in Web and EJB containers may interfere with the
connection management functions of the container and must not be used:
- setExceptionListener
- stop
- setClientID
A J2EE container may throw a JMSException if the application component
violates these restrictions. ...."
 
Resolving the problem
Reference the Information Center article "Options for asynchronous messaging in WebSphere Application Server V5.0 releases", which includes the recommended Message Driven Beans or, though this not recommended, the use of code which includes setMessageListener outside of a WebSphere EJB or Web container.
 
 
Cross Reference information
Segment Product Component Platform Version Edition
Application Servers Runtimes for Java Technology Java SDK
 
 


Document Information


Product categories: Software > Application Servers > Distributed Application & Web Servers > WebSphere Application Server > Java Message Service (JMS)
Operating system(s): Windows
Software version: 6.1
Software edition:
Reference #: 1114239
IBM Group: Software Group
Modified date: Sep 17, 2007