public void MethodReceived(AMQStateManager stateManager, AMQMethodEvent evt)
        {
            _logger.Debug("ConnectionClose frame received");
            ConnectionCloseBody method = (ConnectionCloseBody)evt.Method;

            int    errorCode = method.ReplyCode;
            String reason    = method.ReplyText;

            // send CloseOK
            evt.ProtocolSession.WriteFrame(ConnectionCloseOkBody.CreateAMQFrame(evt.ChannelId));

            if (errorCode != AMQConstant.REPLY_SUCCESS.Code)
            {
                if (errorCode == AMQConstant.NOT_ALLOWED.Code)
                {
                    _logger.Info("Authentication Error: " + Thread.CurrentThread.Name);
                    evt.ProtocolSession.CloseProtocolSession();

                    //todo this is a bit of a fudge (could be conssidered such as each new connection needs a new state manager or at least a fresh state.
                    stateManager.ChangeState(AMQState.CONNECTION_NOT_STARTED);

                    throw new AMQAuthenticationException(errorCode, reason);
                }
                else
                {
                    _logger.Info("Connection close received with error code " + errorCode);
                    throw new AMQConnectionClosedException(errorCode, "Error: " + reason);
                }
            }
            // this actually closes the connection in the case where it is not an error.
            evt.ProtocolSession.CloseProtocolSession();
            stateManager.ChangeState(AMQState.CONNECTION_CLOSED);
        }
Esempio n. 2
0
        public void MethodReceived(AMQStateManager stateManager, AMQMethodEvent evt)
        {
            _logger.Debug("ConnectionTune frame received");
            ConnectionTuneBody frame   = (ConnectionTuneBody)evt.Method;
            AMQProtocolSession session = evt.ProtocolSession;

            ConnectionTuneParameters parameters = session.ConnectionTuneParameters;

            if (parameters == null)
            {
                parameters = new ConnectionTuneParameters();
            }

            _logger.Debug(String.Format("ConnectionTune.heartbeat = {0}.", frame.Heartbeat));

            parameters.FrameMax              = frame.FrameMax;
            parameters.Heartbeat             = frame.Heartbeat;
            session.ConnectionTuneParameters = parameters;

            stateManager.ChangeState(AMQState.CONNECTION_NOT_OPENED);
            session.WriteFrame(ConnectionTuneOkBody.CreateAMQFrame(
                                   evt.ChannelId, frame.ChannelMax, frame.FrameMax, frame.Heartbeat));
            session.WriteFrame(ConnectionOpenBody.CreateAMQFrame(
                                   evt.ChannelId, session.AMQConnection.VirtualHost, null, true));

            if (frame.Heartbeat > 0)
            {
                evt.ProtocolSession.AMQConnection.StartHeartBeatThread(frame.Heartbeat);
            }
        }
        public void MethodReceived(AMQStateManager stateManager, AMQMethodEvent evt)
        {
            ConnectionStartBody body = (ConnectionStartBody)evt.Method;
            AMQProtocolSession  ps   = evt.ProtocolSession;

            try
            {
                if (body.Mechanisms == null)
                {
                    throw new AMQException("mechanism not specified in ConnectionStart method frame");
                }
                string mechanisms        = Encoding.UTF8.GetString(body.Mechanisms);
                string selectedMechanism = ChooseMechanism(mechanisms);
                if (selectedMechanism == null)
                {
                    throw new AMQException("No supported security mechanism found, passed: " + mechanisms);
                }

                byte[] saslResponse = DoAuthentication(selectedMechanism, ps);

                if (body.Locales == null)
                {
                    throw new AMQException("Locales is not defined in Connection Start method");
                }
                string   allLocales = Encoding.ASCII.GetString(body.Locales);
                string[] locales    = allLocales.Split(' ');
                string   selectedLocale;
                if (locales != null && locales.Length > 0)
                {
                    selectedLocale = locales[0];
                }
                else
                {
                    throw new AMQException("No locales sent from server, passed: " + locales);
                }

                stateManager.ChangeState(AMQState.CONNECTION_NOT_TUNED);
                FieldTable clientProperties = new FieldTable();
                clientProperties["product"]  = "Apache.Qpid.NET";
                clientProperties["version"]  = "1.0";
                clientProperties["platform"] = GetFullSystemInfo();
                clientProperties["instance"] = ps.ClientID;
                AMQFrame frame = ConnectionStartOkBody.CreateAMQFrame(
                    evt.ChannelId, clientProperties, selectedMechanism,
                    saslResponse, selectedLocale);
                ps.WriteFrame(frame);
            }
            catch (Exception e)
            {
                throw new AMQException(_log, "Unable to decode data: " + e, e);
            }
        }
        private void CloseConnection()
        {
            _stateManager.ChangeState(AMQState.CONNECTION_CLOSING);

            AMQFrame frame = ConnectionCloseBody.CreateAMQFrame(
                0, 200, "Qpid.NET client is closing the connection.", 0, 0);

            ProtocolWriter.Write(frame);

            _log.Debug("Blocking for connection close ok frame");

            Disconnect();
        }
        public void MethodReceived(AMQStateManager stateManager, AMQMethodEvent evt)
        {
            _logger.Debug("ConnectionCloseOk frame received");
//            ConnectionCloseOkBody method = (ConnectionCloseOkBody)evt.Method;
            stateManager.ChangeState(AMQState.CONNECTION_CLOSED);
        }
Esempio n. 6
0
 public void MethodReceived(AMQStateManager stateManager, AMQMethodEvent evt)
 {
     stateManager.ChangeState(AMQState.CONNECTION_OPEN);
 }