Search in sources :

Example 1 with AmqpPort

use of org.apache.qpid.server.model.port.AmqpPort in project qpid-broker-j by apache.

the class ServerSessionTest method testOverlargeMessageTest.

public void testOverlargeMessageTest() throws Exception {
    final Broker<?> broker = mock(Broker.class);
    when(broker.getContextValue(eq(Long.class), eq(Broker.CHANNEL_FLOW_CONTROL_ENFORCEMENT_TIMEOUT))).thenReturn(0l);
    AmqpPort port = createMockPort();
    final AMQPConnection_0_10 modelConnection = mock(AMQPConnection_0_10.class);
    when(modelConnection.getCategoryClass()).thenReturn(Connection.class);
    when(modelConnection.getTypeClass()).thenReturn(AMQPConnection_0_10.class);
    when(modelConnection.closeAsync()).thenReturn(Futures.immediateFuture(null));
    when(modelConnection.getAddressSpace()).thenReturn(_virtualHost);
    when(modelConnection.getContextProvider()).thenReturn(_virtualHost);
    when(modelConnection.getBroker()).thenReturn(broker);
    when(modelConnection.getEventLogger()).thenReturn(mock(EventLogger.class));
    when(modelConnection.getContextValue(Long.class, Session.PRODUCER_AUTH_CACHE_TIMEOUT)).thenReturn(Session.PRODUCER_AUTH_CACHE_TIMEOUT_DEFAULT);
    when(modelConnection.getContextValue(Integer.class, Session.PRODUCER_AUTH_CACHE_SIZE)).thenReturn(Session.PRODUCER_AUTH_CACHE_SIZE_DEFAULT);
    when(modelConnection.getContextValue(Long.class, Connection.MAX_UNCOMMITTED_IN_MEMORY_SIZE)).thenReturn(Connection.DEFAULT_MAX_UNCOMMITTED_IN_MEMORY_SIZE);
    when(modelConnection.getChildExecutor()).thenReturn(_taskExecutor);
    when(modelConnection.getModel()).thenReturn(BrokerModel.getInstance());
    when(modelConnection.getPort()).thenReturn(port);
    Subject subject = new Subject();
    when(modelConnection.getSubject()).thenReturn(subject);
    when(modelConnection.getMaxMessageSize()).thenReturn(1024l);
    ServerConnection connection = new ServerConnection(1, broker, port, Transport.TCP, modelConnection);
    connection.setVirtualHost(_virtualHost);
    final List<Method> invokedMethods = new ArrayList<>();
    ServerSession session = new ServerSession(connection, new ServerSessionDelegate(), new Binary(getName().getBytes()), 0) {

        @Override
        public void invoke(final Method m) {
            invokedMethods.add(m);
        }
    };
    Session_0_10 modelSession = new Session_0_10(modelConnection, 1, session);
    session.setModelObject(modelSession);
    ServerSessionDelegate delegate = new ServerSessionDelegate();
    MessageTransfer xfr = new MessageTransfer();
    byte[] body1 = new byte[2048];
    xfr.setBody(QpidByteBuffer.wrap(body1));
    delegate.messageTransfer(session, xfr);
    assertFalse("No methods invoked - expecting at least 1", invokedMethods.isEmpty());
    Method firstInvoked = invokedMethods.get(0);
    assertTrue("First invoked method not execution error", firstInvoked instanceof ExecutionException);
    assertEquals(ExecutionErrorCode.RESOURCE_LIMIT_EXCEEDED, ((ExecutionException) firstInvoked).getErrorCode());
    invokedMethods.clear();
    // test the boundary condition
    byte[] body = new byte[1024];
    xfr.setBody(QpidByteBuffer.wrap(body));
    delegate.messageTransfer(session, xfr);
    assertTrue("Methods invoked when not expecting any", invokedMethods.isEmpty());
}
Also used : EventLogger(org.apache.qpid.server.logging.EventLogger) ArrayList(java.util.ArrayList) Method(org.apache.qpid.server.protocol.v0_10.transport.Method) Subject(javax.security.auth.Subject) AmqpPort(org.apache.qpid.server.model.port.AmqpPort) Binary(org.apache.qpid.server.protocol.v0_10.transport.Binary) ExecutionException(org.apache.qpid.server.protocol.v0_10.transport.ExecutionException) MessageTransfer(org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer)

Example 2 with AmqpPort

use of org.apache.qpid.server.model.port.AmqpPort in project qpid-broker-j by apache.

