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);
}
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;
}
});
}
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;
}
});
}
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);
}
}
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);
}
}
Aggregations