/**
  * Make sure that the received packet has a TO and FROM values defined and that it was sent from a
  * previously validated domain. If the packet does not matches any of the above conditions then a
  * PacketRejectedException will be thrown.
  *
  * @param packet the received packet.
  * @throws PacketRejectedException if the packet does not include a TO or FROM or if the packet
  *     was sent from a domain that was not previously validated.
  */
 private void packetReceived(Packet packet) throws PacketRejectedException {
   if (packet.getTo() == null || packet.getFrom() == null) {
     Log.debug(
         "Closing IncomingServerSession due to packet with no TO or FROM: " + packet.toXML());
     // Send a stream error saying that the packet includes no TO or FROM
     StreamError error = new StreamError(StreamError.Condition.improper_addressing);
     connection.deliverRawText(error.toXML());
     // Close the underlying connection
     connection.close();
     open = false;
     throw new PacketRejectedException("Packet with no TO or FROM attributes");
   } else if (!((IncomingServerSession) session).isValidDomain(packet.getFrom().getDomain())) {
     Log.debug(
         "Closing IncomingServerSession due to packet with invalid domain: " + packet.toXML());
     // Send a stream error saying that the packet includes an invalid FROM
     StreamError error = new StreamError(StreamError.Condition.invalid_from);
     connection.deliverRawText(error.toXML());
     // Close the underlying connection
     connection.close();
     open = false;
     throw new PacketRejectedException("Packet with no TO or FROM attributes");
   }
 }
  @Override
  public void processPacket(Packet packet) {
    if (smackXmpp == null) {
      logger.error("Not initialized");
      return;
    }

    if (packet instanceof ColibriConferenceIQ) {
      handleColibriIq((ColibriConferenceIQ) packet);
    } else if (packet instanceof MuteIq) {
      handleMuteIq((MuteIq) packet);
    } else if (packet instanceof RayoIqProvider.DialIq) {
      handleRayoIQ((RayoIqProvider.DialIq) packet);
    } else if (packet instanceof Message) {
      handleMessage((Message) packet);
    } else if (packet instanceof Presence) {
      handlePresence((Presence) packet);
    } else {
      logger.error("Unexpected packet: " + packet.toXML());
    }
  }