{
}
public void methodReceived(AMQStateManager stateManager, QueueBindBody body, int channelId) throws AMQException
{
AMQProtocolSession session = stateManager.getProtocolSession();
VirtualHost virtualHost = session.getVirtualHost();
ExchangeRegistry exchangeRegistry = virtualHost.getExchangeRegistry();
QueueRegistry queueRegistry = virtualHost.getQueueRegistry();
final AMQQueue queue;
final AMQShortString routingKey;
if (body.getQueue() == null)
{
AMQChannel channel = session.getChannel(channelId);
if (channel == null)
{
throw body.getChannelNotFoundException(channelId);
}
queue = channel.getDefaultQueue();
if (queue == null)
{
throw body.getChannelException(AMQConstant.NOT_FOUND, "No default queue defined on channel and queue was null");
}
if (body.getRoutingKey() == null)
{
routingKey = queue.getName();
}
else
{
routingKey = body.getRoutingKey().intern();
}
}
else
{
queue = queueRegistry.getQueue(body.getQueue());
routingKey = body.getRoutingKey() == null ? AMQShortString.EMPTY_STRING : body.getRoutingKey().intern();
}
if (queue == null)
{
throw body.getChannelException(AMQConstant.NOT_FOUND, "Queue " + body.getQueue() + " does not exist.");
}
final Exchange exch = exchangeRegistry.getExchange(body.getExchange());
if (exch == null)
{
throw body.getChannelException(AMQConstant.NOT_FOUND, "Exchange " + body.getExchange() + " does not exist.");
}
try
{
//Perform ACLs
if (!virtualHost.getAccessManager().authoriseBind(session, exch,
queue, routingKey))
{
throw body.getConnectionException(AMQConstant.ACCESS_REFUSED, "Permission denied");
}
if (!exch.isBound(routingKey, body.getArguments(), queue))
{
queue.bind(exch, routingKey, body.getArguments());
}
}
catch (AMQInvalidRoutingKeyException rke)
{
throw body.getChannelException(AMQConstant.INVALID_ROUTING_KEY, routingKey.toString());
}
catch (AMQException e)
{
throw body.getChannelException(AMQConstant.CHANNEL_ERROR, e.toString());
}
if (_log.isInfoEnabled())
{
_log.info("Binding queue " + queue + " to exchange " + exch + " with routing key " + routingKey);
}
if (!body.getNowait())
{
MethodRegistry methodRegistry = session.getMethodRegistry();
AMQMethodBody responseBody = methodRegistry.createQueueBindOkBody();
session.writeFrame(responseBody.generateFrame(channelId));
}
}