Search in sources :

Example 26 with AMQShortString

use of org.apache.qpid.server.protocol.v0_8.AMQShortString in project qpid-broker-j by apache.

the class QueueDeclareBody method process.

public static void process(final QpidByteBuffer buffer, final ServerChannelMethodProcessor dispatcher) throws AMQFrameDecodingException {
    int ticket = buffer.getUnsignedShort();
    AMQShortString queue = AMQShortString.readAMQShortString(buffer);
    byte bitfield = buffer.get();
    boolean passive = (bitfield & 0x01) == 0x01;
    boolean durable = (bitfield & 0x02) == 0x02;
    boolean exclusive = (bitfield & 0x04) == 0x04;
    boolean autoDelete = (bitfield & 0x08) == 0x08;
    boolean nowait = (bitfield & 0x010) == 0x010;
    FieldTable arguments = EncodingUtils.readFieldTable(buffer);
    if (!dispatcher.ignoreAllButCloseOk()) {
        dispatcher.receiveQueueDeclare(queue, passive, durable, exclusive, autoDelete, nowait, arguments);
    }
    if (arguments != null) {
        arguments.clearEncodedForm();
    }
}
Also used : AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) FieldTable(org.apache.qpid.server.protocol.v0_8.FieldTable)

Example 27 with AMQShortString

use of org.apache.qpid.server.protocol.v0_8.AMQShortString in project qpid-broker-j by apache.

the class QueueUnbindBody method process.

public static void process(final QpidByteBuffer buffer, final ServerChannelMethodProcessor dispatcher) throws AMQFrameDecodingException {
    int ticket = buffer.getUnsignedShort();
    AMQShortString queue = AMQShortString.readAMQShortString(buffer);
    AMQShortString exchange = AMQShortString.readAMQShortString(buffer);
    AMQShortString routingKey = AMQShortString.readAMQShortString(buffer);
    FieldTable arguments = EncodingUtils.readFieldTable(buffer);
    if (!dispatcher.ignoreAllButCloseOk()) {
        dispatcher.receiveQueueUnbind(queue, exchange, routingKey, arguments);
    }
    if (arguments != null) {
        arguments.clearEncodedForm();
    }
}
Also used : AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) FieldTable(org.apache.qpid.server.protocol.v0_8.FieldTable)

Example 28 with AMQShortString

use of org.apache.qpid.server.protocol.v0_8.AMQShortString in project qpid-broker-j by apache.

the class AMQPConnection_0_8Test method testConnectionEnforcesMaxSessions.

public void testConnectionEnforcesMaxSessions() throws Exception {
    AMQPConnection_0_8Impl conn = new AMQPConnection_0_8Impl(_broker, _network, _port, _transport, _protocol, 0, _ticker);
    conn.create();
    conn.receiveProtocolHeader(new ProtocolInitiation(ProtocolVersion.v0_8));
    conn.receiveConnectionStartOk(new FieldTable(), SASL_MECH, SASL_RESPONSE, LOCALE);
    int maxChannels = 10;
    conn.receiveConnectionTuneOk(maxChannels, 65535, 0);
    conn.receiveConnectionOpen(new AMQShortString(VIRTUAL_HOST_NAME), AMQShortString.EMPTY_STRING, false);
    // check the channel count is correct
    int channelCount = conn.getSessionModels().size();
    assertEquals("Initial channel count wrong", 0, channelCount);
    assertEquals("Number of channels not correctly set.", maxChannels, conn.getSessionCountLimit());
    assertFalse("Connection should not be closed after opening " + maxChannels + " channels", conn.isClosing());
    for (long currentChannel = 1L; currentChannel <= maxChannels; currentChannel++) {
        conn.receiveChannelOpen((int) currentChannel);
    }
    assertFalse("Connection should not be closed after opening " + maxChannels + " channels", conn.isClosing());
    assertEquals("Maximum number of channels not set.", maxChannels, conn.getSessionModels().size());
    conn.receiveChannelOpen(maxChannels + 1);
    assertTrue("Connection should be closed after opening " + (maxChannels + 1) + " channels", conn.isClosing());
}
Also used : ProtocolInitiation(org.apache.qpid.server.protocol.v0_8.transport.ProtocolInitiation)

