Search in sources :

Example 1 with ObjectMessage

use of javax.jms.ObjectMessage 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 ObjectMessage

use of javax.jms.ObjectMessage in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850LogItemRequestMessageSender method send.

public void send(final Iec61850LogItemRequestMessage iec61850LogItemRequestMessage) {
    LOGGER.debug("Sending Iec61850LogItemRequestMessage");
    this.iec61850LogItemRequestsJmsTemplate.send(new MessageCreator() {

        @Override
        public Message createMessage(final Session session) throws JMSException {
            final ObjectMessage objectMessage = session.createObjectMessage();
            objectMessage.setJMSType(Constants.IEC61850_LOG_ITEM_REQUEST);
            objectMessage.setStringProperty(Constants.IS_INCOMING, iec61850LogItemRequestMessage.isIncoming().toString());
            objectMessage.setStringProperty(Constants.ENCODED_MESSAGE, iec61850LogItemRequestMessage.getEncodedMessage());
            objectMessage.setStringProperty(Constants.DECODED_MESSAGE, iec61850LogItemRequestMessage.getDecodedMessage());
            objectMessage.setStringProperty(Constants.DEVICE_IDENTIFICATION, iec61850LogItemRequestMessage.getDeviceIdentification());
            objectMessage.setStringProperty(Constants.ORGANISATION_IDENTIFICATION, iec61850LogItemRequestMessage.getOrganisationIdentification());
            objectMessage.setStringProperty(Constants.IS_VALID, iec61850LogItemRequestMessage.isValid().toString());
            objectMessage.setIntProperty(Constants.PAYLOAD_MESSAGE_SERIALIZED_SIZE, iec61850LogItemRequestMessage.getPayloadMessageSerializedSize());
            return objectMessage;
        }
    });
}
Also used : 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 3 with ObjectMessage

use of javax.jms.ObjectMessage in project Protocol-Adapter-IEC61850 by OSGP.

the class OsgpRequestMessageSender method send.

public void send(final RequestMessage requestMessage, final String messageType) {
    LOGGER.info("Sending request message to OSGP.");
    this.iec61850RequestsJmsTemplate.send(new MessageCreator() {

        @Override
        public Message createMessage(final Session session) throws JMSException {
            final ObjectMessage objectMessage = session.createObjectMessage(requestMessage);
            objectMessage.setJMSType(messageType);
            objectMessage.setStringProperty(Constants.ORGANISATION_IDENTIFICATION, requestMessage.getOrganisationIdentification());
            objectMessage.setStringProperty(Constants.DEVICE_IDENTIFICATION, requestMessage.getDeviceIdentification());
            return objectMessage;
        }
    });
}
Also used : ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) RequestMessage(com.alliander.osgp.shared.infra.jms.RequestMessage) ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException) MessageCreator(org.springframework.jms.core.MessageCreator) Session(javax.jms.Session)

Example 4 with ObjectMessage

use of javax.jms.ObjectMessage in project Protocol-Adapter-IEC61850 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 (DeviceFunctionDto.valueOf(messageType).equals(DeviceFunctionDto.REGISTER_DEVICE)) {
            this.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(com.alliander.osgp.shared.exceptionhandling.OsgpException) ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException) ResponseMessage(com.alliander.osgp.shared.infra.jms.ResponseMessage) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) UnknownMessageTypeException(com.alliander.osgp.shared.infra.jms.UnknownMessageTypeException)

Example 5 with ObjectMessage

use of javax.jms.ObjectMessage in project camel by apache.

the class JmsBinding method extractBodyFromJms.

/**
     * Extracts the body from the JMS message
     *
     * @param exchange the exchange
     * @param message  the message to extract its body
     * @return the body, can be <tt>null</tt>
     */
public Object extractBodyFromJms(Exchange exchange, Message message) {
    try {
        // if we are configured to not map the jms message then return it as body
        if (!mapJmsMessage) {
            LOG.trace("Option map JMS message is false so using JMS message as body: {}", message);
            return message;
        }
        if (message instanceof ObjectMessage) {
            LOG.trace("Extracting body as a ObjectMessage from JMS message: {}", message);
            ObjectMessage objectMessage = (ObjectMessage) message;
            Object payload = objectMessage.getObject();
            if (payload instanceof DefaultExchangeHolder) {
                DefaultExchangeHolder holder = (DefaultExchangeHolder) payload;
                DefaultExchangeHolder.unmarshal(exchange, holder);
                return exchange.getIn().getBody();
            } else {
                return objectMessage.getObject();
            }
        } else if (message instanceof TextMessage) {
            LOG.trace("Extracting body as a TextMessage from JMS message: {}", message);
            TextMessage textMessage = (TextMessage) message;
            return textMessage.getText();
        } else if (message instanceof MapMessage) {
            LOG.trace("Extracting body as a MapMessage from JMS message: {}", message);
            return createMapFromMapMessage((MapMessage) message);
        } else if (message instanceof BytesMessage) {
            LOG.trace("Extracting body as a BytesMessage from JMS message: {}", message);
            return createByteArrayFromBytesMessage((BytesMessage) message);
        } else if (message instanceof StreamMessage) {
            LOG.trace("Extracting body as a StreamMessage from JMS message: {}", message);
            return message;
        } else {
            return null;
        }
    } catch (JMSException e) {
        throw new RuntimeCamelException("Failed to extract body due to: " + e + ". Message: " + message, e);
    }
}
Also used : DefaultExchangeHolder(org.apache.camel.impl.DefaultExchangeHolder) ObjectMessage(javax.jms.ObjectMessage) MapMessage(javax.jms.MapMessage) BytesMessage(javax.jms.BytesMessage) StreamMessage(javax.jms.StreamMessage) JMSException(javax.jms.JMSException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) TextMessage(javax.jms.TextMessage)

Aggregations

ObjectMessage (javax.jms.ObjectMessage)222 Test (org.junit.Test)83 JMSException (javax.jms.JMSException)81 Session (javax.jms.Session)78 Message (javax.jms.Message)70 MessageProducer (javax.jms.MessageProducer)64 MessageConsumer (javax.jms.MessageConsumer)52 Connection (javax.jms.Connection)46 Queue (javax.jms.Queue)40 TextMessage (javax.jms.TextMessage)38 BytesMessage (javax.jms.BytesMessage)30 Destination (javax.jms.Destination)29 MapMessage (javax.jms.MapMessage)28 AbstractServiceComponentAgentFunctionalIntegrationTest (com.hack23.cia.service.component.agent.impl.AbstractServiceComponentAgentFunctionalIntegrationTest)25 StreamMessage (javax.jms.StreamMessage)21 HashMap (java.util.HashMap)18 Serializable (java.io.Serializable)17 Map (java.util.Map)16 ArrayList (java.util.ArrayList)13 QueueSession (javax.jms.QueueSession)11