Search in sources :

Example 6 with NoopConnectionEstablishmentPolicy

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);
}
Also used : NoopConnectionEstablishmentPolicy(org.apache.qpid.server.virtualhost.NoopConnectionEstablishmentPolicy)

Example 7 with NoopConnectionEstablishmentPolicy

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);
            }
        }
    }
}
Also used : VirtualHostUnavailableException(org.apache.qpid.server.virtualhost.VirtualHostUnavailableException) NoopConnectionEstablishmentPolicy(org.apache.qpid.server.virtualhost.NoopConnectionEstablishmentPolicy) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) AccessControlException(java.security.AccessControlException) AmqpPort(org.apache.qpid.server.model.port.AmqpPort)

Example 8 with NoopConnectionEstablishmentPolicy

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();
}
Also used : AbstractAMQPConnection(org.apache.qpid.server.transport.AbstractAMQPConnection) AMQPConnection(org.apache.qpid.server.transport.AMQPConnection) AbstractAMQPConnection(org.apache.qpid.server.transport.AbstractAMQPConnection) NoopConnectionEstablishmentPolicy(org.apache.qpid.server.virtualhost.NoopConnectionEstablishmentPolicy) Matchers.anyString(org.mockito.Matchers.anyString)

Aggregations

NoopConnectionEstablishmentPolicy (org.apache.qpid.server.virtualhost.NoopConnectionEstablishmentPolicy)8 AbstractAMQPConnection (org.apache.qpid.server.transport.AbstractAMQPConnection)3 AMQPConnection (org.apache.qpid.server.transport.AMQPConnection)2 VirtualHostUnavailableException (org.apache.qpid.server.virtualhost.VirtualHostUnavailableException)2 Matchers.anyString (org.mockito.Matchers.anyString)2 AccessControlException (java.security.AccessControlException)1 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)1 AmqpPort (org.apache.qpid.server.model.port.AmqpPort)1 EventListener (org.apache.qpid.server.store.EventListener)1