Package fr.isis.cloud

Source Code of fr.isis.cloud.ReceiveChatMessage

package fr.isis.cloud;

import java.io.IOException;
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.SendResponse;
import com.google.appengine.api.xmpp.XMPPService;
import com.google.appengine.api.xmpp.XMPPServiceFactory;

@SuppressWarnings("serial")
public class ReceiveChatMessage extends HttpServlet {
  public void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws IOException {

    XMPPService xmpp = XMPPServiceFactory.getXMPPService();
    Message message = xmpp.parseMessage(req);

    JID fromJid = message.getFromJid();
    String body = message.getBody();

    JID jid = new JID("julien.plagnes@gmail.com");

    Message msg = new MessageBuilder().withRecipientJids(jid)
        .withBody("Vous m'avez dit \"" + body + "\"").build();

    boolean messageSent = false;
    XMPPService xmpp1 = XMPPServiceFactory.getXMPPService();
    if (xmpp1.getPresence(jid).isAvailable()) {
      SendResponse status = xmpp1.sendMessage(msg);
      messageSent = (status.getStatusMap().get(jid) == SendResponse.Status.SUCCESS);
    }
  }
}
TOP

Related Classes of fr.isis.cloud.ReceiveChatMessage

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.