use of org.apache.qpid.server.protocol.v0_8.FieldTable in project qpid-broker-j by apache.
the class BasicContentHeaderPropertiesTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
_testTable = new FieldTable();
_testTable.setString("TestString", _testString);
_testTable.setInteger("Testint", _testint);
_testProperties = new BasicContentHeaderProperties();
_testProperties.setHeaders(_testTable);
}
use of org.apache.qpid.server.protocol.v0_8.FieldTable in project qpid-broker-j by apache.
the class MessageConverter_0_10_to_0_8 method convertContentHeaderProperties.
public static BasicContentHeaderProperties convertContentHeaderProperties(MessageTransferMessage messageTransferMessage, NamedAddressSpace addressSpace) {
BasicContentHeaderProperties props = new BasicContentHeaderProperties();
Header header = messageTransferMessage.getHeader();
DeliveryProperties deliveryProps = header.getDeliveryProperties();
MessageProperties messageProps = header.getMessageProperties();
if (deliveryProps != null) {
if (deliveryProps.hasDeliveryMode()) {
props.setDeliveryMode((deliveryProps.getDeliveryMode() == MessageDeliveryMode.PERSISTENT ? BasicContentHeaderProperties.PERSISTENT : BasicContentHeaderProperties.NON_PERSISTENT));
}
if (deliveryProps.hasTtl()) {
props.setExpiration(messageTransferMessage.getArrivalTime() + deliveryProps.getTtl());
} else if (deliveryProps.hasExpiration()) {
props.setExpiration(deliveryProps.getExpiration());
}
if (deliveryProps.hasPriority()) {
props.setPriority((byte) deliveryProps.getPriority().getValue());
}
if (deliveryProps.hasTimestamp()) {
props.setTimestamp(deliveryProps.getTimestamp());
} else {
props.setTimestamp(messageTransferMessage.getArrivalTime());
}
}
if (messageProps != null) {
if (messageProps.hasAppId()) {
try {
props.setAppId(new AMQShortString(messageProps.getAppId()));
} catch (IllegalArgumentException e) {
// pass
}
}
if (messageProps.hasContentType()) {
props.setContentType(messageProps.getContentType());
}
if (messageProps.hasCorrelationId()) {
try {
props.setCorrelationId(new AMQShortString(messageProps.getCorrelationId()));
} catch (IllegalArgumentException e) {
throw new MessageConversionException("Could not convert message from 0-10 to 0-8 because conversion of 'correlationId' failed.", e);
}
}
if (messageProps.hasContentEncoding()) {
props.setEncoding(messageProps.getContentEncoding());
}
if (messageProps.hasMessageId()) {
// Add prefix 'ID:' to workaround broken 0-8..0-9-1 Qpid JMS client
props.setMessageId("ID:" + messageProps.getMessageId().toString());
}
if (messageProps.hasReplyTo()) {
ReplyTo replyTo = messageProps.getReplyTo();
String exchangeName = replyTo.getExchange();
String routingKey = replyTo.getRoutingKey();
if (exchangeName == null) {
exchangeName = "";
}
if (!"".equals(exchangeName) || (routingKey != null && !"".equals(routingKey))) {
MessageDestination destination = addressSpace.getAttainedMessageDestination(exchangeName);
Exchange<?> exchange = destination instanceof Exchange ? (Exchange<?>) destination : null;
String exchangeClass = exchange == null ? ExchangeDefaults.DIRECT_EXCHANGE_CLASS : exchange.getType();
String routingKeyOption = routingKey == null ? "" : "?routingkey='" + routingKey + "'";
final String replyToBindingUrl = String.format("%s://%s//%s", exchangeClass, exchangeName, routingKeyOption);
try {
props.setReplyTo(replyToBindingUrl);
} catch (IllegalArgumentException e) {
throw new MessageConversionException("Could not convert message from 0-10 to 0-8 because conversion of 'reply-to' failed.", e);
}
}
}
if (messageProps.hasUserId()) {
try {
props.setUserId(new AMQShortString(messageProps.getUserId()));
} catch (IllegalArgumentException e) {
// ignore
}
}
if (messageProps.hasApplicationHeaders()) {
Map<String, Object> appHeaders = new HashMap<String, Object>(messageProps.getApplicationHeaders());
if (messageProps.getApplicationHeaders().containsKey("x-jms-type")) {
String jmsType = String.valueOf(appHeaders.remove("x-jms-type"));
try {
props.setType(jmsType);
} catch (IllegalArgumentException e) {
throw new MessageConversionException("Could not convert message from 0-10 to 0-8 because x-jms-type conversion failed.", e);
}
}
FieldTable ft = new FieldTable();
for (Map.Entry<String, Object> entry : appHeaders.entrySet()) {
String headerName = entry.getKey();
try {
ft.put(AMQShortString.validValueOf(headerName), entry.getValue());
} catch (AMQPInvalidClassException e) {
throw new MessageConversionException(String.format("Could not convert message from 0-10 to 0-8 because conversion of application header '%s' failed.", headerName), e);
}
}
props.setHeaders(ft);
}
}
return props;
}
use of org.apache.qpid.server.protocol.v0_8.FieldTable in project qpid-broker-j by apache.
the class BasicContentHeaderProperties method read.
public int read(QpidByteBuffer input) {
_propertyFlags = input.getUnsignedShort();
int length = 2;
if ((_propertyFlags & (CONTENT_TYPE_MASK)) != 0) {
length++;
_contentType = AMQShortString.readAMQShortString(input);
if (_contentType != null) {
length += _contentType.length();
}
}
if ((_propertyFlags & ENCODING_MASK) != 0) {
length++;
_encoding = AMQShortString.readAMQShortString(input);
if (_encoding != null) {
length += _encoding.length();
}
}
if ((_propertyFlags & HEADERS_MASK) != 0) {
int fieldTableLength = input.getInt();
_headers = new FieldTable(input, fieldTableLength);
length += 4;
length += fieldTableLength;
}
if ((_propertyFlags & DELIVERY_MODE_MASK) != 0) {
_deliveryMode = input.get();
length++;
}
if ((_propertyFlags & PRIORITY_MASK) != 0) {
_priority = input.get();
length++;
}
if ((_propertyFlags & CORRELATION_ID_MASK) != 0) {
length++;
_correlationId = AMQShortString.readAMQShortString(input);
if (_correlationId != null) {
length += _correlationId.length();
}
}
if ((_propertyFlags & REPLY_TO_MASK) != 0) {
length++;
_replyTo = AMQShortString.readAMQShortString(input);
if (_replyTo != null) {
length += _replyTo.length();
}
}
if ((_propertyFlags & EXPIRATION_MASK) != 0) {
length++;
AMQShortString expiration = AMQShortString.readAMQShortString(input);
if (expiration != null) {
length += expiration.length();
_expiration = Long.parseLong(expiration.toString());
}
}
if ((_propertyFlags & MESSAGE_ID_MASK) != 0) {
length++;
_messageId = AMQShortString.readAMQShortString(input);
if (_messageId != null) {
length += _messageId.length();
}
}
if ((_propertyFlags & TIMESTAMP_MASK) != 0) {
_timestamp = input.getLong();
length += 8;
}
if ((_propertyFlags & TYPE_MASK) != 0) {
length++;
_type = AMQShortString.readAMQShortString(input);
if (_type != null) {
length += _type.length();
}
}
if ((_propertyFlags & USER_ID_MASK) != 0) {
length++;
_userId = AMQShortString.readAMQShortString(input);
if (_userId != null) {
length += _userId.length();
}
}
if ((_propertyFlags & APPLICATION_ID_MASK) != 0) {
length++;
_appId = AMQShortString.readAMQShortString(input);
if (_appId != null) {
length += _appId.length();
}
}
if ((_propertyFlags & CLUSTER_ID_MASK) != 0) {
length++;
_clusterId = AMQShortString.readAMQShortString(input);
if (_clusterId != null) {
length += _clusterId.length();
}
}
return length;
}
use of org.apache.qpid.server.protocol.v0_8.FieldTable in project qpid-broker-j by apache.
the class ConnectionStartBody method process.
public static void process(final QpidByteBuffer in, final ClientMethodProcessor dispatcher) throws AMQFrameDecodingException {
short versionMajor = in.getUnsignedByte();
short versionMinor = in.getUnsignedByte();
FieldTable serverProperties = EncodingUtils.readFieldTable(in);
byte[] mechanisms = EncodingUtils.readBytes(in);
byte[] locales = EncodingUtils.readBytes(in);
if (!dispatcher.ignoreAllButCloseOk()) {
dispatcher.receiveConnectionStart(versionMajor, versionMinor, serverProperties, mechanisms, locales);
}
if (serverProperties != null) {
serverProperties.clearEncodedForm();
}
}
use of org.apache.qpid.server.protocol.v0_8.FieldTable in project qpid-broker-j by apache.
the class AMQDecoderTest method testContentHeaderPropertiesFrame.
public void testContentHeaderPropertiesFrame() throws AMQProtocolVersionException, AMQFrameDecodingException, IOException {
final BasicContentHeaderProperties props = new BasicContentHeaderProperties();
final FieldTable table = new FieldTable();
table.setString("hello", "world");
table.setInteger("1+1=", 2);
props.setHeaders(table);
final AMQBody body = new ContentHeaderBody(props);
AMQFrame frame = new AMQFrame(1, body);
TestSender sender = new TestSender();
frame.writePayload(sender);
ByteBuffer msg = combine(sender.getSentBuffers());
_decoder.decodeBuffer(msg);
List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
AMQDataBlock firstFrame = frames.get(0);
if (firstFrame instanceof AMQFrame) {
assertEquals(ContentHeaderBody.TYPE, ((AMQFrame) firstFrame).getBodyFrame().getFrameType());
BasicContentHeaderProperties decodedProps = ((ContentHeaderBody) ((AMQFrame) firstFrame).getBodyFrame()).getProperties();
final FieldTable headers = decodedProps.getHeaders();
assertEquals("world", headers.getString("hello"));
} else {
fail("decode was not a frame");
}
}
Aggregations