Exemplo n.º 1
0
  private void processIQ(Element doc) {
    log.debug("processIQ()...");
    IQ packet;
    try {
      packet = getIQ(doc);
    } catch (IllegalArgumentException e) {
      log.debug("Rejecting packet. JID malformed", e);
      IQ reply = new IQ();
      if (!doc.elements().isEmpty()) {
        reply.setChildElement(((Element) doc.elements().get(0)).createCopy());
      }
      reply.setID(doc.attributeValue("id"));
      reply.setTo(session.getAddress());
      String to = doc.attributeValue("to");
      if (to != null) {
        reply.getElement().addAttribute("from", to);
      }
      reply.setError(PacketError.Condition.jid_malformed);
      session.process(reply);
      return;
    }

    //        if (packet.getID() == null) {
    //            // IQ packets MUST have an 'id' attribute
    //            StreamError error = new StreamError(
    //                    StreamError.Condition.invalid_xml);
    //            session.deliverRawText(error.toXML());
    //            session.close();
    //            return;
    //        }

    packet.setFrom(session.getAddress());
    router.route(packet);
    session.incrementClientPacketCount();
  }
Exemplo n.º 2
0
  private void processPresence(Element doc) {
    log.debug("processPresence()...");
    Presence packet;
    try {
      packet = new Presence(doc, false);
    } catch (IllegalArgumentException e) {
      log.debug("Rejecting packet. JID malformed", e);
      Presence reply = new Presence();
      reply.setID(doc.attributeValue("id"));
      reply.setTo(session.getAddress());
      reply.getElement().addAttribute("from", doc.attributeValue("to"));
      reply.setError(PacketError.Condition.jid_malformed);
      session.process(reply);
      return;
    }
    if (session.getStatus() == Session.STATUS_CLOSED && packet.isAvailable()) {
      log.warn("Ignoring available presence packet of closed session: " + packet);
      return;
    }
    packet.setFrom(session.getAddress());
    router.route(packet);
    session.incrementClientPacketCount();

    if (session.getStatus() == Session.STATUS_AUTHENTICATED && packet.isAvailable()) {
      String userName = session.getAddress().getNode();
      System.out.println("Query username : -> " + userName);
      if (null != userName && !"".equals(userName)) {
        NotificationMO mo = new NotificationMO();
        mo.setUsername(userName);
        mo.setStatus(NotificationMO.STATUS_NOT_SEND);
        List<NotificationMO> list = notificationService.queryNotification(mo);
        if (!list.isEmpty()) {
          for (NotificationMO notificationMO : list) {
            notificationManager.sendOfflineNotification(notificationMO);
          }
        } else {
          log.info(" no offline notification, username = "******"userName is null !!!!!!");
      }
    }
  }
Exemplo n.º 3
0
  private void processMessage(Element doc) {
    log.debug("processMessage()...");
    Message packet;
    try {
      packet = new Message(doc, false);
    } catch (IllegalArgumentException e) {
      log.debug("Rejecting packet. JID malformed", e);
      Message reply = new Message();
      reply.setID(doc.attributeValue("id"));
      reply.setTo(session.getAddress());
      reply.getElement().addAttribute("from", doc.attributeValue("to"));
      reply.setError(PacketError.Condition.jid_malformed);
      session.process(reply);
      return;
    }

    packet.setFrom(session.getAddress());
    router.route(packet);
    session.incrementClientPacketCount();
  }