Search in sources :

Example 71 with Binary

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

the class PropertyConverter_1_0_to_0_10Test method testCorrelationIdBinaryConversion.

public void testCorrelationIdBinaryConversion() {
    final String testCorrelationId = "testCorrelationId";
    final Binary correlationId = new Binary(testCorrelationId.getBytes(UTF_8));
    Properties properties = new Properties();
    properties.setCorrelationId(correlationId);
    Message_1_0 message = createTestMessage(properties);
    final MessageTransferMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
    final MessageProperties messageProperties = convertedMessage.getStoredMessage().getMetaData().getMessageProperties();
    assertTrue("Unexpected correlationId", Arrays.equals(testCorrelationId.getBytes(), messageProperties.getCorrelationId()));
}
Also used : MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) Matchers.anyString(org.mockito.Matchers.anyString) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)

Example 72 with Binary

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

the class MessageConverter_0_8_to_1_0 method convertMetaData.

@Override
protected MessageMetaData_1_0 convertMetaData(final AMQMessage serverMessage, final EncodingRetainingSection<?> bodySection, SectionEncoder sectionEncoder) {
    Header header = new Header();
    Properties props = new Properties();
    header.setDurable(serverMessage.isPersistent());
    BasicContentHeaderProperties contentHeader = serverMessage.getContentHeaderBody().getProperties();
    header.setPriority(UnsignedByte.valueOf(contentHeader.getPriority()));
    if (contentHeader.hasExpiration()) {
        final long expiration = serverMessage.getExpiration();
        final long arrivalTime = serverMessage.getArrivalTime();
        header.setTtl(UnsignedInteger.valueOf(Math.max(0, expiration - arrivalTime)));
    }
    if (!GZIPUtils.GZIP_CONTENT_ENCODING.equals(contentHeader.getEncodingAsString()) && bodySection instanceof DataSection) {
        props.setContentEncoding(Symbol.valueOf(contentHeader.getEncodingAsString()));
    }
    Symbol contentType = getContentType(contentHeader.getContentTypeAsString());
    props.setContentType(contentType);
    final AMQShortString correlationId = contentHeader.getCorrelationId();
    if (correlationId != null) {
        final byte[] correlationIdAsBytes = correlationId.getBytes();
        final String correlationIdAsString = contentHeader.getCorrelationIdAsString();
        if (Arrays.equals(correlationIdAsBytes, correlationIdAsString.getBytes(StandardCharsets.UTF_8))) {
            props.setCorrelationId(correlationIdAsString);
        } else {
            props.setCorrelationId(correlationIdAsBytes);
        }
    }
    final AMQShortString messageId = contentHeader.getMessageId();
    if (messageId != null) {
        props.setMessageId(messageId.toString());
    }
    if (contentHeader.getReplyTo() != null) {
        props.setReplyTo(convertReplyTo(contentHeader.getReplyTo()));
    }
    if (contentHeader.getUserId() != null) {
        props.setUserId(new Binary(contentHeader.getUserId().getBytes()));
    }
    if (contentHeader.hasTimestamp()) {
        props.setCreationTime(new Date(contentHeader.getTimestamp()));
    } else {
        props.setCreationTime(new Date(serverMessage.getArrivalTime()));
    }
    if (contentHeader.getType() != null) {
        props.setSubject(contentHeader.getType().toString());
    }
    Map<String, Object> applicationPropertiesMap = new LinkedHashMap<>(FieldTable.convertToMap(contentHeader.getHeaders()));
    if (applicationPropertiesMap.containsKey("qpid.subject")) {
        props.setSubject(String.valueOf(applicationPropertiesMap.get("qpid.subject")));
        applicationPropertiesMap.remove("qpid.subject");
    }
    if (applicationPropertiesMap.containsKey("JMSXGroupID")) {
        props.setGroupId(String.valueOf(applicationPropertiesMap.get("JMSXGroupID")));
        applicationPropertiesMap.remove("JMSXGroupID");
    }
    if (applicationPropertiesMap.containsKey("JMSXGroupSeq")) {
        Object jmsxGroupSeq = applicationPropertiesMap.get("JMSXGroupSeq");
        if (jmsxGroupSeq instanceof Integer) {
            props.setGroupSequence(UnsignedInteger.valueOf((Integer) jmsxGroupSeq));
            applicationPropertiesMap.remove("JMSXGroupSeq");
        }
    }
    MessagePublishInfo messagePublishInfo = serverMessage.getMessagePublishInfo();
    String to = AMQShortString.toString(messagePublishInfo.getExchange());
    if (messagePublishInfo.getRoutingKey() != null) {
        String routingKey = AMQShortString.toString(messagePublishInfo.getRoutingKey());
        if (to != null && !"".equals(to)) {
            to += "/" + routingKey;
        } else {
            to = routingKey;
        }
    }
    props.setTo(to);
    final ApplicationProperties applicationProperties;
    try {
        applicationProperties = new ApplicationProperties(applicationPropertiesMap);
    } catch (IllegalArgumentException e) {
        throw new MessageConversionException("Could not convert message from 0-8 to 1.0 because headers conversion failed.", e);
    }
    MessageAnnotations messageAnnotations = createMessageAnnotation(bodySection, contentHeader.getContentTypeAsString());
    return new MessageMetaData_1_0(header.createEncodingRetainingSection(), null, messageAnnotations == null ? null : messageAnnotations.createEncodingRetainingSection(), props.createEncodingRetainingSection(), applicationProperties.createEncodingRetainingSection(), null, serverMessage.getArrivalTime(), bodySection.getEncodedSize());
}
Also used : MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) MessageMetaData_1_0(org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Header(org.apache.qpid.server.protocol.v1_0.type.messaging.Header) DataSection(org.apache.qpid.server.protocol.v1_0.type.messaging.DataSection) MessageAnnotations(org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary)

Example 73 with Binary

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

the class MessageConverter_1_0_to_v0_8 method getCorrelationIdAsShortString.

private AMQShortString getCorrelationIdAsShortString(final Message_1_0 serverMsg) {
    Object correlationIdObject = getCorrelationId(serverMsg);
    final AMQShortString correlationId;
    try {
        if (correlationIdObject instanceof Binary) {
            correlationId = new AMQShortString(((Binary) correlationIdObject).getArray());
        } else if (correlationIdObject instanceof byte[]) {
            correlationId = new AMQShortString(((byte[]) correlationIdObject));
        } else {
            correlationId = AMQShortString.valueOf(correlationIdObject);
        }
    } catch (IllegalArgumentException e) {
        throw new MessageConversionException("Could not convert message from 1.0 to 0-8 because conversion of 'correlation-id' failed.", e);
    }
    return correlationId;
}
Also used : AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary)

