Search in sources :

Example 1 with CorrelationIds

use of org.opensmartgridplatform.shared.infra.jms.CorrelationIds in project open-smart-grid-platform by OSGP.

the class CommonDefaultResponseMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing common default response message");
    String correlationUid = null;
    String messageType = null;
    int messagePriority = MessagePriorityEnum.DEFAULT.getPriority();
    String organisationIdentification = null;
    String deviceIdentification = null;
    ResponseMessage responseMessage;
    ResponseMessageResultType responseMessageResultType = null;
    OsgpException osgpException = null;
    try {
        correlationUid = message.getJMSCorrelationID();
        messageType = message.getJMSType();
        messagePriority = message.getJMSPriority();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        responseMessage = (ResponseMessage) message.getObject();
        responseMessageResultType = responseMessage.getResult();
        osgpException = responseMessage.getOsgpException();
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        LOGGER.debug("correlationUid: {}", correlationUid);
        LOGGER.debug("messageType: {}", messageType);
        LOGGER.debug("messagePriority: {}", messagePriority);
        LOGGER.debug("organisationIdentification: {}", organisationIdentification);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("responseMessageResultType: {}", responseMessageResultType);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("osgpException", osgpException);
        return;
    }
    try {
        LOGGER.info("Calling application service function to handle response: {}", messageType);
        final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
        this.defaultDeviceResponseService.handleDefaultDeviceResponse(ids, messageType, messagePriority, responseMessageResultType, osgpException);
    } catch (final Exception e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, messageType, messagePriority);
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException)

Example 2 with CorrelationIds

use of org.opensmartgridplatform.shared.infra.jms.CorrelationIds in project open-smart-grid-platform by OSGP.

the class MonitoringService method handleGetPQValuesResponse.

public void handleGetPQValuesResponse(final GetPQValuesResponseDto getPQValuesResponseDto, final CorrelationIds ids, final String messageType, final ResponseMessageResultType responseMessageResultType, final OsgpException osgpException) {
    LOGGER.info("handleResponse for MessageType: {}", messageType);
    final String deviceIdentification = ids.getDeviceIdentification();
    final String organisationIdentification = ids.getOrganisationIdentification();
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    GetPQValuesResponse getPQValuesResponse = null;
    OsgpException exception = osgpException;
    try {
        if (responseMessageResultType == ResponseMessageResultType.NOT_OK || osgpException != null) {
            LOGGER.error("Device Response not ok.", osgpException);
            throw osgpException;
        }
        this.rtuResponseService.handleResponseMessageReceived(LOGGER, deviceIdentification, true);
        getPQValuesResponse = this.mapper.map(getPQValuesResponseDto, GetPQValuesResponse.class);
    } catch (final Exception e) {
        LOGGER.error("Unexpected Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        exception = this.ensureOsgpException(e, "Exception occurred while getting PQ Values Response Data");
    }
    // Support for Push messages, generate correlationUid
    String actualCorrelationUid = ids.getCorrelationUid();
    if ("no-correlationUid".equals(actualCorrelationUid)) {
        actualCorrelationUid = getCorrelationId("DeviceGenerated", deviceIdentification);
    }
    final CorrelationIds actualIds = new CorrelationIds(organisationIdentification, deviceIdentification, actualCorrelationUid);
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(actualIds).withResult(result).withOsgpException(exception).withDataObject(getPQValuesResponse).build();
    this.responseMessageRouter.send(responseMessage, messageType);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) GetPQValuesResponse(org.opensmartgridplatform.domain.da.valueobjects.GetPQValuesResponse) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds)

Example 3 with CorrelationIds

use of org.opensmartgridplatform.shared.infra.jms.CorrelationIds in project open-smart-grid-platform by OSGP.

the class FirmwareManagementServiceTest method testHandleGetFirmwareVersionResponseVersionNotInHistoryButNoCorrespondingFirmwareFile.

