private void handleReportMessage(MapMessage message) throws JMSException { String sender = message.getStringProperty(SENDER); String payload = message.getString(MESSAGE); String timeStamp = message.getString(TIMESTAMP); String severity = message.getString(SEVERITY); messages.add( new ReportMessage( sender, payload, dateTimeProvider.stringToInstant(timeStamp), severity, dateTimeProvider.now())); }
@Test public void reportMessage_shouldBeReflectedInReportMessagesObject_whenMapMessageReceived() throws JMSException { Mockito.when(mapMessage.getStringProperty("sender")).thenReturn("service"); Mockito.when(mapMessage.getString("message")).thenReturn("db load error"); Mockito.when(mapMessage.getString("timestamp")).thenReturn("999"); Mockito.when(mapMessage.getString("severity")).thenReturn("error"); Mockito.when(dateTimeProvider.now()).thenReturn(now); Mockito.when(dateTimeProvider.stringToInstant("999")).thenReturn(sendTime); sut.onMessage(mapMessage); List<ReportMessage> reportMessages = messages.getMessages(); assertEquals(1, reportMessages.size()); ReportMessage reportMessage = reportMessages.get(0); assertEquals("service", reportMessage.getSender()); assertEquals("db load error", reportMessage.getMessage()); assertEquals("error", reportMessage.getSeverity()); assertEquals(now, reportMessage.getReceivedOn()); assertEquals(sendTime, reportMessage.getTimestamp()); }
public Object execute() { if (message instanceof MapMessage) { MapMessage mapMessage = (MapMessage) message; if (ActionCarrier.extractMessageType(mapMessage) == ActionCarrier.SYSTEM_MESSAGE_TYPE_ID) { try { String transportClassName = mapMessage.getStringProperty(ActionCarrier.TRANSPORT_CLASS_TAG); ActionCarrier transport = (ActionCarrier) Reflect.createInstance(transportClassName); transport.extract(mapMessage); getForkingService().isolate(transport.createAction()); } catch (JMSException e) { trace.warn("Failed handling system message. Recovery run may be required.", e); } } else { trace.warn("Unknown message type " + ActionCarrier.extractMessageType(mapMessage) + "."); } } else { trace.warn("JMS Message processed by message daemon is no map message"); } return null; }