Package org.apache.qpid.client.protocol

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


    }

    public void methodReceived(AMQStateManager stateManager, BasicDeliverBody body, int channelId)
        throws AMQException
    {
        final AMQProtocolSession session = stateManager.getProtocolSession();
        final UnprocessedMessage msg = new UnprocessedMessage.UnprocessedDeliverMessage(body);
        _logger.debug("New JmsDeliver method received");
        session.unprocessedMessageReceived(channelId, msg);
    }
View Full Code Here


    { }

    public void methodReceived(AMQStateManager stateManager, BasicCancelOkBody body, int channelId)
        throws AMQException
    {
        AMQProtocolSession session = stateManager.getProtocolSession();



        if (_logger.isInfoEnabled())
        {
            _logger.info("New BasicCancelOk method received for consumer:" + body.getConsumerTag());
        }

        session.confirmConsumerCancelled(channelId, body.getConsumerTag());
    }
View Full Code Here

    public void methodReceived(AMQStateManager stateManager, ChannelCloseBody method, int channelId)
        throws AMQException
    {
        _logger.debug("ChannelClose method received");
        final AMQProtocolSession session = stateManager.getProtocolSession();


        AMQConstant errorCode = AMQConstant.getConstant(method.getReplyCode());
        AMQShortString reason = method.getReplyText();
        if (_logger.isDebugEnabled())
        {
            _logger.debug("Channel close reply code: " + errorCode + ", reason: " + reason);
        }



        ChannelCloseOkBody body = session.getMethodRegistry().createChannelCloseOkBody();
        AMQFrame frame = body.generateFrame(channelId);
        session.writeFrame(frame);

        if (errorCode != AMQConstant.REPLY_SUCCESS)
        {
            if (_logger.isDebugEnabled())
            {
                _logger.debug("Channel close received with errorCode " + errorCode + ", and reason " + reason);
            }

            if (errorCode == AMQConstant.NO_CONSUMERS)
            {
                throw new AMQNoConsumersException("Error: " + reason, null);
            }
            else if (errorCode == AMQConstant.NO_ROUTE)
            {
                throw new AMQNoRouteException("Error: " + reason, null);
            }
            else if (errorCode == AMQConstant.INVALID_ARGUMENT)
            {
                _logger.debug("Broker responded with Invalid Argument.");

                throw new org.apache.qpid.AMQInvalidArgumentException(String.valueOf(reason));
            }
            else if (errorCode == AMQConstant.INVALID_ROUTING_KEY)
            {
                _logger.debug("Broker responded with Invalid Routing Key.");

                throw new AMQInvalidRoutingKeyException(String.valueOf(reason));
            }
            else
            {
                throw new AMQChannelClosedException(errorCode, "Error: " + reason);
            }

        }
        // fixme why is this only done when the close is expected...
        // should the above forced closes not also cause a close?
        // ----------
        // Closing the session only when it is expected allows the errors to be processed
        // Calling this here will prevent failover. So we should do this for all exceptions
        // that should never cause failover. Such as authentication errors.

        session.channelClosed(channelId, errorCode, String.valueOf(reason));
    }
View Full Code Here

    public void methodReceived(AMQStateManager stateManager, ConnectionRedirectBody method, int channelId)
            throws AMQException
    {
        _logger.info("ConnectionRedirect frame received");
        final AMQProtocolSession session = stateManager.getProtocolSession();        

        String host = method.getHost().toString();
        // the host is in the form hostname:port with the port being optional
        int portIndex = host.indexOf(':');

        int port;
        if (portIndex == -1)
        {
            port = DEFAULT_REDIRECT_PORT;
        }
        else
        {
            port = Integer.parseInt(host.substring(portIndex + 1));
            host = host.substring(0, portIndex);

        }

        session.failover(host, port);
    }
View Full Code Here

public void methodReceived(AMQStateManager stateManager, BasicReturnBody body, int channelId)
        throws AMQException
    {
        _logger.debug("New JmsBounce method received");
        final AMQProtocolSession session = stateManager.getProtocolSession();
        final UnprocessedMessage msg = new UnprocessedMessage.UnprocessedBouncedMessage(body);

        session.unprocessedMessageReceived(channelId, msg);
    }
