in broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerSessionDelegate.java [870:993]
public void exchangeDeclare(ServerSession session, ExchangeDeclare method)
{
String exchangeName = method.getExchange();
NamedAddressSpace addressSpace = getAddressSpace(session);
String alternateExchangeName = method.getAlternateExchange();
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(alternateExchangeName))
{
exception(session, method, ExecutionErrorCode.NOT_ALLOWED,
"Attempt to set alternate exchange of the default exchange "
+ " to " + alternateExchangeName + ".");
}
}
else
{
if(method.getPassive())
{
Exchange<?> exchange = getExchange(session, exchangeName, false);
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<>();
if(method.hasArguments())
{
attributes.putAll(method.getArguments());
}
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);
if (method.hasAlternateExchange() && !nameNullOrEmpty(alternateExchangeName))
{
validateAlternateExchangeIsNotQueue(addressSpace, alternateExchangeName);
attributes.put(org.apache.qpid.server.model.Exchange.ALTERNATE_BINDING,
Map.of(AlternateBinding.DESTINATION, alternateExchangeName));
}
validateAndSanitizeExchangeDeclareArguments(attributes, session.getAMQPConnection());
addressSpace.createMessageDestination(Exchange.class, attributes);;
}
catch(ReservedExchangeNameException e)
{
Exchange<?> existingExchange = getExchange(session, exchangeName, false);
if(existingExchange == null
|| !existingExchange.getType().equals(method.getType())
|| (method.hasAlternateExchange() && (existingExchange.getAlternateBinding() == null ||
!alternateExchangeName
.equals(existingExchange.getAlternateBinding().getDestination()))) )
{
exception(session, method, ExecutionErrorCode.NOT_ALLOWED, "Attempt to declare exchange: "
+ exchangeName + " which begins with reserved name or prefix.");
}
}
catch (UnknownAlternateBindingException e)
{
exception(session,
method,
ExecutionErrorCode.NOT_FOUND,
String.format("Unknown alternate destination '%s'", e.getAlternateBindingName()));
}
catch(NoFactoryForTypeException e)
{
exception(session, method, ExecutionErrorCode.NOT_FOUND, "Unknown Exchange Type: " + method.getType());
}
catch(AbstractConfiguredObject.DuplicateNameException e)
{
Exchange<?> exchange = (Exchange<?>) e.getExisting();
if(!exchange.getType().equals(method.getType()))
{
exception(session, method, ExecutionErrorCode.NOT_ALLOWED,
"Attempt to redeclare exchange: " + exchangeName
+ " of type " + exchange.getType()
+ " to " + method.getType() +".");
}
else if(method.hasAlternateExchange()
&& (exchange.getAlternateBinding() == null ||
!alternateExchangeName.equals(exchange.getAlternateBinding().getDestination())))
{
exception(session, method, ExecutionErrorCode.NOT_ALLOWED,
"Attempt to change alternate exchange of: " + exchangeName
+ " from " + exchange.getAlternateBinding()
+ " to " + alternateExchangeName + ".");
}
}
catch (AccessControlException e)
{
exception(session, method, ExecutionErrorCode.UNAUTHORIZED_ACCESS, e.getMessage());
}
catch (IllegalArgumentException | IllegalConfigurationException e)
{
exception(session, method, ExecutionErrorCode.ILLEGAL_ARGUMENT, e.getMessage());
}
}
}
}