Search in sources :

Example 61 with ResponseMessage

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

the class PublicLightingSetTransitionResponseMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing public lighting set transition 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);
        if (this.isSetTransitionResponseLoggingEnabled) {
            final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
            this.adHocManagementService.handleSetTransitionResponse(ids, messageType, messagePriority, responseMessageResultType, osgpException);
        } else {
            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 62 with ResponseMessage

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

the class WebServiceResponseMessageSender method send.

/**
 * Send a response message to the web service adapter using a custom time to live.
 *
 * @param responseMessage The response message to send.
 * @param timeToLive The custom time to live value in milliseconds.
 */
public void send(final ResponseMessage responseMessage, final Long timeToLive) {
    // Keep the original time to live from configuration.
    final Long originalTimeToLive = this.webServiceResponsesJmsTemplate.getTimeToLive();
    if (timeToLive != null) {
        // Set the custom time to live.
        this.webServiceResponsesJmsTemplate.setTimeToLive(timeToLive);
    }
    this.webServiceResponsesJmsTemplate.send(new MessageCreator() {

        @Override
        public Message createMessage(final Session session) throws JMSException {
            final ObjectMessage objectMessage = session.createObjectMessage(responseMessage);
            objectMessage.setJMSType(responseMessage.getMessageType());
            objectMessage.setJMSPriority(responseMessage.getMessagePriority());
            objectMessage.setJMSCorrelationID(responseMessage.getCorrelationUid());
            objectMessage.setStringProperty(Constants.ORGANISATION_IDENTIFICATION, responseMessage.getOrganisationIdentification());
            objectMessage.setStringProperty(Constants.DEVICE_IDENTIFICATION, responseMessage.getDeviceIdentification());
            objectMessage.setStringProperty(Constants.RESULT, responseMessage.getResult().toString());
            if (responseMessage.getOsgpException() != null) {
                objectMessage.setStringProperty(Constants.DESCRIPTION, responseMessage.getOsgpException().getMessage());
            }
            return objectMessage;
        }
    });
    if (timeToLive != null) {
        // Restore the time to live from the configuration.
        this.webServiceResponsesJmsTemplate.setTimeToLive(originalTimeToLive);
    }
}
Also used : ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException) MessageCreator(org.springframework.jms.core.MessageCreator) Session(javax.jms.Session)

Example 63 with ResponseMessage

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

the class AdhocService method handleScanMbusChannelsResponse.

public void handleScanMbusChannelsResponse(final MessageMetadata messageMetadata, final ResponseMessageResultType deviceResult, final OsgpException exception, final ScanMbusChannelsResponseDto resultData) {
    LOGGER.debug("handleScanMbusChannelsResponse for MessageType: {}", messageMetadata.getMessageType());
    ResponseMessageResultType result = deviceResult;
    if (exception != null) {
        LOGGER.error(DEVICE_RESPONSE_NOT_OK_UNEXPECTED_EXCEPTION, exception);
        result = ResponseMessageResultType.NOT_OK;
    }
    final ScanMbusChannelsResponseData scanMbusChannelsResponseData = this.mapperFactory.getMapperFacade().map(resultData, ScanMbusChannelsResponseData.class);
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withMessageMetadata(messageMetadata).withResult(result).withOsgpException(exception).withDataObject(scanMbusChannelsResponseData).build();
    this.webServiceResponseMessageSender.send(responseMessage, messageMetadata.getMessageType());
}
Also used : ScanMbusChannelsResponseData(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ScanMbusChannelsResponseData) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)

Example 64 with ResponseMessage

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

the class AdhocService method handleGetAllAttributeValuesResponse.

public void handleGetAllAttributeValuesResponse(final MessageMetadata messageMetadata, final ResponseMessageResultType deviceResult, final OsgpException exception, final String resultData) {
    LOGGER.debug("handleGetAllAttributeValuesResponse for MessageType: {}", messageMetadata.getMessageType());
    ResponseMessageResultType result = deviceResult;
    if (exception != null) {
        LOGGER.error(DEVICE_RESPONSE_NOT_OK_UNEXPECTED_EXCEPTION, exception);
        result = ResponseMessageResultType.NOT_OK;
    }
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withMessageMetadata(messageMetadata).withResult(result).withOsgpException(exception).withDataObject(resultData).build();
    this.webServiceResponseMessageSender.send(responseMessage, messageMetadata.getMessageType());
}
Also used : ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)

Example 65 with ResponseMessage

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

the class AdhocService method handleGetSpecificAttributeValueResponse.

public void handleGetSpecificAttributeValueResponse(final MessageMetadata messageMetadata, final ResponseMessageResultType deviceResult, final OsgpException exception, final String resultData) {
    LOGGER.debug("handleGetSpecificAttributeValueResponse for MessageType: {}", messageMetadata.getMessageType());
    ResponseMessageResultType result = deviceResult;
    if (exception != null) {
        LOGGER.error(DEVICE_RESPONSE_NOT_OK_UNEXPECTED_EXCEPTION, exception);
        result = ResponseMessageResultType.NOT_OK;
    }
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withMessageMetadata(messageMetadata).withResult(result).withOsgpException(exception).withDataObject(resultData).build();
    this.webServiceResponseMessageSender.send(responseMessage, messageMetadata.getMessageType());
}
Also used : ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)

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