use of org.apache.qpid.server.message.mimecontentconverter.ObjectToMimeContentConverter in project qpid-broker-j by apache.
the class MessageConverter_Internal_to_v0_10 method convertToStoredMessage.
private StoredMessage<MessageMetaData_0_10> convertToStoredMessage(final InternalMessage serverMsg, final NamedAddressSpace addressSpace) {
Object messageBody = serverMsg.getMessageBody();
ObjectToMimeContentConverter converter = MimeContentConverterRegistry.getBestFitObjectToMimeContentConverter(messageBody);
final byte[] messageContent = converter == null ? new byte[] {} : converter.toMimeContent(messageBody);
String mimeType = converter == null ? null : converter.getMimeType();
mimeType = improveMimeType(serverMsg, mimeType);
final MessageMetaData_0_10 messageMetaData_0_10 = convertMetaData(serverMsg, addressSpace, mimeType, messageContent.length);
final int metadataSize = messageMetaData_0_10.getStorableSize();
return new StoredMessage<MessageMetaData_0_10>() {
@Override
public MessageMetaData_0_10 getMetaData() {
return messageMetaData_0_10;
}
@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() {
}
};
}
use of org.apache.qpid.server.message.mimecontentconverter.ObjectToMimeContentConverter 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);
}
use of org.apache.qpid.server.message.mimecontentconverter.ObjectToMimeContentConverter 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() {
}
};
}
Aggregations