throw body.getChannelNotFoundException(channelId);
}
channel.sync();
AMQShortString exchangeName = body.getExchange();
AMQShortString queueName = body.getQueue();
AMQShortString routingKey = body.getRoutingKey();
if (exchangeName == null)
{
throw new AMQException("Exchange exchange must not be null");
}
Exchange exchange = virtualHost.getExchange(exchangeName.toString());
ExchangeBoundOkBody response;
if (exchange == null)
{
response = methodRegistry.createExchangeBoundOkBody(EXCHANGE_NOT_FOUND,
new AMQShortString("Exchange " + exchangeName + " not found"));
}
else if (routingKey == null)
{
if (queueName == null)
{
if (exchange.hasBindings())
{
response = methodRegistry.createExchangeBoundOkBody(OK, null);
}
else
{
response = methodRegistry.createExchangeBoundOkBody(NO_BINDINGS, // replyCode
null); // replyText
}
}
else
{
AMQQueue queue = virtualHost.getQueue(queueName.toString());
if (queue == null)
{
response = methodRegistry.createExchangeBoundOkBody(QUEUE_NOT_FOUND, // replyCode
new AMQShortString("Queue " + queueName + " not found")); // replyText
}
else
{
if (exchange.isBound(queue))
{
response = methodRegistry.createExchangeBoundOkBody(OK, // replyCode
null); // replyText
}
else
{
response = methodRegistry.createExchangeBoundOkBody(QUEUE_NOT_BOUND, // replyCode
new AMQShortString("Queue " + queueName + " not bound to exchange " + exchangeName)); // replyText
}
}
}
}
else if (queueName != null)
{
AMQQueue queue = virtualHost.getQueue(queueName.toString());
if (queue == null)
{
response = methodRegistry.createExchangeBoundOkBody(QUEUE_NOT_FOUND, // replyCode
new AMQShortString("Queue " + queueName + " not found")); // replyText
}
else
{
String bindingKey = body.getRoutingKey() == null ? null : body.getRoutingKey().asString();
if (exchange.isBound(bindingKey, queue))
{
response = methodRegistry.createExchangeBoundOkBody(OK, // replyCode
null); // replyText
}
else
{
String message = "Queue " + queueName + " not bound with routing key " +
body.getRoutingKey() + " to exchange " + exchangeName;
if(message.length()>255)
{
message = message.substring(0,254);
}
response = methodRegistry.createExchangeBoundOkBody(SPECIFIC_QUEUE_NOT_BOUND_WITH_RK, // replyCode
new AMQShortString(message)); // replyText
}
}
}
else
{
if (exchange.isBound(body.getRoutingKey() == null ? "" : body.getRoutingKey().asString()))
{
response = methodRegistry.createExchangeBoundOkBody(OK, // replyCode
null); // replyText
}
else
{
response = methodRegistry.createExchangeBoundOkBody(NO_QUEUE_BOUND_WITH_RK, // replyCode
new AMQShortString("No queue bound with routing key " + body.getRoutingKey() +
" to exchange " + exchangeName)); // replyText
}
}
session.writeFrame(response.generateFrame(channelId));
}