Package org.apache.qpid.server.protocol

Examples of org.apache.qpid.server.protocol.AMQProtocolSession


        return _instance;
    }

    public void methodReceived(AMQStateManager stateManager, AMQMethodEvent<BasicQosBody> evt) throws AMQException
    {
        AMQProtocolSession session = stateManager.getProtocolSession();
        AMQChannel channel = session.getChannel(evt.getChannelId());
        if (channel == null)
        {
            throw evt.getMethod().getChannelNotFoundException(evt.getChannelId());
        }

        channel.setPrefetchCount(evt.getMethod().prefetchCount);
        channel.setPrefetchSize(evt.getMethod().prefetchSize);

        // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
        // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
        // Be aware of possible changes to parameter order as versions change.
        session.writeFrame(BasicQosOkBody.createAMQFrame(evt.getChannelId(), (byte) 8, (byte) 0));
    }
View Full Code Here


        super(groupMgr, base(), policy);
    }

    protected void replicate(AMQStateManager stateManager, AMQMethodEvent<BasicConsumeBody> evt) throws AMQException
    {
        AMQProtocolSession session = stateManager.getProtocolSession();
        VirtualHost virtualHost = session.getVirtualHost();
        ExchangeRegistry exchangeRegistry = virtualHost.getExchangeRegistry();
        QueueRegistry queueRegistry = virtualHost.getQueueRegistry();

        //only replicate if the queue in question is a shared queue
        if (isShared(queueRegistry.getQueue(evt.getMethod().queue)))
View Full Code Here

{
    private final Logger _logger = Logger.getLogger(RemoteCancelHandler.class);

    public void methodReceived(AMQStateManager stateManager, AMQMethodEvent<BasicCancelBody> evt) throws AMQException
    {
        AMQProtocolSession session = stateManager.getProtocolSession();
        VirtualHost virtualHost = session.getVirtualHost();
        QueueRegistry queueRegistry = virtualHost.getQueueRegistry();


        //By convention, consumers setup between brokers use the queue name as the consumer tag:
        AMQQueue queue = queueRegistry.getQueue(evt.getMethod().consumerTag);
View Full Code Here

    {
    }

    public void methodReceived(AMQStateManager stateManager, AMQMethodEvent<ConnectionStartOkBody> evt) throws AMQException
    {
        AMQProtocolSession session = stateManager.getProtocolSession();
        final ConnectionStartOkBody body = evt.getMethod();
        _logger.info("SASL Mechanism selected: " + body.mechanism);
        _logger.info("Locale selected: " + body.locale);

        AuthenticationManager authMgr = ApplicationRegistry.getInstance().getAuthenticationManager();//session.getVirtualHost().getAuthenticationManager();

        SaslServer ss = null;
        try
        {                      
            ss = authMgr.createSaslServer(String.valueOf(body.mechanism), session.getLocalFQDN());

            if (ss == null)
            {
                throw body.getConnectionException(AMQConstant.RESOURCE_ERROR, "Unable to create SASL Server:" + body.mechanism
                );
            }

            session.setSaslServer(ss);

            AuthenticationResult authResult = authMgr.authenticate(ss, body.response);

            //save clientProperties
            if (session.getClientProperties() == null)
            {
                session.setClientProperties(body.clientProperties);
            }

            switch (authResult.status)
            {
                case ERROR:
                    _logger.info("Authentication failed");
                    stateManager.changeState(AMQState.CONNECTION_CLOSING);
                    // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
                    // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
                    // Be aware of possible changes to parameter order as versions change.
                    AMQFrame close = ConnectionCloseBody.createAMQFrame(0,
                                                                        (byte) 8, (byte) 0,    // AMQP version (major, minor)
                                                                        ConnectionCloseBody.getClazz((byte) 8, (byte) 0),        // classId
                                                                        ConnectionCloseBody.getMethod((byte) 8, (byte) 0),    // methodId
                                                                        AMQConstant.NOT_ALLOWED.getCode(),    // replyCode
                                                                        AMQConstant.NOT_ALLOWED.getName());    // replyText
                    session.writeFrame(close);
                    disposeSaslServer(session);
                    break;

                case SUCCESS:
                    _logger.info("Connected as: " + ss.getAuthorizationID());
                    session.setAuthorizedID(new UsernamePrincipal(ss.getAuthorizationID()));

                    stateManager.changeState(AMQState.CONNECTION_NOT_TUNED);
                    // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
                    // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
                    // Be aware of possible changes to parameter order as versions change.
                    AMQFrame tune = ConnectionTuneBody.createAMQFrame(0,
                                                                      (byte) 8, (byte) 0,    // AMQP version (major, minor)
                                                                      Integer.MAX_VALUE,    // channelMax
                                                                      getConfiguredFrameSize(),    // frameMax
                                                                      HeartbeatConfig.getInstance().getDelay());    // heartbeat
                    session.writeFrame(tune);
                    break;
                case CONTINUE:
                    stateManager.changeState(AMQState.CONNECTION_NOT_AUTH);
                    // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
                    // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
                    // Be aware of possible changes to parameter order as versions change.
                    AMQFrame challenge = ConnectionSecureBody.createAMQFrame(0,
                                                                             (byte) 8, (byte) 0,    // AMQP version (major, minor)
                                                                             authResult.challenge);    // challenge
                    session.writeFrame(challenge);
            }
        }
        catch (SaslException e)
        {
            disposeSaslServer(session);
View Full Code Here

        Configurator.configure(this);
    }

    public void methodReceived(AMQStateManager stateManager, AMQMethodEvent<QueueDeclareBody> evt) throws AMQException
    {
        AMQProtocolSession session = stateManager.getProtocolSession();
        VirtualHost virtualHost = session.getVirtualHost();
        ExchangeRegistry exchangeRegistry = virtualHost.getExchangeRegistry();
        QueueRegistry queueRegistry = virtualHost.getQueueRegistry();
        MessageStore store = virtualHost.getMessageStore();

        QueueDeclareBody body = evt.getMethod();

        // if we aren't given a queue name, we create one which we return to the client
        if (body.queue == null)
        {
            body.queue = createName();
        }

        AMQQueue queue;
        //TODO: do we need to check that the queue already exists with exactly the same "configuration"?

        synchronized (queueRegistry)
        {



            if (((queue = queueRegistry.getQueue(body.queue)) == null))
            {
                if(body.queue != null)
                {
                    body.queue = body.queue.intern();
                }

                if (body.passive)
                {
                    String msg = "Queue: " + body.queue + " not found on VirtualHost(" + virtualHost + ").";
                    throw body.getChannelException(AMQConstant.NOT_FOUND, msg);
                }
                else
                {
                    queue = createQueue(body, virtualHost, session);
                    if (queue.isDurable() && !queue.isAutoDelete())
                    {
                        store.createQueue(queue);
                    }
                    queueRegistry.registerQueue(queue);
                    if (autoRegister)
                    {
                        Exchange defaultExchange = exchangeRegistry.getDefaultExchange();

                        queue.bind(body.queue, null, defaultExchange);
                        _log.info("Queue " + body.queue + " bound to default exchange(" + defaultExchange.getName() + ")");
                    }
                }
            }
            else if (queue.getOwner() != null && !session.getContextKey().equals(queue.getOwner()))
            {
                throw body.getChannelException(AMQConstant.ALREADY_EXISTS, "Cannot declare queue('" + body.queue + "'),"
                                                                           + " as exclusive queue with same name "
                                                                           + "declared on another client ID('"
                                                                           + queue.getOwner() + "')");
            }

            AMQChannel channel = session.getChannel(evt.getChannelId());

            if (channel == null)
            {
                throw body.getChannelNotFoundException(evt.getChannelId());
            }

            //set this as the default queue on the channel:
            channel.setDefaultQueue(queue);
        }

        if (!body.nowait)
        {
            // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
            // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
            // Be aware of possible changes to parameter order as versions change.
            AMQFrame response = QueueDeclareOkBody.createAMQFrame(evt.getChannelId(),
                                                                  (byte) 8, (byte) 0,    // AMQP version (major, minor)
                                                                  queue.getConsumerCount(), // consumerCount
                                                                  queue.getMessageCount(), // messageCount
                                                                  body.queue); // queue
            _log.info("Queue " + body.queue + " declared successfully");
            session.writeFrame(response);
        }
    }
View Full Code Here

    {
    }

    public void methodReceived(AMQStateManager stateManager, AMQMethodEvent<ExchangeDeclareBody> evt) throws AMQException
    {
        AMQProtocolSession session = stateManager.getProtocolSession();
        VirtualHost virtualHost = session.getVirtualHost();
        ExchangeRegistry exchangeRegistry = virtualHost.getExchangeRegistry();
        ExchangeFactory exchangeFactory = virtualHost.getExchangeFactory();
       
        final ExchangeDeclareBody body = evt.getMethod();
        if (_logger.isDebugEnabled())
        {
            _logger.debug("Request to declare exchange of type " + body.type + " with name " + body.exchange);
        }
        synchronized(exchangeRegistry)
        {
            Exchange exchange = exchangeRegistry.getExchange(body.exchange);



            if (exchange == null)
            {
                if(body.passive && ((body.type == null) || body.type.length() ==0))
                {
                    throw body.getChannelException(AMQConstant.NOT_FOUND, "Unknown exchange: " + body.exchange);                   
                }
                else
                {
                    try
                    {

                    exchange = exchangeFactory.createExchange(body.exchange == null ? null : body.exchange.intern(),
                                                              body.type == null ? null : body.type.intern(),
                                                              body.durable,
                                                              body.passive, body.ticket);
                    exchangeRegistry.registerExchange(exchange);
                    }
                    catch(AMQUnknownExchangeType e)
                    {
                        throw body.getConnectionException(AMQConstant.COMMAND_INVALID, "Unknown exchange: " + body.exchange,e);
                    }
                }
            }
            else if (!exchange.getType().equals(body.type))
            {

                throw new AMQConnectionException(AMQConstant.NOT_ALLOWED, "Attempt to redeclare exchange: " + body.exchange + " of type " + exchange.getType() + " to " + body.type +".",body.getClazz(), body.getMethod(),body.getMajor(),body.getMinor());   
            }

        }
        if(!body.nowait)
        {
            // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
            // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
            // Be aware of possible changes to parameter order as versions change.
            AMQFrame response = ExchangeDeclareOkBody.createAMQFrame(evt.getChannelId(), (byte)8, (byte)0);
            session.writeFrame(response);
        }
    }
View Full Code Here

    }

    public void methodReceived(AMQStateManager stateManager, AMQMethodEvent<QueueDeleteBody> evt) throws AMQException
    {
        AMQProtocolSession session = stateManager.getProtocolSession();
        VirtualHost virtualHost = session.getVirtualHost();
        QueueRegistry queueRegistry = virtualHost.getQueueRegistry();
        MessageStore store = virtualHost.getMessageStore();

        QueueDeleteBody body = evt.getMethod();
        AMQQueue queue;
        if (body.queue == null)
        {
            AMQChannel channel = session.getChannel(evt.getChannelId());

            if (channel == null)
            {
                throw body.getChannelNotFoundException(evt.getChannelId());
            }

            //get the default queue on the channel:           
            queue = channel.getDefaultQueue();
        }
        else
        {
            queue = queueRegistry.getQueue(body.queue);
        }

        if (queue == null)
        {
            if (_failIfNotFound)
            {
                throw body.getChannelException(AMQConstant.NOT_FOUND, "Queue " + body.queue + " does not exist.");
            }
        }
        else
        {
            if (body.ifEmpty && !queue.isEmpty())
            {
                throw body.getChannelException(AMQConstant.IN_USE, "Queue: " + body.queue + " is not empty.");
            }
            else if (body.ifUnused && !queue.isUnused())
            {
                // TODO - Error code
                throw body.getChannelException(AMQConstant.IN_USE, "Queue: " + body.queue + " is still used.");

            }
            else
            {
                int purged = queue.delete(body.ifUnused, body.ifEmpty);

                if (queue.isDurable())
                {
                    store.removeQueue(queue.getName());
                }
               
                // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
                // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
                // Be aware of possible changes to parameter order as versions change.
                session.writeFrame(QueueDeleteOkBody.createAMQFrame(evt.getChannelId(),
                                                                    (byte) 8, (byte) 0,    // AMQP version (major, minor)
                                                                    purged));    // messageCount
            }
        }
    }
View Full Code Here

    {
    }

    public void methodReceived(AMQStateManager stateManager, AMQMethodEvent<ConnectionSecureOkBody> evt) throws AMQException
    {
        AMQProtocolSession session = stateManager.getProtocolSession();
        ConnectionSecureOkBody body = evt.getMethod();

        //fixme Vhost not defined yet
        //session.getVirtualHost().getAuthenticationManager();
        AuthenticationManager authMgr = ApplicationRegistry.getInstance().getAuthenticationManager();

        SaslServer ss = session.getSaslServer();
        if (ss == null)
        {
            throw new AMQException("No SASL context set up in session");
        }

        AuthenticationResult authResult = authMgr.authenticate(ss, body.response);
        switch (authResult.status)
        {
            case ERROR:
                // Can't do this as we violate protocol. Need to send Close
                // throw new AMQException(AMQConstant.NOT_ALLOWED.getCode(), AMQConstant.NOT_ALLOWED.getName());
                _logger.info("Authentication failed");
                stateManager.changeState(AMQState.CONNECTION_CLOSING);
                // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
                // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
                // Be aware of possible changes to parameter order as versions change.
                AMQFrame close = ConnectionCloseBody.createAMQFrame(0,
                    (byte)8, (byte)0// AMQP version (major, minor)
                    ConnectionCloseBody.getClazz((byte)8, (byte)0),    // classId
                    ConnectionCloseBody.getMethod((byte)8, (byte)0)// methodId
                    AMQConstant.NOT_ALLOWED.getCode()// replyCode
                    AMQConstant.NOT_ALLOWED.getName())// replyText
                session.writeFrame(close);
                disposeSaslServer(session);
                break;
            case SUCCESS:
                _logger.info("Connected as: " + ss.getAuthorizationID());
                stateManager.changeState(AMQState.CONNECTION_NOT_TUNED);
                // TODO: Check the value of channelMax here: This should be the max
                // value of a 2-byte unsigned integer (as channel is only 2 bytes on the wire),
                // not Integer.MAX_VALUE (which is signed 4 bytes).
                // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
                // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
                // Be aware of possible changes to parameter order as versions change.
                AMQFrame tune = ConnectionTuneBody.createAMQFrame(0,
                    (byte)8, (byte)0// AMQP version (major, minor)
                    Integer.MAX_VALUE,  // channelMax
                    ConnectionStartOkMethodHandler.getConfiguredFrameSize()// frameMax
                    HeartbeatConfig.getInstance().getDelay())// heartbeat
                session.writeFrame(tune);
                session.setAuthorizedID(new UsernamePrincipal(ss.getAuthorizationID()));               
                disposeSaslServer(session);
                break;
            case CONTINUE:
                stateManager.changeState(AMQState.CONNECTION_NOT_AUTH);
                // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
                // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
                // Be aware of possible changes to parameter order as versions change.
                AMQFrame challenge = ConnectionSecureBody.createAMQFrame(0,
                    (byte)8, (byte)0// AMQP version (major, minor)
                    authResult.challenge)// challenge
                session.writeFrame(challenge);
        }
    }
View Full Code Here

        return _instance;
    }

    public void methodReceived(AMQStateManager stateManager, AMQMethodEvent<BasicRecoverBody> evt) throws AMQException
    {
        AMQProtocolSession session = stateManager.getProtocolSession();

        _logger.debug("Recover received on protocol session " + session + " and channel " + evt.getChannelId());
        AMQChannel channel = session.getChannel(evt.getChannelId());
        BasicRecoverBody body = evt.getMethod();

        if (channel == null)
        {
            throw body.getChannelNotFoundException(evt.getChannelId());
        }

        channel.resend(body.requeue);

        // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
        // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
        // Be aware of possible changes to parameter order as versions change.
        session.writeFrame(BasicRecoverOkBody.createAMQFrame(evt.getChannelId(), (byte) 8, (byte) 0));
    }
View Full Code Here

        return _instance;
    }

    public void methodReceived(AMQStateManager stateManager, AMQMethodEvent<ConnectionTuneOkBody> evt) throws AMQException
    {
        AMQProtocolSession session = stateManager.getProtocolSession();
        ConnectionTuneOkBody body = evt.getMethod();
        if (_logger.isDebugEnabled())
        {
            _logger.debug(body);
        }
        stateManager.changeState(AMQState.CONNECTION_NOT_OPENED);
        session.initHeartbeats(body.heartbeat);
    }
View Full Code Here

TOP

Related Classes of org.apache.qpid.server.protocol.AMQProtocolSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.