Search in sources :

Example 1 with Delivery

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);
}
Also used : Destination(javax.jms.Destination) Enumeration(java.util.Enumeration) HashMap(java.util.HashMap) Field(com.swiftmq.amqp.v091.types.Field) BytesMessageImpl(com.swiftmq.jms.BytesMessageImpl) TextMessageImpl(com.swiftmq.jms.TextMessageImpl) ContentHeaderProperties(com.swiftmq.amqp.v091.types.ContentHeaderProperties) Delivery(com.swiftmq.impl.amqp.amqp.v00_09_01.Delivery)

Aggregations

ContentHeaderProperties (com.swiftmq.amqp.v091.types.ContentHeaderProperties)1 Field (com.swiftmq.amqp.v091.types.Field)1 Delivery (com.swiftmq.impl.amqp.amqp.v00_09_01.Delivery)1 BytesMessageImpl (com.swiftmq.jms.BytesMessageImpl)1 TextMessageImpl (com.swiftmq.jms.TextMessageImpl)1 Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1 Destination (javax.jms.Destination)1