use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class MessageConverter_1_0_to_v0_8Test method testDataWithContentTypeAmqpList.
public void testDataWithContentTypeAmqpList() throws Exception {
List<Object> originalMap = Collections.singletonList("testValue");
byte[] bytes = new ListToAmqpListConverter().toMimeContent(originalMap);
final Data value = new Data(new Binary(bytes));
Properties properties = new Properties();
properties.setContentType(Symbol.valueOf("amqp/list"));
Message_1_0 sourceMessage = createTestMessage(properties, value.createEncodingRetainingSection());
final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertEquals("Unexpected mime type", "amqp/list", 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 testAmqpValueWithNullWithMapMessageAnnotation.
public void testAmqpValueWithNullWithMapMessageAnnotation() throws Exception {
final Object expected = null;
final AmqpValue amqpValue = new AmqpValue(expected);
Message_1_0 sourceMessage = createTestMessage(MAP_MESSAGE_MESSAGE_ANNOTATION, amqpValue.createEncodingRetainingSection());
final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
assertEquals("Unexpected mime type", "jms/map-message", convertedMessage.getMessageHeader().getMimeType());
assertArrayEquals("Unexpected content size", new MapToJmsMapMessage().toMimeContent(Collections.emptyMap()), getBytes(content));
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class AbstractJDBCMessageStore method storeMetaData.
private void storeMetaData(Connection conn, long messageId, StorableMessageMetaData metaData) throws SQLException {
getLogger().debug("Adding metadata for message {}", messageId);
try (PreparedStatement stmt = conn.prepareStatement("INSERT INTO " + getMetaDataTableName() + "( message_id , meta_data ) values (?, ?)")) {
stmt.setLong(1, messageId);
final int bodySize = 1 + metaData.getStorableSize();
byte[] underlying = new byte[bodySize];
underlying[0] = (byte) metaData.getType().ordinal();
try (QpidByteBuffer buf = QpidByteBuffer.wrap(underlying)) {
buf.position(1);
try (QpidByteBuffer bufSlice = buf.slice()) {
metaData.writeToBuffer(buf);
}
}
try (ByteArrayInputStream bis = new ByteArrayInputStream(underlying)) {
stmt.setBinaryStream(2, bis, underlying.length);
int result = stmt.executeUpdate();
if (result == 0) {
throw new StoreException("Unable to add meta data for message " + messageId);
}
} catch (IOException e) {
throw new SQLException("Failed to close ByteArrayInputStream", e);
}
}
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class BasicContentHeaderPropertiesTest method testPopulatePropertiesFromBuffer.
public void testPopulatePropertiesFromBuffer() throws Exception {
QpidByteBuffer buf = QpidByteBuffer.wrap(new byte[300]);
_testProperties.populatePropertiesFromBuffer(buf, 99, 99);
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class AMQPConnection_1_0Impl method processProtocolHeader.
private void processProtocolHeader(final QpidByteBuffer msg) {
if (msg.remaining() >= 8) {
byte[] header = new byte[8];
msg.get(header);
final AuthenticationProvider<?> authenticationProvider = getPort().getAuthenticationProvider();
if (Arrays.equals(header, SASL_HEADER)) {
if (_saslComplete) {
throw new ConnectionScopedRuntimeException("SASL Layer header received after SASL already established");
}
try (QpidByteBuffer protocolHeader = QpidByteBuffer.wrap(SASL_HEADER)) {
getSender().send(protocolHeader);
}
SaslMechanisms mechanisms = new SaslMechanisms();
ArrayList<Symbol> mechanismsList = new ArrayList<>();
for (String name : authenticationProvider.getAvailableMechanisms(getTransport().isSecure())) {
mechanismsList.add(Symbol.valueOf(name));
}
mechanisms.setSaslServerMechanisms(mechanismsList.toArray(new Symbol[mechanismsList.size()]));
send(new SASLFrame(mechanisms), null);
_connectionState = ConnectionState.AWAIT_SASL_INIT;
_frameHandler = getFrameHandler(true);
} else if (Arrays.equals(header, AMQP_HEADER)) {
if (!_saslComplete) {
final List<String> mechanisms = authenticationProvider.getAvailableMechanisms(getTransport().isSecure());
if (mechanisms.contains(ExternalAuthenticationManagerImpl.MECHANISM_NAME) && getNetwork().getPeerPrincipal() != null) {
setUserPrincipal(new AuthenticatedPrincipal(getNetwork().getPeerPrincipal()));
} else if (mechanisms.contains(AnonymousAuthenticationManager.MECHANISM_NAME)) {
setUserPrincipal(new AuthenticatedPrincipal(((AnonymousAuthenticationManager) authenticationProvider).getAnonymousPrincipal()));
} else {
LOGGER.warn("{} : attempt to initiate AMQP connection without correctly authenticating", getLogSubject());
_connectionState = ConnectionState.CLOSED;
getNetwork().close();
}
}
try (QpidByteBuffer protocolHeader = QpidByteBuffer.wrap(AMQP_HEADER)) {
getSender().send(protocolHeader);
}
_connectionState = ConnectionState.AWAIT_OPEN;
_frameHandler = getFrameHandler(false);
} else {
LOGGER.warn("{} : unknown AMQP header {}", getLogSubject(), Functions.str(header));
_connectionState = ConnectionState.CLOSED;
getNetwork().close();
}
}
}
Aggregations