Search in sources :

Example 1 with ErrorCondition

use of org.apache.qpid.server.protocol.v1_0.type.ErrorCondition in project qpid-broker-j by apache.

the class FrameHandler method createError.

private Error createError(final ErrorCondition framingError, final String description, final Object... args) {
    Error error = new Error();
    error.setCondition(framingError);
    Formatter formatter = new Formatter();
    error.setDescription(formatter.format(description, args).toString());
    return error;
}
Also used : Formatter(java.util.Formatter) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) ConnectionError(org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError)

Example 2 with ErrorCondition

use of org.apache.qpid.server.protocol.v1_0.type.ErrorCondition in project qpid-broker-j by apache.

the class Session_1_0Test method assertDetachSent.

private void assertDetachSent(final AMQPConnection_1_0 connection, final Session_1_0 session, final ErrorCondition expectedError, final int invocationOffset) {
    ArgumentCaptor<FrameBody> frameCapture = ArgumentCaptor.forClass(FrameBody.class);
    verify(connection, times(invocationOffset + 1)).sendFrame(eq(session.getChannelId()), frameCapture.capture());
    List<FrameBody> sentFrames = frameCapture.getAllValues();
    final boolean condition = sentFrames.get(invocationOffset) instanceof Detach;
    assertTrue("unexpected Frame sent", condition);
    Detach sentDetach = (Detach) sentFrames.get(invocationOffset);
    assertTrue("Unexpected closed state", sentDetach.getClosed());
    assertEquals("Closed with unexpected error condition", expectedError, sentDetach.getError().getCondition());
}
Also used : FrameBody(org.apache.qpid.server.protocol.v1_0.type.FrameBody) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach)

Example 3 with ErrorCondition

use of org.apache.qpid.server.protocol.v1_0.type.ErrorCondition in project qpid-broker-j by apache.

the class ProtocolAsserts method assertAttachError.

/**
 * When core spec is not vocal about how the error on attach can be reported,
 * there are potentially several ways of communicating error back to the client:
 * <pre>
 * Attach, Detach(with error)
 * Attach, Detach, End(with error)
 * Attach, Detach, End, Close(with error)
 * End(with error)
 * End, Close(with error)
 * </pre>
 * Thus, in order to assert the error possible codes, we need to get {@link ErrorCarryingFrameBody}
 * (implemented by {@link Detach}, {@link End}, {@link Close}) and examine error field there.
 * If error is set, than assert the error code, otherwise, receive subsequent {@link ErrorCarryingFrameBody}
 * and examine error field there.
 *
 * @param interaction interaction
 * @param expected possible errors
 */
public static void assertAttachError(final Interaction interaction, final ErrorCondition... expected) throws Exception {
    Response<?> response = interaction.consumeResponse().getLatestResponse();
    assertThat(response, is(notNullValue()));
    Object responseBody = response.getBody();
    assertThat(responseBody, is(notNullValue()));
    if (response.getBody() instanceof Attach) {
        // expected either Detach or End or Close
        response = interaction.consumeResponse().getLatestResponse();
        assertThat(response, is(notNullValue()));
        responseBody = response.getBody();
        assertThat(responseBody, is(notNullValue()));
    }
    assertThat(responseBody, instanceOf(ErrorCarryingFrameBody.class));
    Error error = ((ErrorCarryingFrameBody) responseBody).getError();
    if (error != null) {
        assumeThat(error.getCondition(), is(not(NOT_IMPLEMENTED)));
        assertThat(error.getCondition(), oneOf(expected));
    } else {
        // expected either End or Close
        response = interaction.consumeResponse().getLatestResponse();
        assertThat(response, is(notNullValue()));
        Object nextBody = response.getBody();
        assertThat(nextBody, is(notNullValue()));
        assertThat(nextBody, instanceOf(ErrorCarryingFrameBody.class));
        error = ((ErrorCarryingFrameBody) nextBody).getError();
        if (error != null) {
            assumeThat(error.getCondition(), is(not(NOT_IMPLEMENTED)));
            assertThat(error.getCondition(), oneOf(expected));
        } else {
            // expected Close
            response = interaction.consumeResponse().getLatestResponse();
            assertThat(response, is(notNullValue()));
            Object body = response.getBody();
            assertThat(body, is(notNullValue()));
            assertThat(body, instanceOf(Close.class));
            error = ((ErrorCarryingFrameBody) body).getError();
            assertThat(error.getCondition(), is(notNullValue()));
            assumeThat(error.getCondition(), is(not(NOT_IMPLEMENTED)));
            assertThat(error.getCondition(), oneOf(expected));
        }
    }
}
Also used : Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) ErrorCarryingFrameBody(org.apache.qpid.server.protocol.v1_0.type.ErrorCarryingFrameBody) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) Close(org.apache.qpid.server.protocol.v1_0.type.transport.Close)

Example 4 with ErrorCondition

use of org.apache.qpid.server.protocol.v1_0.type.ErrorCondition in project qpid-broker-j by apache.

the class AMQPConnection_1_0Impl method sendConnectionCloseAsync.

