Search in sources :

Example 1 with ErrorCondition

use of org.apache.qpid.protonj2.client.ErrorCondition in project qpid-protonj2 by apache.

the class ClientExceptionSupport method createLinkRedirectException.

/**
 * When a link redirect type exception is received this method is called to create the
 * appropriate redirect exception type containing the error details needed.
 *
 * @param error
 *        the Symbol that defines the redirection error type.
 * @param message
 *        the basic error message that should used or amended for the returned exception.
 * @param condition
 *        the ErrorCondition that describes the redirection.
 *
 * @return an Exception that captures the details of the redirection error.
 */
public static ClientLinkRemotelyClosedException createLinkRedirectException(Symbol error, String message, ErrorCondition condition) {
    ClientLinkRemotelyClosedException result;
    Map<?, ?> info = condition.getInfo();
    if (info == null) {
        result = new ClientLinkRemotelyClosedException(message + " : Redirection information not set.", new ClientErrorCondition(condition));
    } else {
        @SuppressWarnings("unchecked") ClientRedirect redirect = new ClientRedirect((Map<Symbol, Object>) info);
        try {
            result = new ClientLinkRedirectedException(message, redirect.validate(), new ClientErrorCondition(condition));
        } catch (Exception ex) {
            result = new ClientLinkRemotelyClosedException(message + " : " + ex.getMessage(), new ClientErrorCondition(condition));
        }
    }
    return result;
}
Also used : ClientLinkRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientLinkRemotelyClosedException) Symbol(org.apache.qpid.protonj2.types.Symbol) ClientLinkRedirectedException(org.apache.qpid.protonj2.client.exceptions.ClientLinkRedirectedException) ClientLinkRedirectedException(org.apache.qpid.protonj2.client.exceptions.ClientLinkRedirectedException) SaslSystemException(org.apache.qpid.protonj2.engine.sasl.SaslSystemException) ClientIllegalStateException(org.apache.qpid.protonj2.client.exceptions.ClientIllegalStateException) ClientTransactionRolledBackException(org.apache.qpid.protonj2.client.exceptions.ClientTransactionRolledBackException) TimeoutException(java.util.concurrent.TimeoutException) ClientIOException(org.apache.qpid.protonj2.client.exceptions.ClientIOException) SaslException(javax.security.sasl.SaslException) ClientResourceRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientResourceRemotelyClosedException) ClientException(org.apache.qpid.protonj2.client.exceptions.ClientException) ClientLinkRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientLinkRemotelyClosedException) ClientConnectionRedirectedException(org.apache.qpid.protonj2.client.exceptions.ClientConnectionRedirectedException) ClientSessionRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientSessionRemotelyClosedException) ClientConnectionSecurityException(org.apache.qpid.protonj2.client.exceptions.ClientConnectionSecurityException) ClientOperationTimedOutException(org.apache.qpid.protonj2.client.exceptions.ClientOperationTimedOutException) ClientConnectionRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException) ClientConnectionSecuritySaslException(org.apache.qpid.protonj2.client.exceptions.ClientConnectionSecuritySaslException)

Example 2 with ErrorCondition

use of org.apache.qpid.protonj2.client.ErrorCondition in project qpid-protonj2 by apache.

the class ClientExceptionSupport method createConnectionRedirectException.

/**
 * When a connection redirect type exception is received this method is called to create the
 * appropriate redirect exception type containing the error details needed.
 *
 * @param error
 *        the Symbol that defines the redirection error type.
 * @param message
 *        the basic error message that should used or amended for the returned exception.
 * @param condition
 *        the ErrorCondition that describes the redirection.
 *
 * @return an Exception that captures the details of the redirection error.
 */
public static ClientConnectionRemotelyClosedException createConnectionRedirectException(Symbol error, String message, ErrorCondition condition) {
    ClientConnectionRemotelyClosedException result;
    Map<?, ?> info = condition.getInfo();
    if (info == null) {
        result = new ClientConnectionRemotelyClosedException(message + " : Redirection information not set.", new ClientErrorCondition(condition));
    } else {
        @SuppressWarnings("unchecked") ClientRedirect redirect = new ClientRedirect((Map<Symbol, Object>) info);
        try {
            result = new ClientConnectionRedirectedException(message, redirect.validate(), new ClientErrorCondition(condition));
        } catch (Exception ex) {
            result = new ClientConnectionRemotelyClosedException(message + " : " + ex.getMessage(), new ClientErrorCondition(condition));
        }
    }
    return result;
}
Also used : ClientConnectionRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException) Symbol(org.apache.qpid.protonj2.types.Symbol) ClientConnectionRedirectedException(org.apache.qpid.protonj2.client.exceptions.ClientConnectionRedirectedException) ClientLinkRedirectedException(org.apache.qpid.protonj2.client.exceptions.ClientLinkRedirectedException) SaslSystemException(org.apache.qpid.protonj2.engine.sasl.SaslSystemException) ClientIllegalStateException(org.apache.qpid.protonj2.client.exceptions.ClientIllegalStateException) ClientTransactionRolledBackException(org.apache.qpid.protonj2.client.exceptions.ClientTransactionRolledBackException) TimeoutException(java.util.concurrent.TimeoutException) ClientIOException(org.apache.qpid.protonj2.client.exceptions.ClientIOException) SaslException(javax.security.sasl.SaslException) ClientResourceRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientResourceRemotelyClosedException) ClientException(org.apache.qpid.protonj2.client.exceptions.ClientException) ClientLinkRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientLinkRemotelyClosedException) ClientConnectionRedirectedException(org.apache.qpid.protonj2.client.exceptions.ClientConnectionRedirectedException) ClientSessionRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientSessionRemotelyClosedException) ClientConnectionSecurityException(org.apache.qpid.protonj2.client.exceptions.ClientConnectionSecurityException) ClientOperationTimedOutException(org.apache.qpid.protonj2.client.exceptions.ClientOperationTimedOutException) ClientConnectionRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException) ClientConnectionSecuritySaslException(org.apache.qpid.protonj2.client.exceptions.ClientConnectionSecuritySaslException)

