use of com.swiftmq.amqp.v091.types.Field in project swiftmq-ce by iitsoftware.
the class BasicInboundTransformer method transformHeader.
private void transformHeader(MessageImpl msg, ContentHeaderProperties prop, DestinationFactory destinationFactory) throws JMSException {
if (prop.getContentType() != null)
msg.setStringProperty(prefixVendor + "ContentType", prop.getContentType());
if (prop.getContentEncoding() != null)
msg.setStringProperty(prefixVendor + "ContentEncoding", prop.getContentEncoding());
if (prop.getDeliveryMode() != null)
msg.setJMSDeliveryMode(prop.getDeliveryMode() == 1 ? DeliveryMode.NON_PERSISTENT : DeliveryMode.PERSISTENT);
else
msg.setJMSDeliveryMode(defaultDeliveryMode);
if (prop.getPriority() != null)
msg.setJMSPriority(prop.getPriority());
else
msg.setJMSPriority(defaultPriority);
if (prop.getCorrelationId() != null)
msg.setJMSCorrelationID(prop.getCorrelationId());
if (prop.getReplyTo() != null)
msg.setJMSReplyTo(destinationFactory.create(prop.getReplyTo()));
if (prop.getExpiration() != null) {
long value = Long.valueOf(prop.getExpiration());
if (value > 0)
msg.setJMSExpiration(System.currentTimeMillis() + value);
}
if (prop.getMessageId() != null)
msg.setJMSMessageID(prop.getMessageId());
else
msg.setJMSMessageID(nextMsgId());
if (prop.getTimestamp() != null)
msg.setJMSTimestamp(prop.getTimestamp());
else
msg.setJMSTimestamp(System.currentTimeMillis());
if (prop.getType() != null)
msg.setStringProperty(prefixVendor + "Type", prop.getType());
if (prop.getUserId() != null)
msg.setStringProperty(prefixVendor + "UserId", prop.getUserId());
if (prop.getAppId() != null)
msg.setStringProperty(prefixVendor + "AppId", prop.getAppId());
if (prop.getClusterId() != null)
msg.setStringProperty(prefixVendor + "ClusterId", prop.getClusterId());
Map<String, Object> headers = prop.getHeaders();
if (headers != null) {
for (Iterator iter = headers.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
String name = nameTranslator.translate((String) entry.getKey());
Field field = (Field) entry.getValue();
switch(field.getType()) {
case 't':
msg.setBooleanProperty(name, (Boolean) field.getValue());
break;
case 'b':
case 'B':
case 'U':
case 'u':
case 'I':
msg.setIntProperty(name, (Integer) field.getValue());
break;
case 'i':
case 'L':
msg.setLongProperty(name, (Long) field.getValue());
break;
case 'l':
break;
case 'f':
case 'd':
msg.setFloatProperty(name, (Float) field.getValue());
break;
case 'D':
break;
case 's':
msg.setShortProperty(name, (Short) field.getValue());
break;
case 'S':
msg.setStringProperty(name, (String) field.getStringValue());
break;
case 'A':
break;
case 'T':
msg.setLongProperty(name, (Long) field.getValue());
break;
case 'F':
break;
case 'V':
break;
}
}
}
}
use of com.swiftmq.amqp.v091.types.Field 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