@Override
public void sendConnectionCloseAsync(final CloseReason reason, final String description) {
    stopConnection();
    final ErrorCondition cause;
    switch(reason) {
        case MANAGEMENT:
            cause = ConnectionError.CONNECTION_FORCED;
            break;
        case TRANSACTION_TIMEOUT:
            cause = AmqpError.RESOURCE_LIMIT_EXCEEDED;
            break;
        default:
            cause = AmqpError.INTERNAL_ERROR;
    }
    Action<ConnectionHandler> action = object -> closeConnection(cause, description);
    addAsyncTask(action);
}
Also used : AccessControlContext(java.security.AccessControlContext) Arrays(java.util.Arrays) SoleConnectionDetectionPolicy(org.apache.qpid.server.protocol.v1_0.type.extensions.soleconn.SoleConnectionDetectionPolicy) PeekingIterator(com.google.common.collect.PeekingIterator) AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult) ExternalAuthenticationManagerImpl(org.apache.qpid.server.security.auth.manager.ExternalAuthenticationManagerImpl) Map(java.util.Map) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) ProtocolHandler(org.apache.qpid.server.protocol.v1_0.codec.ProtocolHandler) ConnectionError(org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError) End(org.apache.qpid.server.protocol.v1_0.type.transport.End) Futures.allAsList(com.google.common.util.concurrent.Futures.allAsList) Set(java.util.Set) DescribedTypeConstructorRegistry(org.apache.qpid.server.protocol.v1_0.codec.DescribedTypeConstructorRegistry) SaslCode(org.apache.qpid.server.protocol.v1_0.type.security.SaslCode) VirtualHostUnavailableException(org.apache.qpid.server.virtualhost.VirtualHostUnavailableException) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) Transport(org.apache.qpid.server.model.Transport) SASLFrame(org.apache.qpid.server.protocol.v1_0.framing.SASLFrame) OversizeFrameException(org.apache.qpid.server.protocol.v1_0.framing.OversizeFrameException) AggregateTicker(org.apache.qpid.server.transport.AggregateTicker) ByteBufferSender(org.apache.qpid.server.transport.ByteBufferSender) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) AccessController(java.security.AccessController) ValueWriter(org.apache.qpid.server.protocol.v1_0.codec.ValueWriter) ProtocolEngine(org.apache.qpid.server.transport.ProtocolEngine) FrameBody(org.apache.qpid.server.protocol.v1_0.type.FrameBody) FrameWriter(org.apache.qpid.server.protocol.v1_0.codec.FrameWriter) SOLE_CONNECTION_ENFORCEMENT_POLICY(org.apache.qpid.server.protocol.v1_0.type.extensions.soleconn.SoleConnectionConnectionProperties.SOLE_CONNECTION_ENFORCEMENT_POLICY) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Close(org.apache.qpid.server.protocol.v1_0.type.transport.Close) ChannelFrameBody(org.apache.qpid.server.protocol.v1_0.type.transport.ChannelFrameBody) SoleConnectionEnforcementPolicy(org.apache.qpid.server.protocol.v1_0.type.extensions.soleconn.SoleConnectionEnforcementPolicy) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) ConnectionPropertyEnricher(org.apache.qpid.server.plugin.ConnectionPropertyEnricher) SaslFrameBody(org.apache.qpid.server.protocol.v1_0.type.SaslFrameBody) SoleConnectionConnectionProperties(org.apache.qpid.server.protocol.v1_0.type.extensions.soleconn.SoleConnectionConnectionProperties) Connection(org.apache.qpid.server.model.Connection) ServerNetworkConnection(org.apache.qpid.server.transport.ServerNetworkConnection) UnsignedShort(org.apache.qpid.server.protocol.v1_0.type.UnsignedShort) AMQFrame(org.apache.qpid.server.protocol.v1_0.framing.AMQFrame) SaslChallenge(org.apache.qpid.server.protocol.v1_0.type.security.SaslChallenge) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) TransportFrame(org.apache.qpid.server.protocol.v1_0.framing.TransportFrame) AMQPDescribedTypeRegistry(org.apache.qpid.server.protocol.v1_0.type.codec.AMQPDescribedTypeRegistry) SocketAddress(java.net.SocketAddress) SoleConnectionEnforcementPolicyException(org.apache.qpid.server.protocol.v1_0.type.extensions.soleconn.SoleConnectionEnforcementPolicyException) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) LoggerFactory(org.slf4j.LoggerFactory) ConnectionMessages(org.apache.qpid.server.logging.messages.ConnectionMessages) ErrorCondition(org.apache.qpid.server.protocol.v1_0.type.ErrorCondition) Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) ResourceLimitMessages(org.apache.qpid.server.logging.messages.ResourceLimitMessages) AmqpPort(org.apache.qpid.server.model.port.AmqpPort) ValueHandler(org.apache.qpid.server.protocol.v1_0.codec.ValueHandler) SectionDecoderRegistry(org.apache.qpid.server.protocol.v1_0.codec.SectionDecoderRegistry) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) LocalTransaction(org.apache.qpid.server.txn.LocalTransaction) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) Collection(java.util.Collection) AnonymousAuthenticationManager(org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManager) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SaslOutcome(org.apache.qpid.server.protocol.v1_0.type.security.SaslOutcome) UUID(java.util.UUID) PrivilegedAction(java.security.PrivilegedAction) ConnectionLimitException(org.apache.qpid.server.security.limit.ConnectionLimitException) Functions(org.apache.qpid.server.transport.util.Functions) Sets(com.google.common.collect.Sets) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) List(java.util.List) Principal(java.security.Principal) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) AccessControlException(java.security.AccessControlException) Optional(java.util.Optional) FrameHandler(org.apache.qpid.server.protocol.v1_0.framing.FrameHandler) Queue(java.util.Queue) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) SaslMechanisms(org.apache.qpid.server.protocol.v1_0.type.security.SaslMechanisms) Iterators(com.google.common.collect.Iterators) EventLogger(org.apache.qpid.server.logging.EventLogger) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) SaslNegotiator(org.apache.qpid.server.security.auth.sasl.SaslNegotiator) SaslInit(org.apache.qpid.server.protocol.v1_0.type.security.SaslInit) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal) AbstractAMQPConnection(org.apache.qpid.server.transport.AbstractAMQPConnection) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) SaslResponse(org.apache.qpid.server.protocol.v1_0.type.security.SaslResponse) NoSuchElementException(java.util.NoSuchElementException) SubjectAuthenticationResult(org.apache.qpid.server.security.auth.SubjectAuthenticationResult) ServerTransaction(org.apache.qpid.server.txn.ServerTransaction) Logger(org.slf4j.Logger) Action(org.apache.qpid.server.util.Action) Iterator(java.util.Iterator) Broker(org.apache.qpid.server.model.Broker) Protocol(org.apache.qpid.server.model.Protocol) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) SubjectCreator(org.apache.qpid.server.security.SubjectCreator) ConnectionClosingTicker(org.apache.qpid.server.protocol.ConnectionClosingTicker) AMQPSession(org.apache.qpid.server.session.AMQPSession) Collections(java.util.Collections) ErrorCondition(org.apache.qpid.server.protocol.v1_0.type.ErrorCondition)

