Search in sources :

Example 1 with UnknownMessageTypeException

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

the class OsgpResponseMessageListener 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 messageType = objectMessage.getJMSType();
        final String deviceIdentification = objectMessage.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        final ResponseMessage responseMessage = (ResponseMessage) objectMessage.getObject();
        final String result = responseMessage == null ? null : responseMessage.getResult().toString();
        final OsgpException osgpException = responseMessage == null ? null : responseMessage.getOsgpException();
        if (MessageType.valueOf(messageType) == (MessageType.REGISTER_DEVICE)) {
            handleDeviceRegistration(result, deviceIdentification, messageType, osgpException);
        } else {
            throw new UnknownMessageTypeException("Unknown JMSType: " + messageType);
        }
    } catch (final JMSException ex) {
        LOGGER.error("Exception: {} ", ex.getMessage(), ex);
    } catch (final ProtocolAdapterException e) {
        LOGGER.error("ProtocolAdapterException", e);
    } catch (final UnknownMessageTypeException e) {
        LOGGER.error("UnknownMessageTypeException", e);
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) UnknownMessageTypeException(org.opensmartgridplatform.shared.infra.jms.UnknownMessageTypeException)

Example 2 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.messageProcessor.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 3 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 4 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.messageProcessor.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 5 with UnknownMessageTypeException

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

the class OsgpResponseMessageListener 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 messageType = objectMessage.getJMSType();
        final String deviceIdentification = objectMessage.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        final ResponseMessage responseMessage = (ResponseMessage) objectMessage.getObject();
        final String result = responseMessage == null ? null : responseMessage.getResult().toString();
        final OsgpException osgpException = responseMessage == null ? null : responseMessage.getOsgpException();
        if (MessageType.REGISTER_DEVICE.name().equals(messageType)) {
            if (ResponseMessageResultType.valueOf(result).equals(ResponseMessageResultType.NOT_OK)) {
                throw new ProtocolAdapterException(String.format("Response for device: %s for MessageType: %s is: %s, error: %s", deviceIdentification, messageType, result, osgpException));
            } else {
                throw new UnknownMessageTypeException("Unknown JMSType: " + messageType);
            }
        }
    } catch (final JMSException ex) {
        LOGGER.error("Exception: {} ", ex.getMessage(), ex);
    } catch (final ProtocolAdapterException e) {
        LOGGER.error("ProtocolAdapterException", e);
    } catch (final UnknownMessageTypeException e) {
        LOGGER.error("UnknownMessageTypeException", e);
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException) 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