@Test public void testMessageToAdaptrisMessageWithFallback() throws Exception { EmbeddedActiveMq broker = new EmbeddedActiveMq(); AutoConvertMessageTranslator trans = new AutoConvertMessageTranslator(); try { broker.start(); Session session = broker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE); start(trans, session); Message jmsMsg = session.createMessage(); addProperties(jmsMsg); AdaptrisMessage msg = trans.translate(jmsMsg); assertMetadata(msg); } finally { stop(trans); broker.destroy(); } }
public Message translate(AdaptrisMessage msg) throws JMSException { Message result = null; MessageTypeTranslator mt = null; boolean convertingBackToOriginal = false; try { if(convertBackToConsumedType() && (!StringUtils.isEmpty(msg.getMetadataValue(CONSUMED_MESSAGE_TYPE_KEY)))) { SupportedMessageType messageType = null; try { messageType = SupportedMessageType.valueOf(msg.getMetadataValue(CONSUMED_MESSAGE_TYPE_KEY)); mt = messageType.create(this); convertingBackToOriginal = true; } catch (IllegalArgumentException ex) { log.warn("Cannot convert to type: {}", msg.getMetadataValue(CONSUMED_MESSAGE_TYPE_KEY)); for (SupportedMessageType mti : SupportedMessageType.values()) { if (mti.name().equalsIgnoreCase(getJmsOutputType())) { mt = mti.create(this); break; } } } } else { for (SupportedMessageType mti : SupportedMessageType.values()) { if (mti.name().equalsIgnoreCase(getJmsOutputType())) { mt = mti.create(this); break; } } } if (mt != null) { if((convertingBackToOriginal) && (removeOriginalMessageTypeKey())) msg.removeMessageHeader(CONSUMED_MESSAGE_TYPE_KEY); start(mt); result = mt.translate(msg); } else { mt = SupportedMessageType.createFallback(this); start(mt); result = mt.translate(msg); } } finally { stop(mt); } return result; }
AutoConvertMessageTranslator extends MessageTypeTranslatorImp { public Message translate(AdaptrisMessage msg) throws JMSException { Message result = null; MessageTypeTranslator mt = null; boolean convertingBackToOriginal = false; try { if(convertBackToConsumedType() && (!StringUtils.isEmpty(msg.getMetadataValue(CONSUMED_MESSAGE_TYPE_KEY)))) { SupportedMessageType messageType = null; try { messageType = SupportedMessageType.valueOf(msg.getMetadataValue(CONSUMED_MESSAGE_TYPE_KEY)); mt = messageType.create(this); convertingBackToOriginal = true; } catch (IllegalArgumentException ex) { log.warn("Cannot convert to type: {}", msg.getMetadataValue(CONSUMED_MESSAGE_TYPE_KEY)); for (SupportedMessageType mti : SupportedMessageType.values()) { if (mti.name().equalsIgnoreCase(getJmsOutputType())) { mt = mti.create(this); break; } } } } else { for (SupportedMessageType mti : SupportedMessageType.values()) { if (mti.name().equalsIgnoreCase(getJmsOutputType())) { mt = mti.create(this); break; } } } if (mt != null) { if((convertingBackToOriginal) && (removeOriginalMessageTypeKey())) msg.removeMessageHeader(CONSUMED_MESSAGE_TYPE_KEY); start(mt); result = mt.translate(msg); } else { mt = SupportedMessageType.createFallback(this); start(mt); result = mt.translate(msg); } } finally { stop(mt); } return result; } }
AutoConvertMessageTranslator extends MessageTypeTranslatorImp { public Message translate(AdaptrisMessage msg) throws JMSException { Message result = null; MessageTypeTranslator mt = null; boolean convertingBackToOriginal = false; try { if(convertBackToConsumedType() && (!StringUtils.isEmpty(msg.getMetadataValue(CONSUMED_MESSAGE_TYPE_KEY)))) { SupportedMessageType messageType = null; try { messageType = SupportedMessageType.valueOf(msg.getMetadataValue(CONSUMED_MESSAGE_TYPE_KEY)); mt = messageType.create(this); convertingBackToOriginal = true; } catch (IllegalArgumentException ex) { log.warn("Cannot convert to type: {}", msg.getMetadataValue(CONSUMED_MESSAGE_TYPE_KEY)); for (SupportedMessageType mti : SupportedMessageType.values()) { if (mti.name().equalsIgnoreCase(getJmsOutputType())) { mt = mti.create(this); break; } } } } else { for (SupportedMessageType mti : SupportedMessageType.values()) { if (mti.name().equalsIgnoreCase(getJmsOutputType())) { mt = mti.create(this); break; } } } if (mt != null) { if((convertingBackToOriginal) && (removeOriginalMessageTypeKey())) msg.removeMessageHeader(CONSUMED_MESSAGE_TYPE_KEY); start(mt); result = mt.translate(msg); } else { mt = SupportedMessageType.createFallback(this); start(mt); result = mt.translate(msg); } } finally { stop(mt); } return result; } AutoConvertMessageTranslator(); }
AutoConvertMessageTranslator extends MessageTypeTranslatorImp { public Message translate(AdaptrisMessage msg) throws JMSException { Message result = null; MessageTypeTranslator mt = null; boolean convertingBackToOriginal = false; try { if(convertBackToConsumedType() && (!StringUtils.isEmpty(msg.getMetadataValue(CONSUMED_MESSAGE_TYPE_KEY)))) { SupportedMessageType messageType = null; try { messageType = SupportedMessageType.valueOf(msg.getMetadataValue(CONSUMED_MESSAGE_TYPE_KEY)); mt = messageType.create(this); convertingBackToOriginal = true; } catch (IllegalArgumentException ex) { log.warn("Cannot convert to type: {}", msg.getMetadataValue(CONSUMED_MESSAGE_TYPE_KEY)); for (SupportedMessageType mti : SupportedMessageType.values()) { if (mti.name().equalsIgnoreCase(getJmsOutputType())) { mt = mti.create(this); break; } } } } else { for (SupportedMessageType mti : SupportedMessageType.values()) { if (mti.name().equalsIgnoreCase(getJmsOutputType())) { mt = mti.create(this); break; } } } if (mt != null) { if((convertingBackToOriginal) && (removeOriginalMessageTypeKey())) msg.removeMessageHeader(CONSUMED_MESSAGE_TYPE_KEY); start(mt); result = mt.translate(msg); } else { mt = SupportedMessageType.createFallback(this); start(mt); result = mt.translate(msg); } } finally { stop(mt); } return result; } AutoConvertMessageTranslator(); Message translate(AdaptrisMessage msg); AdaptrisMessage translate(Message msg); String getJmsOutputType(); void setJmsOutputType(String outputType); Boolean getConvertBackToConsumedType(); void setConvertBackToConsumedType(Boolean convertBackToConsumedType); Boolean getRemoveOriginalMessageTypeKey(); void setRemoveOriginalMessageTypeKey(Boolean removeOriginalMessageTypeKey); }
AutoConvertMessageTranslator extends MessageTypeTranslatorImp { public Message translate(AdaptrisMessage msg) throws JMSException { Message result = null; MessageTypeTranslator mt = null; boolean convertingBackToOriginal = false; try { if(convertBackToConsumedType() && (!StringUtils.isEmpty(msg.getMetadataValue(CONSUMED_MESSAGE_TYPE_KEY)))) { SupportedMessageType messageType = null; try { messageType = SupportedMessageType.valueOf(msg.getMetadataValue(CONSUMED_MESSAGE_TYPE_KEY)); mt = messageType.create(this); convertingBackToOriginal = true; } catch (IllegalArgumentException ex) { log.warn("Cannot convert to type: {}", msg.getMetadataValue(CONSUMED_MESSAGE_TYPE_KEY)); for (SupportedMessageType mti : SupportedMessageType.values()) { if (mti.name().equalsIgnoreCase(getJmsOutputType())) { mt = mti.create(this); break; } } } } else { for (SupportedMessageType mti : SupportedMessageType.values()) { if (mti.name().equalsIgnoreCase(getJmsOutputType())) { mt = mti.create(this); break; } } } if (mt != null) { if((convertingBackToOriginal) && (removeOriginalMessageTypeKey())) msg.removeMessageHeader(CONSUMED_MESSAGE_TYPE_KEY); start(mt); result = mt.translate(msg); } else { mt = SupportedMessageType.createFallback(this); start(mt); result = mt.translate(msg); } } finally { stop(mt); } return result; } AutoConvertMessageTranslator(); Message translate(AdaptrisMessage msg); AdaptrisMessage translate(Message msg); String getJmsOutputType(); void setJmsOutputType(String outputType); Boolean getConvertBackToConsumedType(); void setConvertBackToConsumedType(Boolean convertBackToConsumedType); Boolean getRemoveOriginalMessageTypeKey(); void setRemoveOriginalMessageTypeKey(Boolean removeOriginalMessageTypeKey);  }