Example 29 with AMQShortString

use of org.apache.qpid.server.protocol.v0_8.AMQShortString in project qpid-broker-j by apache.

the class MessageConverter_0_10_to_0_8 method convertPublishBody.

private MessagePublishInfo convertPublishBody(MessageTransferMessage message) {
    DeliveryProperties delvProps = message.getHeader().getDeliveryProperties();
    final AMQShortString exchangeName = (delvProps == null || delvProps.getExchange() == null) ? null : new AMQShortString(delvProps.getExchange());
    final AMQShortString routingKey = (delvProps == null || delvProps.getRoutingKey() == null) ? null : new AMQShortString(delvProps.getRoutingKey());
    final boolean immediate = delvProps != null && delvProps.getImmediate();
    final boolean mandatory = delvProps != null && !delvProps.getDiscardUnroutable();
    return new MessagePublishInfo(exchangeName, immediate, mandatory, routingKey);
}
Also used : MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)

Example 30 with AMQShortString

use of org.apache.qpid.server.protocol.v0_8.AMQShortString in project qpid-broker-j by apache.

the class MessageConverter_0_10_to_0_8 method convertContentHeaderProperties.

public static BasicContentHeaderProperties convertContentHeaderProperties(MessageTransferMessage messageTransferMessage, NamedAddressSpace addressSpace) {
    BasicContentHeaderProperties props = new BasicContentHeaderProperties();
    Header header = messageTransferMessage.getHeader();
    DeliveryProperties deliveryProps = header.getDeliveryProperties();
    MessageProperties messageProps = header.getMessageProperties();
    if (deliveryProps != null) {
        if (deliveryProps.hasDeliveryMode()) {
            props.setDeliveryMode((deliveryProps.getDeliveryMode() == MessageDeliveryMode.PERSISTENT ? BasicContentHeaderProperties.PERSISTENT : BasicContentHeaderProperties.NON_PERSISTENT));
        }
        if (deliveryProps.hasTtl()) {
            props.setExpiration(messageTransferMessage.getArrivalTime() + deliveryProps.getTtl());
        } else if (deliveryProps.hasExpiration()) {
            props.setExpiration(deliveryProps.getExpiration());
        }
        if (deliveryProps.hasPriority()) {
            props.setPriority((byte) deliveryProps.getPriority().getValue());
        }
        if (deliveryProps.hasTimestamp()) {
            props.setTimestamp(deliveryProps.getTimestamp());
        } else {
            props.setTimestamp(messageTransferMessage.getArrivalTime());
        }
    }
    if (messageProps != null) {
        if (messageProps.hasAppId()) {
            try {
                props.setAppId(new AMQShortString(messageProps.getAppId()));
            } catch (IllegalArgumentException e) {
            // pass
            }
        }
        if (messageProps.hasContentType()) {
            props.setContentType(messageProps.getContentType());
        }
        if (messageProps.hasCorrelationId()) {
            try {
                props.setCorrelationId(new AMQShortString(messageProps.getCorrelationId()));
            } catch (IllegalArgumentException e) {
                throw new MessageConversionException("Could not convert message from 0-10 to 0-8 because conversion of 'correlationId' failed.", e);
            }
        }
        if (messageProps.hasContentEncoding()) {
            props.setEncoding(messageProps.getContentEncoding());
        }
        if (messageProps.hasMessageId()) {
            // Add prefix 'ID:' to workaround broken 0-8..0-9-1 Qpid JMS client
            props.setMessageId("ID:" + messageProps.getMessageId().toString());
        }
        if (messageProps.hasReplyTo()) {
            ReplyTo replyTo = messageProps.getReplyTo();
            String exchangeName = replyTo.getExchange();
            String routingKey = replyTo.getRoutingKey();
            if (exchangeName == null) {
                exchangeName = "";
            }
            if (!"".equals(exchangeName) || (routingKey != null && !"".equals(routingKey))) {
                MessageDestination destination = addressSpace.getAttainedMessageDestination(exchangeName);
                Exchange<?> exchange = destination instanceof Exchange ? (Exchange<?>) destination : null;
                String exchangeClass = exchange == null ? ExchangeDefaults.DIRECT_EXCHANGE_CLASS : exchange.getType();
                String routingKeyOption = routingKey == null ? "" : "?routingkey='" + routingKey + "'";
                final String replyToBindingUrl = String.format("%s://%s//%s", exchangeClass, exchangeName, routingKeyOption);
                try {
                    props.setReplyTo(replyToBindingUrl);
                } catch (IllegalArgumentException e) {
                    throw new MessageConversionException("Could not convert message from 0-10 to 0-8 because conversion of 'reply-to' failed.", e);
                }
            }
        }
        if (messageProps.hasUserId()) {
            try {
                props.setUserId(new AMQShortString(messageProps.getUserId()));
            } catch (IllegalArgumentException e) {
            // ignore
            }
        }
        if (messageProps.hasApplicationHeaders()) {
            Map<String, Object> appHeaders = new HashMap<String, Object>(messageProps.getApplicationHeaders());
            if (messageProps.getApplicationHeaders().containsKey("x-jms-type")) {
                String jmsType = String.valueOf(appHeaders.remove("x-jms-type"));
                try {
                    props.setType(jmsType);
                } catch (IllegalArgumentException e) {
                    throw new MessageConversionException("Could not convert message from 0-10 to 0-8 because x-jms-type conversion failed.", e);
                }
            }
            FieldTable ft = new FieldTable();
            for (Map.Entry<String, Object> entry : appHeaders.entrySet()) {
                String headerName = entry.getKey();
                try {
                    ft.put(AMQShortString.validValueOf(headerName), entry.getValue());
                } catch (AMQPInvalidClassException e) {
                    throw new MessageConversionException(String.format("Could not convert message from 0-10 to 0-8 because conversion of application header '%s' failed.", headerName), e);
                }
            }
            props.setHeaders(ft);
        }
    }
    return props;
}
Also used : AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) MessageDestination(org.apache.qpid.server.message.MessageDestination) AMQPInvalidClassException(org.apache.qpid.server.protocol.v0_8.AMQPInvalidClassException) FieldTable(org.apache.qpid.server.protocol.v0_8.FieldTable) HashMap(java.util.HashMap) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) ReplyTo(org.apache.qpid.server.protocol.v0_10.transport.ReplyTo) Exchange(org.apache.qpid.server.model.Exchange) Header(org.apache.qpid.server.protocol.v0_10.transport.Header) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)45 FieldTable (org.apache.qpid.server.protocol.v0_8.FieldTable)13 Transaction (com.sleepycat.je.Transaction)7 Database (com.sleepycat.je.Database)6 DatabaseEntry (com.sleepycat.je.DatabaseEntry)6 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)6 TupleOutput (com.sleepycat.bind.tuple.TupleOutput)4 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)4 TupleInput (com.sleepycat.bind.tuple.TupleInput)3 DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)3 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)3 URISyntaxException (java.net.URISyntaxException)2 HashSet (java.util.HashSet)2 MessageDestination (org.apache.qpid.server.message.MessageDestination)2 Exchange (org.apache.qpid.server.model.Exchange)2 Header (org.apache.qpid.server.protocol.v0_10.transport.Header)2 MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)2 ReplyTo (org.apache.qpid.server.protocol.v0_10.transport.ReplyTo)2 AMQBody (org.apache.qpid.server.protocol.v0_8.transport.AMQBody)2 ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)2