protected javax . jms . Message convertToJMSMessage ( Message message ) throws JMSException { MessageAttributeValue messageTypeAttribute = message . getMessageAttributes ( ) . get ( SQSMessage . JMS_SQS_MESSAGE_TYPE ) ; javax . jms . Message jmsMessage = null ; if ( messageTypeAttribute == null ) { jmsMessage = new SQSTextMessage ( acknowledger , queueUrl , message ) ; } else { String messageType = messageTypeAttribute . getStringValue ( ) ; if ( SQSMessage . BYTE_MESSAGE_TYPE . equals ( messageType ) ) { try { jmsMessage = new SQSBytesMessage ( acknowledger , queueUrl , message ) ; } catch ( JMSException e ) { LOG . warn ( "MessageReceiptHandle - " + message . getReceiptHandle ( ) + "cannot be serialized to BytesMessage" , e ) ; throw e ; } } else if ( SQSMessage . OBJECT_MESSAGE_TYPE . equals ( messageType ) ) { jmsMessage = new SQSObjectMessage ( acknowledger , queueUrl , message ) ; } else if ( SQSMessage . TEXT_MESSAGE_TYPE . equals ( messageType ) ) { jmsMessage = new SQSTextMessage ( acknowledger , queueUrl , message ) ; } else { throw new JMSException ( "Not a supported JMS message type" ) ; } } jmsMessage . setJMSDestination ( sqsDestination ) ; MessageAttributeValue replyToQueueNameAttribute = message . getMessageAttributes ( ) . get ( SQSMessage . JMS_SQS_REPLY_TO_QUEUE_NAME ) ; MessageAttributeValue replyToQueueUrlAttribute = message . getMessageAttributes ( ) . get ( SQSMessage . JMS_SQS_REPLY_TO_QUEUE_URL ) ; if ( replyToQueueNameAttribute != null && replyToQueueUrlAttribute != null ) { String replyToQueueUrl = replyToQueueUrlAttribute . getStringValue ( ) ; String replyToQueueName = replyToQueueNameAttribute . getStringValue ( ) ; Destination replyToQueue = new SQSQueueDestination ( replyToQueueName , replyToQueueUrl ) ; jmsMessage . setJMSReplyTo ( replyToQueue ) ; } MessageAttributeValue correlationIdAttribute = message . getMessageAttributes ( ) . get ( SQSMessage . JMS_SQS_CORRELATION_ID ) ; if ( correlationIdAttribute != null ) { jmsMessage . setJMSCorrelationID ( correlationIdAttribute . getStringValue ( ) ) ; } return jmsMessage ; }
Convert the return SQS message into JMS message