示例#1
0
  /**
   * Method description
   *
   * @param packet
   * @param repo
   * @param results
   * @param settings
   * @throws PacketErrorTypeException
   */
  @Override
  public void processNullSessionPacket(
      Packet packet,
      NonAuthUserRepository repo,
      Queue<Packet> results,
      Map<String, Object> settings)
      throws PacketErrorTypeException {
    if (packet.getType() == StanzaType.get) {
      try {
        String strvCard =
            repo.getPublicData(packet.getStanzaTo().getBareJID(), ID, VCARD_KEY, null);

        if (strvCard != null) {
          results.offer(parseXMLData(strvCard, packet));
        } else {
          results.offer(packet.okResult((String) null, 1));
        } // end of if (vcard != null)
      } catch (UserNotFoundException e) {
        results.offer(
            Authorization.ITEM_NOT_FOUND.getResponseMessage(packet, "User not found", true));
      } // end of try-catch
    } else {

      // This is most likely a response to the user from the remote
      // entity with vCard request results.
      // Processed in processToUserPacket() method.
    }
  }
示例#2
0
  /**
   * Method description
   *
   * @param connectionId
   * @param packet
   * @param session
   * @param repo
   * @param results
   * @param settings
   * @throws PacketErrorTypeException
   */
  @Override
  public void processFromUserOutPacket(
      JID connectionId,
      Packet packet,
      XMPPResourceConnection session,
      NonAuthUserRepository repo,
      Queue<Packet> results,
      Map<String, Object> settings)
      throws PacketErrorTypeException {
    if (session.isLocalDomain(packet.getStanzaTo().getDomain(), false)) {

      // This is a local user so we can quickly get his vCard from the database
      try {
        String strvCard =
            repo.getPublicData(packet.getStanzaTo().getBareJID(), ID, VCARD_KEY, null);
        Packet result = null;

        if (strvCard != null) {
          result = parseXMLData(strvCard, packet);
        } else {
          result = packet.okResult((String) null, 1);
        } // end of if (vcard != null)
        result.setPacketTo(connectionId);
        results.offer(result);
      } catch (UserNotFoundException e) {
        results.offer(
            Authorization.ITEM_NOT_FOUND.getResponseMessage(packet, "User not found", true));
      } // end of try-catch
    } else {

      // Else forward the packet to a remote server
      results.offer(packet.copyElementOnly());
    }
  }