Search in sources :

Example 26 with FieldTable

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

the class MalformedMessageTest method malformedHeaderValue.

@Test
public void malformedHeaderValue() throws Exception {
    final FieldTable malformedHeader = createHeadersWithMalformedLongString();
    byte[] contentBytes = CONTENT_TEXT.getBytes(StandardCharsets.UTF_8);
    publishMalformedMessage(malformedHeader, contentBytes);
    assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
}
Also used : FieldTable(org.apache.qpid.server.protocol.v0_8.FieldTable) Test(org.junit.Test)

Example 27 with FieldTable

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

the class UpgradeFrom5To6 method upgradeQueueBindings.

private void upgradeQueueBindings(Environment environment, Transaction transaction, final UpgradeInteractionHandler handler, final String virtualHostName) {
    LOGGER.info("Queue Bindings");
    if (environment.getDatabaseNames().contains(OLD_QUEUE_BINDINGS_DB_NAME)) {
        final QueueBindingBinding binding = new QueueBindingBinding();
        CursorOperation bindingCursor = new CursorOperation() {

            @Override
            public void processEntry(Database exchangeDatabase, Database configuredObjectsDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
                // TODO: check and remove orphaned bindings
                BindingRecord bindingRecord = binding.entryToObject(key);
                String exchangeName = bindingRecord.getExchangeName() == null ? ExchangeDefaults.DEFAULT_EXCHANGE_NAME : bindingRecord.getExchangeName().toString();
                String queueName = bindingRecord.getQueueName().toString();
                String routingKey = bindingRecord.getRoutingKey().toString();
                FieldTable arguments = bindingRecord.getArguments();
                UUID bindingId = UUIDGenerator.generateBindingUUID(exchangeName, queueName, routingKey, virtualHostName);
                UpgradeConfiguredObjectRecord configuredObject = createBindingConfiguredObjectRecord(exchangeName, queueName, routingKey, arguments, virtualHostName);
                storeConfiguredObjectEntry(configuredObjectsDatabase, bindingId, configuredObject, transaction);
            }
        };
        new DatabaseTemplate(environment, OLD_QUEUE_BINDINGS_DB_NAME, CONFIGURED_OBJECTS_DB_NAME, transaction).run(bindingCursor);
        environment.removeDatabase(transaction, OLD_QUEUE_BINDINGS_DB_NAME);
        LOGGER.info(bindingCursor.getRowCount() + " Queue Binding Entries");
    }
}
Also used : Transaction(com.sleepycat.je.Transaction) FieldTable(org.apache.qpid.server.protocol.v0_8.FieldTable) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) UUID(java.util.UUID)

Example 28 with FieldTable

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

the class UpgradeFrom5To6 method createBindingConfiguredObjectRecord.

private UpgradeConfiguredObjectRecord createBindingConfiguredObjectRecord(String exchangeName, String queueName, String routingKey, FieldTable arguments, String virtualHostName) {
    Map<String, Object> attributesMap = new HashMap<String, Object>();
    attributesMap.put("name", routingKey);
    attributesMap.put("exchange", UUIDGenerator.generateExchangeUUID(exchangeName, virtualHostName));
    attributesMap.put("queue", UUIDGenerator.generateQueueUUID(queueName, virtualHostName));
    if (arguments != null) {
        attributesMap.put("arguments", FieldTable.convertToMap(arguments));
    }
    String json = serialiseMap(attributesMap);
    UpgradeConfiguredObjectRecord configuredObject = new UpgradeConfiguredObjectRecord(Binding.class.getName(), json);
    return configuredObject;
}
Also used : TupleBinding(com.sleepycat.bind.tuple.TupleBinding) LongBinding(com.sleepycat.bind.tuple.LongBinding) Binding(org.apache.qpid.server.model.Binding) HashMap(java.util.HashMap) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString)

Example 29 with FieldTable

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

the class UpgradeFrom4to5Test method loadBindings.

