我正在尝试创建Restful Webservice作为消息驱动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;Web服务方法
@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中指定任何内容?
发布于 2011-04-24 13:06:16
我已经通过替换下面的代码解决了这个问题
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);
}发布于 2011-04-23 16:27:37
我想这取决于你的应用服务器设置。你在上面的某个地方注射了connectionFactory吗?还是做了上下文查询?
发布于 2011-04-23 17:08:15
connectionFactory为空。它需要以某种方式进行初始化。
https://stackoverflow.com/questions/5762972
复制相似问题