*/
public class DefaultMessagePropertiesConverter implements MessagePropertiesConverter {
public MessageProperties toMessageProperties(final BasicProperties source, final Envelope envelope,
final String charset) {
MessageProperties target = new MessageProperties();
Map<String, Object> headers = source.getHeaders();
if (!CollectionUtils.isEmpty(headers)) {
for (Map.Entry<String, Object> entry : headers.entrySet()) {
target.setHeader(entry.getKey(), convertLongStringIfNecessary(entry.getValue(), charset));
}
}
target.setTimestamp(source.getTimestamp());
target.setMessageId(source.getMessageId());
target.setUserId(source.getUserId());
target.setAppId(source.getAppId());
target.setClusterId(source.getClusterId());
target.setType(source.getType());
Integer deliverMode = source.getDeliveryMode();
if (deliverMode != null) {
target.setDeliveryMode(MessageDeliveryMode.fromInt(deliverMode));
}
target.setExpiration(source.getExpiration());
target.setPriority(source.getPriority());
target.setContentType(source.getContentType());
target.setContentEncoding(source.getContentEncoding());
String correlationId = source.getCorrelationId();
if (correlationId != null) {
try {
target.setCorrelationId(source.getCorrelationId().getBytes(charset));
} catch (UnsupportedEncodingException ex) {
throw new AmqpUnsupportedEncodingException(ex);
}
}
String replyTo = source.getReplyTo();
if (replyTo != null) {
target.setReplyTo(replyTo);
}
if (envelope != null) {
target.setReceivedExchange(envelope.getExchange());
target.setReceivedRoutingKey(envelope.getRoutingKey());
target.setRedelivered(envelope.isRedeliver());
target.setDeliveryTag(envelope.getDeliveryTag());
}
return target;
}