Package com.google.appengine.api.xmpp

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


    tojid = new JID(user);
  }
 
  public void push(String message) throws IOException {
    if (xmpp.getPresence(tojid).isAvailable()) {
      Message msg = new MessageBuilder().withRecipientJids(tojid)
          .withBody("@Push-wish:" + message).build();
      xmpp.sendMessage(msg);
    } else {
      // �� GTalk �ͻ��ˣ�������뱾������û����ƣ����ܽ��յ���Ϣ����������ǣ�push-wish@appspot.com
      log.severe("Can't connect to user: " + tojid.getId() );
View Full Code Here


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

        builder.withFromJid(fromJID);
        builder.withRecipientJids(toJID);
        String testBody = TEST_BODY + System.currentTimeMillis();
        builder.withBody(testBody);
        builder.asXml(false);
        Message msg = builder.build();

        SendResponse response = xmppService.sendMessage(msg);
        assertNotNull("expected a response", response);
        assertEquals(1, response.getStatusMap().size());
        assertEquals(SendResponse.Status.SUCCESS, response.getStatusMap().get(toJID));
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());
        entity.setProperty("from", message.getFromJid().toString());
        entity.setProperty("to", message.getRecipientJids()[0].toString());
        entity.setProperty("body", message.getBody());
        datastoreService.put(entity);
    }
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.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

    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

  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.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.