Package org.apache.qpid.framing

Examples of org.apache.qpid.framing.AMQShortString


        if (_logger.isDebugEnabled())
        {
            _logger.debug("Publish received on channel " + channelId);
        }

        AMQShortString exchangeName = body.getExchange();
        // TODO: check the delivery tag field details - is it unique across the broker or per subscriber?
        if (exchangeName == null)
        {
            exchangeName = AMQShortString.valueOf(ExchangeDefaults.DEFAULT_EXCHANGE_NAME);
        }

        VirtualHost vHost = session.getVirtualHost();
        Exchange exch = vHost.getExchange(exchangeName.toString());
        // if the exchange does not exist we raise a channel exception
        if (exch == null)
        {
            throw body.getChannelException(AMQConstant.NOT_FOUND, "Unknown exchange name");
        }
View Full Code Here


                    throw body.getConnectionException(AMQConstant.NOT_ALLOWED, msg);
                }
            }
            else
            {
                final AMQShortString consumerTagName;

                if (queue.isExclusive() && !queue.isDurable())
                {
                    AMQSessionModel session = queue.getExclusiveOwningSession();
                    if (session == null || session.getConnectionModel() != protocolConnection)
                    {
                        throw body.getConnectionException(AMQConstant.NOT_ALLOWED,
                                                          "Queue " + queue.getName() + " is exclusive, but not created on this Connection.");
                    }
                }

                if (body.getConsumerTag() != null)
                {
                    consumerTagName = body.getConsumerTag().intern(false);
                }
                else
                {
                    consumerTagName = null;
                }

                try
                {
                    if(consumerTagName == null || channel.getSubscription(consumerTagName) == null)
                    {

                        AMQShortString consumerTag = channel.subscribeToQueue(consumerTagName, queue, !body.getNoAck(),
                                                                              body.getArguments(), body.getNoLocal(), body.getExclusive());
                        if (!body.getNowait())
                        {
                            MethodRegistry methodRegistry = protocolConnection.getMethodRegistry();
                            AMQMethodBody responseBody = methodRegistry.createBasicConsumeOkBody(consumerTag);
                            protocolConnection.writeFrame(responseBody.generateFrame(channelId));

                        }
                    }
                    else
                    {
                        AMQShortString msg = new AMQShortString("Non-unique consumer tag, '" + body.getConsumerTag() + "'");

                        MethodRegistry methodRegistry = protocolConnection.getMethodRegistry();
                        AMQMethodBody responseBody = methodRegistry.createConnectionCloseBody(AMQConstant.NOT_ALLOWED.getCode(),    // replyCode
                                                                 msg,               // replytext
                                                                 body.getClazz(),
                                                                 body.getMethod());
                        protocolConnection.writeFrame(responseBody.generateFrame(0));
                    }

                }
                catch (org.apache.qpid.AMQInvalidArgumentException ise)
                {
                    _logger.debug("Closing connection due to invalid selector");

                    MethodRegistry methodRegistry = protocolConnection.getMethodRegistry();
                    AMQMethodBody responseBody = methodRegistry.createChannelCloseBody(AMQConstant.ARGUMENT_INVALID.getCode(),
                                                                                       new AMQShortString(ise.getMessage()),
                                                                                       body.getClazz(),
                                                                                       body.getMethod());
                    protocolConnection.writeFrame(responseBody.generateFrame(channelId));

View Full Code Here

    public MessagePublishInfo convertToInfo(AMQMethodBody methodBody)
    {
        final BasicPublishBody publishBody = ((BasicPublishBody) methodBody);

        final AMQShortString exchange = publishBody.getExchange();
        final AMQShortString routingKey = publishBody.getRoutingKey();

        return new MessagePublishInfoImpl(exchange == null ? null : exchange.intern(),
                                          publishBody.getImmediate(),
                                          publishBody.getMandatory(),
                                          routingKey == null ? null : routingKey.intern(false));

    }
View Full Code Here

    {
        final AMQProtocolSession protocolConnection = stateManager.getProtocolSession();
        final AMQSessionModel session = protocolConnection.getChannel(channelId);
        VirtualHost virtualHost = protocolConnection.getVirtualHost();

        final AMQShortString queueName;

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

        AMQQueue queue;

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

        AMQChannel channel = protocolConnection.getChannel(channelId);

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

        if(body.getPassive())
        {
            queue = virtualHost.getQueue(queueName.toString());
            if (queue == null)
            {
                String msg = "Queue: " + queueName + " not found on VirtualHost(" + virtualHost + ").";
                throw body.getChannelException(AMQConstant.NOT_FOUND, msg);
            }
View Full Code Here

        }
    }

    protected AMQShortString createName()
    {
        return new AMQShortString("tmp_" + UUID.randomUUID());
    }
View Full Code Here

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

        final AMQShortString exchangeName = body.getExchange();
        if (_logger.isDebugEnabled())
        {
            _logger.debug("Request to declare exchange of type " + body.getType() + " with name " + exchangeName);
        }

        Exchange exchange;

        if (body.getPassive())
        {
            exchange = virtualHost.getExchange(exchangeName == null ? null : exchangeName.toString());
            if(exchange == null)
            {
                throw body.getChannelException(AMQConstant.NOT_FOUND, "Unknown exchange: " + exchangeName);
            }
            else if (!(body.getType() == null || body.getType().length() ==0) && !exchange.getTypeName().equals(body.getType().asString()))
            {

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

        }
        else
        {
            try
            {
                exchange = virtualHost.createExchange(null,
                                                      exchangeName == null ? null : exchangeName.intern().toString(),
                                                      body.getType() == null ? null : body.getType().intern().toString(),
                                                      body.getDurable(),
                                                      body.getAutoDelete(),
                        null);

            }
            catch(ReservedExchangeNameException e)
            {
                throw body.getConnectionException(AMQConstant.NOT_ALLOWED,
                                          "Attempt to declare exchange: " + exchangeName +
                                          " which begins with reserved prefix.");

            }
            catch(ExchangeExistsException e)
            {
                exchange = e.getExistingExchange();
                if(!new AMQShortString(exchange.getTypeName()).equals(body.getType()))
                {
                    throw new AMQConnectionException(AMQConstant.NOT_ALLOWED, "Attempt to redeclare exchange: "
                                                                              + exchangeName + " of type "
                                                                              + exchange.getTypeName()
                                                                              + " to " + body.getType() +".",
View Full Code Here

            throw body.getChannelNotFoundException(channelId);
        }
        channel.sync();


        AMQShortString exchangeName = body.getExchange();
        AMQShortString queueName = body.getQueue();
        AMQShortString routingKey = body.getRoutingKey();
        if (exchangeName == null)
        {
            throw new AMQException("Exchange exchange must not be null");
        }
        Exchange exchange = virtualHost.getExchange(exchangeName.toString());
        ExchangeBoundOkBody response;
        if (exchange == null)
        {


            response = methodRegistry.createExchangeBoundOkBody(EXCHANGE_NOT_FOUND,
                                                                new AMQShortString("Exchange " + exchangeName + " not found"));
        }
        else if (routingKey == null)
        {
            if (queueName == null)
            {
                if (exchange.hasBindings())
                {
                    response = methodRegistry.createExchangeBoundOkBody(OK, null);
                }
                else
                {

                    response = methodRegistry.createExchangeBoundOkBody(NO_BINDINGS,  // replyCode
                        null)// replyText
                }
            }
            else
            {

                AMQQueue queue = virtualHost.getQueue(queueName.toString());
                if (queue == null)
                {

                    response = methodRegistry.createExchangeBoundOkBody(QUEUE_NOT_FOUND,  // replyCode
                        new AMQShortString("Queue " + queueName + " not found"))// replyText
                }
                else
                {
                    if (exchange.isBound(queue))
                    {

                        response = methodRegistry.createExchangeBoundOkBody(OK,  // replyCode
                            null)// replyText
                    }
                    else
                    {

                        response = methodRegistry.createExchangeBoundOkBody(QUEUE_NOT_BOUND,  // replyCode
                            new AMQShortString("Queue " + queueName + " not bound to exchange " + exchangeName))// replyText
                    }
                }
            }
        }
        else if (queueName != null)
        {
            AMQQueue queue = virtualHost.getQueue(queueName.toString());
            if (queue == null)
            {

                response = methodRegistry.createExchangeBoundOkBody(QUEUE_NOT_FOUND,  // replyCode
                    new AMQShortString("Queue " + queueName + " not found"))// replyText
            }
            else
            {
                String bindingKey = body.getRoutingKey() == null ? null : body.getRoutingKey().asString();
                if (exchange.isBound(bindingKey, queue))
                {

                    response = methodRegistry.createExchangeBoundOkBody(OK,  // replyCode
                        null)// replyText
                }
                else
                {

                    String message = "Queue " + queueName + " not bound with routing key " +
                                        body.getRoutingKey() + " to exchange " + exchangeName;

                    if(message.length()>255)
                    {
                        message = message.substring(0,254);
                    }
                    response = methodRegistry.createExchangeBoundOkBody(SPECIFIC_QUEUE_NOT_BOUND_WITH_RK,  // replyCode
                        new AMQShortString(message))// replyText
                }
            }
        }
        else
        {
            if (exchange.isBound(body.getRoutingKey() == null ? "" : body.getRoutingKey().asString()))
            {

                response = methodRegistry.createExchangeBoundOkBody(OK,  // replyCode
                    null)// replyText
            }
            else
            {

                response = methodRegistry.createExchangeBoundOkBody(NO_QUEUE_BOUND_WITH_RK,  // replyCode
                    new AMQShortString("No queue bound with routing key " + body.getRoutingKey() +
                    " to exchange " + exchangeName))// replyText
            }
        }
        session.writeFrame(response.generateFrame(channelId));
    }
View Full Code Here

    {
        AMQProtocolSession session = stateManager.getProtocolSession();
        VirtualHost virtualHost = session.getVirtualHost();

        final AMQQueue queue;
        final AMQShortString routingKey;


        AMQChannel channel = session.getChannel(channelId);
        if (channel == null)
        {
View Full Code Here

        body.flip();

        BasicContentHeaderProperties properties =
                (BasicContentHeaderProperties) message_0_8.getContentHeaderBody().getProperties();

        final AMQShortString exchange = message_0_8.getMessagePublishInfo().getExchange();
        if(exchange != null)
        {
            deliveryProps.setExchange(exchange.toString());
        }

        deliveryProps.setExpiration(message_0_8.getExpiration());
        deliveryProps.setImmediate(message_0_8.isImmediate());
        deliveryProps.setPriority(MessageDeliveryPriority.get(properties.getPriority()));
        deliveryProps.setRoutingKey(message_0_8.getRoutingKey());
        deliveryProps.setTimestamp(properties.getTimestamp());

        messageProps.setContentEncoding(properties.getEncodingAsString());
        messageProps.setContentLength(size);
        if(properties.getAppId() != null)
        {
            messageProps.setAppId(properties.getAppId().getBytes());
        }
        messageProps.setContentType(properties.getContentTypeAsString());
        if(properties.getCorrelationId() != null)
        {
            messageProps.setCorrelationId(properties.getCorrelationId().getBytes());
        }

        if(properties.getReplyTo() != null && properties.getReplyTo().length() != 0)
        {
            String origReplyToString = properties.getReplyTo().asString();
            ReplyTo replyTo = new ReplyTo();
            // if the string looks like a binding URL, then attempt to parse it...
            try
            {
                AMQBindingURL burl = new AMQBindingURL(origReplyToString);
                AMQShortString routingKey = burl.getRoutingKey();
                if(routingKey != null)
                {
                    replyTo.setRoutingKey(routingKey.asString());
                }

                AMQShortString exchangeName = burl.getExchangeName();
                if(exchangeName != null)
                {
                    replyTo.setExchange(exchangeName.asString());
                }
            }
            catch (URISyntaxException e)
            {
                replyTo.setRoutingKey(origReplyToString);
View Full Code Here

        for (int i = 0; i < 25; i++)
        {
            sb.append("message [" + i + "]");
        }
        AMQException e = new AMQException(AMQConstant.INTERNAL_ERROR, sb.toString(), null);
        AMQShortString message = AMQShortString.validValueOf(e.getMessage());
        assertEquals(sb.substring(0, AMQShortString.MAX_LENGTH - 3) + "...", message.toString());
    }
View Full Code Here

TOP

Related Classes of org.apache.qpid.framing.AMQShortString

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.