예제 #1
0
  /** Invoked when a message is received. */
  public void messageReceived(IoSession session, Object message) throws Exception {
    log.debug("messageReceived()...");
    // <iq id="567-3" type="result"><test>aaaa</test></iq>
    // <iq id="567-3" type="result"><test>aaaa</test></iq>
    // log.info("RCVD: " + message);

    // Get the stanza handler
    StanzaHandler handler = (StanzaHandler) session.getAttribute(STANZA_HANDLER);

    // Get the XMPP packet parser
    int hashCode = Thread.currentThread().hashCode();
    XMPPPacketReader parser = parsers.get(hashCode);
    if (parser == null) {
      parser = new XMPPPacketReader();
      parser.setXPPFactory(factory);
      parsers.put(hashCode, parser);
    }

    // The stanza handler processes the message
    try {
      handler.process((String) message, parser);
    } catch (Exception e) {
      log.error("Closing connection due to error while processing message: " + message, e);
      Connection connection = (Connection) session.getAttribute(CONNECTION);
      connection.close();
    }
  }
예제 #2
0
 @Override
 protected void processPresence(Presence packet) throws UnauthorizedException {
   // Overwrite the FROM attribute to avoid spoofing
   packet.setFrom(session.getAddress());
   super.processPresence(packet);
 }