Package com.google.appengine.api.xmpp

Examples of com.google.appengine.api.xmpp.XMPPService


@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);
    }
  }
View Full Code Here


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("coralie.ratier@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);
        }

       
View Full Code Here

        throws IOException, ServletException {

        log.info("PresenceServlet: ..." + req.getPathInfo());

        DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
        XMPPService xmpp = XMPPServiceFactory.getXMPPService();

        Presence presence = xmpp.parsePresence(req);
        JID userJID = presence.getFromJid();

        if (presence.getPresenceType() == PresenceType.AVAILABLE ||
            presence.getPresenceType() == PresenceType.UNAVAILABLE) {
            // Store the user's presence.
            Entity userEntity = MainPageServlet.getUserEntity(userJID);
            userEntity.setProperty("is_available",
                                   presence.getPresenceType() == PresenceType.AVAILABLE);

            // Interpret no show value or "none" as "chat".
            if (presence.getPresenceShow() == null ||
                presence.getPresenceShow() == PresenceShow.NONE) {
                userEntity.setProperty("presence_show", "chat");
            } else {
                userEntity.setProperty("presence_show",
                                       presence.getPresenceShow().toString().toLowerCase());
            }

            userEntity.setProperty("status_message", presence.getStatus());
            datastore.put(userEntity);

        } else if (presence.getPresenceType() == PresenceType.PROBE) {
            // Respond to the probe by sending the app's presence.
            Entity statusEntity = MainPageServlet.getStatusEntity();
            xmpp.sendPresence(userJID,
                              ((Boolean)statusEntity.getProperty("presence_available")) ?
                              PresenceType.AVAILABLE : PresenceType.UNAVAILABLE,
                              PresenceShow.valueOf(((String)statusEntity.getProperty("presence_show")).toUpperCase()),
                              (String)statusEntity.getProperty("status_message"));
        }
View Full Code Here

        throws IOException, ServletException {

        log.info("SubscriptionServlet: ..." + req.getPathInfo());

        DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
        XMPPService xmpp = XMPPServiceFactory.getXMPPService();

        Subscription sub = xmpp.parseSubscription(req);
        JID userJID = sub.getFromJid();
        Entity userEntity = MainPageServlet.getUserEntity(userJID);

        if (sub.getSubscriptionType() == SubscriptionType.SUBSCRIBED) {
            userEntity.setProperty("accepted_invitation", true);
View Full Code Here

        throws IOException, ServletException {

        log.info("XmppErrorServlet");

        DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
        XMPPService xmpp = XMPPServiceFactory.getXMPPService();

        Message message = xmpp.parseMessage(req);
        Entity statusEntity = MainPageServlet.getStatusEntity();
        statusEntity.setProperty("last_error", message.getBody());
        statusEntity.setProperty("Last_error_datetime", new Date());
        datastore.put(statusEntity);
    }
View Full Code Here

        throws IOException, ServletException {

        log.info("ChatServlet");

        DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
        XMPPService xmpp = XMPPServiceFactory.getXMPPService();

        Message message = xmpp.parseMessage(req);
        JID userJID = message.getFromJid();
        Entity userEntity = MainPageServlet.getUserEntity(userJID);
        userEntity.setProperty("last_chat_message", message.getBody());
        datastore.put(userEntity);

        Message reply = new MessageBuilder()
            .withRecipientJids(userJID)
            .withBody("I got your message! It had " +
                      message.getBody().length() + " characters.")
            .build();
        // (Ignore the send response.)
        xmpp.sendMessage(reply);
    }
View Full Code Here

        String command = req.getParameter("command");

        String adminMessage;

        DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
        XMPPService xmpp = XMPPServiceFactory.getXMPPService();

        if (jid != null && command.equals("chat")) {
            Message message = new MessageBuilder()
                .withMessageType(MessageType.CHAT)
                .withRecipientJids(jid)
                .withBody(req.getParameter("chat_message"))
                .build();
            SendResponse sendResponse = xmpp.sendMessage(message);
            if (sendResponse.getStatusMap().get(jid) == SendResponse.Status.SUCCESS) {
                adminMessage = "Chat message sent to JID " + jidStr + ".";
            } else if (sendResponse.getStatusMap().get(jid) == SendResponse.Status.INVALID_ID) {
                adminMessage = "Message not sent: invalid JID " + jidStr + ".";
            } else {
                adminMessage = "Message not sent to " + jidStr + ": internal service error.";
            }
           
        } else if (jid != null && command.equals("invite")) {
            xmpp.sendInvitation(jid);
            adminMessage = "Chat message sent to JID " + jidStr + ".";

        } else if (jid != null && command.equals("probe")) {
            xmpp.sendPresence(jid, PresenceType.PROBE, null, null);
            adminMessage = "A presence probe has been sent to JID " + jidStr + ".";

        } else if (command.equals("presence")) {
            // Store the app's presence.
            Entity statusEntity = MainPageServlet.getStatusEntity();

            if (req.getParameter("presence_available").equals("true")) {
                statusEntity.setProperty("presence_available", true);
            } else if (req.getParameter("presence_available").equals("false")) {
                statusEntity.setProperty("presence_available", false);
            }

            if (req.getParameter("presence_show").equals("chat") ||
                req.getParameter("presence_show").equals("away") ||
                req.getParameter("presence_show").equals("dnd") ||
                req.getParameter("presence_show").equals("xa")) {
                statusEntity.setProperty("presence_show",
                                         req.getParameter("presence_show"));
            }

            statusEntity.setProperty("status_message",
                                     req.getParameter("status_message"));

            datastore.put(statusEntity);

            // Send presence messages to all subscribed users.  As
            // written, this could be slow or broken for a large number
            // of users.  A more robust solution would use a task queue
            // and a query cursor.  (Unlike sendMessage(),
            // sendPresence() only accepts one JID at a time.)
            Query q = new Query("ChatUser").addFilter("is_subscribed",
                                                      Query.FilterOperator.EQUAL,
                                                      true);
            PreparedQuery pq = datastore.prepare(q);
            for (Entity e : pq.asIterable()) {
                String recipJidStr = (String)(e.getProperty("jid"));
                JID recipJid = new JID(recipJidStr);
                xmpp.sendPresence(recipJid,
                                  ((Boolean)statusEntity.getProperty("presence_available")) ?
                                  PresenceType.AVAILABLE : PresenceType.UNAVAILABLE,
                                  PresenceShow.valueOf(((String)statusEntity.getProperty("presence_show")).toUpperCase()),
                                  (String)statusEntity.getProperty("status_message"));
            }
View Full Code Here

    }

    public void doPost(HttpServletRequest req,
                       HttpServletResponse resp)
        throws IOException {
        XMPPService xmpp = XMPPServiceFactory.getXMPPService();
        Message message = xmpp.parseMessage(req);

        String answer = doArithmetic(message.getBody());
        if (answer == null) {
            answer = "I didn't understand: " + message.getBody();
        }

        Message reply = new MessageBuilder()
            .withRecipientJids(message.getFromJid())
            .withBody(answer)
            .build();
        SendResponse success = xmpp.sendMessage(reply);
        if (success.getStatusMap().get(message.getFromJid())
            != SendResponse.Status.SUCCESS) {
            log.warning("Could not send XMPP reply to " + message.getFromJid());
        }
    }
View Full Code Here

    public static void Init(){
        Log.info("[done]");
    }
    static void Enter(String ns){
        XMPPService xms = XMS.get();
        if (null == xms){
            xms = XMPPServiceFactory.getXMPPService();
            XMS.set(xms);
        }
        /*
 
View Full Code Here

  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    long beginTime = System.currentTimeMillis();
    boolean debugMode = false;
   
    XMPPService xmpp = XMPPServiceFactory.getXMPPService();
    Message message = null;
    try {
      /* Step 1 : Get the message */
      message = xmpp.parseMessage(req);

      /* Step 2 : Check the message body */
      // The body cannot be empty
      if (StringUtil.isEmpty(message.getBody())) {
        sendResponseToSender(xmpp, message.getFromJid(), "Bad request message format ;(");
View Full Code Here

TOP

Related Classes of com.google.appengine.api.xmpp.XMPPService

Copyright © 2018 www.massapicom. 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.