use of org.apache.qpid.server.message.MessageDestination in project qpid-broker-j by apache.
the class AMQChannel method receiveExchangeBound.
@Override
public void receiveExchangeBound(final AMQShortString exchangeName, final AMQShortString routingKey, final AMQShortString queueName) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("RECV[" + _channelId + "] ExchangeBound[" + " exchange: " + exchangeName + " routingKey: " + routingKey + " queue: " + queueName + " ]");
}
NamedAddressSpace virtualHost = _connection.getAddressSpace();
MethodRegistry methodRegistry = _connection.getMethodRegistry();
sync();
int replyCode;
String replyText;
if (isDefaultExchange(exchangeName)) {
if (routingKey == null) {
if (queueName == null) {
replyCode = virtualHost.hasMessageSources() ? ExchangeBoundOkBody.OK : ExchangeBoundOkBody.NO_BINDINGS;
replyText = null;
} else {
MessageSource queue = virtualHost.getAttainedMessageSource(queueName.toString());
if (queue == null) {
replyCode = ExchangeBoundOkBody.QUEUE_NOT_FOUND;
replyText = "Queue '" + queueName + "' not found";
} else {
replyCode = ExchangeBoundOkBody.OK;
replyText = null;
}
}
} else {
if (queueName == null) {
replyCode = virtualHost.getAttainedMessageDestination(routingKey.toString()) instanceof Queue ? ExchangeBoundOkBody.OK : ExchangeBoundOkBody.NO_QUEUE_BOUND_WITH_RK;
replyText = null;
} else {
MessageDestination destination = virtualHost.getAttainedMessageDestination(queueName.toString());
Queue<?> queue = destination instanceof Queue ? (Queue) destination : null;
if (queue == null) {
replyCode = ExchangeBoundOkBody.QUEUE_NOT_FOUND;
replyText = "Queue '" + queueName + "' not found";
} else {
replyCode = queueName.equals(routingKey) ? ExchangeBoundOkBody.OK : ExchangeBoundOkBody.SPECIFIC_QUEUE_NOT_BOUND_WITH_RK;
replyText = null;
}
}
}
} else {
Exchange<?> exchange = getExchange(exchangeName.toString());
if (exchange == null) {
replyCode = ExchangeBoundOkBody.EXCHANGE_NOT_FOUND;
replyText = "Exchange '" + exchangeName + "' not found";
} else if (routingKey == null) {
if (queueName == null) {
if (exchange.hasBindings()) {
replyCode = ExchangeBoundOkBody.OK;
replyText = null;
} else {
replyCode = ExchangeBoundOkBody.NO_BINDINGS;
replyText = null;
}
} else {
Queue<?> queue = getQueue(queueName.toString());
if (queue == null) {
replyCode = ExchangeBoundOkBody.QUEUE_NOT_FOUND;
replyText = "Queue '" + queueName + "' not found";
} else {
if (exchange.isBound(queue)) {
replyCode = ExchangeBoundOkBody.OK;
replyText = null;
} else {
replyCode = ExchangeBoundOkBody.QUEUE_NOT_BOUND;
replyText = "Queue '" + queueName + "' not bound to exchange '" + exchangeName + "'";
}
}
}
} else if (queueName != null) {
Queue<?> queue = getQueue(queueName.toString());
if (queue == null) {
replyCode = ExchangeBoundOkBody.QUEUE_NOT_FOUND;
replyText = "Queue '" + queueName + "' not found";
} else {
String bindingKey = routingKey == null ? null : routingKey.toString();
if (exchange.isBound(bindingKey, queue)) {
replyCode = ExchangeBoundOkBody.OK;
replyText = null;
} else {
replyCode = ExchangeBoundOkBody.SPECIFIC_QUEUE_NOT_BOUND_WITH_RK;
replyText = "Queue '" + queueName + "' not bound with routing key '" + routingKey + "' to exchange '" + exchangeName + "'";
}
}
} else {
if (exchange.isBound(routingKey == null ? "" : routingKey.toString())) {
replyCode = ExchangeBoundOkBody.OK;
replyText = null;
} else {
replyCode = ExchangeBoundOkBody.NO_QUEUE_BOUND_WITH_RK;
replyText = "No queue bound with routing key '" + routingKey + "' to exchange '" + exchangeName + "'";
}
}
}
ExchangeBoundOkBody exchangeBoundOkBody = methodRegistry.createExchangeBoundOkBody(replyCode, AMQShortString.validValueOf(replyText));
_connection.writeFrame(exchangeBoundOkBody.generateFrame(getChannelId()));
}
use of org.apache.qpid.server.message.MessageDestination in project qpid-broker-j by apache.
the class MessageConverter_Internal_to_v0_8 method createMessagePublishInfo.
private MessagePublishInfo createMessagePublishInfo(final InternalMessage serverMsg, final NamedAddressSpace addressSpace) {
String to = serverMsg.getTo();
final String exchangeName;
final String routingKey;
if (to == null || "".equals(to)) {
to = serverMsg.getInitialRoutingAddress();
}
if (to != null && !"".equals(to)) {
DestinationAddress destinationAddress = new DestinationAddress(addressSpace, to);
MessageDestination messageDestination = destinationAddress.getMessageDestination();
if (messageDestination instanceof Queue) {
exchangeName = "";
routingKey = messageDestination.getName();
} else if (messageDestination instanceof Exchange) {
exchangeName = messageDestination.getName();
routingKey = destinationAddress.getRoutingKey();
} else {
exchangeName = "";
routingKey = to;
}
} else {
exchangeName = "";
routingKey = "";
}
return new MessagePublishInfo(convertToShortStringForProperty("to", exchangeName), false, false, convertToShortStringForProperty("to' or 'subject", routingKey));
}
use of org.apache.qpid.server.message.MessageDestination in project qpid-broker-j by apache.
the class AnonymousRelayDestination method send.
@Override
public void send(final ServerMessage<?> message, final ServerTransaction txn, final SecurityToken securityToken) throws UnroutableMessageException {
final ReceivingDestination destination;
final String routingAddress = message.getTo();
DestinationAddress destinationAddress = new DestinationAddress(_addressSpace, routingAddress);
MessageDestination messageDestination = destinationAddress.getMessageDestination();
if (messageDestination != null) {
destination = new NodeReceivingDestination(destinationAddress, _target.getDurable(), _target.getExpiryPolicy(), _target.getCapabilities(), _eventLogger);
} else {
destination = null;
}
if (destination == null) {
if (_discardUnroutable) {
_eventLogger.message(ExchangeMessages.DISCARDMSG("", routingAddress));
} else {
throw new UnroutableMessageException(AmqpError.NOT_FOUND, String.format("Unknown destination '%s'", routingAddress));
}
} else {
destination.send(message, txn, securityToken);
}
}
use of org.apache.qpid.server.message.MessageDestination in project qpid-broker-j by apache.
the class LegacyAccessControlAdapter method authoriseAction.
Result authoriseAction(final PermissionedObject configuredObject, String actionName, final Map<String, Object> arguments) {
Class<? extends ConfiguredObject> categoryClass = configuredObject.getCategoryClass();
if (categoryClass == Exchange.class) {
MessageDestination exchange = (MessageDestination) configuredObject;
if ("publish".equals(actionName)) {
final ObjectProperties props = new ObjectProperties(exchange.getAddressSpace().getName(), exchange.getName(), (String) arguments.get("routingKey"));
props.put(ObjectProperties.Property.DURABLE, exchange.isDurable());
if (exchange instanceof Exchange<?>) {
LifetimePolicy lifetimePolicy = ((Exchange) exchange).getLifetimePolicy();
props.put(ObjectProperties.Property.AUTO_DELETE, lifetimePolicy != LifetimePolicy.PERMANENT);
props.put(ObjectProperties.Property.TEMPORARY, lifetimePolicy != LifetimePolicy.PERMANENT);
}
return _accessControl.authorise(PUBLISH, EXCHANGE, props);
}
} else if (categoryClass == VirtualHost.class) {
if ("connect".equals(actionName)) {
String virtualHostName = configuredObject.getName();
ObjectProperties properties = new ObjectProperties(virtualHostName);
properties.put(ObjectProperties.Property.VIRTUALHOST_NAME, virtualHostName);
return _accessControl.authorise(LegacyOperation.ACCESS, ObjectType.VIRTUALHOST, properties);
}
} else if (categoryClass == Broker.class) {
if ("manage".equals(actionName)) {
return _accessControl.authorise(LegacyOperation.ACCESS, ObjectType.MANAGEMENT, ObjectProperties.EMPTY);
}
} else if (categoryClass == Queue.class) {
Queue queue = (Queue) configuredObject;
if ("publish".equals(actionName)) {
final ObjectProperties _props = new ObjectProperties(queue.getParent().getName(), "", queue.getName());
return _accessControl.authorise(PUBLISH, EXCHANGE, _props);
}
}
return Result.DEFER;
}
use of org.apache.qpid.server.message.MessageDestination in project qpid-broker-j by apache.
the class LegacyAccessControlAdapter method createObjectPropertiesForExchangeBind.
private ObjectProperties createObjectPropertiesForExchangeBind(final Map<String, Object> arguments, final PermissionedObject configuredObject) {
ObjectProperties properties = new ObjectProperties();
Exchange<?> exchange = (Exchange<?>) configuredObject;
final QueueManagingVirtualHost virtualhost = exchange.getVirtualHost();
properties.setName(exchange.getName());
final String destination = (String) arguments.get("destination");
properties.put(ObjectProperties.Property.QUEUE_NAME, destination);
properties.put(ObjectProperties.Property.ROUTING_KEY, (String) arguments.get("bindingKey"));
properties.put(ObjectProperties.Property.VIRTUALHOST_NAME, virtualhost.getName());
MessageDestination dest = virtualhost.getAttainedMessageDestination(destination);
if (dest != null) {
// express rules about the binding of temporary queues (whose names cannot be predicted).
if (dest instanceof ConfiguredObject) {
ConfiguredObject queue = (ConfiguredObject) dest;
properties.put(ObjectProperties.Property.TEMPORARY, queue.getLifetimePolicy() != LifetimePolicy.PERMANENT);
}
properties.put(ObjectProperties.Property.DURABLE, dest.isDurable());
}
return properties;
}
Aggregations