Search in sources :

Example 1 with MessageProcessor

use of com.alliander.osgp.shared.infra.jms.MessageProcessor in project Protocol-Adapter-IEC61850 by OSGP.

the class DeviceRequestMessageListener method onMessage.

/*
     * (non-Javadoc)
     *
     * @see
     * org.springframework.jms.listener.SessionAwareMessageListener#onMessage
     * (javax.jms.Message, javax.jms.Session)
     */
@Override
public void onMessage(final Message message, final Session session) throws JMSException {
    final ObjectMessage objectMessage = (ObjectMessage) message;
    String messageType = null;
    MessageProcessor processor = null;
    try {
        messageType = message.getJMSType();
        LOGGER.info("Received message of type: {}", messageType);
        processor = this.iec61850RequestMessageProcessorMap.getMessageProcessor(objectMessage);
    } catch (final IllegalArgumentException | JMSException e) {
        LOGGER.error("Unexpected IllegalArgumentException | JMSExceptionduring during onMessage(Message)", e);
        this.createAndSendException(objectMessage, messageType);
        return;
    }
    processor.processMessage(objectMessage);
}
Also used : ObjectMessage(javax.jms.ObjectMessage) MessageProcessor(com.alliander.osgp.shared.infra.jms.MessageProcessor) JMSException(javax.jms.JMSException)

Example 2 with MessageProcessor

use of com.alliander.osgp.shared.infra.jms.MessageProcessor in project Protocol-Adapter-IEC61850 by OSGP.

the class DeviceRequestMessageProcessorMap method getMessageProcessor.

@Override
public MessageProcessor getMessageProcessor(final ObjectMessage message) throws JMSException {
    if (message.getJMSType() == null) {
        LOGGER.error("Unknown message type: {}", message.getJMSType());
        throw new JMSException("Unknown message type");
    }
    final DeviceRequestMessageType messageType = DeviceRequestMessageType.valueOf(message.getJMSType());
    if (messageType.name() == null) {
        LOGGER.error("No message processor found for message type: {}", message.getJMSType());
        throw new JMSException("Unknown message processor for message type: " + message.getJMSType());
    }
    final MessageProcessor messageProcessor = this.messageProcessors.get(messageType.ordinal());
    if (messageProcessor == null) {
        LOGGER.error("No message processor instance found in message processor map for message type: {}", message.getJMSType());
        throw new JMSException("Unknown message processor");
    }
    return messageProcessor;
}
Also used : MessageProcessor(com.alliander.osgp.shared.infra.jms.MessageProcessor) JMSException(javax.jms.JMSException)

Example 3 with MessageProcessor

use of com.alliander.osgp.shared.infra.jms.MessageProcessor in project Protocol-Adapter-OSLP by OSGP.

the class DeviceRequestMessageProcessorMap method getMessageProcessor.

@Override
public MessageProcessor getMessageProcessor(final ObjectMessage message) throws JMSException {
    if (message.getJMSType() == null) {
        LOGGER.error("Unknown message type: {}", message.getJMSType());
        throw new JMSException("Unknown message type");
    }
    final DeviceRequestMessageType messageType = DeviceRequestMessageType.valueOf(message.getJMSType());
    if (messageType.name() == null) {
        LOGGER.error("No message processor found for message type: {}", message.getJMSType());
        throw new JMSException("Unknown message processor");
    }
    final MessageProcessor messageProcessor = this.messageProcessors.get(messageType.ordinal());
    if (messageProcessor == null) {
        throw new IllegalArgumentException("Message type is not supported: " + message.getJMSType());
    }
    return messageProcessor;
}
Also used : MessageProcessor(com.alliander.osgp.shared.infra.jms.MessageProcessor) JMSException(javax.jms.JMSException)

Example 4 with MessageProcessor

use of com.alliander.osgp.shared.infra.jms.MessageProcessor in project Protocol-Adapter-OSLP by OSGP.

the class DeviceRequestMessageListener method onMessage.

@Override
public void onMessage(final Message message) {
    final ObjectMessage objectMessage = (ObjectMessage) message;
    String messageType = null;
    try {
        messageType = message.getJMSType();
        LOGGER.info("Received message of type: {}", messageType);
        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(com.alliander.osgp.shared.infra.jms.MessageProcessor) JMSException(javax.jms.JMSException) NotSupportedException(com.alliander.osgp.shared.exceptionhandling.NotSupportedException)

Aggregations

MessageProcessor (com.alliander.osgp.shared.infra.jms.MessageProcessor)4 JMSException (javax.jms.JMSException)4 ObjectMessage (javax.jms.ObjectMessage)2 NotSupportedException (com.alliander.osgp.shared.exceptionhandling.NotSupportedException)1