Search in sources :

Example 51 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 testToConversionWhenExchangeLengthExceeds255.

public void testToConversionWhenExchangeLengthExceeds255() throws IOException {
    final String testExchange = generateLongString();
    final String testRoutingKey = "testRoutingKey";
    String to = testExchange + "/" + testRoutingKey;
    InternalMessage message = createTestMessage(to);
    try {
        _messageConverter.convert(message, _addressSpace);
        fail("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)

Example 52 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 convertToStoredMessage.

private StoredMessage<MessageMetaData> convertToStoredMessage(final InternalMessage serverMsg, final NamedAddressSpace addressSpace) {
    Object messageBody = serverMsg.getMessageBody();
    ObjectToMimeContentConverter converter = MimeContentConverterRegistry.getBestFitObjectToMimeContentConverter(messageBody);
    final byte[] messageContent;
    try {
        messageContent = converter == null ? new byte[] {} : converter.toMimeContent(messageBody);
    } catch (IllegalArgumentException e) {
        throw new MessageConversionException("Could not convert message from Internal to 0-8 because" + " conversion of message content failed.", e);
    }
    String mimeType = converter == null ? null : converter.getMimeType();
    mimeType = improveMimeType(serverMsg, mimeType);
    final MessageMetaData messageMetaData_0_8 = convertMetaData(serverMsg, addressSpace, mimeType, messageContent.length);
    final int metadataSize = messageMetaData_0_8.getStorableSize();
    return new StoredMessage<MessageMetaData>() {

        @Override
        public MessageMetaData getMetaData() {
            return messageMetaData_0_8;
        }

        @Override
        public long getMessageNumber() {
            return serverMsg.getMessageNumber();
        }

        @Override
        public QpidByteBuffer getContent(final int offset, final int length) {
            return QpidByteBuffer.wrap(messageContent, offset, length);
        }

        @Override
        public int getContentSize() {
            return messageContent.length;
        }

        @Override
        public int getMetadataSize() {
            return metadataSize;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean isInMemory() {
            return true;
        }

        @Override
        public boolean flowToDisk() {
            return false;
        }

        @Override
        public void reallocate() {
        }
    };
}
Also used : ObjectToMimeContentConverter(org.apache.qpid.server.message.mimecontentconverter.ObjectToMimeContentConverter) MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) StoredMessage(org.apache.qpid.server.store.StoredMessage)

Example 53 with MessageConversionException

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

the class PropertyConverter_Internal_to_v0_8Test method testCorrelationIdConversionWhenLengthExceeds255.

public void testCorrelationIdConversionWhenLengthExceeds255() {
    final String correlationId = generateLongString();
    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) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader)

Example 54 with MessageConversionException

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

the class PropertyConverter_Internal_to_v0_8Test method testHeadersConversionWhenKeyLengthExceeds255.

public void testHeadersConversionWhenKeyLengthExceeds255() {
    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) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader)

Example 55 with MessageConversionException

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

the class AbstractConsumerTarget method sendNextMessage.

@Override
public boolean sendNextMessage() {
    MessageContainer messageContainer = null;
    MessageInstanceConsumer consumer = null;
    boolean iteratedCompleteList = false;
    while (messageContainer == null) {
        if (_pullIterator == null || !_pullIterator.hasNext()) {
            if (iteratedCompleteList) {
                break;
            }
            iteratedCompleteList = true;
            _pullIterator = getConsumers().iterator();
        }
        if (_pullIterator.hasNext()) {
            consumer = _pullIterator.next();
            messageContainer = consumer.pullMessage();
        }
    }
    if (messageContainer != null) {
        MessageInstance entry = messageContainer.getMessageInstance();
        try {
            send(consumer, entry, false);
        } catch (MessageConversionException mce) {
            restoreCredit(entry.getMessage());
            final TransactionLogResource owningResource = entry.getOwningResource();
            if (owningResource instanceof MessageSource) {
                final MessageSource.MessageConversionExceptionHandlingPolicy handlingPolicy = ((MessageSource) owningResource).getMessageConversionExceptionHandlingPolicy();
                switch(handlingPolicy) {
                    case CLOSE:
                        entry.release(consumer);
                        throw new ConnectionScopedRuntimeException(String.format("Unable to convert message %s for this consumer", entry.getMessage()), mce);
                    case ROUTE_TO_ALTERNATE:
                        if (consumer.acquires()) {
                            int enqueues = entry.routeToAlternate(null, null);
                            if (enqueues == 0) {
                                LOGGER.info("Failed to convert message {} for this consumer because '{}'." + "  Message discarded.", entry.getMessage(), mce.getMessage());
                            } else {
                                LOGGER.info("Failed to convert message {} for this consumer because '{}'." + "  Message routed to alternate.", entry.getMessage(), mce.getMessage());
                            }
                        } else {
                            LOGGER.info("Failed to convert message {} for this browser because '{}'." + "  Message skipped.", entry.getMessage(), mce.getMessage());
                        }
                        break;
                    case REJECT:
                        entry.reject(consumer);
                        entry.release(consumer);
                        LOGGER.info("Failed to convert message {} for this consumer because '{}'." + "  Message skipped.", entry.getMessage(), mce.getMessage());
                        break;
                    default:
                        throw new ServerScopedRuntimeException("Unrecognised policy " + handlingPolicy);
                }
            } else {
                throw new ConnectionScopedRuntimeException(String.format("Unable to convert message %s for this consumer", entry.getMessage()), mce);
            }
        } finally {
            if (messageContainer.getMessageReference() != null) {
                messageContainer.getMessageReference().release();
            }
        }
        return true;
    } else {
        return false;
    }
}
Also used : MessageInstance(org.apache.qpid.server.message.MessageInstance) MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) MessageContainer(org.apache.qpid.server.message.MessageContainer) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) MessageInstanceConsumer(org.apache.qpid.server.message.MessageInstanceConsumer) MessageSource(org.apache.qpid.server.message.MessageSource) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

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