【问题标题】:not able to invoke messge bean from restful webservice无法从restful webservice调用messge bean
【发布时间】:2011-08-11 09:39:25
【问题描述】:

我正在尝试创建 Restful Webservice 作为 Message Driven Bean 的客户端,但是当我调用 restful 方法时,它给了我以下错误

Connection connection =  connectionFactory.createConnection();

SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
java.lang.NullPointerException
        at com.quant.ws.GetConnection.startThread(GetConnection.java:99)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 

下面是代码:

// Inside class declaration
@Resource(mappedName = "jms/testFactory")
private static ConnectionFactory connectionFactory;

@Resource(mappedName = "jms/test")
private static Queue queue;

网络服务方法

@GET
@Path("startThread")
@Produces("application/xml")
public String startThread()
{

    try{
    Connection connection =  connectionFactory.createConnection(); // its line number 99
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = session.createProducer( queue);
    Message message = session.createTextMessage();
    message.setStringProperty("name", "start");
    producer.send(message);
    }catch(JMSException e){
        System.out.println(e);
    }
   return "<data>START</data>";
}

我需要在 sun-web.xml 或 web.xml 中指定任何内容吗?

【问题讨论】:

  • NullPointerException 说它发生在第 99 行。上面的第 99 行是哪一行?
  • 连接连接 = connectionFactory.createConnection();是行号 99

标签: web-services rest jms ejb nullpointerexception


【解决方案1】:

我认为这取决于您的应用服务器设置。你在上面的某个地方注入了connectionFactory吗?还是进行了上下文查找?

【讨论】:

  • 如果您的工厂和队列使用这些名称注册,则应该这样做。
【解决方案2】:

connectionFactory 为空。它需要以某种方式初始化。

【讨论】:

  • 好吧,我不知道该怎么做
【解决方案3】:

我已经通过替换以下代码解决了它

  try{
       InitialContext ctx = new InitialContext();
      queue = (Queue) ctx.lookup("jms/test");
      QueueConnectionFactory factory =
      (QueueConnectionFactory) ctx.lookup("jms/testFactory");
      Connection connection = factory.createConnection();
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer( queue);

        Message message = session.createTextMessage();
        message.setStringProperty("name", "start");
        producer.send(message);

     }
     catch(NamingException e){
         System.out.println(e);
     }
     catch(JMSException e){
     System.out.println(e);
     }

【讨论】:

    猜你喜欢
    • 2013-11-05
    • 1970-01-01
    • 2015-04-30
    • 2011-12-23
    • 2015-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多