/**
   * Search for a given Symbol in a given array of Symbol object.
   *
   * @param symbols the set of Symbols to search.
   * @param key the value to try and find in the Symbol array.
   * @return true if the key is found in the given Symbol array.
   */
  public static boolean contains(Symbol[] symbols, Symbol key) {
    if (symbols == null || symbols.length == 0) {
      return false;
    }

    for (Symbol symbol : symbols) {
      if (symbol.equals(key)) {
        return true;
      }
    }

    return false;
  }
Example #2
0
  /**
   * Given an ErrorCondition instance create a new Exception that best matches the error type.
   *
   * @param endpoint The target of the error.
   * @param errorCondition The ErrorCondition returned from the remote peer.
   * @param defaultException The default exception to throw if no error information is provided from
   *     the remote.
   * @return a new Exception instance that best matches the ErrorCondition value.
   */
  public static Exception convertToException(
      Endpoint endpoint, ErrorCondition errorCondition, Exception defaultException) {
    Exception remoteError = defaultException;

    if (errorCondition != null && errorCondition.getCondition() != null) {
      Symbol error = errorCondition.getCondition();
      String message = extractErrorMessage(errorCondition);

      if (error.equals(AmqpError.UNAUTHORIZED_ACCESS)) {
        remoteError = new JMSSecurityException(message);
      } else if (error.equals(AmqpError.RESOURCE_LIMIT_EXCEEDED)) {
        remoteError = new ResourceAllocationException(message);
      } else if (error.equals(AmqpError.NOT_FOUND)) {
        if (endpoint instanceof Connection) {
          remoteError = new JmsResourceNotFoundException(message);
        } else {
          remoteError = new InvalidDestinationException(message);
        }
      } else if (error.equals(TransactionErrors.TRANSACTION_ROLLBACK)) {
        remoteError = new TransactionRolledBackException(message);
      } else if (error.equals(ConnectionError.REDIRECT)) {
        remoteError = createRedirectException(error, message, errorCondition);
      } else if (error.equals(AmqpError.INVALID_FIELD)) {
        Map<?, ?> info = errorCondition.getInfo();
        if (info != null && CONTAINER_ID.equals(info.get(INVALID_FIELD))) {
          remoteError = new InvalidClientIDException(message);
        } else {
          remoteError = new JMSException(message);
        }
      } else {
        remoteError = new JMSException(message);
      }
    } else if (remoteError == null) {
      remoteError = new JMSException("Unknown error from remote peer");
    }

    return remoteError;
  }