我可以使用一个servlet接收xmpp消息,另一个用于在App Engine中发送它们吗?

时间:2012-12-21 06:39:19

标签: google-app-engine xmpp

xmpp服务所需的servlet URL映射(/ _ah / xmpp / message / chat /)是否限制我仅使用该servlet发送和接收xmpp消息?

我的应用程序接收消息,将它们添加到'inQueue'进行处理,一旦处理完毕,结果就会添加到'outQueue'中。理想情况下,我希望分配给outQueue的worker servlet发送响应。

我正在使用推送队列,而且HTTP POST请求显然会调用servlet ......

当我尝试使用xmpp服务从我的outQueue worker发送消息时(显然没有映射到/ _ah / xmpp / message / chat /),它预计什么都不做。

在servlet中映射到/ _ah / xmpp / message / chat /:

//Generate a Memcache key 
String key = generateMemcacheKey(message);

//Serialize the message as xml using getStanza (for now, just put in the senderJID as string)
String senderJIDString = message.getFromJid().getId();

//Cache the message in Memcache
cache.put(key, senderJIDString);

//Enqueue a task for the message
private Queue queue = QueueFactory.getQueue("inQueue");
queue.add(TaskOptions.Builder.withUrl("/xmppParser").param("memcacheKey", key));

在xmppParser servlet中的doPost方法:

//Extract message from memcache
String key = req.getParameter("memcacheKey");
String recipientJIDString = (String)cache.get(key);

//Todo Detect language

//Todo Parse Message into an Imperative accordingly (For now, just reply hello)

//Todo Handle Session status

//Put Imperative into memcache (For now, just put recipientID in)
cache.put(key, recipientJIDString);

//Enqueue appropriately
Queue queue = QueueFactory.getQueue("outQueue");
queue.add(TaskOptions.Builder.withUrl("/responseServlet").param("memcacheKey", key
));

现在我希望这个responseServlet发送回复:

//Get a handler on the memcache
MemcacheService cache = MemcacheServiceFactory.getMemcacheService();

//Extract the key to the response from the request
String key = req.getParameter("memcacheKey");

//Extract the message from the memcache ( For now it's just the JID of the sender)
String recipientJIDString = (String)cache.get(key);

//Parse it into a message (For now just make a simple "I hear you" message)
JID recipientJID = new JID(recipientJIDString);
Message response = new MessageBuilder()
    .withMessageType(MessageType.NORMAL)
    .withRecipientJids(recipientJID)
    .withBody("I hear you")
    .build();

//Send the message
XMPPService xmpp = XMPPServiceFactory.getXMPPService();
xmpp.sendMessage(response);

servlet映射都是kosher,xmpp服务无法发送消息。它引发了一个空指针异常,但是memcache查看器确认了recipientJID也是犹太洁食......我猜测只有映射到/ _ah / xmpp / message / chat /的servlet才能发送消息,或者我错了?

我被迫在实际网站上进行测试,因为开发服务器似乎没有支持XMPP,这增加了我忽略某些生产环境配置的可能性......

非常有责任!

RAM

0 个答案:

没有答案