Search in sources :

Example 6 with UnknownMessageTypeException

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

the class CommonRequestMessageListener method onMessage.

@Override
public void onMessage(final Message message) {
    try {
        LOGGER.info("Received message of type: {}", message.getJMSType());
        final ObjectMessage objectMessage = (ObjectMessage) message;
        final String correlationUid = objectMessage.getJMSCorrelationID();
        final String messageType = objectMessage.getJMSType();
        final String organisationIdentification = objectMessage.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        final String deviceIdentification = objectMessage.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        final Serializable dataObject = objectMessage.getObject();
        if (MessageType.RELAY_STATUS_UPDATED_EVENTS.name().equals(messageType)) {
            this.notificationService.sendNotification(organisationIdentification, deviceIdentification, null, correlationUid, null, NotificationType.DEVICE_UPDATED);
        } else {
            LOGGER.debug("Unknown message received. MessageType: {}, correlationUID: {}, organisation: {}, deviceIdentification: {}, dataObject: {}", messageType, correlationUid, organisationIdentification, deviceIdentification, dataObject == null ? "null" : dataObject.getClass().getCanonicalName());
            throw new UnknownMessageTypeException("Unknown JMSType: " + messageType);
        }
    } catch (final JMSException ex) {
        LOGGER.error("Caught JMSException: {} ", ex, ex);
    } catch (final UnknownMessageTypeException e) {
        LOGGER.error("Caught UnknownMessageTypeException", e);
    }
}
Also used : Serializable(java.io.Serializable) ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException) UnknownMessageTypeException(org.opensmartgridplatform.shared.infra.jms.UnknownMessageTypeException)

Example 7 with UnknownMessageTypeException

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

the class OsgpCoreRequestMessageListener method onMessage.

@Override
public void onMessage(final Message message) {
    try {
        LOGGER.info("Received message");
        final ObjectMessage objectMessage = (ObjectMessage) message;
        final String messageType = objectMessage.getJMSType();
        final RequestMessage requestMessage = (RequestMessage) objectMessage.getObject();
        this.osgpCoreRequestMessageProcessor.processMessage(requestMessage, messageType);
    } catch (final JMSException e) {
        // Can't read message.
        LOGGER.error("Exception: {}, StackTrace: {}", e.getMessage(), e.getStackTrace(), e);
    } catch (final UnknownMessageTypeException e) {
        // Don't know this message.
        LOGGER.error("UnknownMessageTypeException", e);
    }
}
Also used : ObjectMessage(javax.jms.ObjectMessage) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) JMSException(javax.jms.JMSException) UnknownMessageTypeException(org.opensmartgridplatform.shared.infra.jms.UnknownMessageTypeException)

Example 8 with UnknownMessageTypeException

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

the class OsgpCoreRequestMessageProcessor method processMessage.

public void processMessage(final RequestMessage requestMessage, final String messageType) throws UnknownMessageTypeException {
    final String organisationIdentification = requestMessage.getOrganisationIdentification();
    final String deviceIdentification = requestMessage.getDeviceIdentification();
    final String correlationUid = requestMessage.getCorrelationUid();
    final Object dataObject = requestMessage.getRequest();
    LOGGER.info("Received request message from OSGP-CORE with messageType: {} deviceIdentification: {}, organisationIdentification: {}, correlationUid: {}, className: {}", messageType, deviceIdentification, organisationIdentification, correlationUid, dataObject.getClass().getCanonicalName());
    if (MessageType.EVENT_NOTIFICATION == MessageType.valueOf(messageType)) {
        final Event event = (Event) dataObject;
        this.handleLightMeasurementDeviceTransition(organisationIdentification, correlationUid, event);
    } else {
        throw new UnknownMessageTypeException("Unknown JMSType: " + messageType);
    }
}
Also used : Event(org.opensmartgridplatform.domain.core.entities.Event) UnknownMessageTypeException(org.opensmartgridplatform.shared.infra.jms.UnknownMessageTypeException)

Aggregations

UnknownMessageTypeException (org.opensmartgridplatform.shared.infra.jms.UnknownMessageTypeException)8 JMSException (javax.jms.JMSException)7 ObjectMessage (javax.jms.ObjectMessage)7 RequestMessage (org.opensmartgridplatform.shared.infra.jms.RequestMessage)4 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)2 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)2 Serializable (java.io.Serializable)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException)1 Event (org.opensmartgridplatform.domain.core.entities.Event)1