Search in sources :

Example 51 with Binary

use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.

the class AbstractLinkEndpoint method handleOversizedUnsettledMapIfNecessary.

private Attach handleOversizedUnsettledMapIfNecessary(final Attach attachToSend) {
    final AMQPDescribedTypeRegistry describedTypeRegistry = getSession().getConnection().getDescribedTypeRegistry();
    final ValueWriter<Attach> valueWriter = describedTypeRegistry.getValueWriter(attachToSend);
    if (valueWriter.getEncodedSize() + 8 > getSession().getConnection().getMaxFrameSize()) {
        _localIncompleteUnsettled = true;
        attachToSend.setIncompleteUnsettled(true);
        final int targetSize = getSession().getConnection().getMaxFrameSize();
        int lowIndex = 0;
        Map<Binary, DeliveryState> localUnsettledMap = attachToSend.getUnsettled();
        if (localUnsettledMap == null) {
            localUnsettledMap = Collections.emptyMap();
        }
        int highIndex = localUnsettledMap.size();
        int currentIndex = (highIndex - lowIndex) / 2;
        int oldIndex;
        HashMap<Binary, DeliveryState> unsettledMap = null;
        int totalSize;
        do {
            HashMap<Binary, DeliveryState> partialUnsettledMap = new HashMap<>(currentIndex);
            final Iterator<Map.Entry<Binary, DeliveryState>> iterator = localUnsettledMap.entrySet().iterator();
            for (int i = 0; i < currentIndex; ++i) {
                final Map.Entry<Binary, DeliveryState> entry = iterator.next();
                partialUnsettledMap.put(entry.getKey(), entry.getValue());
            }
            attachToSend.setUnsettled(partialUnsettledMap);
            totalSize = describedTypeRegistry.getValueWriter(attachToSend).getEncodedSize() + FRAME_HEADER_SIZE;
            if (totalSize > targetSize) {
                highIndex = currentIndex;
            } else if (totalSize < targetSize) {
                lowIndex = currentIndex;
                unsettledMap = partialUnsettledMap;
            } else {
                lowIndex = highIndex = currentIndex;
                unsettledMap = partialUnsettledMap;
            }
            oldIndex = currentIndex;
            currentIndex = lowIndex + (highIndex - lowIndex) / 2;
        } while (oldIndex != currentIndex);
        if (unsettledMap == null || unsettledMap.isEmpty()) {
            final End endWithError = new End();
            endWithError.setError(new Error(AmqpError.FRAME_SIZE_TOO_SMALL, "Cannot fit a single unsettled delivery into Attach frame."));
            getSession().end(endWithError);
        }
        attachToSend.setUnsettled(unsettledMap);
    } else {
        _localIncompleteUnsettled = false;
    }
    return attachToSend;
}
Also used : AMQPDescribedTypeRegistry(org.apache.qpid.server.protocol.v1_0.type.codec.AMQPDescribedTypeRegistry) HashMap(java.util.HashMap) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) End(org.apache.qpid.server.protocol.v1_0.type.transport.End) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) HashMap(java.util.HashMap) Map(java.util.Map)

Example 52 with Binary

use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.

the class MessageConverter_from_1_0 method getUserId.

public static Binary getUserId(final Message_1_0 serverMsg) {
    Binary userId = null;
    final PropertiesSection propertiesSection = serverMsg.getPropertiesSection();
    if (propertiesSection != null) {
        final Properties properties = propertiesSection.getValue();
        propertiesSection.dispose();
        if (properties != null) {
            userId = properties.getUserId();
        }
    }
    return userId;
}
Also used : PropertiesSection(org.apache.qpid.server.protocol.v1_0.type.messaging.PropertiesSection) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)

Example 53 with Binary

use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.

the class MessageConverter_v1_0_to_InternalTest method testData.

public void testData() throws Exception {
    final byte[] expected = getObjectBytes("helloworld".getBytes(UTF_8));
    final Data value = new Data(new Binary(expected));
    final Message_1_0 sourceMessage = createTestMessage(value.createEncodingRetainingSection());
    final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
    assertEquals("Unexpected mime type", "application/octet-stream", convertedMessage.getMessageHeader().getMimeType());
    assertArrayEquals("Unexpected content", expected, ((byte[]) convertedMessage.getMessageBody()));
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) Data(org.apache.qpid.server.protocol.v1_0.type.messaging.Data) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary)

Example 54 with Binary

use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.

the class MessageConverter_v1_0_to_InternalTest method testAmqpValueWithMap.

public void testAmqpValueWithMap() throws Exception {
    final Map<Object, Object> originalMap = new LinkedHashMap<>();
    originalMap.put("binaryEntry", new Binary(new byte[] { 0x00, (byte) 0xFF }));
    originalMap.put("intEntry", 42);
    originalMap.put("uuidEntry", UUID.randomUUID());
    originalMap.put("nullEntry", null);
    originalMap.put(43, "nonstringkey");
    originalMap.put("mapEntry", Collections.singletonMap("foo", "bar"));
    final AmqpValue amqpValue = new AmqpValue(originalMap);
    Message_1_0 sourceMessage = createTestMessage(amqpValue.createEncodingRetainingSection());
    final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
    assertEquals("Unexpected mime type", null, convertedMessage.getMessageHeader().getMimeType());
    Map<Object, Object> convertedMap = (Map<Object, Object>) convertedMessage.getMessageBody();
    assertEquals("Unexpected size", originalMap.size(), convertedMap.size());
    assertArrayEquals("Unexpected binary entry", ((Binary) originalMap.get("binaryEntry")).getArray(), (byte[]) convertedMap.get("binaryEntry"));
    assertEquals("Unexpected int entry", originalMap.get("intEntry"), convertedMap.get("intEntry"));
    assertEquals("Unexpected null entry", originalMap.get("nullEntry"), convertedMap.get("nullEntry"));
    assertEquals("Unexpected uuid entry", originalMap.get("uuidEntry"), convertedMap.get("uuidEntry"));
    assertEquals("Unexpected nonstringkey entry", originalMap.get(43), convertedMap.get(43));
    assertEquals("Unexpected map entry", new HashMap((Map) originalMap.get("mapEntry")), new HashMap((Map) convertedMap.get("mapEntry")));
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) AmqpValue(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue) LinkedHashMap(java.util.LinkedHashMap)

Example 55 with Binary

use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.

the class PropertyConverter_Internal_to_v1_0Test method testUserIdConversion.

public void testUserIdConversion() {
    final String userId = "testUserId";
    final AMQMessageHeader header = mock(AMQMessageHeader.class);
    when(header.getUserId()).thenReturn(userId);
    InternalMessage originalMessage = createTestMessage(header);
    Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
    Binary convertedUserId = MessageConverter_from_1_0.getUserId(convertedMessage);
    assertTrue("Unexpected userId", Arrays.equals(userId.getBytes(UTF_8), convertedUserId.getArray()));
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary)

Aggregations

Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)104 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)46 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)45 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)43 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)42 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)37 Data (org.apache.qpid.server.protocol.v1_0.type.messaging.Data)32 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)29 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)29 Test (org.junit.Test)29 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)28 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)23 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)22 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)21 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)19 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)16 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)13 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)12 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)12 HashMap (java.util.HashMap)11