use of org.apache.qpid.server.filter.AMQInvalidArgumentException in project qpid-broker-j by apache.
the class AbstractExchange method onOpen.
@Override
protected void onOpen() {
super.onOpen();
final ConfiguredDerivedMethodAttribute<Exchange<?>, Collection<Binding>> durableBindingsAttribute = (ConfiguredDerivedMethodAttribute<Exchange<?>, Collection<Binding>>) getModel().getTypeRegistry().getAttributeTypes(getTypeClass()).get(DURABLE_BINDINGS);
final Collection<Binding> bindings = durableBindingsAttribute.convertValue(getActualAttributes().get(DURABLE_BINDINGS), this);
if (bindings != null) {
_bindings.addAll(bindings);
for (Binding b : _bindings) {
final MessageDestination messageDestination = getOpenedMessageDestination(b.getDestination());
if (messageDestination != null) {
Map<String, Object> arguments = b.getArguments() == null ? Collections.emptyMap() : b.getArguments();
try {
onBind(new BindingIdentifier(b.getBindingKey(), messageDestination), arguments);
} catch (AMQInvalidArgumentException e) {
throw new IllegalConfigurationException("Unexpected bind argument : " + e.getMessage(), e);
}
messageDestination.linkAdded(this, b);
}
}
}
if (getLifetimePolicy() == LifetimePolicy.DELETE_ON_CREATING_LINK_CLOSE) {
if (_creatingLinkInfo != null) {
final LinkModel link;
if (_creatingLinkInfo.isSendingLink()) {
link = _virtualHost.getSendingLink(_creatingLinkInfo.getRemoteContainerId(), _creatingLinkInfo.getLinkName());
} else {
link = _virtualHost.getReceivingLink(_creatingLinkInfo.getRemoteContainerId(), _creatingLinkInfo.getLinkName());
}
addLifetimeConstraint(link);
} else {
throw new IllegalArgumentException("Exchanges created with a lifetime policy of " + getLifetimePolicy() + " must be created from a AMQP 1.0 link.");
}
}
if (getAlternateBinding() != null) {
String alternateDestination = getAlternateBinding().getDestination();
_alternateBindingDestination = getOpenedMessageDestination(alternateDestination);
if (_alternateBindingDestination != null) {
_alternateBindingDestination.addReference(this);
} else {
LOGGER.warn("Cannot find alternate binding destination '{}' for exchange '{}'", alternateDestination, toString());
}
}
}
use of org.apache.qpid.server.filter.AMQInvalidArgumentException in project qpid-broker-j by apache.
the class TopicExchangeImpl method unbind.
private synchronized boolean unbind(final BindingIdentifier binding) {
if (_bindings.containsKey(binding)) {
Map<String, Object> bindingArgs = _bindings.remove(binding);
LOGGER.debug("deregisterQueue args: {}", bindingArgs);
String bindingKey = TopicNormalizer.normalize(binding.getBindingKey());
TopicExchangeResult result = _topicExchangeResults.get(bindingKey);
result.removeBinding(binding);
if (FilterSupport.argumentsContainFilter(bindingArgs)) {
try {
result.removeFilteredDestination(binding.getDestination(), FilterSupport.createMessageFilter(bindingArgs, binding.getDestination()));
} catch (AMQInvalidArgumentException e) {
return false;
}
} else {
result.removeUnfilteredDestination(binding.getDestination());
}
// shall we delete the result from _topicExchangeResults if result is empty?
return true;
} else {
return false;
}
}
use of org.apache.qpid.server.filter.AMQInvalidArgumentException in project qpid-broker-j by apache.
the class ServerSessionDelegate method messageSubscribe.
@Override
public void messageSubscribe(ServerSession session, MessageSubscribe method) {
/*
TODO - work around broken Python tests
Correct code should read like
if not hasAcceptMode() exception ILLEGAL_ARGUMENT "Accept-mode not supplied"
else if not method.hasAcquireMode() exception ExecutionErrorCode.ILLEGAL_ARGUMENT, "Acquire-mode not supplied"
*/
if (!method.hasAcceptMode()) {
method.setAcceptMode(MessageAcceptMode.EXPLICIT);
}
if (!method.hasAcquireMode()) {
method.setAcquireMode(MessageAcquireMode.PRE_ACQUIRED);
}
if (!method.hasQueue()) {
exception(session, method, ExecutionErrorCode.ILLEGAL_ARGUMENT, "queue not supplied");
} else {
String destination = method.getDestination();
if (destination == null) {
exception(session, method, ExecutionErrorCode.INVALID_ARGUMENT, "Subscriber must provide a destination. The protocol specification marking the destination argument as optional is considered a mistake.");
} else if (session.getSubscription(destination) != null) {
exception(session, method, ExecutionErrorCode.NOT_ALLOWED, "Subscription already exists with destination '" + destination + "'");
} else {
String queueName = method.getQueue();
NamedAddressSpace addressSpace = getAddressSpace(session);
final Collection<MessageSource> sources = new HashSet<>();
final MessageSource queue = addressSpace.getAttainedMessageSource(queueName);
if (method.getArguments() != null && method.getArguments().get("x-multiqueue") instanceof Collection) {
for (Object object : (Collection<Object>) method.getArguments().get("x-multiqueue")) {
String sourceName = String.valueOf(object);
sourceName = sourceName.trim();
if (sourceName.length() != 0) {
MessageSource source = addressSpace.getAttainedMessageSource(sourceName);
if (source == null) {
sources.clear();
break;
} else {
sources.add(source);
}
}
}
queueName = method.getArguments().get("x-multiqueue").toString();
} else if (queue != null) {
sources.add(queue);
}
if (sources.isEmpty()) {
exception(session, method, ExecutionErrorCode.NOT_FOUND, "Queue: " + queueName + " not found");
} else if (!verifySessionAccess(session, sources)) {
exception(session, method, ExecutionErrorCode.RESOURCE_LOCKED, "Exclusive Queue: " + queueName + " owned exclusively by another session");
} else {
ProtocolEngine protocolEngine = getServerConnection(session).getAmqpConnection();
FlowCreditManager_0_10 creditManager = new WindowCreditManager(0L, 0L);
FilterManager filterManager = null;
try {
filterManager = FilterManagerFactory.createManager(method.getArguments());
} catch (AMQInvalidArgumentException amqe) {
exception(session, method, ExecutionErrorCode.ILLEGAL_ARGUMENT, "Exception Creating FilterManager");
return;
}
if (method.hasArguments() && method.getArguments().containsKey(AMQPFilterTypes.REPLAY_PERIOD.toString())) {
Object value = method.getArguments().get(AMQPFilterTypes.REPLAY_PERIOD.toString());
final long period;
if (value instanceof Number) {
period = ((Number) value).longValue();
} else if (value instanceof String) {
try {
period = Long.parseLong(value.toString());
} catch (NumberFormatException e) {
exception(session, method, ExecutionErrorCode.ILLEGAL_ARGUMENT, "Cannot parse value " + value + " as a number for filter " + AMQPFilterTypes.REPLAY_PERIOD.toString());
return;
}
} else {
exception(session, method, ExecutionErrorCode.ILLEGAL_ARGUMENT, "Cannot parse value " + value + " as a number for filter " + AMQPFilterTypes.REPLAY_PERIOD.toString());
return;
}
final long startingFrom = System.currentTimeMillis() - (1000l * period);
if (filterManager == null) {
filterManager = new FilterManager();
}
MessageFilter filter = new ArrivalTimeFilter(startingFrom, period == 0);
filterManager.add(filter.getName(), filter);
}
boolean multiQueue = sources.size() > 1;
ConsumerTarget_0_10 target = new ConsumerTarget_0_10(session, destination, method.getAcceptMode(), method.getAcquireMode(), MessageFlowMode.WINDOW, creditManager, method.getArguments(), multiQueue);
Integer priority = null;
if (method.hasArguments() && method.getArguments().containsKey("x-priority")) {
Object value = method.getArguments().get("x-priority");
if (value instanceof Number) {
priority = ((Number) value).intValue();
} else if (value instanceof String) {
try {
priority = Integer.parseInt(value.toString());
} catch (NumberFormatException e) {
}
}
}
session.register(destination, target);
try {
EnumSet<ConsumerOption> options = EnumSet.noneOf(ConsumerOption.class);
if (method.getAcquireMode() == MessageAcquireMode.PRE_ACQUIRED) {
options.add(ConsumerOption.ACQUIRES);
}
if (method.getAcquireMode() != MessageAcquireMode.NOT_ACQUIRED || method.getAcceptMode() == MessageAcceptMode.EXPLICIT) {
options.add(ConsumerOption.SEES_REQUEUES);
}
if (method.getExclusive()) {
options.add(ConsumerOption.EXCLUSIVE);
}
for (MessageSource source : sources) {
source.addConsumer(target, filterManager, MessageTransferMessage.class, destination, options, priority);
}
target.updateNotifyWorkDesired();
} catch (Queue.ExistingExclusiveConsumer existing) {
exception(session, method, ExecutionErrorCode.RESOURCE_LOCKED, "Queue has an exclusive consumer");
} catch (Queue.ExistingConsumerPreventsExclusive exclusive) {
exception(session, method, ExecutionErrorCode.RESOURCE_LOCKED, "Queue has an existing consumer - can't subscribe exclusively");
} catch (AccessControlException e) {
exception(session, method, ExecutionErrorCode.UNAUTHORIZED_ACCESS, e.getMessage());
} catch (MessageSource.ConsumerAccessRefused consumerAccessRefused) {
exception(session, method, ExecutionErrorCode.RESOURCE_LOCKED, "Queue has an incompatible exclusivity policy");
} catch (MessageSource.QueueDeleted queueDeleted) {
exception(session, method, ExecutionErrorCode.NOT_FOUND, "Queue was deleted");
}
}
}
}
}
use of org.apache.qpid.server.filter.AMQInvalidArgumentException in project qpid-broker-j by apache.
the class ServerSessionDelegate method exchangeBind.
@Override
public void exchangeBind(ServerSession session, ExchangeBind method) {
NamedAddressSpace addressSpace = getAddressSpace(session);
if (!method.hasQueue()) {
exception(session, method, ExecutionErrorCode.ILLEGAL_ARGUMENT, "queue not set");
} else {
final String exchangeName = method.getExchange();
if (nameNullOrEmpty(exchangeName)) {
exception(session, method, ExecutionErrorCode.INVALID_ARGUMENT, "Bind not allowed for default exchange");
} else {
// should raise exception ILLEGAL_ARGUMENT "binding-key not set"
if (!method.hasBindingKey()) {
method.setBindingKey(method.getQueue());
}
Queue<?> queue = getQueue(addressSpace, method.getQueue());
Exchange<?> exchange = getExchange(addressSpace, exchangeName, false);
if (queue == null) {
exception(session, method, ExecutionErrorCode.NOT_FOUND, "Queue: '" + method.getQueue() + "' not found");
} else if (exchange == null) {
exception(session, method, ExecutionErrorCode.NOT_FOUND, "Exchange: '" + exchangeName + "' not found");
} else if (exchange.getType().equals(ExchangeDefaults.HEADERS_EXCHANGE_CLASS) && (!method.hasArguments() || method.getArguments() == null || !method.getArguments().containsKey("x-match"))) {
exception(session, method, ExecutionErrorCode.INTERNAL_ERROR, "Bindings to an exchange of type " + ExchangeDefaults.HEADERS_EXCHANGE_CLASS + " require an x-match header");
} else {
if (!exchange.isBound(method.getBindingKey(), method.getArguments(), queue)) {
try {
exchange.addBinding(method.getBindingKey(), queue, method.getArguments());
} catch (AccessControlException e) {
exception(session, method, ExecutionErrorCode.UNAUTHORIZED_ACCESS, e.getMessage());
} catch (AMQInvalidArgumentException e) {
exception(session, method, ExecutionErrorCode.INVALID_ARGUMENT, String.format("Cannot bind queue '%s' to exchange '%s' due to invalid argument : %s", queue.getName(), exchangeName, e.getMessage()));
}
} else {
// todo
}
}
}
}
}
use of org.apache.qpid.server.filter.AMQInvalidArgumentException in project qpid-broker-j by apache.
the class AMQChannel method receiveQueueBind.
@Override
public void receiveQueueBind(final AMQShortString queueName, final AMQShortString exchange, AMQShortString bindingKey, final boolean nowait, final FieldTable argumentsTable) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("RECV[" + _channelId + "] QueueBind[" + " queue: " + queueName + " exchange: " + exchange + " bindingKey: " + bindingKey + " nowait: " + nowait + " arguments: " + argumentsTable + " ]");
}
NamedAddressSpace virtualHost = _connection.getAddressSpace();
Queue<?> queue;
if (queueName == null) {
queue = getDefaultQueue();
if (queue != null) {
if (bindingKey == null) {
bindingKey = AMQShortString.valueOf(queue.getName());
}
}
} else {
queue = getQueue(queueName.toString());
}
if (queue == null) {
String message = queueName == null ? "No default queue defined on channel and queue was null" : "Queue " + queueName + " does not exist.";
closeChannel(ErrorCodes.NOT_FOUND, message);
} else if (isDefaultExchange(exchange)) {
_connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Cannot bind the queue '" + queueName + "' to the default exchange", getChannelId());
} else {
final String exchangeName = exchange.toString();
final Exchange<?> exch = getExchange(exchangeName);
if (exch == null) {
closeChannel(ErrorCodes.NOT_FOUND, "Exchange '" + exchangeName + "' does not exist.");
} else {
try {
Map<String, Object> arguments = FieldTable.convertToMap(argumentsTable);
String bindingKeyStr = bindingKey == null ? "" : AMQShortString.toString(bindingKey);
if (!exch.isBound(bindingKeyStr, arguments, queue)) {
try {
if (!exch.addBinding(bindingKeyStr, queue, arguments) && ExchangeDefaults.TOPIC_EXCHANGE_CLASS.equals(exch.getType())) {
exch.replaceBinding(bindingKeyStr, queue, arguments);
}
} catch (AMQInvalidArgumentException e) {
_connection.sendConnectionClose(ErrorCodes.ARGUMENT_INVALID, String.format("Cannot bind queue '%s' to exchange '%s' due to invalid argument : %s", queueName, exch.getName(), e.getMessage()), getChannelId());
}
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Binding queue " + queue + " to exchange " + exch + " with routing key " + bindingKeyStr);
}
if (!nowait) {
sync();
MethodRegistry methodRegistry = _connection.getMethodRegistry();
AMQMethodBody responseBody = methodRegistry.createQueueBindOkBody();
_connection.writeFrame(responseBody.generateFrame(getChannelId()));
}
} catch (AccessControlException e) {
_connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, e.getMessage(), getChannelId());
}
}
}
}
Aggregations