Search in sources :

Example 66 with MessageMetadata

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);
}
Also used : UnsignedOslpEnvelopeDto(org.opensmartgridplatform.oslp.UnsignedOslpEnvelopeDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)

Example 67 with MessageMetadata

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());
    }
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) TransitionMessageDataContainer(org.opensmartgridplatform.domain.core.valueobjects.TransitionMessageDataContainer) JMSException(javax.jms.JMSException) JMSException(javax.jms.JMSException)

Example 68 with MessageMetadata

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);
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) JMSException(javax.jms.JMSException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)

Example 69 with 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);
}
Also used : FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) UpdateFirmwareResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareResponseDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ObjectMessage(javax.jms.ObjectMessage) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) Test(org.junit.jupiter.api.Test)

Example 70 with MessageMetadata

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();
}
Also used : FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ObjectMessage(javax.jms.ObjectMessage) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)147 JMSException (javax.jms.JMSException)65 Device (org.opensmartgridplatform.domain.core.entities.Device)29 Test (org.junit.jupiter.api.Test)25 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)23 ProtocolResponseMessage (org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)22 DeviceRequest (org.opensmartgridplatform.adapter.protocol.iec61850.device.DeviceRequest)20 RequestMessageData (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.RequestMessageData)20 Iec61850DeviceResponseHandler (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.Iec61850DeviceResponseHandler)20 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)19 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)18 CommonRequestMessage (org.opensmartgridplatform.adapter.ws.core.infra.jms.CommonRequestMessage)15 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)14 RequestMessage (org.opensmartgridplatform.shared.infra.jms.RequestMessage)14 ObjectMessage (javax.jms.ObjectMessage)13 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)13 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)13 Serializable (java.io.Serializable)12 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)12 UpdateFirmwareRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto)10