Search in sources :

Example 1 with AmqpErrorException

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

the class ValueHandlerTest method performTest.

private void performTest(final byte type, final byte[] encodedBytes, ValueHandler valueHandler) {
    QpidByteBuffer qbb = QpidByteBuffer.wrap(encodedBytes);
    try {
        valueHandler.parse(qbb);
        fail(String.format("AmqpErrorException is expected for %#02x", type));
    } catch (AmqpErrorException e) {
        assertEquals(String.format("Unexpected error code for %#02x", type), AmqpError.DECODE_ERROR, e.getError().getCondition());
    } catch (Exception e) {
        fail(String.format("Unexpected exception for %#02x: %s", type, e));
    }
}
Also used : AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException)

Example 2 with AmqpErrorException

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

the class AbstractLinkEndpoint method receiveAttach.

@Override
public void receiveAttach(final Attach attach) throws AmqpErrorException {
    _errored = false;
    boolean isAttachingRemoteTerminusNull = (attach.getRole() == Role.SENDER ? attach.getSource() == null : attach.getTarget() == null);
    boolean isAttachingLocalTerminusNull = (attach.getRole() == Role.SENDER ? attach.getTarget() == null : attach.getSource() == null);
    boolean isLocalTerminusNull = (attach.getRole() == Role.SENDER ? getTarget() == null : getSource() == null);
    if (isAttachingRemoteTerminusNull) {
        throw new AmqpErrorException(AmqpError.INVALID_FIELD, "received Attach with remote null terminus.");
    }
    if (isAttachingLocalTerminusNull) {
        recoverLink(attach);
    } else if (isLocalTerminusNull) {
        establishLink(attach);
    } else if (attach.getUnsettled() != null) {
        // TODO: QPID-7845 : Functionality for resuming links is not fully implemented
        if (attach.getUnsettled().isEmpty()) {
            resumeLink(attach);
        } else {
            throw new AmqpErrorException(new Error(AmqpError.NOT_IMPLEMENTED, "Resuming link is not implemented."));
        }
    } else {
        reattachLink(attach);
    }
}
Also used : AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)

Example 3 with AmqpErrorException

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

the class ExchangeSendingDestination method getQueue.

private static Queue<?> getQueue(Exchange<?> exchange, Source source, String subscriptionName, BindingInfo bindingInfo) throws AmqpErrorException {
    boolean isDurable = source.getExpiryPolicy() == TerminusExpiryPolicy.NEVER;
    boolean isShared = hasCapability(source.getCapabilities(), SHARED_CAPABILITY);
    QueueManagingVirtualHost virtualHost;
    if (exchange.getAddressSpace() instanceof QueueManagingVirtualHost) {
        virtualHost = (QueueManagingVirtualHost) exchange.getAddressSpace();
    } else {
        throw new AmqpErrorException(new Error(AmqpError.INTERNAL_ERROR, "Address space of unexpected type"));
    }
    Queue<?> queue;
    final Map<String, Object> attributes = new HashMap<>();
    ExclusivityPolicy exclusivityPolicy;
    if (isShared) {
        exclusivityPolicy = ExclusivityPolicy.SHARED_SUBSCRIPTION;
    } else {
        exclusivityPolicy = ExclusivityPolicy.LINK;
    }
    org.apache.qpid.server.model.LifetimePolicy lifetimePolicy = getLifetimePolicy(source.getExpiryPolicy());
    attributes.put(Queue.ID, UUID.randomUUID());
    attributes.put(Queue.NAME, subscriptionName);
    attributes.put(Queue.LIFETIME_POLICY, lifetimePolicy);
    attributes.put(Queue.EXCLUSIVE, exclusivityPolicy);
    attributes.put(Queue.DURABLE, isDurable);
    Map<String, Map<String, Object>> bindings = bindingInfo.getBindings();
    try {
        queue = virtualHost.getSubscriptionQueue(exchange.getName(), attributes, bindings);
    } catch (NotFoundException e) {
        throw new AmqpErrorException(new Error(AmqpError.NOT_FOUND, e.getMessage()));
    } catch (IllegalStateException e) {
        throw new AmqpErrorException(new Error(AmqpError.RESOURCE_LOCKED, "Subscription is already in use"));
    }
    return queue;
}
Also used : QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) HashMap(java.util.HashMap) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) TokenMgrError(org.apache.qpid.server.filter.selector.TokenMgrError) NotFoundException(org.apache.qpid.server.model.NotFoundException) ExclusivityPolicy(org.apache.qpid.server.model.ExclusivityPolicy) LifetimePolicy(org.apache.qpid.server.model.LifetimePolicy) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with AmqpErrorException

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

