public IQ sendFormattedError(JingleError error) {
    IQ perror = null;
    if (error != null) {
      perror = createIQ(getSid(), getInitiator(), getResponder(), IQ.Type.ERROR);

      // Fill in the fields with the info from the Jingle packet
      perror.addExtension(error);

      getConnection().sendPacket(perror);
      System.err.println(perror.toXML());
    }
    return perror;
  }
Example #2
0
 /**
  * Convenience method to create a new empty {@link Type#RESULT IQ.Type.RESULT} IQ based on a
  * {@link Type#GET IQ.Type.GET} or {@link Type#SET IQ.Type.SET} IQ. The new packet will be
  * initialized with:
  *
  * <ul>
  *   <li>The sender set to the recipient of the originating IQ.
  *   <li>The recipient set to the sender of the originating IQ.
  *   <li>The type set to {@link Type#RESULT IQ.Type.RESULT}.
  *   <li>The id set to the id of the originating IQ.
  *   <li>No child element of the IQ element.
  * </ul>
  *
  * @param iq the {@link Type#GET IQ.Type.GET} or {@link Type#SET IQ.Type.SET} IQ packet.
  * @throws IllegalArgumentException if the IQ packet does not have a type of {@link Type#GET
  *     IQ.Type.GET} or {@link Type#SET IQ.Type.SET}.
  * @return a new {@link Type#RESULT IQ.Type.RESULT} IQ based on the originating IQ.
  */
 public static IQ createResultIQ(final IQ request) {
   if (!(request.getType() == Type.GET || request.getType() == Type.SET)) {
     throw new IllegalArgumentException(
         "IQ must be of type 'set' or 'get'. Original IQ: " + request.toXML());
   }
   final IQ result =
       new IQ() {
         public String getChildElementXML() {
           return null;
         }
       };
   result.setType(Type.RESULT);
   result.setPacketID(request.getPacketID());
   result.setFrom(request.getTo());
   result.setTo(request.getFrom());
   return result;
 }