Example 74 with Binary

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

the class MessageConverter_1_0_to_v0_8Test method testDataWithContentTypeJavaObjectStream.

public void testDataWithContentTypeJavaObjectStream() throws Exception {
    final byte[] expected = getObjectBytes("helloworld".getBytes(UTF_8));
    final Data value = new Data(new Binary(expected));
    Properties properties = new Properties();
    properties.setContentType(Symbol.valueOf("application/java-object-stream"));
    Message_1_0 sourceMessage = createTestMessage(properties, value.createEncodingRetainingSection());
    final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
    assertEquals("Unexpected mime type", "application/java-object-stream", convertedMessage.getMessageHeader().getMimeType());
    final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
    assertArrayEquals("Unexpected content", expected, getBytes(content));
}
Also used : NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) Data(org.apache.qpid.server.protocol.v1_0.type.messaging.Data) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties) AMQMessage(org.apache.qpid.server.protocol.v0_8.AMQMessage)

Example 75 with Binary

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

the class MessageConverter_1_0_to_v0_8Test method testDataWithMapMessageAnnotationAndContentTypeAmqpMap.

public void testDataWithMapMessageAnnotationAndContentTypeAmqpMap() throws Exception {
    Map<String, Object> originalMap = Collections.singletonMap("testKey", "testValue");
    byte[] data = new MapToAmqpMapConverter().toMimeContent(originalMap);
    String expectedMimeType = "amqp/map";
    final Data value = new Data(new Binary(data));
    Properties properties = new Properties();
    properties.setContentType(Symbol.valueOf(expectedMimeType));
    Message_1_0 sourceMessage = createTestMessage(properties, MAP_MESSAGE_MESSAGE_ANNOTATION, value.createEncodingRetainingSection());
    final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
    assertEquals("Unexpected mime type", expectedMimeType, convertedMessage.getMessageHeader().getMimeType());
    final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
    assertArrayEquals("Unexpected content", data, getBytes(content));
}
Also used : MapToAmqpMapConverter(org.apache.qpid.server.protocol.v0_10.transport.mimecontentconverter.MapToAmqpMapConverter) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) Data(org.apache.qpid.server.protocol.v1_0.type.messaging.Data) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties) AMQMessage(org.apache.qpid.server.protocol.v0_8.AMQMessage)

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