Search in sources :

Example 21 with CorrelationIds

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

the class AbstractDomainResponseMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing response message");
    String correlationUid = null;
    String messageType = null;
    String organisationIdentification = null;
    String deviceIdentification = null;
    final String notificationMessage;
    final NotificationType notificationType;
    final ResponseMessageResultType resultType;
    final String resultDescription;
    final Serializable dataObject;
    try {
        correlationUid = message.getJMSCorrelationID();
        messageType = message.getJMSType();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        resultType = ResponseMessageResultType.valueOf(message.getStringProperty(Constants.RESULT));
        resultDescription = message.getStringProperty(Constants.DESCRIPTION);
        notificationMessage = message.getStringProperty(Constants.DESCRIPTION);
        notificationType = NotificationType.valueOf(messageType);
        dataObject = message.getObject();
    } catch (final JMSException | IllegalArgumentException | NullPointerException 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 to handle response: {}", messageType);
        final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
        this.handleMessage(ids, messageType, resultType, resultDescription, dataObject);
    } catch (final Exception e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, notificationType);
        return;
    }
    /*
     * Keep the notification part apart from handling the message. Exception
     * handling that might be appropriate for issues with the message could
     * likely not be appropriate for exceptions in the notification
     * mechanism. The latter kind of issues should be covered by re-sending
     * of notifications for existing response data or by application-side
     * attempts to retrieve results after some amount of time.
     */
    this.sendNotification(organisationIdentification, deviceIdentification, resultType.name(), correlationUid, notificationMessage, notificationType);
}
Also used : Serializable(java.io.Serializable) NotificationType(org.opensmartgridplatform.adapter.ws.schema.microgrids.notification.NotificationType) JMSException(javax.jms.JMSException) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) JMSException(javax.jms.JMSException)

Example 22 with CorrelationIds

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

the class CommonGetFirmwareResponseMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing common get firmware version 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;
    Object dataObject;
    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();
        dataObject = responseMessage.getDataObject();
    } 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);
        @SuppressWarnings("unchecked") final List<FirmwareVersionDto> firmwareVersions = (List<FirmwareVersionDto>) dataObject;
        final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
        this.firmwareManagementService.handleGetFirmwareVersionResponse(firmwareVersions, 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) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException) List(java.util.List) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds)

Example 23 with CorrelationIds

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

the class LoggingMessageListener method onMessage.

@Override
public void onMessage(final Message message) {
    try {
        LOGGER.info("Received logging message");
        if (message instanceof TextMessage) {
            LOGGER.warn("A TextMessage is received. TextMessages belong with configuration setting : auditlogging.message.create.json=true");
            return;
        }
        final ObjectMessage objectMessage = (ObjectMessage) message;
        // Create a log item.
        final Date timestamp = new Date(objectMessage.getLongProperty(Constants.TIME_STAMP));
        final String organisationIdentification = objectMessage.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        final String deviceIdentification = objectMessage.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        final String correlationUid = objectMessage.getJMSCorrelationID();
        final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
        final MethodResult methodResult = methodResultFor(objectMessage);
        final WebServiceMonitorLogItem webServiceMonitorLogItem = new WebServiceMonitorLogItem(timestamp, ids, objectMessage.getStringProperty(Constants.USER_NAME), methodResult);
        // Save the log item in the data base.
        this.webServiceMonitorLogRepository.save(webServiceMonitorLogItem);
    } catch (final JMSException e) {
        LOGGER.error("Exception: {}, StackTrace: {}", e.getMessage(), e.getStackTrace(), e);
    }
}
Also used : ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException) WebServiceMonitorLogItem(org.opensmartgridplatform.logging.domain.entities.WebServiceMonitorLogItem) TextMessage(javax.jms.TextMessage) Date(java.util.Date) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) MethodResult(org.opensmartgridplatform.logging.domain.entities.MethodResult)

Example 24 with CorrelationIds

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

the class GetMeasurementReportResponseMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing Measurement Report message");
    String correlationUid = null;
    String messageType = null;
    String organisationIdentification = null;
    String deviceIdentification = null;
    ResponseMessage responseMessage = null;
    ResponseMessageResultType responseMessageResultType = null;
    OsgpException osgpException = null;
    Object dataObject = null;
    try {
        correlationUid = message.getJMSCorrelationID();
        messageType = message.getJMSType();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        responseMessage = (ResponseMessage) message.getObject();
        responseMessageResultType = responseMessage.getResult();
        osgpException = responseMessage.getOsgpException();
        dataObject = responseMessage.getDataObject();
    } 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);
        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 MeasurementReportDto dataResponse = (MeasurementReportDto) dataObject;
        final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
        this.monitoringService.handleGetMeasurementReportResponse(dataResponse, ids, messageType, responseMessageResultType, osgpException);
    } catch (final Exception e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, messageType);
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) MeasurementReportDto(org.opensmartgridplatform.dto.da.measurements.MeasurementReportDto) 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 25 with CorrelationIds

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

the class SetDataResponseMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing microgrids set data response message");
    String correlationUid = null;
    String messageType = null;
    String organisationIdentification = null;
    String deviceIdentification = null;
    ResponseMessage responseMessage;
    ResponseMessageResultType responseMessageResultType = null;
    OsgpException osgpException = null;
    Object dataObject;
    try {
        correlationUid = message.getJMSCorrelationID();
        messageType = message.getJMSType();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        responseMessage = (ResponseMessage) message.getObject();
        responseMessageResultType = responseMessage.getResult();
        osgpException = responseMessage.getOsgpException();
        dataObject = responseMessage.getDataObject();
    } 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);
        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 EmptyResponseDto emptyResponse = (EmptyResponseDto) dataObject;
        final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
        this.adHocManagementService.handleSetDataResponse(emptyResponse, ids, messageType, responseMessageResultType, osgpException);
    } catch (final Exception e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, messageType);
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) EmptyResponseDto(org.opensmartgridplatform.dto.valueobjects.microgrids.EmptyResponseDto) 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)

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