private List<BindingRecord> loadBindings() {
    final BindingTuple bindingTuple = new BindingTuple();
    final List<BindingRecord> queueBindings = new ArrayList<BindingRecord>();
    CursorOperation databaseOperation = new CursorOperation() {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
            BindingRecord bindingRecord = bindingTuple.entryToObject(key);
            AMQShortString queueName = bindingRecord.getQueueName();
            AMQShortString exchangeName = bindingRecord.getExchangeName();
            AMQShortString routingKey = bindingRecord.getRoutingKey();
            FieldTable arguments = bindingRecord.getArguments();
            queueBindings.add(new BindingRecord(exchangeName, queueName, routingKey, arguments));
        }
    };
    new DatabaseTemplate(_environment, BINDING_DB_NAME, null).run(databaseOperation);
    return queueBindings;
}
Also used : AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) Transaction(com.sleepycat.je.Transaction) FieldTable(org.apache.qpid.server.protocol.v0_8.FieldTable) BindingTuple(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom4To5.BindingTuple) ArrayList(java.util.ArrayList) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) BindingRecord(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom4To5.BindingRecord)

Example 30 with FieldTable

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

the class AMQDecoderTest method testContentHeaderPropertiesFrame.

@Test
public void testContentHeaderPropertiesFrame() throws AMQProtocolVersionException, AMQFrameDecodingException, IOException {
    final BasicContentHeaderProperties props = new BasicContentHeaderProperties();
    Map<String, Object> headersMap = new LinkedHashMap<>();
    headersMap.put("hello", "world");
    headersMap.put("1+1=", 2);
    final FieldTable table = FieldTableFactory.createFieldTable(headersMap);
    props.setHeaders(table);
    final AMQBody body = new ContentHeaderBody(props);
    AMQFrame frame = new AMQFrame(1, body);
    TestSender sender = new TestSender();
    frame.writePayload(sender);
    ByteBuffer msg = combine(sender.getSentBuffers());
    _decoder.decodeBuffer(msg);
    List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
    AMQDataBlock firstFrame = frames.get(0);
    if (firstFrame instanceof AMQFrame) {
        assertEquals((long) ContentHeaderBody.TYPE, (long) ((AMQFrame) firstFrame).getBodyFrame().getFrameType());
        BasicContentHeaderProperties decodedProps = ((ContentHeaderBody) ((AMQFrame) firstFrame).getBodyFrame()).getProperties();
        final Map<String, Object> headers = decodedProps.getHeadersAsMap();
        assertEquals("world", headers.get("hello"));
    } else {
        fail("decode was not a frame");
    }
}
Also used : ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) AMQBody(org.apache.qpid.server.protocol.v0_8.transport.AMQBody) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) ByteBuffer(java.nio.ByteBuffer) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) LinkedHashMap(java.util.LinkedHashMap) AMQDataBlock(org.apache.qpid.server.protocol.v0_8.transport.AMQDataBlock) AMQFrame(org.apache.qpid.server.protocol.v0_8.transport.AMQFrame) Test(org.junit.Test)

Aggregations

FieldTable (org.apache.qpid.server.protocol.v0_8.FieldTable)26 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)20 Test (org.junit.Test)7 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)6 Database (com.sleepycat.je.Database)5 DatabaseEntry (com.sleepycat.je.DatabaseEntry)5 Transaction (com.sleepycat.je.Transaction)5 HashMap (java.util.HashMap)5 ChannelOpenOkBody (org.apache.qpid.server.protocol.v0_8.transport.ChannelOpenOkBody)5 FrameTransport (org.apache.qpid.tests.protocol.v0_8.FrameTransport)5 Interaction (org.apache.qpid.tests.protocol.v0_8.Interaction)5 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)4 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)3 ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)3 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 UUID (java.util.UUID)2 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)2 AMQPInvalidClassException (org.apache.qpid.server.protocol.v0_8.AMQPInvalidClassException)2 LongBinding (com.sleepycat.bind.tuple.LongBinding)1