JmsSpecificInfoExtractor { static RetrieveInfo extractFrom (Message message) throws JMSException { Destination replyTo = message.getJMSReplyTo(); String correlationId = message.getJMSCorrelationID(); Map<String, Object> customHeaders = null; Enumeration<String> enumeration = message.getPropertyNames(); if (enumeration.hasMoreElements()) { customHeaders = new HashMap<>(3, 1.0f); while (enumeration.hasMoreElements()) { String key = enumeration.nextElement(); customHeaders.put(key, String.valueOf(message.getObjectProperty(key))); } } return new RetrieveInfo(correlationId, replyTo, customHeaders); } private  JmsSpecificInfoExtractor();   }
@Test void testCreateMessageDetails() throws JMSException { Destination replyDestination = jmsHelper.createQueue("reply"); Destination incomingDestination = jmsHelper.createQueue("incoming"); Message message = jmsHelper.createMessage("payload"); message.setJMSDestination(incomingDestination); message.setJMSCorrelationID("c1"); message.setJMSReplyTo(replyDestination); message.setObjectProperty("k1", "v1"); message.setObjectProperty("k3", "v2"); RetrieveInfo info = JmsSpecificInfoExtractor.extractFrom(message); assertThat(info.correlationId, is("c1")); assertThat(info.customHeaders.size(), is(2)); assertThat(info.customHeaders.get("k1"), is("v1")); assertThat(info.customHeaders.get("k3"), is("v2")); assertThat(info.replyDestination, is(replyDestination)); }