@Override
public void exchangeDeclare(Session session, ExchangeDeclare method)
{
String exchangeName = method.getExchange();
VirtualHostImpl virtualHost = getVirtualHost(session);
//we must check for any unsupported arguments present and throw not-implemented
if(method.hasArguments())
{
Map<String,Object> args = method.getArguments();
//QPID-3392: currently we don't support any!
if(!args.isEmpty())
{
exception(session, method, ExecutionErrorCode.NOT_IMPLEMENTED, "Unsupported exchange argument(s) found " + args.keySet().toString());
return;
}
}
if(nameNullOrEmpty(method.getExchange()))
{
// special case handling to fake the existence of the default exchange for 0-10
if(!ExchangeDefaults.DIRECT_EXCHANGE_CLASS.equals(method.getType()))
{
exception(session, method, ExecutionErrorCode.NOT_ALLOWED,
"Attempt to redeclare default exchange "
+ " of type " + ExchangeDefaults.DIRECT_EXCHANGE_CLASS
+ " to " + method.getType() +".");
}
if(!nameNullOrEmpty(method.getAlternateExchange()))
{
exception(session, method, ExecutionErrorCode.NOT_ALLOWED,
"Attempt to set alternate exchange of the default exchange "
+ " to " + method.getAlternateExchange() +".");
}
}
else
{
if(method.getPassive())
{
ExchangeImpl exchange = getExchange(session, exchangeName);
if(exchange == null)
{
exception(session, method, ExecutionErrorCode.NOT_FOUND, "not-found: exchange-name '" + exchangeName + "'");
}
else
{
if (!exchange.getType().equals(method.getType())
&& (method.getType() != null && method.getType().length() > 0))
{
exception(session, method, ExecutionErrorCode.NOT_ALLOWED, "Attempt to redeclare exchange: "
+ exchangeName + " of type " + exchange.getType() + " to " + method.getType() + ".");
}
}
}
else
{
try
{
Map<String,Object> attributes = new HashMap<String, Object>();
attributes.put(org.apache.qpid.server.model.Exchange.ID, null);
attributes.put(org.apache.qpid.server.model.Exchange.NAME, method.getExchange());
attributes.put(org.apache.qpid.server.model.Exchange.TYPE, method.getType());
attributes.put(org.apache.qpid.server.model.Exchange.DURABLE, method.getDurable());
attributes.put(org.apache.qpid.server.model.Exchange.LIFETIME_POLICY,
method.getAutoDelete() ? LifetimePolicy.DELETE_ON_NO_LINKS : LifetimePolicy.PERMANENT);
attributes.put(org.apache.qpid.server.model.Exchange.ALTERNATE_EXCHANGE, method.getAlternateExchange());
virtualHost.createExchange(attributes);
}
catch(ReservedExchangeNameException e)
{
exception(session, method, ExecutionErrorCode.NOT_ALLOWED, "Attempt to declare exchange: "
+ exchangeName + " which begins with reserved name or prefix.");