Package com.google.appengine.api.xmpp

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


     *
     * @param msgAttr a map of attributes as described
     * @return an intance of SendResponse
     */
    public static SendResponse send(XMPPService xmppService, @SuppressWarnings("rawtypes") Map msgAttr) {
        MessageBuilder msgBuilder = new MessageBuilder();

        if (msgAttr.containsKey(XML_BODY_ATTR) && msgAttr.containsKey(TEXT_BODY_ATTR)) {
            throw new RuntimeException("You have to choose between XML and text bodies, you can't have both!");
        }

        // sets the body of the message
        if (msgAttr.containsKey(XML_BODY_ATTR)) {
            msgBuilder.asXml(true);
            Object xml = new StreamingMarkupBuilder().bind(msgAttr.get(XML_BODY_ATTR));
            msgBuilder.withBody(String.valueOf(xml));
        } else if (msgAttr.containsKey(TEXT_BODY_ATTR)) {
            msgBuilder.withBody(String.valueOf(msgAttr.get(TEXT_BODY_ATTR)));
        }

        // sets the recepients of the message
        if (msgAttr.containsKey(TO_ATTR)) {
            Object to = msgAttr.get(TO_ATTR);
            if (to instanceof String) {
                msgBuilder.withRecipientJids(new JID((String) to));
            } else if (to instanceof List<?>) {
                List<?> toList = (List<?>)to;
                JID[] jids = new JID[toList.size()];
                for (int i = 0; i < toList.size(); i++) {
                    jids[i] = new JID(String.valueOf(toList.get(i)));
                }
                msgBuilder.withRecipientJids(jids);
            }
        }

        // sets the sender of the message
        if (msgAttr.containsKey(FROM_ATTR)) {
            msgBuilder.withFromJid(new JID(String.valueOf(msgAttr.get(FROM_ATTR))));
        }

        // sets the type of the message
        if (msgAttr.containsKey(TYPE_ATTR)) {
            Object type = msgAttr.get(TYPE_ATTR);
            if (type instanceof MessageType) {
                msgBuilder.withMessageType((MessageType) type);
            } else if (type instanceof String) {
                msgBuilder.withMessageType(MessageType.valueOf((String) type));
            }
        }

        return xmppService.sendMessage(msgBuilder.build());
    }
View Full Code Here


    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

      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

        JID fromJID = new JID(appId + "@" + xmppServer);
        // We're sending messages to ourselves, so toJID and fromJID are the same.
        @SuppressWarnings("UnnecessaryLocalVariable")
        JID toJID = fromJID;

        MessageBuilder builder = new MessageBuilder();
        builder.withMessageType(MessageType.valueOf("CHAT"));
        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

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

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

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

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.