Example #3
0
 /**
  * Convenience method to create a new {@link Type#ERROR IQ.Type.ERROR} IQ based on a {@link
  * Type#GET IQ.Type.GET} or {@link Type#SET IQ.Type.SET} IQ. The new packet will be initialized
  * with:
  *
  * <ul>
  *   <li>The sender set to the recipient of the originating IQ.
  *   <li>The recipient set to the sender of the originating IQ.
  *   <li>The type set to {@link Type#ERROR IQ.Type.ERROR}.
  *   <li>The id set to the id of the originating IQ.
  *   <li>The child element contained in the associated originating IQ.
  *   <li>The provided {@link XMPPError XMPPError}.
  * </ul>
  *
  * @param iq the {@link Type#GET IQ.Type.GET} or {@link Type#SET IQ.Type.SET} IQ packet.
  * @param error the error to associate with the created IQ packet.
  * @throws IllegalArgumentException if the IQ packet does not have a type of {@link Type#GET
  *     IQ.Type.GET} or {@link Type#SET IQ.Type.SET}.
  * @return a new {@link Type#ERROR IQ.Type.ERROR} IQ based on the originating IQ.
  */
 public static IQ createErrorResponse(final IQ request, final XMPPError error) {
   if (!(request.getType() == Type.GET || request.getType() == Type.SET)) {
     throw new IllegalArgumentException(
         "IQ must be of type 'set' or 'get'. Original IQ: " + request.toXML());
   }
   final IQ result =
       new IQ() {
         public String getChildElementXML() {
           return request.getChildElementXML();
         }
       };
   result.setType(Type.ERROR);
   result.setPacketID(request.getPacketID());
   result.setFrom(request.getTo());
   result.setTo(request.getFrom());
   result.setError(error);
   return result;
 }
  /**
   * FIXME: replace with IQ.createErrorResponse Prosody does not allow to include request body in
   * error response. Replace this method with IQ.createErrorResponse once fixed.
   */
  private IQ createErrorResponse(IQ request, XMPPError error) {
    IQ.Type requestType = request.getType();
    if (!(requestType == IQ.Type.GET || requestType == IQ.Type.SET)) {
      throw new IllegalArgumentException(
          "IQ must be of type 'set' or 'get'. Original IQ: " + request.toXML());
    }

    final IQ result =
        new IQ() {
          @Override
          public String getChildElementXML() {
            return "";
          }
        };
    result.setType(IQ.Type.ERROR);
    result.setPacketID(request.getPacketID());
    result.setFrom(request.getTo());
    result.setTo(request.getFrom());
    result.setError(error);
    return result;
  }
  /*
   * (non-Javadoc)
   *
   * @see com.saic.uicds.xmpp.communications.CommandWithReply#waitForSuccessOrFailure()
   */
  public boolean waitForSuccessOrFailure() {

    boolean success = true;

    if (connection.isConnected() && result == null) {
      int seconds = connection.getWaitTimeInSeconds() * 1000;
      // System.out.println("+++++ wait " + connection.getWaitTimeInSeconds() +
      // " seconds +++++");
      // System.out.println("Waiting for "+packetID);

      result = (IQ) collector.nextResult(seconds);

      // Stop queuing results
      collector.cancel();

      if (result == null) {
        errorMessage = "No response from the server.";
        success = false;
      } else if (result.getType() == IQ.Type.ERROR) {
        xmppError = result.getError();
        if (result.getError() != null) {
          errorMessage = result.getError().getMessage();
          errorCondition = result.getError().getCondition();
          errorType = result.getError().getType();
          errorCode = result.getError().getCode();
        } else {
          errorMessage = null;
          errorCondition = "";
          errorCode = 0;
          errorType = XMPPError.Type.CANCEL;
        }
        if (errorMessage == null) {
          errorMessage = "NULL error message";
        }
        if (result.getError() != null) {
          PacketExtension pe = null;
          pe =
              result
                  .getError()
                  .getExtension("unsupported", "http://jabber.org/protocol/pubsub#errors");
          if (pe != null) {
            unsupported = true;
            errorMessage += " - (action is unsupported by the server)";
          }
          pe =
              result
                  .getError()
                  .getExtension("payload-too-big", "http://jabber.org/protocol/pubsub#errors");
          if (pe != null) {
            payloadTooBig = true;
            errorMessage += " - (payload is too big)";
          }
          pe =
              result
                  .getError()
                  .getExtension("invalid-payload", "http://jabber.org/protocol/pubsub#errors");
          if (pe != null) {
            invalidPayload = true;
            errorMessage += " - (invalid payload)";
          }
          pe =
              result
                  .getError()
                  .getExtension("item-required", "http://jabber.org/protocol/pubsub#errors");
          if (pe != null) {
            itemRequired = true;
            errorMessage += " - (item element is required for this node)";
          }
          pe =
              result
                  .getError()
                  .getExtension("payload-required", "http://jabber.org/protocol/pubsub#errors");
          if (pe != null) {
            payloadRequired = true;
            errorMessage += " - (payload is required for this node)";
          }
          pe =
              result
                  .getError()
                  .getExtension("item-forbidden", "http://jabber.org/protocol/pubsub#errors");
          if (pe != null) {
            itemForbidden = true;
            errorMessage += " - (cannot publish item to transient node)";
          }
          pe =
              result
                  .getError()
                  .getExtension("invalid-jid", "http://jabber.org/protocol/pubsub#errors");
          if (pe != null) {
            invalidJID = true;
            errorMessage += " - (the bare JID portions of the JIDs do not match)";
          }
        }

        success = false;
      } else {
        // Pull out the subscription id if applicable
        Matcher m = subidPattern.matcher(result.toXML());
        if (m.find()) {
          subscriptionID = m.group(1);
          // System.out.println("GOT subid " + subscriptionID);
        } else {
          // System.err.println("No subid in " + result.toXML());
        }
        // Collection<String> exts = result.getPropertyNames();
        // System.out.println(exts.size()+" EXTENSIONS in "+result.getType());
        // for (Object o : exts) {
        // String ex = (String)o;
        // if (ex != null) {
        // System.out.println("FOUND "+ex);
        // }
        // }
      }
    } else {
      success = false;
      // Stop queuing results
      collector.cancel();
    }

    return success;
  }