the class LinkImpl method attach.

@Override
public final synchronized ListenableFuture<? extends LinkEndpoint<S, T>> attach(final Session_1_0 session, final Attach attach) {
    try {
        if (_role == attach.getRole()) {
            throw new AmqpErrorException(new Error(AmqpError.ILLEGAL_STATE, "Cannot switch SendingLink to ReceivingLink and vice versa"));
        }
        if (_linkEndpoint != null && !session.equals(_linkEndpoint.getSession())) {
            SettableFuture<LinkEndpoint<S, T>> future = SettableFuture.create();
            _thiefQueue.add(new ThiefInformation(session, attach, future));
            startLinkStealingIfNecessary();
            return future;
        } else {
            if (_linkEndpoint == null) {
                _linkEndpoint = createLinkEndpoint(session, attach);
            }
            _linkEndpoint.receiveAttach(attach);
            _linkRegistry.linkChanged(this);
            return Futures.immediateFuture(_linkEndpoint);
        }
    } catch (Exception e) {
        LOGGER.debug("Error attaching link", e);
        return rejectLink(session, e);
    }
}
Also used : AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) LinkError(org.apache.qpid.server.protocol.v1_0.type.transport.LinkError) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with AmqpErrorException

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

the class MessageFormat_1_0 method createMessage.

@Override
public Message_1_0 createMessage(final QpidByteBuffer payload, final MessageStore store, final Object connectionReference) {
    List<EncodingRetainingSection<?>> dataSections = new ArrayList<>();
    List<EncodingRetainingSection<?>> allSections;
    try {
        allSections = getSectionDecoder().parseAll(payload);
    } catch (AmqpErrorException e) {
        throw new AmqpErrorRuntimeException(e);
    }
    MessageMetaData_1_0 mmd = createMessageMetaData(allSections, dataSections);
    MessageHandle<MessageMetaData_1_0> handle = store.addMessage(mmd);
    for (EncodingRetainingSection<?> dataSection : dataSections) {
        try (QpidByteBuffer encodedForm = dataSection.getEncodedForm()) {
            handle.addContent(encodedForm);
        }
        dataSection.dispose();
    }
    final StoredMessage<MessageMetaData_1_0> storedMessage = handle.allContentAdded();
    return new Message_1_0(storedMessage, connectionReference);
}
Also used : EncodingRetainingSection(org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection) ArrayList(java.util.ArrayList) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AmqpErrorRuntimeException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorRuntimeException)

Aggregations

AmqpErrorException (org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException)20 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)10 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)10 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)8 Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)8 MessageSource (org.apache.qpid.server.message.MessageSource)7 BaseSource (org.apache.qpid.server.protocol.v1_0.type.BaseSource)6 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)6 ArrayList (java.util.ArrayList)5 Symbol (org.apache.qpid.server.protocol.v1_0.type.Symbol)5 EncodingRetainingSection (org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 TokenMgrError (org.apache.qpid.server.filter.selector.TokenMgrError)4 AmqpValueSection (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValueSection)4 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)4 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)3 AmqpSequenceSection (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpSequenceSection)3 DataSection (org.apache.qpid.server.protocol.v1_0.type.messaging.DataSection)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2