Example 5 with ErrorCondition

use of org.apache.qpid.server.protocol.v1_0.type.ErrorCondition in project qpid-broker-j by apache.

the class AMQPConnection_1_0Impl method receiveClose.

@Override
public void receiveClose(final int channel, final Close close) {
    switch(_connectionState) {
        case AWAIT_AMQP_OR_SASL_HEADER:
        case AWAIT_SASL_INIT:
        case AWAIT_SASL_RESPONSE:
        case AWAIT_AMQP_HEADER:
            throw new ConnectionScopedRuntimeException("Received unexpected close when AMQP connection has not been established.");
        case AWAIT_OPEN:
            closeReceived();
            closeConnection(ConnectionError.CONNECTION_FORCED, "Connection close sent before connection was opened");
            break;
        case OPENED:
            _connectionState = ConnectionState.CLOSE_RECEIVED;
            closeReceived();
            if (close.getError() != null) {
                final Error error = close.getError();
                ErrorCondition condition = error.getCondition();
                Symbol errorCondition = condition == null ? null : condition.getValue();
                LOGGER.info("{} : Connection closed with error : {} - {}", getLogSubject(), errorCondition, close.getError().getDescription());
            }
            sendClose(new Close());
            _connectionState = ConnectionState.CLOSED;
            _orderlyClose.set(true);
            addCloseTicker();
            break;
        case CLOSE_SENT:
            closeReceived();
            _connectionState = ConnectionState.CLOSED;
            _orderlyClose.set(true);
            break;
        case CLOSE_RECEIVED:
        case CLOSED:
            break;
        default:
            throw new ServerScopedRuntimeException("Unknown state: " + _connectionState);
    }
}
Also used : ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ErrorCondition(org.apache.qpid.server.protocol.v1_0.type.ErrorCondition) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) ConnectionError(org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) Close(org.apache.qpid.server.protocol.v1_0.type.transport.Close) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

Aggregations

Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)5 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)4 ErrorCondition (org.apache.qpid.server.protocol.v1_0.type.ErrorCondition)3 Close (org.apache.qpid.server.protocol.v1_0.type.transport.Close)3 ConnectionError (org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError)3 PrivilegedAction (java.security.PrivilegedAction)2 Symbol (org.apache.qpid.server.protocol.v1_0.type.Symbol)2 End (org.apache.qpid.server.protocol.v1_0.type.transport.End)2 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)2 ServerScopedRuntimeException (org.apache.qpid.server.util.ServerScopedRuntimeException)2 Iterators (com.google.common.collect.Iterators)1 PeekingIterator (com.google.common.collect.PeekingIterator)1 Sets (com.google.common.collect.Sets)1 Futures.allAsList (com.google.common.util.concurrent.Futures.allAsList)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 SocketAddress (java.net.SocketAddress)1 AccessControlContext (java.security.AccessControlContext)1 AccessControlException (java.security.AccessControlException)1 AccessController (java.security.AccessController)1 Principal (java.security.Principal)1