Search in sources :

Example 56 with ResponseMessage

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

the class ProtocolResponseMessageSendingHandlerTest method sendsProtocolResponseMessageThatAvoidsRetries.

@Test
void sendsProtocolResponseMessageThatAvoidsRetries() {
    final ProtocolResponseMessageSendingHandler protocolResponseMessageSendingHandler = this.aProtocolResponseMessageSendingHandler();
    protocolResponseMessageSendingHandler.handlePublishedMessage("any/topic", "any-payload".getBytes(StandardCharsets.UTF_8));
    verify(this.outboundOsgpCoreResponseMessageSender).send(this.responseMessageCaptor.capture());
    final ResponseMessage actualResponseMessage = this.responseMessageCaptor.getValue();
    final MessageMetadata actualMessageMetadata = actualResponseMessage.messageMetadata();
    assertThat(actualMessageMetadata.isScheduled()).isFalse();
    assertThat(actualMessageMetadata.isBypassRetry()).isTrue();
    final RetryHeader retryHeader = actualResponseMessage.getRetryHeader();
    if (retryHeader != null) {
        assertThat(retryHeader.getScheduledRetryTime()).isNull();
        assertThat(retryHeader.getMaxRetries()).isZero();
    }
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) RetryHeader(org.opensmartgridplatform.shared.infra.jms.RetryHeader) Test(org.junit.jupiter.api.Test)

Example 57 with ResponseMessage

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

the class DeviceManagementService method handleHealthStatusResponse.

public void handleHealthStatusResponse(final GetHealthStatusResponseDto getHealthStatusResponseDto, final String deviceIdentification, final String organisationIdentification, final String correlationUid, final String messageType, final ResponseMessageResultType responseMessageResultType, final OsgpException osgpException) {
    LOGGER.info("handleResponse for MessageType: {}", messageType);
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    GetHealthStatusResponse getHealthStatusResponse = null;
    OsgpException exception = null;
    try {
        if (responseMessageResultType == ResponseMessageResultType.NOT_OK || osgpException != null) {
            LOGGER.error("Device Response not ok.", osgpException);
            throw osgpException;
        }
        this.rtuResponseService.handleResponseMessageReceived(LOGGER, deviceIdentification, true);
        getHealthStatusResponse = this.mapper.map(getHealthStatusResponseDto, GetHealthStatusResponse.class);
    } catch (final Exception e) {
        LOGGER.error("Unexpected Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        exception = this.ensureOsgpException(e, "Exception occurred while getting Health Status Response Data");
    }
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withCorrelationUid(correlationUid).withOrganisationIdentification(organisationIdentification).withDeviceIdentification(deviceIdentification).withMessageType(messageType).withResult(result).withOsgpException(exception).withDataObject(getHealthStatusResponse).build();
    this.responseMessageRouter.send(responseMessage, messageType);
}
Also used : GetHealthStatusResponse(org.opensmartgridplatform.domain.da.valueobjects.GetHealthStatusResponse) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) 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)

Example 58 with ResponseMessage

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

the class AdHocManagementService method handleGetStatusResponse.

public void handleGetStatusResponse(final DeviceStatusDto deviceStatusDto, final CorrelationIds ids, final String messageType, final int messagePriority, final ResponseMessageResultType deviceResult, final OsgpException exception) {
    LOGGER.info("handleResponse for MessageType: {}", messageType);
    final GetStatusResponse response = new GetStatusResponse();
    response.setOsgpException(exception);
    response.setResult(deviceResult);
    if (deviceResult == ResponseMessageResultType.NOT_OK || exception != null) {
        LOGGER.error("Device Response not ok.", exception);
    } else {
        final DeviceStatus status = this.domainCoreMapper.map(deviceStatusDto, DeviceStatus.class);
        try {
            final Device dev = this.deviceDomainService.searchDevice(ids.getDeviceIdentification());
            if (LightMeasurementDevice.LMD_TYPE.equals(dev.getDeviceType())) {
                this.handleLmd(status, response);
            } else {
                this.handleSsld(ids.getDeviceIdentification(), status, DomainType.PUBLIC_LIGHTING, response);
            }
        } catch (final FunctionalException e) {
            LOGGER.error("Caught FunctionalException", e);
        }
    }
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(ids).withResult(response.getResult()).withOsgpException(response.getOsgpException()).withDataObject(response.getDeviceStatusMapped()).withMessagePriority(messagePriority).build();
    this.webServiceResponseMessageSender.send(responseMessage);
}
Also used : GetStatusResponse(org.opensmartgridplatform.adapter.domain.shared.GetStatusResponse) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) CdmaDevice(org.opensmartgridplatform.domain.core.valueobjects.CdmaDevice) RtuDevice(org.opensmartgridplatform.domain.core.entities.RtuDevice) Device(org.opensmartgridplatform.domain.core.entities.Device) DeviceStatus(org.opensmartgridplatform.domain.core.valueobjects.DeviceStatus) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage)

Example 59 with ResponseMessage

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

the class PublicLightingDefaultResponseMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing public lighting 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 60 with ResponseMessage

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

the class PublicLightingGetStatusResponseMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing public lighting get status 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;
    }
    if (OsgpSystemCorrelationUid.CORRELATION_UID.equals(correlationUid)) {
        LOGGER.info("Received message for device: {} of type: {} with correlation UID: {} and result: {}.", deviceIdentification, messageType, correlationUid, responseMessageResultType.name());
        this.adHocManagementService.updateLastCommunicationTime(deviceIdentification);
        return;
    }
    try {
        LOGGER.info("Calling application service function to handle response: {}", messageType);
        final DeviceStatusDto deviceLightStatus = (DeviceStatusDto) dataObject;
        final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
        this.adHocManagementService.handleGetStatusResponse(deviceLightStatus, 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) DeviceStatusDto(org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto) 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

ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)144 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)78 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)66 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)33 JMSException (javax.jms.JMSException)29 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)23 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)20 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)20 ConstraintViolationException (javax.validation.ConstraintViolationException)19 Test (org.junit.jupiter.api.Test)19 CorrelationIds (org.opensmartgridplatform.shared.infra.jms.CorrelationIds)18 ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)16 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)12 ObjectMessage (javax.jms.ObjectMessage)9 ProtocolResponseMessage (org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)8 Transactional (org.springframework.transaction.annotation.Transactional)5 ArrayList (java.util.ArrayList)4 Device (org.opensmartgridplatform.domain.core.entities.Device)4 UnknownEntityException (org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)4 FirmwareVersion (org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)4