Esempio n. 1
0
  /**
   * Delivers the packet to the packet recipient.
   *
   * @param packet the packet to deliver
   * @throws PacketException if the packet is null or the recipient was not found.
   */
  public static void deliver(Packet packet) throws PacketException {
    if (packet == null) {
      throw new PacketException("Packet was null");
    }

    try {
      JID recipient = packet.getTo();
      if (recipient != null) {
        ClientSession clientSession = SessionManager.getInstance().getSession(recipient);
        if (clientSession != null) {
          clientSession.deliver(packet);
        }
      }
    } catch (Exception e) {
      log.error("Could not deliver packet: " + packet.toString(), e);
    }
  }
  @Override
  public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed)
      throws PacketRejectedException {
    if (!processed && incoming) {
      if (packet instanceof IQ) {
        Log.debug(
            "Incomping unprocessed package i might be interested in. Package: \n"
                + packet.toString()
                + "\n");
        IQ myPacket = (IQ) packet;
        if (myPacket.getFrom() == null || myPacket.getTo() == null) {
          /*
           * If getTo() == null this is maybe a roster update from the
           * Client to the Server, check if we should mirror this
           * package to external component
           */
          if (myPacket.getFrom() != null
              && myPacket.getType().equals(IQ.Type.set)
              && myPacket.getTo() == null) {
            if (XpathHelper.findNodesInDocument(
                        myPacket.getChildElement().getDocument(), "//roster:item")
                    .size()
                > 0) {
              _packetProcessor.get("clientToComponentUpdate").process(myPacket);
            }
          }
          return;
        }
        @SuppressWarnings("unused")
        String to = myPacket.getTo().toString();
        String from = myPacket.getFrom().toString();

        if (myPacket.getType().equals(IQ.Type.get) && from.equals(_mySubdomain)) {
          if (XpathHelper.findNodesInDocument(myPacket.getElement().getDocument(), "//roster:*")
                  .size()
              == 1) {
            // This Package is a roster request by remote component
            _packetProcessor.get("sendRoster").process(packet);
          }
        } else if (myPacket.getType().equals(IQ.Type.set) && from.equals(_mySubdomain)) {
          if (XpathHelper.findNodesInDocument(myPacket.getElement().getDocument(), "//roster:item")
                  .size()
              >= 1) {
            // Component sends roster update
            _packetProcessor.get("receiveChanges").process(packet);
          }
        } else if (myPacket.getType().equals(IQ.Type.get)
            && myPacket.toString().contains("http://jabber.org/protocol/disco#info")
            && myPacket.getTo().toString().equals(_mySubdomain)) {
          /*
           * modify the disco#info for spark clients if enabled in
           * admin panel
           */
          _packetProcessor.get("sparkIQRegistered").process(packet);
        } else if (myPacket.getType().equals(IQ.Type.set)
            && myPacket.getTo().toString().equals(_mySubdomain)) {
          System.out.println("war das ein remove an mich????");
          _packetProcessor.get("handleCleanUp").process(packet);
        }
      }
      // else if (packet instanceof Presence) {
      // if (packet.getFrom().toString().equals(_mySubdomain)
      // &&
      // !JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent",
      // false)) {
      // System.out.println("MACH EIN CLEANUP!!!!!!");
      // _packetProcessor.get("handleCleanUp").process(packet);
      // }
      // }
    }
  }