use of org.apache.qpid.server.virtualhost.NoopConnectionEstablishmentPolicy in project qpid-broker-j by apache.
the class ServerConnection method setVirtualHost.
public void setVirtualHost(NamedAddressSpace addressSpace) {
addressSpace.registerConnection(_amqpConnection, new NoopConnectionEstablishmentPolicy());
_amqpConnection.setAddressSpace(addressSpace);
}
use of org.apache.qpid.server.virtualhost.NoopConnectionEstablishmentPolicy in project qpid-broker-j by apache.
the class AMQPConnection_0_8Impl method receiveConnectionOpen.
@Override
public void receiveConnectionOpen(AMQShortString virtualHostName, AMQShortString capabilities, boolean insist) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("RECV ConnectionOpen[" + " virtualHost: " + virtualHostName + " capabilities: " + capabilities + " insist: " + insist + " ]");
}
assertState(ConnectionState.AWAIT_OPEN);
String virtualHostStr = AMQShortString.toString(virtualHostName);
if ((virtualHostStr != null) && virtualHostStr.charAt(0) == '/') {
virtualHostStr = virtualHostStr.substring(1);
}
NamedAddressSpace addressSpace = ((AmqpPort) getPort()).getAddressSpace(virtualHostStr);
if (addressSpace == null) {
sendConnectionClose(ErrorCodes.NOT_FOUND, "Unknown virtual host: '" + virtualHostName + "'", 0);
} else {
// Check virtualhost access
if (!addressSpace.isActive()) {
String redirectHost = addressSpace.getRedirectHost(getPort());
if (redirectHost != null) {
sendConnectionClose(0, new AMQFrame(0, new ConnectionRedirectBody(getProtocolVersion(), AMQShortString.valueOf(redirectHost), null)));
} else {
sendConnectionClose(ErrorCodes.CONNECTION_FORCED, "Virtual host '" + addressSpace.getName() + "' is not active", 0);
}
} else {
try {
addressSpace.registerConnection(this, new NoopConnectionEstablishmentPolicy());
setAddressSpace(addressSpace);
if (addressSpace.authoriseCreateConnection(this)) {
MethodRegistry methodRegistry = getMethodRegistry();
AMQMethodBody responseBody = methodRegistry.createConnectionOpenOkBody(virtualHostName);
writeFrame(responseBody.generateFrame(0));
_state = ConnectionState.OPEN;
} else {
sendConnectionClose(ErrorCodes.ACCESS_REFUSED, "Connection refused", 0);
}
} catch (AccessControlException | VirtualHostUnavailableException e) {
sendConnectionClose(ErrorCodes.ACCESS_REFUSED, e.getMessage(), 0);
}
}
}
}
use of org.apache.qpid.server.virtualhost.NoopConnectionEstablishmentPolicy in project qpid-broker-j by apache.
the class VirtualHostTest method testDeleteVirtualHost_ClosesConnections.
public void testDeleteVirtualHost_ClosesConnections() {
String virtualHostName = getName();
QueueManagingVirtualHost<?> virtualHost = createVirtualHost(virtualHostName);
assertEquals("Unexpected state", State.ACTIVE, virtualHost.getState());
AbstractAMQPConnection connection = createMockProtocolConnection(virtualHost);
assertEquals("Unexpected number of connections before connection registered", 0, virtualHost.getConnectionCount());
AMQPConnection modelConnection = mock(AMQPConnection.class);
when(modelConnection.closeAsync()).thenReturn(Futures.immediateFuture(null));
virtualHost.registerConnection(modelConnection, new NoopConnectionEstablishmentPolicy());
assertEquals("Unexpected number of connections after connection registered", 1, virtualHost.getConnectionCount());
virtualHost.delete();
assertEquals("Unexpected state", State.DELETED, virtualHost.getState());
assertEquals("Unexpected number of connections after virtualhost deleted", 0, virtualHost.getConnectionCount());
verify(modelConnection).closeAsync();
}
Aggregations