Search in sources :

Example 21 with MessageConversionException

use of org.apache.qpid.server.protocol.converter.MessageConversionException in project qpid-broker-j by apache.

the class PropertyConverter_Internal_to_v0_10Test method testHeadersConversionWithUnsupportedTypes.

public void testHeadersConversionWithUnsupportedTypes() throws IOException {
    final Map<String, Object> properties = Collections.singletonMap("bigDecimalProperty", new BigDecimal(1));
    final AMQMessageHeader header = mock(AMQMessageHeader.class);
    when(header.getHeaderNames()).thenReturn(properties.keySet());
    doAnswer(invocation -> {
        final String originalArgument = (String) (invocation.getArguments())[0];
        return properties.get(originalArgument);
    }).when(header).getHeader(any(String.class));
    InternalMessage originalMessage = createTestMessage(header);
    try {
        _messageConverter.convert(originalMessage, _addressSpace);
        fail("Expected exception not thrown");
    } catch (MessageConversionException e) {
    // pass
    }
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) Matchers.anyString(org.mockito.Matchers.anyString) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader) BigDecimal(java.math.BigDecimal)

Example 22 with MessageConversionException

use of org.apache.qpid.server.protocol.converter.MessageConversionException in project qpid-broker-j by apache.

the class PropertyConverter_Internal_to_v0_10Test method testHeadersConversionWhenKeyLengthExceeds255.

public void testHeadersConversionWhenKeyLengthExceeds255() throws IOException {
    final Map<String, Object> properties = Collections.singletonMap(generateLongString(), "test");
    final AMQMessageHeader header = mock(AMQMessageHeader.class);
    when(header.getHeaderNames()).thenReturn(properties.keySet());
    doAnswer(invocation -> {
        final String originalArgument = (String) (invocation.getArguments())[0];
        return properties.get(originalArgument);
    }).when(header).getHeader(any(String.class));
    InternalMessage originalMessage = createTestMessage(header);
    try {
        _messageConverter.convert(originalMessage, _addressSpace);
        fail("Expected exception not thrown");
    } catch (MessageConversionException e) {
    // pass
    }
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) Matchers.anyString(org.mockito.Matchers.anyString) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader)

Example 23 with MessageConversionException

use of org.apache.qpid.server.protocol.converter.MessageConversionException in project qpid-broker-j by apache.

the class PropertyConverter_Internal_to_v0_10Test method testCorrelationIdConversionWhenLengthExceeds16Bits.

public void testCorrelationIdConversionWhenLengthExceeds16Bits() throws IOException {
    final String correlationId = generateLongLongString();
    final AMQMessageHeader header = mock(AMQMessageHeader.class);
    when(header.getCorrelationId()).thenReturn(correlationId);
    InternalMessage originalMessage = createTestMessage(header);
    try {
        _messageConverter.convert(originalMessage, _addressSpace);
        fail("Expected exception is not thrown");
    } catch (MessageConversionException e) {
    // pass
    }
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) Matchers.anyString(org.mockito.Matchers.anyString) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader)

Example 24 with MessageConversionException

use of org.apache.qpid.server.protocol.converter.MessageConversionException in project qpid-broker-j by apache.

the class MessageConverter_Internal_to_v0_8 method convertMetaData.

private MessageMetaData convertMetaData(final InternalMessage serverMsg, final NamedAddressSpace addressSpace, final String bodyMimeType, final int size) {
    MessagePublishInfo publishInfo = createMessagePublishInfo(serverMsg, addressSpace);
    final BasicContentHeaderProperties props = new BasicContentHeaderProperties();
    props.setAppId(serverMsg.getMessageHeader().getAppId());
    props.setContentType(bodyMimeType);
    props.setCorrelationId(convertToShortStringForProperty("correlation-id", serverMsg.getMessageHeader().getCorrelationId()));
    props.setDeliveryMode(serverMsg.isPersistent() ? BasicContentHeaderProperties.PERSISTENT : BasicContentHeaderProperties.NON_PERSISTENT);
    props.setExpiration(serverMsg.getExpiration());
    props.setMessageId(convertToOptionalAMQPShortString(serverMsg.getMessageHeader().getMessageId()));
    props.setPriority(serverMsg.getMessageHeader().getPriority());
    props.setReplyTo(convertToShortStringForProperty("reply-to", getReplyTo(serverMsg, addressSpace)));
    props.setTimestamp(serverMsg.getMessageHeader().getTimestamp());
    props.setUserId(convertToOptionalAMQPShortString(serverMsg.getMessageHeader().getUserId()));
    props.setEncoding(convertToShortStringForProperty("encoding", serverMsg.getMessageHeader().getEncoding()));
    Map<String, Object> headerProps = new LinkedHashMap<String, Object>();
    for (String headerName : serverMsg.getMessageHeader().getHeaderNames()) {
        headerProps.put(headerName, serverMsg.getMessageHeader().getHeader(headerName));
    }
    try {
        props.setHeaders(FieldTable.convertToFieldTable(headerProps));
    } catch (IllegalArgumentException | AMQPInvalidClassException e) {
        throw new MessageConversionException("Could not convert message from internal to 0-8 because headers conversion failed.", e);
    }
    final ContentHeaderBody chb = new ContentHeaderBody(props);
    chb.setBodySize(size);
    return new MessageMetaData(publishInfo, chb, serverMsg.getArrivalTime());
}
Also used : MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) LinkedHashMap(java.util.LinkedHashMap)

