javax.jms.IllegalStateException: Method not allowed when cal
azarny Apr 6, 2005 3:58 AMHello Everyone,
Enviroment jboss 4.0.1 on windows xp.
When i call QueueReceiver.setMessageListener i get next exception
Whats wrong ? Or can anybody point me to the right way ?
javax.jms.IllegalStateException: Method not allowed at org.jboss.resource.adapter.jms.JmsSession.checkStrict(JmsSession.java:399) at org.jboss.resource.adapter.jms.JmsMessageConsumer.setMessageListener(JmsMessageConsumer.java:111) at com.lcp.core.gate.Gate.<init>(Gate.java:44)
source is
package com.lcp.core.gate;
import com.lcp.core.IStat;
import com.lcp.util.configHelper;
import com.lcp.exception.MustBeImplementedInDerivedClass;
import javax.jms.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.apache.log4j.Logger;
public class Gate implements IGate, MessageListener {
private static final Logger log = Logger.getLogger(configHelper.LoggerName);
protected QueueConnection queueConnection = null;
protected QueueSession queueSession = null;
protected QueueSender queueSender = null;
protected Context jndiContext = null;
protected QueueConnectionFactory queueConnectionFactory = null;
protected Queue queue = null;
protected QueueReceiver queueReceiver = null;
protected String queueName = null;
public Gate(String oper_id) throws JMSException {
super();
try {
jndiContext = new InitialContext();
queueConnectionFactory = (QueueConnectionFactory) jndiContext.lookup("java:JmsXA"); // todo think how to send queue name
System.out.println(">>>>>>>>>>>>>> queueConnectionFactory " + queueConnectionFactory);
Object o = jndiContext.lookup(configHelper.getValue("lcp.queue.prefix") + oper_id);
System.out.println(">>>>>>>>>>>>>> o " + o);
queue = (Queue) o;
queueConnection = queueConnectionFactory.createQueueConnection();
System.out.println(">>>>>>>>>>>>>> queueConnection " + queueConnection);
queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
System.out.println(">>>>>>>>>>>>>> queueSession " + queueSession);
queueSender = queueSession.createSender(queue);
System.out.println(">>>>>>>>>>>>>> queueSender " + queueSender);
queueReceiver = queueSession.createReceiver(queue);
queueReceiver.setMessageListener(new Gate());
} catch (NamingException e) {
log.error("NamigException", e);
}
}
public Gate() {
super(); // just empty constructor for listener
System.out.println(">>>>>>>>>>>>>>>>>>>>>>> Gate with empty constructor");
}
public void SendViaJMS(String stat_id) {
try {
TextMessage statMessage = queueSession.createTextMessage();
statMessage.setText(stat_id);
queueSender.send(statMessage);
} catch (JMSException e) {
log.error("Cant send message to JMS", e);
}
}
public void SendViaJMS(IStat Stat) {
SendViaJMS(Stat.getStat_id());
}
public void ProcessMessage(String msg) throws MustBeImplementedInDerivedClass {
throw new MustBeImplementedInDerivedClass("Must be Implemented In Derived class");
}
public void onMessage(Message message) {
TextMessage tmstat_id = (TextMessage) message;
try {
System.out.println(">>>>>>>>>>>>>>> text message = " + tmstat_id.getText());
} catch (JMSException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
}