View Full Code Here

    public void methodReceived(AMQStateManager stateManager, ConnectionTuneBody frame, int channelId)
                throws AMQException
    {
        _logger.debug("ConnectionTune frame received");
        final AMQProtocolSession session = stateManager.getProtocolSession();
        final MethodRegistry methodRegistry = session.getMethodRegistry();


        ConnectionTuneParameters params = session.getConnectionTuneParameters();
        if (params == null)
        {
            params = new ConnectionTuneParameters();
        }

        params.setFrameMax(frame.getFrameMax());
        params.setChannelMax(frame.getChannelMax());
        params.setHeartbeat(Integer.getInteger("amqj.heartbeat.delay", frame.getHeartbeat()));
        session.setConnectionTuneParameters(params);

        stateManager.changeState(AMQState.CONNECTION_NOT_OPENED);

        ConnectionTuneOkBody tuneOkBody = methodRegistry.createConnectionTuneOkBody(params.getChannelMax(),
                                                                                    params.getFrameMax(),
                                                                                    params.getHeartbeat());
        // Be aware of possible changes to parameter order as versions change.
        session.writeFrame(tuneOkBody.generateFrame(channelId));

        String host = session.getAMQConnection().getVirtualHost();
        AMQShortString virtualHost = new AMQShortString("/" + host);

        ConnectionOpenBody openBody = methodRegistry.createConnectionOpenBody(virtualHost,null,true);

        // Be aware of possible changes to parameter order as versions change.
        session.writeFrame(openBody.generateFrame(channelId));
    }
View Full Code Here

    public void methodReceived(AMQStateManager stateManager,  ChannelCloseOkBody method, int channelId)
        throws AMQException
    {
        _logger.info("Received channel-close-ok for channel-id " + channelId);

        final AMQProtocolSession session = stateManager.getProtocolSession();
        // todo this should do the local closure
    }
View Full Code Here

            throws AMQException
    {
        _log.debug("public void methodReceived(AMQStateManager stateManager, AMQProtocolSession protocolSession, "
            + "AMQMethodEvent evt): called");

        final AMQProtocolSession session = stateManager.getProtocolSession();


        ProtocolVersion pv = new ProtocolVersion((byte) body.getVersionMajor(), (byte) body.getVersionMinor());

        // For the purposes of interop, we can make the client accept the broker's version string.
        // If it does, it then internally records the version as being the latest one that it understands.
        // It needs to do this since frame lookup is done by version.
        if (Boolean.getBoolean("qpid.accept.broker.version") && !pv.isSupported())
        {

            pv = ProtocolVersion.getLatestSupportedVersion();
        }

        if (pv.isSupported())
        {
            session.setProtocolVersion(pv);

            try
            {
                // Used to hold the SASL mechanism to authenticate with.
                String mechanism;

                if (body.getMechanisms()== null)
                {
                    throw new AMQException("mechanism not specified in ConnectionStart method frame");
                }
                else
                {
                    mechanism = chooseMechanism(body.getMechanisms());
                    _log.debug("mechanism = " + mechanism);
                }

                if (mechanism == null)
                {
                    throw new AMQException("No supported security mechanism found, passed: " + new String(body.getMechanisms()));
                }

                byte[] saslResponse;
                try
                {
                    SaslClient sc =
                        Sasl.createSaslClient(new String[] { mechanism }, null, "AMQP", "localhost", null,
                            createCallbackHandler(mechanism, session));
                    if (sc == null)
                    {
                        throw new AMQException(
                            "Client SASL configuration error: no SaslClient could be created for mechanism " + mechanism
                            + ". Please ensure all factories are registered. See DynamicSaslRegistrar for "
                            + " details of how to register non-standard SASL client providers.");
                    }

                    session.setSaslClient(sc);
                    saslResponse = (sc.hasInitialResponse() ? sc.evaluateChallenge(new byte[0]) : null);
                }
                catch (SaslException e)
                {
                    session.setSaslClient(null);
                    throw new AMQException("Unable to create SASL client: " + e, e);
                }

                if (body.getLocales() == null)
                {
                    throw new AMQException("Locales is not defined in Connection Start method");
                }

                final String locales = new String(body.getLocales(), "utf8");
                final StringTokenizer tokenizer = new StringTokenizer(locales, " ");
                String selectedLocale = null;
                if (tokenizer.hasMoreTokens())
                {
                    selectedLocale = tokenizer.nextToken();
                }
                else
                {
                    throw new AMQException("No locales sent from server, passed: " + locales);
                }

                stateManager.changeState(AMQState.CONNECTION_NOT_TUNED);
                FieldTable clientProperties = FieldTableFactory.newFieldTable();

                clientProperties.setString(new AMQShortString(ClientProperties.instance.toString()),
                    session.getClientID());
                clientProperties.setString(new AMQShortString(ClientProperties.product.toString()),
                    QpidProperties.getProductName());
                clientProperties.setString(new AMQShortString(ClientProperties.version.toString()),
                    QpidProperties.getReleaseVersion());
                clientProperties.setString(new AMQShortString(ClientProperties.platform.toString()), getFullSystemInfo());


                ConnectionStartOkBody connectionStartOkBody = session.getMethodRegistry().createConnectionStartOkBody(clientProperties,new AMQShortString(mechanism),saslResponse,new AMQShortString(locales));
                // 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(connectionStartOkBody.generateFrame(channelId));
                       
            }
            catch (UnsupportedEncodingException e)
            {
                throw new AMQException("Unable to decode data: " + e, e);
            }
        }
        else
        {
            _log.error("Broker requested Protocol [" + body.getVersionMajor() + "-" + body.getVersionMinor()
                + "] which is not supported by this version of the client library");

            session.closeProtocolSession();
        }
    }
