Java Code Examples for org.apache.qpid.proton.amqp.Symbol#equals()

The following examples show how to use org.apache.qpid.proton.amqp.Symbol#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AmqpSupport.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
/**
 * Given an ErrorCondition instance create a new Exception that best matches
 * the error type that indicates a non-fatal error usually at the link level
 * such as link closed remotely or link create failed due to security access
 * issues.
 *
 * @param provider
 * 		the AMQP provider instance that originates this exception
 * @param endpoint
 *      The target of the error.
 * @param errorCondition
 *      The ErrorCondition returned from the remote peer.
 *
 * @return a new Exception instance that best matches the ErrorCondition value.
 */
public static ProviderException convertToNonFatalException(AmqpProvider provider, Endpoint endpoint, ErrorCondition errorCondition) {
    ProviderException remoteError = null;

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

        if (error.equals(AmqpError.UNAUTHORIZED_ACCESS)) {
            remoteError = new ProviderSecurityException(message);
        } else if (error.equals(AmqpError.RESOURCE_LIMIT_EXCEEDED)) {
            remoteError = new ProviderResourceAllocationException(message);
        } else if (error.equals(AmqpError.NOT_FOUND)) {
            remoteError = new ProviderInvalidDestinationException(message);
        } else if (error.equals(TransactionErrors.TRANSACTION_ROLLBACK)) {
            remoteError = new ProviderTransactionRolledBackException(message);
        } else {
            remoteError = new ProviderException(message);
        }
    } else if (remoteError == null) {
        remoteError = new ProviderException("Unknown error from remote peer");
    }

    return remoteError;
}
 
Example 2
Source File: AmqpSupport.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * 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 3
Source File: ProtonServerSenderContext.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private static boolean hasCapabilities(Symbol symbol, Source source) {
   if (source != null) {
      if (source.getCapabilities() != null) {
         for (Symbol cap : source.getCapabilities()) {
            if (symbol.equals(cap)) {
               return true;
            }
         }
      }
   }
   return false;
}
 
Example 4
Source File: ProtonServerSenderContext.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private static boolean hasRemoteDesiredCapability(Link link, Symbol capability) {
   Symbol[] remoteDesiredCapabilities = link.getRemoteDesiredCapabilities();
   if (remoteDesiredCapabilities != null) {
      for (Symbol cap : remoteDesiredCapabilities) {
         if (capability.equals(cap)) {
            return true;
         }
      }
   }
   return false;
}
 
Example 5
Source File: AmqpSupport.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * 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 6
Source File: AmqpSupport.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
/**
 * Given an ErrorCondition instance create a new Exception that best matches
 * the error type that indicates the connection creation failed for some reason.
 *
 * @param provider
 * 		the AMQP provider instance that originates this exception
 * @param endpoint
 *      The target of the error.
 * @param errorCondition
 *      The ErrorCondition returned from the remote peer.
 *
 * @return a new Exception instance that best matches the ErrorCondition value.
 */
public static ProviderConnectionRemotelyClosedException convertToConnectionClosedException(AmqpProvider provider, Endpoint endpoint, ErrorCondition errorCondition) {
    ProviderConnectionRemotelyClosedException remoteError = null;

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

        if (error.equals(AmqpError.UNAUTHORIZED_ACCESS)) {
            remoteError = new ProviderConnectionSecurityException(message);
        } else if (error.equals(AmqpError.RESOURCE_LIMIT_EXCEEDED)) {
            remoteError = new ProviderConnectionResourceAllocationException(message);
        } else if (error.equals(ConnectionError.CONNECTION_FORCED)) {
            remoteError = new ProviderConnectionRemotelyClosedException(message);
        } else if (error.equals(AmqpError.NOT_FOUND)) {
            remoteError = new ProviderConnectionResourceNotFoundException(message);
        } else if (error.equals(ConnectionError.REDIRECT)) {
            remoteError = createRedirectException(provider, 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 ProviderInvalidClientIDException(message);
            } else {
                remoteError = new ProviderConnectionRemotelyClosedException(message);
            }
        } else {
            remoteError = new ProviderConnectionRemotelyClosedException(message);
        }
    } else if (remoteError == null) {
        remoteError = new ProviderConnectionRemotelyClosedException("Unknown error from remote peer");
    }

    return remoteError;
}
 
Example 7
Source File: AmqpMessageSupport.java    From qpid-jms with Apache License 2.0 3 votes vote down vote up
/**
 * Check whether the content-type field of the properties section (if present) in
 * the given message matches the provided string (where null matches if there is
 * no content type present.
 *
 * @param contentType
 *        content type string to compare against, or null if none
 * @param messageContentType
 *        the content type value read from an AMQP message object.
 *
 * @return true if content type matches
 */
public static boolean isContentType(Symbol contentType, Symbol messageContentType) {
    if (contentType == null) {
        return messageContentType == null;
    } else if (messageContentType == null) {
        return false;
    } else {
        return contentType.equals(messageContentType);
    }
}