继承人的代码
它基本上需要一条消息并将其回显。问题是它根本没有回复:(在谷歌应用程序引擎,我的应用程序页面中,我收到错误-“在此服务器上找不到请求的 URL /guestbook。”
package guestbook;
import java.io.IOException;
import java.util.logging.Logger;
import javax.servlet.http.*;
import com.google.appengine.api.xmpp.JID;
import com.google.appengine.api.xmpp.Message;
import com.google.appengine.api.xmpp.MessageBuilder;
import com.google.appengine.api.xmpp.XMPPService;
import com.google.appengine.api.xmpp.XMPPServiceFactory;
@SuppressWarnings("serial")
public class GuestbookServlet extends HttpServlet {
private static final Logger LOG =
Logger.getLogger(GuestbookServlet.class.getName());
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
// Parse incoming message
XMPPService xmpp = XMPPServiceFactory.getXMPPService();
Message msg = xmpp.parseMessage(req);
JID jid = msg.getFromJid();
String body = msg.getBody();
LOG.info(jid.getId() + " --> JEliza: " + body);
// Get a response from Eliza
String response = "echo: " + body;
LOG.info(jid.getId() + " <-- JEliza: " + response);
// Send out response
msg = new MessageBuilder()
.withRecipientJids(jid)
.withBody(response)
.build();
xmpp.sendMessage(msg);
/*Message message = xmpp.parseMessage(req);
JID fromJid = message.getFromJid();
String body = message.getBody();
String respMsg = null;
if (body.equals("/list")) {
respMsg = "Hi";
} else if (body.equals("/help")) {
respMsg = "Welcome to the Guestbook Chatbot!\nThe following commands are supported: \n /list \n /help";
} else {
respMsg = "Command '" + body + "' not supported! \nEnter '/help' for list of commands.";
}
JID tojid = new JID(fromJid.getId());
Message msg = new MessageBuilder().withRecipientJids(tojid).withBody(respMsg).build();
boolean messageSent = false;
xmpp = XMPPServiceFactory.getXMPPService();
if (xmpp.getPresence(tojid).isAvailable()) {
SendResponse status = xmpp.sendMessage(msg);
messageSent = (status.getStatusMap().get(tojid) == SendResponse.Status.SUCCESS);
}*/
}
}