Example 3 with ErrorCondition

use of org.apache.qpid.protonj2.client.ErrorCondition in project qpid-protonj2 by apache.

the class ClientExceptionSupport method convertToLinkClosedException.

/**
 * Given an ErrorCondition instance create a new Exception that best matches
 * the error type that indicates the link creation failed for some reason.
 *
 * @param errorCondition
 *      The ErrorCondition returned from the remote peer.
 * @param defaultMessage
 *      The message to use if the remote provided no condition for the closure
 *
 * @return a new Exception instance that best matches the ErrorCondition value.
 */
public static ClientLinkRemotelyClosedException convertToLinkClosedException(ErrorCondition errorCondition, String defaultMessage) {
    final ClientLinkRemotelyClosedException remoteError;
    if (errorCondition != null && errorCondition.getCondition() != null) {
        String message = extractErrorMessage(errorCondition);
        Symbol error = errorCondition.getCondition();
        if (message == null) {
            message = defaultMessage;
        }
        if (error.equals(LinkError.REDIRECT)) {
            remoteError = createLinkRedirectException(error, message, errorCondition);
        } else {
            remoteError = new ClientLinkRemotelyClosedException(message, new ClientErrorCondition(errorCondition));
        }
    } else {
        remoteError = new ClientLinkRemotelyClosedException(defaultMessage);
    }
    return remoteError;
}
Also used : ClientLinkRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientLinkRemotelyClosedException) Symbol(org.apache.qpid.protonj2.types.Symbol)

Example 4 with ErrorCondition

use of org.apache.qpid.protonj2.client.ErrorCondition in project qpid-protonj2 by apache.

the class ClientExceptionSupport method convertToSessionClosedException.

/**
 * Given an ErrorCondition instance create a new Exception that best matches
 * the error type that indicates the session creation failed for some reason.
 *
 * @param errorCondition
 *      The ErrorCondition returned from the remote peer.
 *
 * @return a new Exception instance that best matches the ErrorCondition value.
 */
public static ClientSessionRemotelyClosedException convertToSessionClosedException(ErrorCondition errorCondition) {
    final ClientSessionRemotelyClosedException remoteError;
    if (errorCondition != null && errorCondition.getCondition() != null) {
        String message = extractErrorMessage(errorCondition);
        if (message == null) {
            message = "Session remotely closed without explanation";
        }
        remoteError = new ClientSessionRemotelyClosedException(message, new ClientErrorCondition(errorCondition));
    } else {
        remoteError = new ClientSessionRemotelyClosedException("Session remotely closed without explanation");
    }
    return remoteError;
}
Also used : ClientSessionRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientSessionRemotelyClosedException)

Example 5 with ErrorCondition

use of org.apache.qpid.protonj2.client.ErrorCondition in project qpid-protonj2 by apache.

the class ClientErrorConditionTest method testCreateWithErrorConditionThatOnlyHasConditionData.

@Test
void testCreateWithErrorConditionThatOnlyHasConditionData() {
    ErrorCondition condition = ErrorCondition.create("amqp:error", null);
    ClientErrorCondition clientCondition = new ClientErrorCondition(condition);
    assertEquals("amqp:error", clientCondition.condition());
    assertNull(clientCondition.description());
    assertNotNull(clientCondition.info());
    org.apache.qpid.protonj2.types.transport.ErrorCondition protonError = clientCondition.getProtonErrorCondition();
    assertNotNull(protonError);
    assertEquals("amqp:error", protonError.getCondition().toString());
    assertNull(protonError.getDescription());
    assertNotNull(protonError.getInfo());
}
Also used : ErrorCondition(org.apache.qpid.protonj2.client.ErrorCondition) Test(org.junit.jupiter.api.Test)

Aggregations

ErrorCondition (org.apache.qpid.protonj2.types.transport.ErrorCondition)47 Test (org.junit.jupiter.api.Test)26 ProtonBuffer (org.apache.qpid.protonj2.buffer.ProtonBuffer)18 InputStream (java.io.InputStream)16 ProtonBufferInputStream (org.apache.qpid.protonj2.buffer.ProtonBufferInputStream)16 Connection (org.apache.qpid.protonj2.engine.Connection)16 Engine (org.apache.qpid.protonj2.engine.Engine)16 ProtonTestConnector (org.apache.qpid.protonj2.test.driver.ProtonTestConnector)16 Session (org.apache.qpid.protonj2.engine.Session)13 Symbol (org.apache.qpid.protonj2.types.Symbol)13 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 TransactionManager (org.apache.qpid.protonj2.engine.TransactionManager)6 Rejected (org.apache.qpid.protonj2.types.messaging.Rejected)5 Close (org.apache.qpid.protonj2.types.transport.Close)5 ErrorCondition (org.apache.qpid.protonj2.client.ErrorCondition)4 Transaction (org.apache.qpid.protonj2.engine.Transaction)4 TransactionController (org.apache.qpid.protonj2.engine.TransactionController)4 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3