尝试设置值jms / Topic时出现异常null

时间:2011-05-29 22:56:01

标签: exception java-ee jms

我问这个问题很长一段时间后我真的无法理解问题出在哪里,也许你可以帮助我。

我正在使用JMS主题为异步消息创建J2EE Web应用程序。问题是当通过查找InitialContext检索我的主题时,我的主题始终设置为null并抛出此异常:

    ATTENTION: RAR7096: Exception null while trying to set the value jms/Topic on property Name 
GRAVE: enterprise_naming.serialctx_communication_exception
GRAVE: com.sun.appserv.connectors.internal.api.PoolingException
        at com.sun.enterprise.resource.beans.AdministeredObjectResource.createAdministeredObject(AdministeredObjectResource.java:199)
        at com.sun.enterprise.resource.naming.AdministeredObjectFactory.getObjectInstance(AdministeredObjectFactory.java:128)
        at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
        at com.sun.enterprise.naming.impl.SerialContext.getObjectInstance(SerialContext.java:472)
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:437)
        at javax.naming.InitialContext.lookup(InitialContext.java:392)
        at javax.naming.InitialContext.lookup(InitialContext.java:392)
        at org.apache.jsp.index_jsp.jspInit(index_jsp.java from :36)
        at org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:90)
        at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:208)
        at org.apache.jasper.servlet.JspServletWrapper.getDependants(JspServletWrapper.java:317)
        at org.apache.jasper.compiler.Compiler.isOutDated(Compiler.java:615)
        at org.apache.jasper.compiler.Compiler.isOutDated(Compiler.java:483)
        at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:618)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:483)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:373)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
        at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
        at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
        at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
        at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
        at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
        at java.lang.Thread.run(Thread.java:680)
Caused by: java.security.PrivilegedActionException: com.sun.appserv.connectors.internal.api.ConnectorRuntimeException
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.enterprise.resource.beans.AdministeredObjectResource.createAdministeredObject(AdministeredObjectResource.java:176)
        ... 41 more
Caused by: com.sun.appserv.connectors.internal.api.ConnectorRuntimeException
        at com.sun.enterprise.connectors.util.SetMethodAction.handleException(SetMethodAction.java:140)
        at com.sun.enterprise.connectors.util.SetMethodAction.run(SetMethodAction.java:126)
        ... 43 more
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.sun.enterprise.connectors.util.SetMethodAction.run(SetMethodAction.java:99)
        ... 43 more
Caused by: java.lang.IllegalArgumentException: MQ:Topic:Invalid Topic Name - jms/Topic
        at com.sun.messaging.Topic.setName(Topic.java:90)
        ... 48 more

这是我的代码,有问题的行是“topic =(主题)ic.lookup(”jms / Topic“);”

<%!
@Resource(mappedName = "jms/ConnectionFactory")
ConnectionFactory connectionFactory;
@Resource(mappedName = "jms/Topic")
Topic topic;
Connection connection = null;
Session jmsSession = null;
MessageProducer messageProducer = null;

public void jspInit() {
    try {
        InitialContext ic = new InitialContext();
        connectionFactory = (ConnectionFactory) ic.lookup("jms/ConnectionFactory");
        topic = (Topic) ic.lookup("jms/Topic");
        connection = connectionFactory.createConnection();
        jmsSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        messageProducer = jmsSession.createProducer(topic);
        connection.start();
    } catch (Exception e) {
        System.out.println("Couldn't create nsl : " + e.getMessage());
    }
}

我希望你能帮我弄清楚这个文件有什么问题!

谢谢!

编辑:服务器资源 The jms/Topic seem's OK ?

2 个答案:

答案 0 :(得分:3)

不要在物理目的地使用斜线字符,“jms/Topic”对于Glassfish来说是错误的。

ATTENTION:
RAR7096:
Exception null while trying to set the value jms/Topic on property Name

此处引用的“名称”属性是“物理目的地名称”。 Glassfish对该领域有严格的命名约定。在屏幕截图中,这是“Nom de la destination physique”。尝试将其更新为“jmsTopic”,看看结果如何。

PS:我知道这是一个老问题,但其他人可能会遇到这个问题。希望它有所帮助。

链接到类似问题:https://developer.jboss.org/thread/205474

答案 1 :(得分:1)

有几件事:

  • 您注入了Connectionfactory和主题,然后您也尝试查找它们。我看到你使用Glassfish服务器,至少是JEE5,因此不需要查找。现在,如果注射没有被提起,那可能与我的第二点有关。
  • 为什么你要在JSP中完成所有这些工作?那种代码应该(至少)进入一个servlet。

我可以向你保证,servlet中的@Resource注入被正确拾取,丢弃了Initialcontext的东西。并将您的代码移动到servlet: - )

其他事情:如果工厂和主题存在,您可能需要检查服务器...如果他们不存在,您可以手动创建它们,也可以将它们添加到项目中以便在部署时创建,尽管我亲自不喜欢后者。

在Glassfish 2中,至少通过资源,JMS资源,目标资源在服务器控制台中列出和定义JMS资源。

编辑:签出this article,它提到完全相同的错误,在这种情况下,它链接到sun-ejb-jar.xml中的条目 - 项目定义资源所在的位置。检查sun-ejb-jar.xml部署描述符

可能是个好主意