MessageTransfer xfr;
DeliveryProperties deliveryProps;
MessageProperties messageProps = null;
if(serverMsg instanceof MessageTransferMessage)
{
MessageTransferMessage msg = (MessageTransferMessage) serverMsg;
Struct[] headers;
if(msg.getHeader() == null)
{
headers = EMPTY_STRUCT_ARRAY;
}
else
{
headers = msg.getHeader().getStructs();
}
ArrayList<Struct> newHeaders = new ArrayList<Struct>(headers.length);
DeliveryProperties origDeliveryProps = null;
for(Struct header : headers)
{
if(header instanceof DeliveryProperties)
{
origDeliveryProps = (DeliveryProperties) header;
}
else
{
if(header instanceof MessageProperties)
{
messageProps = (MessageProperties) header;
}
newHeaders.add(header);
}
}
deliveryProps = new DeliveryProperties();
if(origDeliveryProps != null)
{
if(origDeliveryProps.hasDeliveryMode())
{
deliveryProps.setDeliveryMode(origDeliveryProps.getDeliveryMode());
}
if(origDeliveryProps.hasExchange())
{
deliveryProps.setExchange(origDeliveryProps.getExchange());
}
if(origDeliveryProps.hasExpiration())
{
deliveryProps.setExpiration(origDeliveryProps.getExpiration());
}
if(origDeliveryProps.hasPriority())
{
deliveryProps.setPriority(origDeliveryProps.getPriority());
}
if(origDeliveryProps.hasRoutingKey())
{
deliveryProps.setRoutingKey(origDeliveryProps.getRoutingKey());
}
if(origDeliveryProps.hasTimestamp())
{
deliveryProps.setTimestamp(origDeliveryProps.getTimestamp());
}
}
deliveryProps.setRedelivered(entry.isRedelivered());
newHeaders.add(deliveryProps);
if(_trace != null && messageProps == null)
{
messageProps = new MessageProperties();
newHeaders.add(messageProps);
}
Header header = new Header(newHeaders);
xfr = new MessageTransfer(_destination,_acceptMode,_acquireMode,header,msg.getBody());
}
else if(serverMsg instanceof AMQMessage)
{
AMQMessage message_0_8 = (AMQMessage) serverMsg;
deliveryProps = new DeliveryProperties();
messageProps = new MessageProperties();
int size = (int) message_0_8.getSize();
ByteBuffer body = ByteBuffer.allocate(size);
message_0_8.getContent(body, 0);
body.flip();
Struct[] headers = new Struct[] { deliveryProps, messageProps };
BasicContentHeaderProperties properties =
(BasicContentHeaderProperties) message_0_8.getContentHeaderBody().properties;
final AMQShortString exchange = message_0_8.getMessagePublishInfo().getExchange();
if(exchange != null)
{
deliveryProps.setExchange(exchange.toString());
}
deliveryProps.setExpiration(message_0_8.getExpiration());
deliveryProps.setImmediate(message_0_8.isImmediate());
deliveryProps.setPriority(MessageDeliveryPriority.get(properties.getPriority()));
deliveryProps.setRedelivered(entry.isRedelivered());
deliveryProps.setRoutingKey(message_0_8.getRoutingKey());
deliveryProps.setTimestamp(properties.getTimestamp());
messageProps.setContentEncoding(properties.getEncodingAsString());
messageProps.setContentLength(size);
if(properties.getAppId() != null)
{
messageProps.setAppId(properties.getAppId().getBytes());
}
messageProps.setContentType(properties.getContentTypeAsString());
if(properties.getCorrelationId() != null)
{
messageProps.setCorrelationId(properties.getCorrelationId().getBytes());
}
// TODO - ReplyTo
if(properties.getUserId() != null)
{
messageProps.setUserId(properties.getUserId().getBytes());
}
FieldTable fieldTable = properties.getHeaders();
final Map<String, Object> appHeaders = FieldTable.convertToMap(fieldTable);
messageProps.setApplicationHeaders(appHeaders);
Header header = new Header(headers);
xfr = new MessageTransfer(_destination,_acceptMode,_acquireMode,header, body);
}
else
{
deliveryProps = new DeliveryProperties();
messageProps = new MessageProperties();
int size = (int) serverMsg.getSize();
ByteBuffer body = ByteBuffer.allocate(size);
serverMsg.getContent(body, 0);
body.flip();
Struct[] headers = new Struct[] { deliveryProps, messageProps };
deliveryProps.setExpiration(serverMsg.getExpiration());
deliveryProps.setImmediate(serverMsg.isImmediate());
deliveryProps.setPriority(MessageDeliveryPriority.get(serverMsg.getMessageHeader().getPriority()));
deliveryProps.setRedelivered(entry.isRedelivered());
deliveryProps.setRoutingKey(serverMsg.getRoutingKey());
deliveryProps.setTimestamp(serverMsg.getMessageHeader().getTimestamp());
messageProps.setContentEncoding(serverMsg.getMessageHeader().getEncoding());
messageProps.setContentLength(size);
messageProps.setContentType(serverMsg.getMessageHeader().getMimeType());
if(serverMsg.getMessageHeader().getCorrelationId() != null)
{
messageProps.setCorrelationId(serverMsg.getMessageHeader().getCorrelationId().getBytes());
}
// TODO - ReplyTo
final Map<String, Object> appHeaders = new HashMap<String, Object>();
/*properties.getHeaders().processOverElements(
new FieldTable.FieldTableElementProcessor()
{
public boolean processElement(String propertyName, AMQTypedValue value)
{
Object val = value.getValue();
if(val instanceof AMQShortString)
{
val = val.toString();
}
appHeaders.put(propertyName, val);
return true;
}
public Object getResult()
{
return appHeaders;
}
});
messageProps.setApplicationHeaders(appHeaders);
*/
Header header = new Header(headers);
xfr = new MessageTransfer(_destination,_acceptMode,_acquireMode,header, body);
}
boolean excludeDueToFederation = false;
if(_trace != null)
{
if(!messageProps.hasApplicationHeaders())
{
messageProps.setApplicationHeaders(new HashMap<String,Object>());
}
Map<String,Object> appHeaders = messageProps.getApplicationHeaders();
String trace = (String) appHeaders.get("x-qpid.trace");
if(trace == null)
{
trace = _trace;
}