@Test
void testHandleGetFirmwareVersionResponseVersionNotInHistoryButNoCorrespondingFirmwareFile() {
    // Arrange
    // Mock that FUNCTIONAL VERSION 3 and SECURITY VERSION 1 is now
    // installed,
    // no firmware file will hold this combination, so it will fail to save
    final FirmwareVersionDto firmwareVersionDto1 = new FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareModuleType.SECURITY, VERSION_3);
    final FirmwareVersionDto firmwareVersionDto2 = new FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareModuleType.FUNCTIONAL, VERSION_3);
    final List<FirmwareVersionDto> versionsOnDeviceDtos = Arrays.asList(firmwareVersionDto1, firmwareVersionDto2);
    final FirmwareVersion firmwareVersion1 = new FirmwareVersion(FirmwareModuleType.SECURITY, VERSION_1);
    final FirmwareVersion firmwareVersion3 = new FirmwareVersion(FirmwareModuleType.FUNCTIONAL, VERSION_3);
    final List<FirmwareVersion> versionsOnDevice = Arrays.asList(firmwareVersion1, firmwareVersion3);
    final FirmwareFile firmwareFile = new FirmwareFile.Builder().withFilename("filename").withDescription("description").withPushToNewDevices(false).build();
    final FirmwareModule firmwareModule1 = new FirmwareModule(FirmwareModuleType.SECURITY.getDescription().toLowerCase());
    firmwareFile.addFirmwareModule(firmwareModule1, VERSION_3);
    final FirmwareModule firmwareModule2 = new FirmwareModule(FirmwareModuleType.FUNCTIONAL.getDescription().toLowerCase());
    firmwareFile.addFirmwareModule(firmwareModule2, VERSION_3);
    when(this.domainCoreMapper.mapAsList(versionsOnDeviceDtos, FirmwareVersion.class)).thenReturn(versionsOnDevice);
    when(this.ssldPendingFirmwareUpdateRepository.findByDeviceIdentification("DVC")).thenReturn(Collections.emptyList());
    when(this.firmwareFileRepository.findByDeviceModel(any(DeviceModel.class))).thenReturn(Collections.singletonList(firmwareFile));
    final CorrelationIds ids = new CorrelationIds("ORG", "DVC", "CORR");
    // Act
    this.firmwareManagementService.handleGetFirmwareVersionResponse(versionsOnDeviceDtos, ids, "FW", 0, ResponseMessageResultType.OK, null);
    // Validate
    verify(this.deviceFirmwareFileRepository, never()).save(any(DeviceFirmwareFile.class));
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) FirmwareModule(org.opensmartgridplatform.domain.core.entities.FirmwareModule) FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) FirmwareFile(org.opensmartgridplatform.domain.core.entities.FirmwareFile) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) Test(org.junit.jupiter.api.Test)

Example 4 with CorrelationIds

use of org.opensmartgridplatform.shared.infra.jms.CorrelationIds in project open-smart-grid-platform by OSGP.

the class GetPQValuesRequestMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) {
    LOGGER.info("Processing DA Get PQ Values request message");
    String correlationUid = null;
    String messageType = null;
    String organisationIdentification = null;
    String deviceIdentification = null;
    GetPQValuesRequest getPQValuesRequest = null;
    try {
        correlationUid = message.getJMSCorrelationID();
        messageType = message.getJMSType();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        if (message.getObject() instanceof GetPQValuesRequest) {
            getPQValuesRequest = (GetPQValuesRequest) message.getObject();
        }
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        LOGGER.debug("correlationUid: {}", correlationUid);
        LOGGER.debug("messageType: {}", messageType);
        LOGGER.debug("organisationIdentification: {}", organisationIdentification);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        return;
    }
    try {
        LOGGER.info("Calling application service function: {}", messageType);
        final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
        this.monitoringService.getPQValues(ids, messageType, getPQValuesRequest);
    } catch (final Exception e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, messageType);
    }
}
Also used : GetPQValuesRequest(org.opensmartgridplatform.domain.da.valueobjects.GetPQValuesRequest) JMSException(javax.jms.JMSException) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) JMSException(javax.jms.JMSException)

Example 5 with CorrelationIds

use of org.opensmartgridplatform.shared.infra.jms.CorrelationIds in project open-smart-grid-platform by OSGP.

the class WebServiceMonitorInterceptor method createAndSendLoggingRequestMessage.

/**
 * Create the logging Request Message and send it using {@link
 * WebServiceMonitorInterceptor#loggingMessageSender}.
 *
 * @param messageContext The messageContext.
 * @param endpoint The endpoint.
 * @param overrideResult When set, use this value as result for the {@link LoggingRequestMessage}.
 * @throws WebServiceMonitorInterceptorException
 */
