final AMQQueue queue;
final AMQShortString routingKey;
AMQChannel channel = session.getChannel(channelId);
if (channel == null)
{
throw body.getChannelNotFoundException(channelId);
}
if (body.getQueue() == null)
{
queue = channel.getDefaultQueue();
if (queue == null)
{
throw body.getChannelException(AMQConstant.NOT_FOUND, "No default queue defined on channel and queue was null");
}
routingKey = body.getRoutingKey() == null ? null : body.getRoutingKey().intern(false);
}
else
{
queue = virtualHost.getQueue(body.getQueue().toString());
routingKey = body.getRoutingKey() == null ? null : body.getRoutingKey().intern(false);
}
if (queue == null)
{
throw body.getChannelException(AMQConstant.NOT_FOUND, "Queue " + body.getQueue() + " does not exist.");
}
final Exchange exch = virtualHost.getExchange(body.getExchange() == null ? null : body.getExchange().toString());
if (exch == null)
{
throw body.getChannelException(AMQConstant.NOT_FOUND, "Exchange " + body.getExchange() + " does not exist.");
}
if(exch.getBinding(String.valueOf(routingKey), queue, FieldTable.convertToMap(body.getArguments())) == null)
{
throw body.getChannelException(AMQConstant.NOT_FOUND,"No such binding");
}
else
{
exch.removeBinding(String.valueOf(routingKey), queue, FieldTable.convertToMap(body.getArguments()));
}
if (_log.isInfoEnabled())
{
_log.info("Binding queue " + queue + " to exchange " + exch + " with routing key " + routingKey);
}
final MethodRegistry registry = session.getMethodRegistry();
final AMQMethodBody responseBody;
if (registry instanceof MethodRegistry_0_9)
{
responseBody = ((MethodRegistry_0_9)registry).createQueueUnbindOkBody();
}
else if (registry instanceof MethodRegistry_0_91)
{
responseBody = ((MethodRegistry_0_91)registry).createQueueUnbindOkBody();
}
else
{
// 0-8 does not support QueueUnbind
throw new AMQException(AMQConstant.COMMAND_INVALID, "QueueUnbind not present in AMQP version: " + session.getProtocolVersion(), null);
}
channel.sync();
session.writeFrame(responseBody.generateFrame(channelId));
}