use of com.swiftmq.impl.amqp.amqp.v00_09_01.Delivery in project swiftmq-ce by iitsoftware.
the class BasicOutboundTransformer method transform.
public Delivery transform(MessageImpl jmsMessage) throws Exception {
jmsMessage.reset();
ContentHeaderProperties prop = new ContentHeaderProperties();
byte[] body = null;
if (jmsMessage instanceof TextMessageImpl) {
String text = ((TextMessageImpl) jmsMessage).getText();
if (text != null)
body = text.getBytes("utf-8");
} else if (jmsMessage instanceof BytesMessageImpl) {
BytesMessageImpl bytesMessage = (BytesMessageImpl) jmsMessage;
if (bytesMessage.getBodyLength() > 0) {
body = new byte[(int) bytesMessage.getBodyLength()];
bytesMessage.readBytes(body);
}
} else
throw new Exception("Unable to tranform (only Text/BytesMessages supported): " + jmsMessage);
// Fill props
prop.setWeight(0);
prop.setBodySize(Long.valueOf(body.length));
prop.setContentType(jmsMessage.getStringProperty(prefixVendor + "ContentType"));
prop.setContentEncoding(jmsMessage.getStringProperty(prefixVendor + "ContentEncoding"));
prop.setDeliveryMode(jmsMessage.getJMSDeliveryMode() == DeliveryMode.NON_PERSISTENT ? 1 : 2);
prop.setPriority(jmsMessage.getJMSPriority());
prop.setCorrelationId(jmsMessage.getJMSCorrelationID());
Destination replyTo = jmsMessage.getJMSReplyTo();
if (replyTo != null)
prop.setReplyTo(replyTo.toString());
prop.setExpiration(String.valueOf(jmsMessage.getJMSExpiration()));
prop.setMessageId(jmsMessage.getJMSMessageID());
prop.setTimestamp(jmsMessage.getJMSTimestamp());
prop.setType(jmsMessage.getStringProperty(prefixVendor + "Type"));
prop.setUserId(jmsMessage.getStringProperty(prefixVendor + "UserId"));
prop.setAppId(jmsMessage.getStringProperty(prefixVendor + "AppId"));
prop.setClusterId(jmsMessage.getStringProperty(prefixVendor + "ClusterId"));
Map<String, Object> headers = new HashMap<String, Object>();
for (Enumeration _enum = jmsMessage.getPropertyNames(); _enum.hasMoreElements(); ) {
String name = (String) _enum.nextElement();
if (!name.startsWith(prefixVendor)) {
Object value = jmsMessage.getObjectProperty(name);
char type = toFieldType(value);
if (value instanceof String)
value = ((String) value).getBytes("utf-8");
headers.put(nameTranslator.translate(name), new Field(type, value));
}
}
if (headers.size() > 0)
prop.setHeaders(headers);
return new Delivery(prop, body);
}
Aggregations