use of org.apache.qpid.server.protocol.converter.MessageConversionException in project qpid-broker-j by apache.
the class PropertyConverter_1_0_to_0_8Test method testContentEncodingConversionWhenLengthExceeds255.
public void testContentEncodingConversionWhenLengthExceeds255() {
String contentEncoding = generateLongString();
final Properties properties = new Properties();
properties.setContentEncoding(Symbol.valueOf(contentEncoding));
Message_1_0 message = createTestMessage(properties);
try {
_messageConverter.convert(message, _namedAddressSpace);
fail("expected exception not thrown");
} catch (MessageConversionException e) {
// pass
}
}
use of org.apache.qpid.server.protocol.converter.MessageConversionException in project qpid-broker-j by apache.
the class PropertyConverter_1_0_to_0_8Test method testToConversionWhenRoutingKeyLengthExceeds255.
public void testToConversionWhenRoutingKeyLengthExceeds255() {
final String testExchange = "testExchange";
final String testRoutingKey = generateLongString();
String to = testExchange + "/" + testRoutingKey;
Properties properties = new Properties();
properties.setTo(to);
Message_1_0 message = createTestMessage(properties);
try {
_messageConverter.convert(message, _namedAddressSpace);
fail("Exception is not thrown");
} catch (MessageConversionException e) {
// pass
}
}
use of org.apache.qpid.server.protocol.converter.MessageConversionException in project qpid-broker-j by apache.
the class PropertyConverter_1_0_to_0_8Test method testReplyToConversionWhenResultExceeds255.
public void testReplyToConversionWhenResultExceeds255() {
final String replyTo = generateLongString() + "/" + generateLongString();
Properties properties = new Properties();
properties.setReplyTo(replyTo);
Message_1_0 message = createTestMessage(properties);
try {
_messageConverter.convert(message, _namedAddressSpace);
fail("expected exception not thrown");
} catch (MessageConversionException e) {
// pass
}
}
use of org.apache.qpid.server.protocol.converter.MessageConversionException in project qpid-broker-j by apache.
the class MessageConverter_from_1_0 method convertBodyToObject.
static Object convertBodyToObject(final Message_1_0 serverMessage) {
SectionDecoderImpl sectionDecoder = new SectionDecoderImpl(MessageConverter_v1_0_to_Internal.TYPE_REGISTRY.getSectionDecoderRegistry());
Object bodyObject = null;
List<EncodingRetainingSection<?>> sections = null;
try {
try (QpidByteBuffer allData = serverMessage.getContent()) {
sections = sectionDecoder.parseAll(allData);
}
List<EncodingRetainingSection<?>> bodySections = new ArrayList<>(sections.size());
ListIterator<EncodingRetainingSection<?>> iterator = sections.listIterator();
EncodingRetainingSection<?> previousSection = null;
while (iterator.hasNext()) {
EncodingRetainingSection<?> section = iterator.next();
if (section instanceof AmqpValueSection || section instanceof DataSection || section instanceof AmqpSequenceSection) {
if (previousSection != null && (previousSection.getClass() != section.getClass() || section instanceof AmqpValueSection)) {
throw new MessageConversionException("Message is badly formed and has multiple body section which are not all Data or not all AmqpSequence");
} else {
previousSection = section;
}
bodySections.add(section);
}
}
// In 1.0 of the spec, it is illegal to have message with no body but AMQP-127 asks to have that restriction lifted
if (!bodySections.isEmpty()) {
EncodingRetainingSection<?> firstBodySection = bodySections.get(0);
if (firstBodySection instanceof AmqpValueSection) {
bodyObject = convertValue(firstBodySection.getValue());
} else if (firstBodySection instanceof DataSection) {
int totalSize = 0;
for (EncodingRetainingSection<?> section : bodySections) {
totalSize += ((DataSection) section).getValue().getArray().length;
}
byte[] bodyData = new byte[totalSize];
ByteBuffer buf = ByteBuffer.wrap(bodyData);
for (EncodingRetainingSection<?> section : bodySections) {
buf.put(((DataSection) section).getValue().asByteBuffer());
}
bodyObject = bodyData;
} else {
ArrayList<Object> totalSequence = new ArrayList<>();
for (EncodingRetainingSection<?> section : bodySections) {
totalSequence.addAll(((AmqpSequenceSection) section).getValue());
}
bodyObject = convertValue(totalSequence);
}
}
} catch (AmqpErrorException e) {
throw new ConnectionScopedRuntimeException(e);
} finally {
if (sections != null) {
sections.forEach(EncodingRetaining::dispose);
}
}
return bodyObject;
}
use of org.apache.qpid.server.protocol.converter.MessageConversionException in project qpid-broker-j by apache.
the class MessageConverter_from_1_0 method getAmqp0xConvertedContentAndMimeType.
public static ConvertedContentAndMimeType getAmqp0xConvertedContentAndMimeType(final Message_1_0 serverMsg) {
Object bodyObject = convertBodyToObject(serverMsg);
ObjectToMimeContentConverter converter = getBestFitObjectToMimeContentConverter(bodyObject);
ContentHint contentHint = getAmqp0xTypeHint(serverMsg);
Class<?> typeHint = contentHint.getContentClass();
if (typeHint == null && bodyObject == null) {
typeHint = Void.class;
}
if (converter == null) {
converter = getBestFitObjectToMimeContentConverter(bodyObject, typeHint);
if (converter == null) {
throw new MessageConversionException(String.format("Could not convert message from 1.0 to 0-x because conversion of content failed." + " Could not find mime type converter for the content '%s'.", bodyObject == null ? null : bodyObject.getClass().getSimpleName()));
}
}
final byte[] messageContent = converter.toMimeContent(bodyObject);
String mimeType = converter.getMimeType();
if (bodyObject instanceof byte[]) {
if (Serializable.class == typeHint) {
mimeType = "application/java-object-stream";
} else if (String.class == typeHint) {
mimeType = "text/plain";
} else if ((Map.class == typeHint || List.class == typeHint) && contentHint.getContentType() != null) {
mimeType = contentHint.getContentType();
}
}
return new ConvertedContentAndMimeType(messageContent, mimeType);
}
Aggregations