Package com.google.appengine.api.xmpp

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


        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.)
View Full Code Here


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

  }

  // For testing. Real requests are POST
  public void doGet(HttpServletRequest req, HttpServletResponse res)
      throws IOException {
    Message message =new MessageBuilder()
        .withMessageType(MessageType.CHAT)
        .withFromJid(new JID(req.getParameter("from")))
        .withRecipientJids(new JID(req.getParameter("to")))
        .withBody(req.getParameter("body"))
        .build();
View Full Code Here

  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 ;(");
        return;
      }
      // This is the case where help about command is asked
      if (message.getBody().trim().equalsIgnoreCase("help")) {
        String msg = "_Send a message containing a list (separated by a space) of the driveways you want to get trips informations._\n\n*The available driveways are "
            + Arrays.asList(Driveway.values()) + ".*\n\nExample of message (without \") : \"A1 A6 A3\" or \"A1\"\n\n;)";
        sendResponseToSender(xmpp, message.getFromJid(), msg);
        return;
      }

      /* Step 3 : Get the trips informations and send the response */
      // Get all trips informations from CITA
      List<Duration> tripsCitaInfos = InfoGetter.getCitaInfo();
      // Prepare response message body for the driveways specified into
      // the message
      StringBuilder xmlppReponseBody = new StringBuilder("\n");
      // Extract the list of specified driveways and parse it, building
      // the response in the same time...
      String[] driveways = message.getBody().trim().split(" ");
      for (String driveway : driveways) {
        // No processing if the driveway is not filled
        if (driveway == null) {
          continue;
        }
        // turn debug mode on if requested
        if ("D".equalsIgnoreCase(driveway)) {
          debugMode = true;
          continue;
        }
        // Check that the driveway is in the available list, if not send
        // an response and quit...
        if (!Driveway.isMember(driveway.trim().toUpperCase())) {
          sendResponseToSender(xmpp, message.getFromJid(), "The driveway '" + driveway.trim().toUpperCase() + "' is unknown. ;)\n Please type 'help' for more information on how to use this bot.");
          return;
        }
        // Get the list of trips for the current driveway
        List<Trip> trips = Trip.fromDriveway(Driveway.valueOf(driveway.trim().toUpperCase()));
        if (trips == null) {
          continue;
        }
        // Parse list of trips for the current driveway
        xmlppReponseBody.append("*").append(driveway.toUpperCase().trim()).append("* :\n");
        for (Duration duration : tripsCitaInfos) {
          if (trips.contains(duration.getTrip())) {
            xmlppReponseBody.append("'").append(duration.getTrip().getStartPoint()).append("' To '").append(duration.getTrip().getEndinPoint()).append("' : ");
            if (duration.getDuration() == -1) {
              xmlppReponseBody.append(" _FLUID_\n");
            } else {
              xmlppReponseBody.append(duration.getDuration()).append(" minute(s)\n");
            }
          }
        }
        xmlppReponseBody.append("\n\n");
      }
     
      if (debugMode) {
        xmlppReponseBody.append("Debug mode:\nResponse generated in " + (System.currentTimeMillis() - beginTime) + "ms.\n\n");
      }

      /* Step 4 : Send the response to the sender buddy */
      boolean sent = sendResponseToSender(xmpp, message.getFromJid(), xmlppReponseBody.toString());
      if (sent) {
        LOGGER.info("Message to " + message.getFromJid().getId() + " successfully sent !");
      } else {
        LOGGER.info("Message to " + message.getFromJid().getId() + " send failed !");
      }

    } catch (Exception e) {
      // We trace the error
      LOGGER.severe("Error from XMPP BOT : " + e.getMessage());
      // In case of error we return a message response indicating that an
      // error occur...
      try {
        sendResponseToSender(xmpp, message.getFromJid(), "Oups an error occured!");
      } catch (Exception e1) {
        LOGGER.severe("Error from XMPP BOT : " + e1.getMessage());
      }
    }