View Full Code Here

    public void methodReceived(AMQStateManager stateManager, AccessRequestOkBody method, int channelId)
        throws AMQException
    {
        _logger.debug("AccessRequestOk method received");
        final AMQProtocolSession session = stateManager.getProtocolSession();
        session.setTicket(method.getTicket(), channelId);

    }
View Full Code Here

    public void methodReceived(AMQStateManager stateManager,  ChannelCloseBody method, int channelId)
        throws AMQException
    {
        _logger.debug("ChannelClose method received");
        final AMQProtocolSession session = stateManager.getProtocolSession();


        AMQConstant errorCode = AMQConstant.getConstant(method.getReplyCode());
        AMQShortString reason = method.getReplyText();
        if (_logger.isDebugEnabled())
        {
            _logger.debug("Channel close reply code: " + errorCode + ", reason: " + reason);
        }

        // For this test Method Handler .. don't send Close-OK
        // // TODO: Be aware of possible changes to parameter order as versions change.
        // AMQFrame frame = ChannelCloseOkBody.createAMQFrame(evt.getChannelId(), method.getMajor(), method.getMinor());
        // protocolSession.writeFrame(frame);
        if (errorCode != AMQConstant.REPLY_SUCCESS)
        {
            _logger.error("Channel close received with errorCode " + errorCode + ", and reason " + reason);
            if (errorCode == AMQConstant.NO_CONSUMERS)
            {
                throw new AMQNoConsumersException("Error: " + reason, null);
            }
            else if (errorCode == AMQConstant.NO_ROUTE)
            {
                throw new AMQNoRouteException("Error: " + reason, null);
            }
            else if (errorCode == AMQConstant.INVALID_ARGUMENT)
            {
                _logger.debug("Broker responded with Invalid Argument.");

                throw new AMQInvalidArgumentException(String.valueOf(reason));
            }
            else if (errorCode == AMQConstant.INVALID_ROUTING_KEY)
            {
                _logger.debug("Broker responded with Invalid Routing Key.");

                throw new AMQInvalidRoutingKeyException(String.valueOf(reason));
            }
            else
            {
                throw new AMQChannelClosedException(errorCode, "Error: " + reason);
            }

        }

        session.channelClosed(channelId, errorCode, String.valueOf(reason));
    }
View Full Code Here

TOP

Related Classes of org.apache.qpid.client.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.