I followed your advice and wrote a MDB:

  |     public void onMessage(Message sourceMessage) {
  |         Connection connection = null;
  |         try {
  |             connection = getTargetConnectionFactory().createConnection();
  |             Session session = connection.createSession(true, 
Session.AUTO_ACKNOWLEDGE);
  |             
  |             // Body
  |             Message targetMessage;
  |             if (sourceMessage instanceof TextMessage) {
  |                 // Text
  |                 TextMessage sourceTextMessage = (TextMessage) sourceMessage;
  |                 targetMessage = 
session.createTextMessage(sourceTextMessage.getText());
  |             } else if (sourceMessage instanceof BytesMessage) {
  |                 // Bytes
  |                 BytesMessage sourceBytesMessage = (BytesMessage) 
sourceMessage;
  |                 BytesMessage targetBytesMessage = 
session.createBytesMessage();
  |                 byte[] bytes = new byte[getByteBufferSize()];
  |                 int byteCount;
  |                 while((byteCount=sourceBytesMessage.readBytes(bytes))>0) {
  |                     targetBytesMessage.writeBytes(bytes, 0, byteCount);
  |                 }
  |                 targetMessage = targetBytesMessage;
  |             } else if (sourceMessage instanceof MapMessage) {
  |                 // Map
  |                 MapMessage sourceMapMessage = (MapMessage) sourceMessage;
  |                 MapMessage targetMapMessage = session.createMapMessage();
  |                 Enumeration mapNameEnum = sourceMapMessage.getMapNames();
  |                 while (mapNameEnum.hasMoreElements()) {
  |                     String mapName = (String) mapNameEnum.nextElement();
  |                     targetMapMessage.setObjectProperty(mapName, 
sourceMapMessage.getObject(mapName));                    
  |                 }
  |                 targetMessage = targetMapMessage;
  |             } else if (sourceMessage instanceof ObjectMessage) {
  |                 // Object
  |                 ObjectMessage sourceObjectMessage = (ObjectMessage) 
sourceMessage;
  |                 targetMessage = 
session.createObjectMessage(sourceObjectMessage.getObject());
  |             } else if (sourceMessage instanceof StreamMessage) {
  |                 // Stream
  |                 StreamMessage sourceStreamMessage = (StreamMessage) 
sourceMessage;
  |                 StreamMessage targetStreamMessage = 
session.createStreamMessage();
  |                 byte[] bytes = new byte[getByteBufferSize()];
  |                 int byteCount;
  |                 while((byteCount=sourceStreamMessage.readBytes(bytes))>0) {
  |                     targetStreamMessage.writeBytes(bytes, 0, byteCount);
  |                 }
  |                 targetMessage = targetStreamMessage;
  |             } else {
  |                 targetMessage = null;
  |             }
  |             
  |             if (targetMessage == null) {
  |                 log.error("Message couldn't be copied");
  |             } else {
  |                 // Header
  |                 Enumeration propertyNameEnum = 
sourceMessage.getPropertyNames();
  |                 while (propertyNameEnum.hasMoreElements()) {
  |                     String propertyName = (String) 
propertyNameEnum.nextElement();
  |                     targetMessage.setObjectProperty(propertyName, 
sourceMessage.getObjectProperty(propertyName));
  |                 }            
  |                 
  |                 // Message producer
  |                 MessageProducer messageProducer = 
session.createProducer(getTargetDestination());
  |                 
messageProducer.setDeliveryMode(sourceMessage.getJMSDeliveryMode());
  |                 messageProducer.setPriority(sourceMessage.getJMSPriority());
  |                 final long timestamp = sourceMessage.getJMSTimestamp();
  |                 if (timestamp>0) {
  |                     final long expiration = 
sourceMessage.getJMSExpiration();            
  |                     if ((expiration>0)&&(expiration>timestamp)) {
  |                         messageProducer.setTimeToLive(timestamp);           
     
  |                     }                
  |                 } else {
  |                     messageProducer.setDisableMessageTimestamp(true);
  |                 }
  |                 messageProducer.send(targetMessage);
  |             }
  |         } catch(JMSException jmsExc) {
  |             log.error("Bridge message", jmsExc);
  |         } finally {
  |             if (connection != null) {
  |                 try {
  |                     connection.close();
  |                 } catch (JMSException e) {
  |                 }
  |             }
  |         }
  |     }
  | 

I couldn't find an easier way to do it, could you? 

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3913512#3913512

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3913512


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to