Search in sources :

Example 1 with NotSupportedException

use of org.opensmartgridplatform.shared.exceptionhandling.NotSupportedException in project open-smart-grid-platform by OSGP.

the class DeviceRequestMessageListener method sendNotSupportedException.

private void sendNotSupportedException(final ObjectMessage objectMessage, final MessageMetadata messageMetadata) {
    try {
        final Exception exception = new NotSupportedException(ComponentType.PROTOCOL_IEC60870, messageMetadata.getMessageType());
        final FunctionalException osgpException = new FunctionalException(FunctionalExceptionType.UNSUPPORTED_DEVICE_ACTION, ComponentType.PROTOCOL_IEC60870, exception);
        final ProtocolResponseMessage protocolResponseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(messageMetadata.builder().withScheduled(false).build()).result(ResponseMessageResultType.NOT_OK).osgpException(osgpException).dataObject(objectMessage.getObject()).build();
        this.deviceResponseMessageSender.send(protocolResponseMessage);
    } catch (final Exception e) {
        LOGGER.error("Unexpected error during sendException(ObjectMessage, Exception)", e);
    }
}
Also used : ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) NotSupportedException(org.opensmartgridplatform.shared.exceptionhandling.NotSupportedException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) JMSException(javax.jms.JMSException) NotSupportedException(org.opensmartgridplatform.shared.exceptionhandling.NotSupportedException)

Example 2 with NotSupportedException

use of org.opensmartgridplatform.shared.exceptionhandling.NotSupportedException in project open-smart-grid-platform by OSGP.

the class DeviceRequestMessageListener method onMessage.

@Override
public void onMessage(final Message message) {
    final ObjectMessage objectMessage = (ObjectMessage) message;
    String messageType = null;
    final int messagePriority;
    try {
        messageType = message.getJMSType();
        messagePriority = message.getJMSPriority();
        LOGGER.info("Received message of type: {} with message priority: {}", messageType, messagePriority);
        final MessageProcessor processor = this.oslpRequestMessageProcessorMap.getMessageProcessor(objectMessage);
        processor.processMessage(objectMessage);
    } catch (final JMSException ex) {
        LOGGER.error("Unexpected JMSException during onMessage(Message)", ex);
        this.sendException(objectMessage, ex, "JMSException while processing message");
    } catch (final IllegalArgumentException e) {
        LOGGER.error("Unexpected IllegalArgumentException during onMessage(Message)", e);
        this.sendException(objectMessage, new NotSupportedException(ComponentType.PROTOCOL_OSLP, messageType), "Unsupported device function: " + messageType);
    }
}
Also used : ObjectMessage(javax.jms.ObjectMessage) MessageProcessor(org.opensmartgridplatform.shared.infra.jms.MessageProcessor) JMSException(javax.jms.JMSException) NotSupportedException(org.opensmartgridplatform.shared.exceptionhandling.NotSupportedException)

Aggregations

JMSException (javax.jms.JMSException)2 NotSupportedException (org.opensmartgridplatform.shared.exceptionhandling.NotSupportedException)2 ObjectMessage (javax.jms.ObjectMessage)1 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)1 MessageProcessor (org.opensmartgridplatform.shared.infra.jms.MessageProcessor)1 ProtocolResponseMessage (org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)1