this.name = name;
}
public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body)
throws IOException {
Message message = new Message();
message.body = body;
try {
message.type = Byte.parseByte(properties.getType());
} catch (NumberFormatException nfe) {
if (logger.isLoggable(BasicLevel.WARN)) {
logger.log(BasicLevel.WARN, "Message Type field could not be parsed.", nfe);
}
message.type = Message.BYTES;
}
message.correlationId = properties.getCorrelationId();
Integer deliveryMode = properties.getDeliveryMode();
if (deliveryMode != null) {
if (deliveryMode.intValue() == 1) {
message.persistent = false;
} else if (deliveryMode.intValue() == 2) {
message.persistent = true;
}
}
if (properties.getPriority() != null)
message.priority = properties.getPriority().intValue();
if (properties.getTimestamp() != null)
message.timestamp = properties.getTimestamp().getTime();
try {
if (properties.getExpiration() != null)
message.expiration = Long.parseLong(properties.getExpiration());
} catch (NumberFormatException nfe) {
if (logger.isLoggable(BasicLevel.WARN)) {
logger.log(BasicLevel.WARN, "Expiration field could not be parsed.", nfe);
}
}
if (properties.getHeaders() != null) {
Map<String, Object> props = properties.getHeaders();
for (Map.Entry<String, Object> prop : props.entrySet()) {
try {
if (prop.getValue() instanceof LongString) {
message.setProperty(prop.getKey(), prop.getValue().toString());
} else {
message.setProperty(prop.getKey(), prop.getValue());
}
} catch (ClassCastException exc) {
if (logger.isLoggable(BasicLevel.ERROR)) {
logger.log(BasicLevel.ERROR, "Property can't be mapped to JMS message property.", exc);
}