Example 25 with MessageConversionException

use of org.apache.qpid.server.protocol.converter.MessageConversionException in project qpid-broker-j by apache.

the class MessageConverter_Internal_to_v1_0 method convertMetaData.

@Override
protected MessageMetaData_1_0 convertMetaData(final InternalMessage serverMessage, final EncodingRetainingSection<?> bodySection, final SectionEncoder sectionEncoder) {
    Header header = new Header();
    header.setDurable(serverMessage.isPersistent());
    header.setPriority(UnsignedByte.valueOf(serverMessage.getMessageHeader().getPriority()));
    if (serverMessage.getExpiration() != 0l && serverMessage.getArrivalTime() != 0l && serverMessage.getExpiration() >= serverMessage.getArrivalTime()) {
        header.setTtl(UnsignedInteger.valueOf(serverMessage.getExpiration() - serverMessage.getArrivalTime()));
    }
    Properties properties = new Properties();
    if (serverMessage.getMessageHeader().getEncoding() != null) {
        properties.setContentEncoding(Symbol.valueOf(serverMessage.getMessageHeader().getEncoding()));
    }
    properties.setCorrelationId(getCorrelationId(serverMessage));
    properties.setCreationTime(new Date(serverMessage.getMessageHeader().getTimestamp()));
    properties.setMessageId(getMessageId(serverMessage));
    Symbol contentType = getContentTypeSymbol(serverMessage.getMessageBody(), serverMessage.getMessageHeader().getMimeType());
    properties.setContentType(contentType);
    final String userId = serverMessage.getMessageHeader().getUserId();
    if (userId != null) {
        properties.setUserId(new Binary(userId.getBytes(StandardCharsets.UTF_8)));
    }
    properties.setReplyTo(serverMessage.getMessageHeader().getReplyTo());
    properties.setTo(serverMessage.getTo());
    ApplicationProperties applicationProperties = null;
    if (!serverMessage.getMessageHeader().getHeaderNames().isEmpty()) {
        try {
            applicationProperties = new ApplicationProperties(serverMessage.getMessageHeader().getHeaderMap());
        } catch (IllegalArgumentException e) {
            throw new MessageConversionException("Could not convert message from internal to 1.0" + " because conversion of 'application headers' failed.", e);
        }
    }
    final MessageAnnotations messageAnnotation = createMessageAnnotation(serverMessage.getMessageBody(), serverMessage.getMessageHeader().getMimeType(), bodySection);
    return new MessageMetaData_1_0(header.createEncodingRetainingSection(), null, messageAnnotation == null ? null : messageAnnotation.createEncodingRetainingSection(), properties.createEncodingRetainingSection(), applicationProperties == null ? null : applicationProperties.createEncodingRetainingSection(), null, serverMessage.getArrivalTime(), bodySection.getEncodedSize());
}
Also used : MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) Header(org.apache.qpid.server.protocol.v1_0.type.messaging.Header) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) 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) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties) Date(java.util.Date)

Aggregations

MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)55 Matchers.anyString (org.mockito.Matchers.anyString)25 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)22 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)22 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)17 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)15 MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)14 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)12 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)12 AMQMessageHeader (org.apache.qpid.server.message.AMQMessageHeader)8 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)8 DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)8 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)6 AmqpValue (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue)6 Date (java.util.Date)4 LinkedHashMap (java.util.LinkedHashMap)4 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)4 Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)4 ReplyTo (org.apache.qpid.server.protocol.v0_10.transport.ReplyTo)3 MessageMetaData_1_0 (org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0)3