View Full Code Here

  private boolean sendResponseToSender(XMPPService xmpp, JID sender, String messageBody) throws Exception {
    boolean sent = false;
    // Send the message only if the buddy is online
    if (xmpp.getPresence(sender).isAvailable()) {
      // Create a message container
      Message msg = new MessageBuilder().withRecipientJids(sender).withBody(messageBody.trim()).withFromJid(new JID(APPLICATION_JID)).withMessageType(MessageType.CHAT).build();
      SendResponse status = xmpp.sendMessage(msg);
      // Check delivery status
      if ((status.getStatusMap().get(sender) == SendResponse.Status.SUCCESS)) {
        sent = true;
      }
View Full Code Here

   * @param strMessage 要发送的消息内容
   */
  public static void sendMessage(JID fromJID, String strMessage)
  {
    XMPPService xmpp = XMPPServiceFactory.getXMPPService();
    Message MsgSend = new MessageBuilder()
        .withRecipientJids(fromJID)
        .withBody(strMessage)
        .build();
    if(xmpp.getPresence(fromJID).isAvailable())
    {
View Full Code Here

  {
    req.setCharacterEncoding("UTF-8");
    resp.setCharacterEncoding("UTF-8");
    resp.setContentType("text/html; charset=utf-8");
    XMPPService xmpp = XMPPServiceFactory.getXMPPService();
    Message message = xmpp.parseMessage(req);
    JID fromJID = message.getFromJid();                    //发送者JID
    String msgbody = message.getBody();                    //接收到的消息
    msgbody = msgbody.trim();
    if(msgbody.isEmpty())
    {
      return;
    }
View Full Code Here

  public void doPost(HttpServletRequest req, HttpServletResponse res)
      throws IOException {
    XMPPService xmpp = XMPPServiceFactory.getXMPPService();
   
    // receive message
    Message message = xmpp.parseMessage(req);
    JID from = message.getFromJid();
    JID[] recipients = message.getRecipientJids();
    JID to = (recipients.length > 0) ? recipients[0] : null;
   
    String body = message.getBody();
    if (body != null && body.startsWith("{") || body.trim().startsWith("{")) {
      // the body contains a JSON object
      ObjectNode json = null;
      try {
        String agentUrl = "xmpp:" + to.getId();
        String agentId = xmppService != null ? xmppService
            .getAgentId(agentUrl) : null;
       
        json = JOM.getInstance().readValue(body, ObjectNode.class);
        if (isResponse(json)) {
          // TODO: handle response
        } else if (isRequest(json)) {
          // this is a request
         
          // append the sender to the request parameters
          RequestParams params = new RequestParams();
          params.put(Sender.class, from.getId());
         
          // TODO: cleanup logger info
          logger.info("request agentUrl =" + agentUrl + ", agentId="
              + agentId + " request=" + json + ", sender="
              + from.getId());
         
          // invoke the agent
          JSONRequest request = new JSONRequest(json);
          JSONResponse response = agentFactory.receive(agentId,
              request, params);
         
          // reply to message
          Message msg = new MessageBuilder().withRecipientJids(from)
              .withFromJid(to).withBody(response.toString())
              .build();
          xmpp.sendMessage(msg);
        } else {
          throw new Exception(
              "Request does not contain a valid JSON-RPC request or response");
        }
      } catch (Exception err) {
        // generate JSON error response
        JSONRPCException jsonError = new JSONRPCException(
            JSONRPCException.CODE.INTERNAL_ERROR, err.getMessage());
        JSONResponse response = new JSONResponse(jsonError);
       
        // send exception as response
        Message msg = new MessageBuilder().withRecipientJids(from)
            .withFromJid(to).withBody(response.toString()).build();
        xmpp.sendMessage(msg);
      }
    }
  }
View Full Code Here

        b.append(" 議事録'");
        b.append(document.getProperty("title"));
        b.append("' に");
        b.append(document.getProperty("memoCount"));
        b.append(" 件目が投稿されました.");
        Message message =
            new MessageBuilder()
                .withRecipientJids(new JID(ADMIN_EMAIL))
                .withBody(b.toString())
                .build();
        XMPPServiceFactory.getXMPPService().sendMessage(message);
View Full Code Here

TOP

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

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.