the class ServerConnectionDelegate method connectionOpen.

@Override
public void connectionOpen(ServerConnection sconn, ConnectionOpen open) {
    assertState(sconn, ConnectionState.AWAIT_OPEN);
    NamedAddressSpace addressSpace;
    String vhostName;
    if (open.hasVirtualHost()) {
        vhostName = open.getVirtualHost();
    } else {
        vhostName = "";
    }
    AmqpPort port = sconn.getPort();
    addressSpace = port.getAddressSpace(vhostName);
    if (addressSpace != null) {
        if (!addressSpace.isActive()) {
            sconn.setState(ServerConnection.State.CLOSING);
            final String redirectHost = addressSpace.getRedirectHost(port);
            if (redirectHost == null) {
                sconn.sendConnectionClose(ConnectionCloseCode.CONNECTION_FORCED, "Virtual host '" + vhostName + "' is not active");
            } else {
                sconn.invoke(new ConnectionRedirect(redirectHost, new ArrayList<Object>()));
            }
            return;
        }
        try {
            sconn.setVirtualHost(addressSpace);
            if (!addressSpace.authoriseCreateConnection(sconn.getAmqpConnection())) {
                sconn.setState(ServerConnection.State.CLOSING);
                sconn.sendConnectionClose(ConnectionCloseCode.CONNECTION_FORCED, "Connection not authorized");
                return;
            }
        } catch (AccessControlException | VirtualHostUnavailableException e) {
            sconn.setState(ServerConnection.State.CLOSING);
            sconn.sendConnectionClose(ConnectionCloseCode.CONNECTION_FORCED, e.getMessage());
            return;
        }
        sconn.setState(ServerConnection.State.OPEN);
        _state = ConnectionState.OPEN;
        sconn.invoke(new ConnectionOpenOk(Collections.emptyList()));
    } else {
        sconn.setState(ServerConnection.State.CLOSING);
        sconn.sendConnectionClose(ConnectionCloseCode.INVALID_PATH, "Unknown virtualhost '" + vhostName + "'");
    }
}
Also used : VirtualHostUnavailableException(org.apache.qpid.server.virtualhost.VirtualHostUnavailableException) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) ArrayList(java.util.ArrayList) AccessControlException(java.security.AccessControlException) AmqpPort(org.apache.qpid.server.model.port.AmqpPort)

Example 3 with AmqpPort

use of org.apache.qpid.server.model.port.AmqpPort in project qpid-broker-j by apache.

the class ServerSessionTest method createMockPort.

public AmqpPort createMockPort() {
    AmqpPort port = mock(AmqpPort.class);
    TaskExecutor childExecutor = new TaskExecutorImpl();
    childExecutor.start();
    when(port.getChildExecutor()).thenReturn(childExecutor);
    when(port.getCategoryClass()).thenReturn(Port.class);
    when(port.getModel()).thenReturn(BrokerModel.getInstance());
    return port;
}
Also used : CurrentThreadTaskExecutor(org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor) TaskExecutor(org.apache.qpid.server.configuration.updater.TaskExecutor) TaskExecutorImpl(org.apache.qpid.server.configuration.updater.TaskExecutorImpl) AmqpPort(org.apache.qpid.server.model.port.AmqpPort)

Example 4 with AmqpPort

use of org.apache.qpid.server.model.port.AmqpPort 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)

Aggregations

AmqpPort (org.apache.qpid.server.model.port.AmqpPort)4 AccessControlException (java.security.AccessControlException)2 ArrayList (java.util.ArrayList)2 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)2 VirtualHostUnavailableException (org.apache.qpid.server.virtualhost.VirtualHostUnavailableException)2 Subject (javax.security.auth.Subject)1 CurrentThreadTaskExecutor (org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor)1 TaskExecutor (org.apache.qpid.server.configuration.updater.TaskExecutor)1 TaskExecutorImpl (org.apache.qpid.server.configuration.updater.TaskExecutorImpl)1 EventLogger (org.apache.qpid.server.logging.EventLogger)1 Binary (org.apache.qpid.server.protocol.v0_10.transport.Binary)1 ExecutionException (org.apache.qpid.server.protocol.v0_10.transport.ExecutionException)1 MessageTransfer (org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer)1 Method (org.apache.qpid.server.protocol.v0_10.transport.Method)1 NoopConnectionEstablishmentPolicy (org.apache.qpid.server.virtualhost.NoopConnectionEstablishmentPolicy)1