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));
}
}
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);
}
}
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;
}
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);
}
}
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);
}
Aggregations