use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class OslpSigningService method handleError.
/**
* Handle an error from the signing server.
*/
public void handleError(final String deviceIdentification, final ResponseMessage responseMessage) {
final UnsignedOslpEnvelopeDto unsignedOslpEnvelopeDto = (UnsignedOslpEnvelopeDto) responseMessage.getDataObject();
final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withDeviceIdentification(deviceIdentification).withOrganisationIdentification(unsignedOslpEnvelopeDto.getOrganisationIdentification()).withCorrelationUid(unsignedOslpEnvelopeDto.getCorrelationUid()).withMessageType(unsignedOslpEnvelopeDto.getMessageType()).withDomain(unsignedOslpEnvelopeDto.getDomain()).withDomainVersion(unsignedOslpEnvelopeDto.getDomainVersion()).withMessagePriority(responseMessage.getMessagePriority()).withScheduled(unsignedOslpEnvelopeDto.isScheduled()).build();
final ProtocolResponseMessage protocolResponseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(messageMetadata).result(responseMessage.getResult()).osgpException(responseMessage.getOsgpException()).build();
this.deviceResponseMessageSender.send(protocolResponseMessage);
}
use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class PublicLightingSetTransitionRequestMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) {
LOGGER.debug("Processing public lighting set transition request message");
final MessageMetadata metadata;
Object dataObject;
try {
metadata = MessageMetadata.fromMessage(message);
dataObject = message.getObject();
} catch (final JMSException e) {
LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
return;
}
try {
LOGGER.info("Calling application service function: {}", metadata.getMessageType());
final TransitionMessageDataContainer transitionMessageDataContainer = (TransitionMessageDataContainer) dataObject;
this.setTransitionService.setTransitionForDevice(metadata, transitionMessageDataContainer.getTransitionType(), transitionMessageDataContainer.getDateTime());
} catch (final Exception e) {
this.handleError(e, metadata.getCorrelationUid(), metadata.getOrganisationIdentification(), metadata.getDeviceIdentification(), metadata.getMessageType(), metadata.getMessagePriority());
}
}
use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class OsgpCoreResponseMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) throws JMSException {
LOGGER.debug("Processing response message");
final MessageMetadata messageMetadata = MessageMetadata.fromMessage(message);
final ResponseMessage responseMessage;
OsgpException osgpException = null;
try {
responseMessage = (ResponseMessage) message.getObject();
osgpException = responseMessage.getOsgpException();
} catch (final JMSException e) {
LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
LOGGER.debug(messageMetadata.toString());
LOGGER.debug("osgpException", osgpException);
return;
}
try {
if (osgpException != null) {
this.handleError(osgpException, messageMetadata, responseMessage);
} else if (this.hasRegularResponseObject(responseMessage)) {
LOGGER.info("Calling application service function to handle response: {} with correlationUid: {}", messageMetadata.getMessageType(), messageMetadata.getCorrelationUid());
this.handleMessage(messageMetadata, responseMessage, osgpException);
} else {
LOGGER.error("No osgpException, yet dataObject ({}) is not of the regular type for handling response: {}", responseMessage.getDataObject() == null ? null : responseMessage.getDataObject().getClass().getName(), messageMetadata.getMessageType());
this.handleError(new TechnicalException(ComponentType.DOMAIN_SMART_METERING, "Unexpected response data handling request.", null), messageMetadata);
}
} catch (final Exception e) {
this.handleError(e, messageMetadata);
}
}
use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class GetFirmwareFileResponseMessageProcessorTest method processMessageShouldSendOkResponseMessageContainingFirmwareVersions.
@Test
void processMessageShouldSendOkResponseMessageContainingFirmwareVersions() throws OsgpException, JMSException {
// arrange
final FirmwareFileDto firmwareFileDto = this.setupFirmwareFileDto();
final ResponseMessage responseMessage = this.setupResponseMessage(firmwareFileDto);
final ObjectMessage message = new ObjectMessageBuilder().withMessageType(MessageType.GET_FIRMWARE_FILE.name()).withObject(responseMessage).build();
final UpdateFirmwareResponseDto updateFirmwareResponseDto = new UpdateFirmwareResponseDto(firmwareFileDto.getFirmwareIdentification());
final ArgumentCaptor<ResponseMessage> responseMessageArgumentCaptor = ArgumentCaptor.forClass(ResponseMessage.class);
final MessageMetadata messageMetadata = new MessageMetadata.Builder(MessageMetadata.fromMessage(message)).withMessageType(MessageType.UPDATE_FIRMWARE.name()).build();
when(this.domainHelperService.findDlmsDevice(any(MessageMetadata.class))).thenReturn(this.dlmsDevice);
when(this.dlmsConnectionManagerMock.getDlmsMessageListener()).thenReturn(this.dlmsMessageListenerMock);
when(this.firmwareService.updateFirmware(same(this.dlmsConnectionManagerMock), same(this.dlmsDevice), same(firmwareFileDto), any(MessageMetadata.class))).thenReturn(updateFirmwareResponseDto);
// act
this.getFirmwareFileResponseMessageProcessor.processMessageTasks(message.getObject(), messageMetadata, this.dlmsConnectionManagerMock);
// assert
verify(this.responseMessageSender, times(1)).send(responseMessageArgumentCaptor.capture());
assertThat(responseMessageArgumentCaptor.getValue().getDataObject()).isSameAs(updateFirmwareResponseDto);
assertThat(responseMessageArgumentCaptor.getValue().getResult()).isSameAs(ResponseMessageResultType.OK);
}
use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class GetFirmwareFileResponseMessageProcessorTest method processMessageShouldSendNotOkResponseMessageContainingOriginalFirmwareUpdateRequest.
@Test
void processMessageShouldSendNotOkResponseMessageContainingOriginalFirmwareUpdateRequest() throws OsgpException, JMSException {
// arrange
final FirmwareFileDto firmwareFileDto = this.setupFirmwareFileDto();
final ResponseMessage responseMessage = this.setupResponseMessage(firmwareFileDto);
final ObjectMessage message = new ObjectMessageBuilder().withMessageType(MessageType.GET_FIRMWARE_FILE.name()).withObject(responseMessage).build();
final MessageMetadata messageMetadata = new MessageMetadata.Builder(MessageMetadata.fromMessage(message)).withMessageType(MessageType.UPDATE_FIRMWARE.name()).build();
final ArgumentCaptor<ResponseMessage> responseMessageArgumentCaptor = ArgumentCaptor.forClass(ResponseMessage.class);
when(this.domainHelperService.findDlmsDevice(any(MessageMetadata.class))).thenReturn(this.dlmsDevice);
when(this.dlmsConnectionManagerMock.getDlmsMessageListener()).thenReturn(this.dlmsMessageListenerMock);
when(this.firmwareService.updateFirmware(same(this.dlmsConnectionManagerMock), same(this.dlmsDevice), same(firmwareFileDto), any(MessageMetadata.class))).thenThrow(new ProtocolAdapterException("Firmware file fw is not available."));
// act
this.getFirmwareFileResponseMessageProcessor.processMessageTasks(message.getObject(), messageMetadata, this.dlmsConnectionManagerMock);
// assert
verify(this.responseMessageSender, times(1)).send(responseMessageArgumentCaptor.capture());
final ResponseMessage capturedValue = responseMessageArgumentCaptor.getValue();
assertThat(((UpdateFirmwareRequestDto) capturedValue.getDataObject()).getFirmwareIdentification()).isSameAs(firmwareFileDto.getFirmwareIdentification());
assertThat(capturedValue.getResult()).isSameAs(ResponseMessageResultType.NOT_OK);
assertThat(capturedValue.bypassRetry()).isFalse();
}
Aggregations