Package com.google.appengine.api.xmpp

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


      JID toJid = new JID(getServletContext().getInitParameter("admin.gmail.email"));
      JID fromJid = new JID("filedownloadrelay@appspot.com");
      // --Create the message
      com.google.appengine.api.xmpp.Message xMsg = new MessageBuilder().withRecipientJids(toJid).withBody(trace).withMessageType(MessageType.NORMAL).withFromJid(fromJid).build();
      // --Get a XMPP service provider
      XMPPService xmpp = XMPPServiceFactory.getXMPPService();
      // --Send the message only if the receiver buddy is connected
      if (xmpp.getPresence(toJid).isAvailable()) {
        // Do not care about the message delivery status...
        // xmpp.sendMessage(xMsg);
      }

      // Display a information log
View Full Code Here


   * @param fromJID 来源JID
   * @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())
    {
      SendResponse success = xmpp.sendMessage(MsgSend);
      if(success.getStatusMap().get(fromJID) != SendResponse.Status.SUCCESS//发送失败,重试一次
      {
        success = xmpp.sendMessage(MsgSend);
      }
    }
  }
View Full Code Here

    for (Entity result : pq.asIterable())
    {
      Key key = result.getKey();
      try{
        JID fromJID = new JID(key.getName());
        XMPPService xmpp = XMPPServiceFactory.getXMPPService();
        if(xmpp.getPresence(fromJID).isAvailable())
        {
          doCheckMention(fromJID);
        }
      } catch(XMPPFailureException e){
        Common.log.warning(key.getName() + ":cromn " + e.getMessage());
View Full Code Here

    throws IOException
  {
    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())
    {
View Full Code Here

   * @param req
   * @param res
   */
  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

  private static final long serialVersionUID = 379460891011536344L;
  private static final Logger log = Logger.getLogger(PullwishFromGTalk.class.getName());

  public void doPost(HttpServletRequest req, HttpServletResponse res)
      throws IOException {
    XMPPService xmpp = XMPPServiceFactory.getXMPPService();
    Message message = xmpp.parseMessage(req);
    JID fromJid = message.getFromJid();
    String body = message.getBody();
    Message msg;

    try {
      URL url = new URL("http://d3viewer.appspot.com/comment/");
      HttpURLConnection connection = (HttpURLConnection) url
          .openConnection();
      connection.setDoOutput(true);
      connection.setRequestMethod("POST");
      String security = URLEncoder.encode(fromJid.getId() + " says: " + body,
          "UTF-8");
      OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
      writer.write("message=" + security);
      writer.close();

      if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
        // OK
      } else {
        msg = new MessageBuilder().withRecipientJids(fromJid)
            .withBody("I can't connect to server.").build();
      }
    } catch (MalformedURLException e) {
      log.severe(e.getMessage());
    } catch (IOException e) {
      log.severe(e.getMessage());
    }

    if (body.contains("shutout") || body.contains("quiet") || body.contains("silence")) {
      ServerConfig.shutout = true;
      msg = new MessageBuilder().withRecipientJids(fromJid)
          .withBody("I'm quiet now.").build();
    } else if (body.contains("shout")) {
      ServerConfig.shutout = false;
      msg = new MessageBuilder().withRecipientJids(fromJid)
          .withBody("I will shout aloud.").build();
    } else {
      msg = new MessageBuilder().withRecipientJids(fromJid)
          .withBody("I can't understand you.").build();
    }
    // SendResponse status =
    xmpp.sendMessage(msg);
    // messageSent = (status.getStatusMap().get(copy2jid) ==
  }
View Full Code Here

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws IOException {
        XMPPService xmppService = XMPPServiceFactory.getXMPPService();
        Message message = xmppService.parseMessage(req);

        log.info("Chat received: " + message.getStanza());

        Entity entity = new Entity("XmppMsg", "test");
        entity.setProperty("type", message.getMessageType().toString());
View Full Code Here

   * @param req
   * @param res
   */
    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.invoke(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

   * @param req
   * @param res
   */
    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

   * @param req
   * @param res
   */
  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
      try {
        String agentUrl = "xmpp:" + to.getId();
        String agentId = xmppService != null ? xmppService
            .getAgentId(new URI(agentUrl)) : null;
       
        logger.info("request agentUrl =" + agentUrl + ", agentId="
            + agentId + " request=" + body + ", sender="
            + from.getId());
       
        // invoke the agent
        host.receive(agentId, body, new URI(from.getId()), null);
       
      } 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

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.