@Test public void testForeignObjectMessageTransformCreateNewMessage() throws JMSException { final String MESSAGE_BODY = "TEST-MESSAGE-BODY"; ForeignJmsObjectMessage foreignMessage = new ForeignJmsObjectMessage(); foreignMessage.setBooleanProperty("boolProperty", true); foreignMessage.setObject(MESSAGE_BODY); JmsMessage transformed = JmsMessageTransformation.transformMessage(createMockJmsConnection(), foreignMessage); assertNotSame(foreignMessage, transformed); assertFalse(transformed.equals(foreignMessage)); assertTrue(transformed instanceof JmsObjectMessage); JmsObjectMessage message = (JmsObjectMessage) transformed; assertTrue(message.propertyExists("boolProperty")); assertEquals(MESSAGE_BODY, message.getObject()); }
public static JmsMessage transformMessage(JmsConnection connection, Message message) throws JMSException { JmsMessage jmsMessage = null; JmsMessageFactory factory = connection.getMessageFactory(); if (message instanceof BytesMessage) { BytesMessage bytesMsg = (BytesMessage) message; bytesMsg.reset(); JmsBytesMessage msg = factory.createBytesMessage(); try { for (;;) { msg.writeByte(bytesMsg.readByte()); } } catch (MessageEOFException e) { } jmsMessage = msg; } else if (message instanceof MapMessage) { MapMessage mapMsg = (MapMessage) message; JmsMapMessage msg = factory.createMapMessage(); Enumeration<?> iter = mapMsg.getMapNames(); while (iter.hasMoreElements()) { String name = iter.nextElement().toString(); msg.setObject(name, mapMsg.getObject(name)); } jmsMessage = msg; } else if (message instanceof ObjectMessage) { ObjectMessage objMsg = (ObjectMessage) message; JmsObjectMessage msg = factory.createObjectMessage(); msg.setObject(objMsg.getObject()); jmsMessage = msg; } else if (message instanceof StreamMessage) { StreamMessage streamMessage = (StreamMessage) message; streamMessage.reset(); JmsStreamMessage msg = factory.createStreamMessage(); Object obj = null; try { while ((obj = streamMessage.readObject()) != null) { msg.writeObject(obj); } } catch (MessageEOFException e) { } jmsMessage = msg; } else if (message instanceof TextMessage) { TextMessage textMsg = (TextMessage) message; JmsTextMessage msg = factory.createTextMessage(); msg.setText(textMsg.getText()); jmsMessage = msg; } else { jmsMessage = factory.createMessage(); } copyProperties(connection, message, jmsMessage); return jmsMessage; }
JmsMessageTransformation { public static JmsMessage transformMessage(JmsConnection connection, Message message) throws JMSException { JmsMessage jmsMessage = null; JmsMessageFactory factory = connection.getMessageFactory(); if (message instanceof BytesMessage) { BytesMessage bytesMsg = (BytesMessage) message; bytesMsg.reset(); JmsBytesMessage msg = factory.createBytesMessage(); try { for (;;) { msg.writeByte(bytesMsg.readByte()); } } catch (MessageEOFException e) { } jmsMessage = msg; } else if (message instanceof MapMessage) { MapMessage mapMsg = (MapMessage) message; JmsMapMessage msg = factory.createMapMessage(); Enumeration<?> iter = mapMsg.getMapNames(); while (iter.hasMoreElements()) { String name = iter.nextElement().toString(); msg.setObject(name, mapMsg.getObject(name)); } jmsMessage = msg; } else if (message instanceof ObjectMessage) { ObjectMessage objMsg = (ObjectMessage) message; JmsObjectMessage msg = factory.createObjectMessage(); msg.setObject(objMsg.getObject()); jmsMessage = msg; } else if (message instanceof StreamMessage) { StreamMessage streamMessage = (StreamMessage) message; streamMessage.reset(); JmsStreamMessage msg = factory.createStreamMessage(); Object obj = null; try { while ((obj = streamMessage.readObject()) != null) { msg.writeObject(obj); } } catch (MessageEOFException e) { } jmsMessage = msg; } else if (message instanceof TextMessage) { TextMessage textMsg = (TextMessage) message; JmsTextMessage msg = factory.createTextMessage(); msg.setText(textMsg.getText()); jmsMessage = msg; } else { jmsMessage = factory.createMessage(); } copyProperties(connection, message, jmsMessage); return jmsMessage; } }
JmsMessageTransformation { public static JmsMessage transformMessage(JmsConnection connection, Message message) throws JMSException { JmsMessage jmsMessage = null; JmsMessageFactory factory = connection.getMessageFactory(); if (message instanceof BytesMessage) { BytesMessage bytesMsg = (BytesMessage) message; bytesMsg.reset(); JmsBytesMessage msg = factory.createBytesMessage(); try { for (;;) { msg.writeByte(bytesMsg.readByte()); } } catch (MessageEOFException e) { } jmsMessage = msg; } else if (message instanceof MapMessage) { MapMessage mapMsg = (MapMessage) message; JmsMapMessage msg = factory.createMapMessage(); Enumeration<?> iter = mapMsg.getMapNames(); while (iter.hasMoreElements()) { String name = iter.nextElement().toString(); msg.setObject(name, mapMsg.getObject(name)); } jmsMessage = msg; } else if (message instanceof ObjectMessage) { ObjectMessage objMsg = (ObjectMessage) message; JmsObjectMessage msg = factory.createObjectMessage(); msg.setObject(objMsg.getObject()); jmsMessage = msg; } else if (message instanceof StreamMessage) { StreamMessage streamMessage = (StreamMessage) message; streamMessage.reset(); JmsStreamMessage msg = factory.createStreamMessage(); Object obj = null; try { while ((obj = streamMessage.readObject()) != null) { msg.writeObject(obj); } } catch (MessageEOFException e) { } jmsMessage = msg; } else if (message instanceof TextMessage) { TextMessage textMsg = (TextMessage) message; JmsTextMessage msg = factory.createTextMessage(); msg.setText(textMsg.getText()); jmsMessage = msg; } else { jmsMessage = factory.createMessage(); } copyProperties(connection, message, jmsMessage); return jmsMessage; }  }
JmsMessageTransformation { public static JmsMessage transformMessage(JmsConnection connection, Message message) throws JMSException { JmsMessage jmsMessage = null; JmsMessageFactory factory = connection.getMessageFactory(); if (message instanceof BytesMessage) { BytesMessage bytesMsg = (BytesMessage) message; bytesMsg.reset(); JmsBytesMessage msg = factory.createBytesMessage(); try { for (;;) { msg.writeByte(bytesMsg.readByte()); } } catch (MessageEOFException e) { } jmsMessage = msg; } else if (message instanceof MapMessage) { MapMessage mapMsg = (MapMessage) message; JmsMapMessage msg = factory.createMapMessage(); Enumeration<?> iter = mapMsg.getMapNames(); while (iter.hasMoreElements()) { String name = iter.nextElement().toString(); msg.setObject(name, mapMsg.getObject(name)); } jmsMessage = msg; } else if (message instanceof ObjectMessage) { ObjectMessage objMsg = (ObjectMessage) message; JmsObjectMessage msg = factory.createObjectMessage(); msg.setObject(objMsg.getObject()); jmsMessage = msg; } else if (message instanceof StreamMessage) { StreamMessage streamMessage = (StreamMessage) message; streamMessage.reset(); JmsStreamMessage msg = factory.createStreamMessage(); Object obj = null; try { while ((obj = streamMessage.readObject()) != null) { msg.writeObject(obj); } } catch (MessageEOFException e) { } jmsMessage = msg; } else if (message instanceof TextMessage) { TextMessage textMsg = (TextMessage) message; JmsTextMessage msg = factory.createTextMessage(); msg.setText(textMsg.getText()); jmsMessage = msg; } else { jmsMessage = factory.createMessage(); } copyProperties(connection, message, jmsMessage); return jmsMessage; }  static JmsDestination transformDestination(JmsConnection connection, Destination destination); static JmsMessage transformMessage(JmsConnection connection, Message message); static void copyProperties(JmsConnection connection, Message source, JmsMessage target); static void setUnresolvedDestinationHandler(JmsUnresolvedDestinationTransformer handler); static JmsUnresolvedDestinationTransformer getUnresolvedDestinationTransformer(); }
JmsMessageTransformation { public static JmsMessage transformMessage(JmsConnection connection, Message message) throws JMSException { JmsMessage jmsMessage = null; JmsMessageFactory factory = connection.getMessageFactory(); if (message instanceof BytesMessage) { BytesMessage bytesMsg = (BytesMessage) message; bytesMsg.reset(); JmsBytesMessage msg = factory.createBytesMessage(); try { for (;;) { msg.writeByte(bytesMsg.readByte()); } } catch (MessageEOFException e) { } jmsMessage = msg; } else if (message instanceof MapMessage) { MapMessage mapMsg = (MapMessage) message; JmsMapMessage msg = factory.createMapMessage(); Enumeration<?> iter = mapMsg.getMapNames(); while (iter.hasMoreElements()) { String name = iter.nextElement().toString(); msg.setObject(name, mapMsg.getObject(name)); } jmsMessage = msg; } else if (message instanceof ObjectMessage) { ObjectMessage objMsg = (ObjectMessage) message; JmsObjectMessage msg = factory.createObjectMessage(); msg.setObject(objMsg.getObject()); jmsMessage = msg; } else if (message instanceof StreamMessage) { StreamMessage streamMessage = (StreamMessage) message; streamMessage.reset(); JmsStreamMessage msg = factory.createStreamMessage(); Object obj = null; try { while ((obj = streamMessage.readObject()) != null) { msg.writeObject(obj); } } catch (MessageEOFException e) { } jmsMessage = msg; } else if (message instanceof TextMessage) { TextMessage textMsg = (TextMessage) message; JmsTextMessage msg = factory.createTextMessage(); msg.setText(textMsg.getText()); jmsMessage = msg; } else { jmsMessage = factory.createMessage(); } copyProperties(connection, message, jmsMessage); return jmsMessage; }  static JmsDestination transformDestination(JmsConnection connection, Destination destination); static JmsMessage transformMessage(JmsConnection connection, Message message); static void copyProperties(JmsConnection connection, Message source, JmsMessage target); static void setUnresolvedDestinationHandler(JmsUnresolvedDestinationTransformer handler); static JmsUnresolvedDestinationTransformer getUnresolvedDestinationTransformer();  }