JmsMessageType messageType = JmsMessageHelper.discoverMessageTypeFromPayload(payload);
try {
switch (messageType) {
case Bytes:
BytesMessage bytesMessage = typeConverter.convertTo(BytesMessage.class, payload);
answer = bytesMessage;
break;
case Map:
MapMessage mapMessage = session.createMapMessage();
Map<String, Object> objMap = (Map<String, Object>) payload;
Set<String> keys = objMap.keySet();
for (String key : keys) {
Object value = objMap.get(key);
mapMessage.setObject(key, value);
}
answer = mapMessage;
break;
case Object:
ObjectMessage objectMessage = session.createObjectMessage();
objectMessage.setObject((Serializable) payload);
answer = objectMessage;
break;
case Text:
TextMessage textMessage = session.createTextMessage();
textMessage.setText((String) payload);
answer = textMessage;
break;
case Stream:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream is = typeConverter.convertTo(InputStream.class, payload);
int reads = is.read();
while (reads != -1) {
baos.write(reads);
reads = is.read();
}
BytesMessage bytesStreamMessage = session.createBytesMessage();
bytesStreamMessage.writeBytes(baos.toByteArray());
baos.close();
is.close();
answer = bytesStreamMessage;
break;
default: