use of com.swiftmq.amqp.v100.messaging.AMQPMessage in project swiftmq-ce by iitsoftware.
the class JMSMappingInboundTransformer method transform.
public MessageImpl transform(TransferFrame frame, DestinationFactory destinationFactory) throws AMQPException, JMSException {
jmsTypeProp = getValue(PROP_JMS_TYPE, null);
MessageImpl jmsMessage = null;
try {
AMQPMessage amqpMessage = null;
if (frame.getMorePayloads() != null) {
List morePayloads = frame.getMorePayloads();
byte[][] b = new byte[morePayloads.size() + 1][];
b[0] = frame.getPayload();
for (int i = 0; i < morePayloads.size(); i++) b[i + 1] = (byte[]) morePayloads.get(i);
amqpMessage = new AMQPMessage(b, frame.getPayloadLength());
} else
amqpMessage = new AMQPMessage(frame.getPayload());
jmsMessage = messageFactory.create(amqpMessage);
jmsMessage.setLongProperty(prefixVendor + Util.PROP_MESSAGE_FORMAT, frame.getMessageFormat().getValue());
jmsMessage.setBooleanProperty(amqpNative, false);
Header header = amqpMessage.getHeader();
if (header != null)
transformHeader(header, jmsMessage);
DeliveryAnnotations deliveryAnnotations = amqpMessage.getDeliveryAnnotations();
if (deliveryAnnotations != null)
transformMap(deliveryAnnotations.getValue(), jmsMessage, prefixDA);
MessageAnnotations messageAnnotations = amqpMessage.getMessageAnnotations();
if (messageAnnotations != null)
transformMap(messageAnnotations.getValue(), jmsMessage, prefixMA);
Properties properties = amqpMessage.getProperties();
if (properties != null)
transformProperties(properties, jmsMessage, destinationFactory);
ApplicationProperties applicationProperties = amqpMessage.getApplicationProperties();
if (applicationProperties != null)
transformApplicationProperties(applicationProperties, jmsMessage);
Footer footer = amqpMessage.getFooter();
if (footer != null)
transformMap(footer.getValue(), jmsMessage, prefixFT);
} catch (Exception e) {
throw new AMQPException(e.toString());
}
jmsMessage.reset();
return jmsMessage;
}
use of com.swiftmq.amqp.v100.messaging.AMQPMessage in project swiftmq-ce by iitsoftware.
the class MessageTypeBodyFactory method createBody.
public void createBody(MessageImpl jmsMessage, AMQPMessage amqpMessage) throws JMSException, AMQPException {
jmsMessage.reset();
if (jmsMessage instanceof TextMessageImpl) {
amqpMessage.setAmqpValue(new AmqpValue(new AMQPString(((TextMessageImpl) jmsMessage).getText())));
} else if (jmsMessage instanceof MapMessageImpl) {
MapMessageImpl msg = (MapMessageImpl) jmsMessage;
Map map = new HashMap();
for (Enumeration _enum = msg.getMapNames(); _enum.hasMoreElements(); ) {
String name = (String) _enum.nextElement();
map.put(new AMQPString(name), Util.convertJMStoAMQP(msg.getObject(name)));
}
try {
amqpMessage.setAmqpValue(new AmqpValue(new AMQPMap(map)));
} catch (IOException e) {
throw new AMQPException(e.toString());
}
} else if (jmsMessage instanceof BytesMessageImpl) {
BytesMessageImpl msg = (BytesMessageImpl) jmsMessage;
byte[] b = new byte[(int) msg.getBodyLength()];
msg.readBytes(b);
amqpMessage.addData(new Data(b));
} else if (jmsMessage instanceof ObjectMessageImpl) {
amqpMessage.setAmqpValue(new AmqpValue(Util.convertJMStoAMQP(((ObjectMessageImpl) jmsMessage).getObject())));
} else if (jmsMessage instanceof StreamMessageImpl) {
List list = new ArrayList();
StreamMessageImpl msg = (StreamMessageImpl) jmsMessage;
try {
for (; ; ) {
list.add(Util.convertJMStoAMQP(msg.readObject()));
}
} catch (MessageEOFException e) {
}
try {
amqpMessage.addAmqpSequence(new AmqpSequence(list));
} catch (IOException e) {
throw new AMQPException(e.toString());
}
}
}
use of com.swiftmq.amqp.v100.messaging.AMQPMessage in project rabbitmq-stream-java-client by rabbitmq.
the class SwiftMqCodec method createMessage.
protected Message createMessage(byte[] data) {
AMQPMessage amqpMessage;
try {
amqpMessage = new AMQPMessage(data);
} catch (Exception e) {
throw new StreamException("Error while decoding AMQP 1.0 message");
}
Object body = extractBody(amqpMessage);
com.rabbitmq.stream.Properties properties = createProperties(amqpMessage);
Map<String, Object> applicationProperties = createApplicationProperties(amqpMessage);
Map<String, Object> messageAnnotations = createMessageAnnotations(amqpMessage);
return new SwiftMqMessage(amqpMessage, body, properties, applicationProperties, messageAnnotations);
}
Aggregations