Java Code Examples for org.apache.qpid.proton.amqp.transport.ErrorCondition#getCondition()

The following examples show how to use org.apache.qpid.proton.amqp.transport.ErrorCondition#getCondition() . 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 activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * Attempt to read and return the embedded error message in the given ErrorCondition
 * object.  If no message can be extracted a generic message is returned.
 *
 * @param errorCondition The ErrorCondition to extract the error message from.
 * @return an error message extracted from the given ErrorCondition.
 */
public static String extractErrorMessage(ErrorCondition errorCondition) {
   String message = "Received error from remote peer without description";
   if (errorCondition != null) {
      if (errorCondition.getDescription() != null && !errorCondition.getDescription().isEmpty()) {
         message = errorCondition.getDescription();
      }

      Symbol condition = errorCondition.getCondition();
      if (condition != null) {
         message = message + " [condition = " + condition + "]";
      }
   }

   return message;
}
 
Example 2
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 3
Source File: AmqpSupport.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
/**
 * Attempt to read and return the embedded error message in the given ErrorCondition
 * object.  If no message can be extracted a generic message is returned.
 *
 * @param errorCondition
 *      The ErrorCondition to extract the error message from.
 *
 * @return an error message extracted from the given ErrorCondition.
 */
public static String extractErrorMessage(ErrorCondition errorCondition) {
    String message = "Received error from remote peer without description";
    if (errorCondition != null) {
        if (errorCondition.getDescription() != null && !errorCondition.getDescription().isEmpty()) {
            message = errorCondition.getDescription();
        }

        Symbol condition = errorCondition.getCondition();
        if (condition != null) {
            message = message + " [condition = " + condition + "]";
        }
    }

    return message;
}
 
Example 4
Source File: ClientHandlerBase.java    From enmasse with Apache License 2.0 5 votes vote down vote up
protected void handleError(ProtonConnection connection, ErrorCondition error) {
    if (error == null || error.getCondition() == null) {
        log.info("{}: link closed without error", containerId);
    } else {
        log.info("{}: link closed with error {}", containerId, error);
        connection.close();
        if (unauthorizedAccess.equals(error.getCondition()) || error.getDescription().contains("not authorized")) {
            resultPromise.completeExceptionally(new UnauthorizedAccessException(error.getDescription()));
            connectPromise.completeExceptionally(new UnauthorizedAccessException(error.getDescription()));
        } else {
            resultPromise.completeExceptionally(new RuntimeException(error.getDescription()));
            connectPromise.completeExceptionally(new RuntimeException(error.getDescription()));
        }
    }
}
 
Example 5
Source File: TransportImpl.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
private void processEnd()
{
    if(_connectionEndpoint != null && _isOpenSent)
    {
        EndpointImpl endpoint = _connectionEndpoint.getTransportHead();
        while(endpoint != null)
        {
            SessionImpl session;
            TransportSession transportSession;

            if((endpoint instanceof SessionImpl)) {
                if ((session = (SessionImpl)endpoint).getLocalState() == EndpointState.CLOSED
                    && (transportSession = session.getTransportSession()).isLocalChannelSet()
                    && !_isCloseSent)
                {
                    if (hasSendableMessages(session)) {
                        endpoint = endpoint.transportNext();
                        continue;
                    }

                    int channel = freeLocalChannel(transportSession);
                    End end = new End();
                    ErrorCondition localError = endpoint.getCondition();
                    if( localError.getCondition() !=null )
                    {
                        end.setError(localError);
                    }

                    writeFrame(channel, end, null, null);
                }

                endpoint.clearModified();
            }

            endpoint = endpoint.transportNext();
        }
    }
}
 
Example 6
Source File: ProtonHelper.java    From vertx-proton with Apache License 2.0 5 votes vote down vote up
static <T> AsyncResult<T> future(T value, ErrorCondition err) {
  if (err.getCondition() != null) {
    return Future.failedFuture(err.toString());
  } else {
    return Future.succeededFuture(value);
  }
}
 
Example 7
Source File: AmqpProvider.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
private static String extractTransportErrorMessage(ErrorCondition errorCondition) {
    String message = "Error without description from proton Transport";
    if (errorCondition != null) {
        if (errorCondition.getDescription() != null && !errorCondition.getDescription().isEmpty()) {
            message = "Error in proton Transport: " + errorCondition.getDescription();
        }

        Symbol condition = errorCondition.getCondition();
        if (condition != null) {
            message = message + " [condition = " + condition + "]";
        }
    }

    return message;
}
 
Example 8
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 9
Source File: TransportImpl.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
private boolean isConditionPopulated(ErrorCondition error) {
    return error != null && error.getCondition() != null;
}
 
Example 10
Source File: TransportImpl.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
private void processDetach()
{
    if(_connectionEndpoint != null && _isOpenSent)
    {
        EndpointImpl endpoint = _connectionEndpoint.getTransportHead();
        while(endpoint != null)
        {

            if(endpoint instanceof LinkImpl)
            {
                LinkImpl link = (LinkImpl) endpoint;
                TransportLink<?> transportLink = getTransportState(link);
                SessionImpl session = link.getSession();
                TransportSession transportSession = getTransportState(session);

                if(((link.getLocalState() == EndpointState.CLOSED) || link.detached())
                   && transportLink.isLocalHandleSet()
                   && transportSession.isLocalChannelSet()
                   && !_isCloseSent)
                {
                    if((link instanceof SenderImpl)
                       && link.getQueued() > 0
                       && !transportLink.detachReceived()
                       && !transportSession.endReceived()
                       && !_closeReceived) {
                        endpoint = endpoint.transportNext();
                        continue;
                    }

                    UnsignedInteger localHandle = transportLink.getLocalHandle();
                    transportLink.clearLocalHandle();
                    transportSession.freeLocalHandle(localHandle);

                    Detach detach = new Detach();
                    detach.setHandle(localHandle);
                    detach.setClosed(!link.detached());

                    ErrorCondition localError = link.getCondition();
                    if( localError.getCondition() !=null )
                    {
                        detach.setError(localError);
                    }

                    writeFrame(transportSession.getLocalChannel(), detach, null, null);
                }

                endpoint.clearModified();

            }
            endpoint = endpoint.transportNext();
        }
    }
}