use of org.apache.qpid.server.model.NamedAddressSpace in project qpid-broker-j by apache.
the class AMQChannel method receiveQueueUnbind.
@Override
public void receiveQueueUnbind(final AMQShortString queueName, final AMQShortString exchange, final AMQShortString bindingKey, final FieldTable arguments) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("RECV[" + _channelId + "] QueueUnbind[" + " queue: " + queueName + " exchange: " + exchange + " bindingKey: " + bindingKey + " arguments: " + arguments + " ]");
}
NamedAddressSpace virtualHost = _connection.getAddressSpace();
final boolean useDefaultQueue = queueName == null;
final Queue<?> queue = useDefaultQueue ? getDefaultQueue() : getQueue(queueName.toString());
if (queue == null) {
String message = useDefaultQueue ? "No default queue defined on channel and queue was null" : "Queue '" + queueName + "' does not exist.";
closeChannel(ErrorCodes.NOT_FOUND, message);
} else if (isDefaultExchange(exchange)) {
_connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Cannot unbind the queue '" + queue.getName() + "' from the default exchange", getChannelId());
} else {
final Exchange<?> exch = getExchange(exchange.toString());
if (exch == null) {
closeChannel(ErrorCodes.NOT_FOUND, "Exchange '" + exchange + "' does not exist.");
} else if (!exch.hasBinding(AMQShortString.toString(bindingKey), queue)) {
closeChannel(ErrorCodes.NOT_FOUND, "No such binding");
} else {
try {
exch.deleteBinding(AMQShortString.toString(bindingKey), queue);
final AMQMethodBody responseBody = _connection.getMethodRegistry().createQueueUnbindOkBody();
sync();
_connection.writeFrame(responseBody.generateFrame(getChannelId()));
} catch (AccessControlException e) {
_connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, e.getMessage(), getChannelId());
}
}
}
}
use of org.apache.qpid.server.model.NamedAddressSpace in project qpid-broker-j by apache.
the class AMQChannel method receiveBasicGet.
@Override
public void receiveBasicGet(final AMQShortString queueName, final boolean noAck) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("RECV[" + _channelId + "] BasicGet[" + " queue: " + queueName + " noAck: " + noAck + " ]");
}
NamedAddressSpace vHost = _connection.getAddressSpace();
sync();
MessageSource queue = queueName == null ? getDefaultQueue() : vHost.getAttainedMessageSource(queueName.toString());
if (queue == null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("No queue for '" + queueName + "'");
}
if (queueName != null) {
_connection.sendConnectionClose(ErrorCodes.NOT_FOUND, "No such queue, '" + queueName + "'", _channelId);
} else {
_connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "No queue name provided, no default queue defined.", _channelId);
}
} else {
try {
if (!performGet(queue, !noAck)) {
MethodRegistry methodRegistry = _connection.getMethodRegistry();
BasicGetEmptyBody responseBody = methodRegistry.createBasicGetEmptyBody(null);
_connection.writeFrame(responseBody.generateFrame(_channelId));
}
} catch (AccessControlException e) {
_connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, e.getMessage(), _channelId);
} catch (MessageSource.ExistingExclusiveConsumer e) {
_connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Queue has an exclusive consumer", _channelId);
} catch (MessageSource.ExistingConsumerPreventsExclusive e) {
_connection.sendConnectionClose(ErrorCodes.INTERNAL_ERROR, "The GET request has been evaluated as an exclusive consumer, " + "this is likely due to a programming error in the Qpid broker", _channelId);
} catch (MessageSource.ConsumerAccessRefused consumerAccessRefused) {
_connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Queue has an incompatible exclusivity policy", _channelId);
} catch (MessageSource.QueueDeleted queueDeleted) {
_connection.sendConnectionClose(ErrorCodes.NOT_FOUND, "Queue has been deleted", _channelId);
}
}
}
use of org.apache.qpid.server.model.NamedAddressSpace in project qpid-broker-j by apache.
the class AMQChannel method receiveBasicConsume.
@Override
public void receiveBasicConsume(final AMQShortString queue, final AMQShortString consumerTag, final boolean noLocal, final boolean noAck, final boolean exclusive, final boolean nowait, final FieldTable arguments) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("RECV[" + _channelId + "] BasicConsume[" + " queue: " + queue + " consumerTag: " + consumerTag + " noLocal: " + noLocal + " noAck: " + noAck + " exclusive: " + exclusive + " nowait: " + nowait + " arguments: " + arguments + " ]");
}
AMQShortString consumerTag1 = consumerTag;
NamedAddressSpace vHost = _connection.getAddressSpace();
sync();
String queueName = AMQShortString.toString(queue);
MessageSource queue1 = queueName == null ? getDefaultQueue() : vHost.getAttainedMessageSource(queueName);
final Collection<MessageSource> sources = new HashSet<>();
if (arguments != null && arguments.get("x-multiqueue") instanceof Collection) {
for (Object object : (Collection<Object>) arguments.get("x-multiqueue")) {
String sourceName = String.valueOf(object);
sourceName = sourceName.trim();
if (sourceName.length() != 0) {
MessageSource source = vHost.getAttainedMessageSource(sourceName);
if (source == null) {
sources.clear();
break;
} else {
sources.add(source);
}
}
}
queueName = arguments.get("x-multiqueue").toString();
} else if (queue1 != null) {
sources.add(queue1);
}
if (sources.isEmpty()) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("No queue for '" + queueName + "'");
}
if (queueName != null) {
closeChannel(ErrorCodes.NOT_FOUND, "No such queue, '" + queueName + "'");
} else {
_connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "No queue name provided, no default queue defined.", _channelId);
}
} else {
try {
consumerTag1 = consumeFromSource(consumerTag1, sources, !noAck, arguments, exclusive, noLocal);
if (!nowait) {
MethodRegistry methodRegistry = _connection.getMethodRegistry();
AMQMethodBody responseBody = methodRegistry.createBasicConsumeOkBody(consumerTag1);
_connection.writeFrame(responseBody.generateFrame(_channelId));
}
} catch (ConsumerTagInUseException cte) {
_connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Non-unique consumer tag, '" + consumerTag1 + "'", _channelId);
} catch (AMQInvalidArgumentException ise) {
_connection.sendConnectionClose(ErrorCodes.ARGUMENT_INVALID, ise.getMessage(), _channelId);
} catch (Queue.ExistingExclusiveConsumer e) {
_connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, "Cannot subscribe to queue '" + queue1.getName() + "' as it already has an existing exclusive consumer", _channelId);
} catch (Queue.ExistingConsumerPreventsExclusive e) {
_connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, "Cannot subscribe to queue '" + queue1.getName() + "' exclusively as it already has a consumer", _channelId);
} catch (AccessControlException e) {
_connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, "Cannot subscribe to queue '" + queue1.getName() + "' permission denied", _channelId);
} catch (MessageSource.ConsumerAccessRefused consumerAccessRefused) {
_connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, "Cannot subscribe to queue '" + queue1.getName() + "' as it already has an incompatible exclusivity policy", _channelId);
} catch (MessageSource.QueueDeleted queueDeleted) {
_connection.sendConnectionClose(ErrorCodes.NOT_FOUND, "Cannot subscribe to queue '" + queue1.getName() + "' as it has been deleted", _channelId);
}
}
}
use of org.apache.qpid.server.model.NamedAddressSpace in project qpid-broker-j by apache.
the class OAuth2AuthenticationProviderImplTest method testAuthenticateViaAuthorizationCode.
public void testAuthenticateViaAuthorizationCode() throws Exception {
Map<String, OAuth2MockEndpoint> mockEndpoints = new HashMap<>();
mockEndpoints.put(TEST_TOKEN_ENDPOINT_PATH, createMockTokenEndpoint());
mockEndpoints.put(TEST_IDENTITY_RESOLVER_ENDPOINT_PATH, createMockIdentityResolverEndpoint());
_server.setEndpoints(mockEndpoints);
final NamedAddressSpace mockAddressSpace = mock(NamedAddressSpace.class);
when(mockAddressSpace.getName()).thenReturn("mock");
AuthenticationResult authenticationResult = _authProvider.authenticateViaAuthorizationCode(TEST_VALID_AUTHORIZATION_CODE, TEST_REDIRECT_URI, mockAddressSpace);
assertSuccess(authenticationResult);
}
use of org.apache.qpid.server.model.NamedAddressSpace in project qpid-broker-j by apache.
the class VirtualHostAliasTest method testPriority.
public void testPriority() {
NamedAddressSpace addressSpace = _port.getAddressSpace("blue");
assertNotNull(addressSpace);
assertEquals(_vhosts.get("blue"), addressSpace);
addressSpace = _port.getAddressSpace("black");
assertNotNull(addressSpace);
assertEquals(_vhosts.get("black"), addressSpace);
Map<String, Object> attributes = new HashMap<>();
attributes.put(VirtualHostAlias.NAME, "matcher10");
attributes.put(VirtualHostAlias.TYPE, PatternMatchingAlias.TYPE_NAME);
attributes.put(VirtualHostAlias.PRIORITY, 10);
attributes.put(PatternMatchingAlias.PATTERN, "bl.*");
attributes.put(PatternMatchingAlias.VIRTUAL_HOST_NODE, _vhosts.get("purple").getParent());
_port.createChild(VirtualHostAlias.class, attributes);
addressSpace = _port.getAddressSpace("blue");
assertNotNull(addressSpace);
assertEquals(_vhosts.get("purple"), addressSpace);
addressSpace = _port.getAddressSpace("black");
assertNotNull(addressSpace);
assertEquals(_vhosts.get("purple"), addressSpace);
attributes = new HashMap<>();
attributes.put(VirtualHostAlias.NAME, "matcher5");
attributes.put(VirtualHostAlias.TYPE, PatternMatchingAlias.TYPE_NAME);
attributes.put(VirtualHostAlias.PRIORITY, 5);
attributes.put(PatternMatchingAlias.PATTERN, ".*u.*");
attributes.put(PatternMatchingAlias.VIRTUAL_HOST_NODE, _vhosts.get("red").getParent());
_port.createChild(VirtualHostAlias.class, attributes);
addressSpace = _port.getAddressSpace("blue");
assertNotNull(addressSpace);
assertEquals(_vhosts.get("red"), addressSpace);
addressSpace = _port.getAddressSpace("black");
assertNotNull(addressSpace);
assertEquals(_vhosts.get("purple"), addressSpace);
addressSpace = _port.getAddressSpace("purple");
assertNotNull(addressSpace);
assertEquals(_vhosts.get("red"), addressSpace);
}
Aggregations