AMQP-170 AMQP headers of LongString type are now converted to a java.lang.String if 1024 bytes or smaller, else the header value will be the DataInputStream retrieved from that LongString instance

This commit is contained in:
Mark Fisher
2011-05-27 14:15:37 -04:00
parent 862920929d
commit 9f69efa051

View File

@@ -37,6 +37,7 @@ import com.rabbitmq.client.AMQP.BasicProperties;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Envelope;
import com.rabbitmq.client.ShutdownSignalException;
import com.rabbitmq.client.impl.LongString;
/**
* @author Mark Fisher
@@ -151,7 +152,22 @@ public abstract class RabbitUtils {
Map<String, Object> headers = source.getHeaders();
if (!CollectionUtils.isEmpty(headers)) {
for (Map.Entry<String, Object> entry : headers.entrySet()) {
target.setHeader(entry.getKey(), entry.getValue());
Object value = entry.getValue();
if (value instanceof LongString) {
try {
LongString longString = (LongString) value;
if (longString.length() <= 1024) {
value = new String(longString.getBytes(), charset);
}
else {
value = longString.getStream();
}
}
catch (Exception e) {
throw convertRabbitAccessException(e);
}
}
target.setHeader(entry.getKey(), value);
}
}
target.setTimestamp(source.getTimestamp());