JMS - javax.jms.IllegalStateException in JBOSS问题之解决

本文介绍了一种在JBOSS应用服务器中解决JMS Subscriber设置监听器时出现IllegalStateException异常的方法,通过修改jms-ds.xml配置文件中的Strict属性为false来实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

在jms中的代码如下:

   

java 代码
  1. private  void  registerSubscriber(JMSTopicMetaData jmsMetaData) throws  Exception {   
  2.     TopicConnectionFactory topicCntFact = jmsMetaData   
  3.             .getTopicConnectionFactory();   
  4.     Topic topic = jmsMetaData.getTopic();   
  5.        
  6.     // 将自己作为一个Subscriber向Topic注册。   
  7.     TopicConnection cnt = topicCntFact.createTopicConnection();   
  8.     cnt.setExceptionListener(new  TopicConnectionExceptionListenerImpl());   
  9.     TopicSession session = cnt.createTopicSession(false ,Session.AUTO_ACKNOWLEDGE);   
  10.     TopicSubscriber subscriber = session.createSubscriber(topic);   
  11.     subscriber.setMessageListener(this );   
  12.     cnt.start();   
  13. }  

 subscriber.setMessageListener(this);代码执行过程中抛出以下异常。(用的服务器是jboss4.0.5GA,在weblogic8.1)

上面没有错误出现。

java 代码
  1. 15 :21 :58 ,193  ERROR [STDERR] javax.jms.IllegalStateException: This method is not applicable inside the application server. See the J2EE spec, e.g.   
  2. J2EE1.4  Section 6.6   
  3. 15 :21 :58 ,193  ERROR [STDERR] javax.jms.IllegalStateException: This method is not applicable inside the application server. See the J2EE spec, e.g.   
  4. J2EE1.4  Section 6.6   
  5. 15 :21 :58 ,193  ERROR [STDERR] at org.jboss.resource.adapter.jms.JmsSession.checkStrict(JmsSession.java:542 )   
  6. 15 :21 :58 ,193  ERROR [STDERR] at org.jboss.resource.adapter.jms.JmsMessageConsumer.setMessageListener(JmsMessageConsumer.java:136 )   
  7. 15 :21 :58 ,193  ERROR [STDERR] at dk.itu.projekt.jms.SubscriptionHelper.<init>(Unknown Source)   
  8. 15 :21 :58 ,193  ERROR [STDERR] at dk.itu.projekt.jms.MessageReceiver.recieveMessage(Unknown Source)   
  9. 15 :21 :58 ,193  ERROR [STDERR] at dk.itu.projekt.gui.servlets.EmployeeServlet.service(Unknown Source)   
  10. 15 :21 :58 ,193  ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810 )   
  11. 15 :21 :58 ,193  ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252 )   
  12. 15 :21 :58 ,193  ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173 )   
  13. 15 :21 :58 ,193  ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96 )   
  14. 15 :21 :58 ,193  ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202 )   
  15. 15 :21 :58 ,193  ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173 )   
  16. 15 :21 :58 ,193  ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213 )   
  17. 15 :21 :58 ,193  ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178 )   
  18. 15 :21 :58 ,193  ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175 )   
  19. 15 :21 :58 ,193  ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74 )   
  20. 15 :21 :58 ,193  ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126 )   
  21. 15 :21 :58 ,193  ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105 )   
  22. 15 :21 :58 ,193  ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107 )   
  23. 15 :21 :58 ,193  ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148 )   
  24. 15 :21 :58 ,193  ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869 )   
  25. 15 :21 :58 ,193  ERROR [STDERR] at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:   
  26. 664 )   
  27. 15 :21 :58 ,193  ERROR [STDERR] at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527 )   
  28. 15 :21 :58 ,193  ERROR [STDERR] at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112 )   
  29. 15 :21 :58 ,193  ERROR [STDERR] at java.lang.Thread.run(Thread.java:595 )   

找了半天才在jboss的论坛上发现以下解决办法:

java 代码
  1. change the jms-ds.xml file to look like this :   
  2.   
  3. <!-- JMS XA Resource adapter, use this  to get transacted JMS in beans -->   
  4. <tx-connection-factory>   
  5. <jndi-name>JmsXA</jndi-name>   
  6. <xa-transaction/>   
  7. <rar-name>jms-ra.rar</rar-name>   
  8. <connection-definition>org.jboss.resource.adapter.jms.JmsConnectionFactory</connection-definition>   
  9. <config-property name="SessionDefaultType"  type="java.lang.String" >javax.jms.Topic</config-property>   
  10. <config-property name="JmsProviderAdapterJNDI"  type="java.lang.String" >java:/DefaultJMSProvider</config-property>   
  11. <config-property name="Strict"  type="java.lang.Boolean" >false </config-property>   
  12. <max-pool-size>20 </max-pool-size>   
  13. <security-domain-and-application>JmsXARealm</security-domain-and-application>   
  14. </tx-connection-factory>   
  15.   
  16. The <config-property> for  Strict is what you need to add. This will let JBoss grant access to the Queue ConnectionFactory to your servlet even though the J2EE spec doesn't require JBoss to do  so. Normally JMS ConnectionFactories are only accessible from the EJB container.   
在jms-ds.xml文件中增加 <config-property name="Strict" type="java.lang.Boolean">false</config-property>。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值