private void createAndSendLoggingRequestMessage(final MessageContext messageContext, final Object endpoint, final String overrideResult) throws WebServiceMonitorInterceptorException {
    if (!this.soapMessageLoggingEnabled) {
        return;
    }
    // Get the current time.
    final Date now = new Date();
    // Get EndPointClass and EndPointMethod.
    final EndpointClassAndMethod classAndMethod = this.getEndPointClassAndMethod(endpoint);
    // Get the request.
    final SoapMessage request = this.getSoapRequest(messageContext);
    final SoapHeader soapHeader = request.getSoapHeader();
    // Read OrganisationIdentification, UserName and ApplicationName from
    // header from request.
    final String organisationIdentification = this.getHeaderValue(soapHeader, this.organisationIdentificationHeader);
    final String userName = this.getHeaderValue(soapHeader, this.userNameHeader);
    final String appName = this.getHeaderValue(soapHeader, this.applicationNameHeader);
    // Read correlationUid and deviceId from request.
    final Map<String, Object> requestData = this.parseSoapMessage(request);
    if (requestData == null) {
        throw new WebServiceMonitorInterceptorException("unable to get correlationUid or deviceId from request");
    }
    // Get the response.
    final SoapMessage response = this.getSoapResponse(messageContext);
    // Read correlationUid and deviceId and result and data size from
    // response.
    final Map<String, Object> responseData = this.parseSoapMessage(response);
    if (responseData == null) {
        throw new WebServiceMonitorInterceptorException("unable to get correlationUid or deviceId or result from response");
    }
    // Check response for correlationId, otherwise request.
    String correlationUid = (String) responseData.get(CORRELATION_UID);
    if (StringUtils.isEmpty(correlationUid)) {
        correlationUid = (String) requestData.get(CORRELATION_UID);
    }
    // Creating the logging request message.
    final String deviceIdentification = (String) requestData.get(DEVICE_ID);
    final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
    final ResponseResultAndDataSize responseResultAndDataSize = this.resultAndDataSizeFrom(responseData);
    final LoggingRequestMessage loggingRequestMessage = new LoggingRequestMessage(now, ids, userName, appName, classAndMethod, responseResultAndDataSize);
    if (!StringUtils.isEmpty(overrideResult)) {
        loggingRequestMessage.setResponseResult(overrideResult);
    }
    this.loggingMessageSender.send(loggingRequestMessage);
}
Also used : EndpointClassAndMethod(org.opensmartgridplatform.adapter.ws.infra.jms.EndpointClassAndMethod) ResponseResultAndDataSize(org.opensmartgridplatform.adapter.ws.infra.jms.ResponseResultAndDataSize) LoggingRequestMessage(org.opensmartgridplatform.adapter.ws.infra.jms.LoggingRequestMessage) WebServiceMonitorInterceptorException(org.opensmartgridplatform.domain.core.exceptions.WebServiceMonitorInterceptorException) SoapHeader(org.springframework.ws.soap.SoapHeader) Date(java.util.Date) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) SoapMessage(org.springframework.ws.soap.SoapMessage)

Aggregations

CorrelationIds (org.opensmartgridplatform.shared.infra.jms.CorrelationIds)42 JMSException (javax.jms.JMSException)31 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)24 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)18 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)18 Test (org.junit.jupiter.api.Test)7 FirmwareVersion (org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)7 Serializable (java.io.Serializable)6 FirmwareVersionDto (org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto)5 Date (java.util.Date)4 DeviceFirmwareFile (org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile)4 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)4 FirmwareFile (org.opensmartgridplatform.domain.core.entities.FirmwareFile)4 FirmwareModule (org.opensmartgridplatform.domain.core.entities.FirmwareModule)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 DeviceStatusDto (org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto)3 ApplicationDataLookupKey (org.opensmartgridplatform.adapter.ws.domain.entities.ApplicationDataLookupKey)2 GenericNotification (org.opensmartgridplatform.adapter.ws.schema.shared.notification.GenericNotification)2 Schedule (org.opensmartgridplatform.domain.core.valueobjects.Schedule)2 GetPQValuesResponseDto (org.opensmartgridplatform.dto.da.GetPQValuesResponseDto)2