コード例 #1
0
 protected void doDisconnect() throws Exception {
   try {
     if (groupChat != null) {
       groupChat.leave();
     }
     if (xmppConnection != null) {
       xmppConnection.close();
     }
   } finally {
     xmppConnection = null;
   }
 }
コード例 #2
0
  protected void sendMessage(UMOEvent event) throws Exception {
    if (chat == null && groupChat == null) {
      UMOMessage msg = event.getMessage();
      boolean group = msg.getBooleanProperty(XmppConnector.XMPP_GROUP_CHAT, false);
      String nickname = msg.getStringProperty(XmppConnector.XMPP_NICKNAME, "mule");
      String recipient = event.getEndpoint().getEndpointURI().getPath().substring(1);

      if (group) {
        groupChat = new GroupChat(xmppConnection, recipient);
        if (!groupChat.isJoined()) {
          groupChat.join(nickname);
        }
      } else {
        chat = new Chat(xmppConnection, recipient);
      }
    }

    Object msgObj = event.getMessage().getPayload();
    Message message;
    // avoid duplicate transformation
    if (!(msgObj instanceof Message)) {
      message = (Message) event.getTransformedMessage();
    } else {
      message = (Message) msgObj;
    }

    if (logger.isTraceEnabled()) {
      logger.trace("Transformed packet: " + message.toXML());
    }

    if (chat != null) {
      chat.sendMessage(message);
    } else {
      groupChat.sendMessage(message);
    }

    if (logger.isDebugEnabled()) {
      logger.debug("Packet successfully sent");
    }
  }
コード例 #3
0
  protected UMOMessage doSend(UMOEvent event) throws Exception {
    sendMessage(event);

    if (useRemoteSync(event)) {
      Message response;

      if (groupChat != null) {
        response = groupChat.nextMessage(event.getTimeout());
      } else {
        response = chat.nextMessage(event.getTimeout());
      }

      if (response != null) {
        if (logger.isDebugEnabled()) {
          logger.debug("Got a response from chat: " + chat);
        }
        return new MuleMessage(connector.getMessageAdapter(response));
      }
    }
    return null;
  }