use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class MessageConverter_1_0_to_v0_8Test method doTestDataWithAnnotation.
private void doTestDataWithAnnotation(final byte[] data, final MessageAnnotations messageAnnotations, final String expectedMimeType) throws Exception {
final Data value = new Data(new Binary(data));
Message_1_0 sourceMessage = createTestMessage(messageAnnotations, value.createEncodingRetainingSection());
final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertEquals("Unexpected mime type", expectedMimeType, convertedMessage.getMessageHeader().getMimeType());
final QpidByteBuffer content = convertedMessage.getContent();
assertArrayEquals("Unexpected content", data, getBytes(content));
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class MessageConverter_1_0_to_v0_8Test method testDataWithContentTypeJmsStreamMessage.
public void testDataWithContentTypeJmsStreamMessage() throws Exception {
List<Object> originalMap = Collections.singletonList("testValue");
byte[] bytes = new ListToJmsStreamMessage().toMimeContent(originalMap);
final Data value = new Data(new Binary(bytes));
Properties properties = new Properties();
properties.setContentType(Symbol.valueOf("jms/stream-message"));
Message_1_0 sourceMessage = createTestMessage(properties, value.createEncodingRetainingSection());
final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertEquals("Unexpected mime type", "jms/stream-message", convertedMessage.getMessageHeader().getMimeType());
final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
assertArrayEquals("Unexpected content", bytes, getBytes(content));
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class MessageConverter_1_0_to_v0_8Test method createTestMessage.
private Message_1_0 createTestMessage(final Header header, final DeliveryAnnotations deliveryAnnotations, final MessageAnnotations messageAnnotations, final Properties properties, final ApplicationProperties applicationProperties, final long arrivalTime, final EncodingRetainingSection section) {
final StoredMessage<MessageMetaData_1_0> storedMessage = mock(StoredMessage.class);
MessageMetaData_1_0 metaData = new MessageMetaData_1_0(header.createEncodingRetainingSection(), deliveryAnnotations.createEncodingRetainingSection(), messageAnnotations.createEncodingRetainingSection(), properties.createEncodingRetainingSection(), applicationProperties.createEncodingRetainingSection(), new Footer(Collections.emptyMap()).createEncodingRetainingSection(), arrivalTime, 0);
when(storedMessage.getMetaData()).thenReturn(metaData);
if (section != null) {
// TODO this seems to leak QBBs
final QpidByteBuffer combined = section.getEncodedForm();
when(storedMessage.getContentSize()).thenReturn((int) section.getEncodedSize());
final ArgumentCaptor<Integer> offsetCaptor = ArgumentCaptor.forClass(Integer.class);
final ArgumentCaptor<Integer> sizeCaptor = ArgumentCaptor.forClass(Integer.class);
when(storedMessage.getContent(offsetCaptor.capture(), sizeCaptor.capture())).then(invocation -> combined.view(offsetCaptor.getValue(), sizeCaptor.getValue()));
} else {
when(storedMessage.getContent(0, 0)).thenReturn(QpidByteBuffer.emptyQpidByteBuffer());
}
return new Message_1_0(storedMessage);
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class AbstractJDBCMessageStore method addContent.
private void addContent(final Connection conn, long messageId, QpidByteBuffer contentBody) {
getLogger().debug("Adding content for message {}", messageId);
try (PreparedStatement stmt = conn.prepareStatement("INSERT INTO " + getMessageContentTableName() + "( message_id, content ) values (?, ?)");
QpidByteBuffer bodyDuplicate = contentBody.duplicate();
InputStream inputStream = bodyDuplicate.asInputStream()) {
stmt.setLong(1, messageId);
stmt.setBinaryStream(2, inputStream, contentBody.remaining());
stmt.executeUpdate();
} catch (SQLException | IOException e) {
JdbcUtils.closeConnection(conn, getLogger());
throw new StoreException("Error adding content for message " + messageId + ": " + e.getMessage(), e);
}
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class AbstractJDBCMessageStore method getStorableMessageMetaData.
private StorableMessageMetaData getStorableMessageMetaData(final long messageId, final InputStream stream) throws SQLException {
try {
int typeOrdinal = stream.read() & 0xff;
MessageMetaDataType type = MessageMetaDataTypeRegistry.fromOrdinal(typeOrdinal);
try (QpidByteBuffer buf = QpidByteBuffer.asQpidByteBuffer(stream)) {
return type.createMetaData(buf);
}
} catch (IOException | RuntimeException e) {
throw new StoreException("Failed to stream metadata for message with id " + messageId, e);
}
}
Aggregations