use of com.alliander.osgp.shared.infra.jms.RequestMessage in project Protocol-Adapter-OSLP by OSGP.
the class SigningServerRequestMessageSender method send.
public void send(final RequestMessage requestMessage, final String messageType) {
LOGGER.info("Sending request message to signing server, with reply-to-queue: {}.", this.replyToQueue.toString());
this.signingServerRequestsJmsTemplate.send(new MessageCreator() {
@Override
public Message createMessage(final Session session) throws JMSException {
final ObjectMessage objectMessage = session.createObjectMessage(requestMessage);
objectMessage.setJMSType(messageType);
objectMessage.setJMSReplyTo(SigningServerRequestMessageSender.this.replyToQueue);
objectMessage.setJMSCorrelationID(requestMessage.getCorrelationUid());
objectMessage.setStringProperty(Constants.ORGANISATION_IDENTIFICATION, requestMessage.getOrganisationIdentification());
objectMessage.setStringProperty(Constants.DEVICE_IDENTIFICATION, requestMessage.getDeviceIdentification());
return objectMessage;
}
});
}
use of com.alliander.osgp.shared.infra.jms.RequestMessage in project Protocol-Adapter-OSLP by OSGP.
the class DeviceManagementService method addEventNotifications.
/**
* Send a list of event notifications to OSGP Core.
*
* @param deviceIdentification
* The identification of the device.
* @param eventNotifications
* The event notifications.
*
* @throws ProtocolAdapterException
* In case the device can not be found in the database.
*/
public void addEventNotifications(final String deviceUid, final List<Oslp.EventNotification> eventNotifications) {
LOGGER.info("addEventNotifications called for device {}", deviceUid);
final OslpDevice oslpDevice = this.oslpDeviceSettingsService.getDeviceByUid(deviceUid);
final String deviceIdentification = oslpDevice.getDeviceIdentification();
final List<EventNotificationDto> eventNotificationDtos = new ArrayList<>();
for (final Oslp.EventNotification eventNotification : eventNotifications) {
final String eventType = eventNotification.getEvent().name();
final String description = eventNotification.getDescription();
final int index = eventNotification.getIndex().isEmpty() ? 0 : (int) eventNotification.getIndex().byteAt(0);
String timestamp = eventNotification.getTimestamp();
LOGGER.debug("-->> timestamp: {}", timestamp);
// illegal timestamp value of 20000000xxxxxx.
if (!StringUtils.isEmpty(timestamp) && timestamp.startsWith("20000000")) {
final DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyyMMddHHmmss");
timestamp = DateTime.now().withZone(DateTimeZone.UTC).toString(dateTimeFormatter);
LOGGER.info("Using DateTime.now() instead of '20000000xxxxxx', value is: {}", timestamp);
}
final EventNotificationDto dto = this.createEventNotificationDto(deviceIdentification, deviceUid, eventType, description, index, timestamp);
eventNotificationDtos.add(dto);
}
final RequestMessage requestMessage = new RequestMessage("no-correlationUid", "no-organisation", deviceIdentification, new ArrayList<>(eventNotificationDtos));
this.osgpRequestMessageSender.send(requestMessage, DeviceFunctionDto.ADD_EVENT_NOTIFICATION.name());
}
use of com.alliander.osgp.shared.infra.jms.RequestMessage in project Protocol-Adapter-OSLP by OSGP.
the class OslpSigningService method buildAndSignEnvelope.
/**
* Build OslpEnvelope for an OSLP response using the arguments supplied and
* have the envelope signed by the signing server.
*/
public void buildAndSignEnvelope(final byte[] deviceId, final byte[] sequenceNumber, final Oslp.Message payloadMessage, final Integer channelId, final OslpChannelHandlerServer oslpChannelHandlerServer) {
this.oslpChannelHandlerServer = oslpChannelHandlerServer;
final String correlationUid = channelId.toString();
// Create DTO to transfer data using request message.
final UnsignedOslpEnvelopeDto unsignedOslpEnvelopeDto = new UnsignedOslpEnvelopeDto(sequenceNumber, deviceId, payloadMessage, correlationUid);
final RequestMessage requestMessage = new RequestMessage(correlationUid, "organisationIdentification", "deviceIdentification", unsignedOslpEnvelopeDto);
// Send request message to signing server.
this.signingServerRequestMessageSender.send(requestMessage, SIGNING_REQUEST_MESSAGE_TYPE);
}
use of com.alliander.osgp.shared.infra.jms.RequestMessage in project Protocol-Adapter-OSLP by OSGP.
the class OslpSigningService method buildAndSignEnvelope.
/**
* Build OslpEnvelope for an OSLP request using the arguments supplied and
* have the envelope signed by the signing server.
*/
public void buildAndSignEnvelope(final String organisationIdentification, final String deviceIdentification, final String correlationUid, final byte[] deviceId, final byte[] sequenceNumber, final String ipAddress, final String domain, final String domainVersion, final String messageType, final int retryCount, final boolean isScheduled, final Oslp.Message payloadMessage, final Serializable extraData) {
// Create DTO to transfer data using request message.
final UnsignedOslpEnvelopeDto oslpEnvelopeDto = new UnsignedOslpEnvelopeDto(sequenceNumber, deviceId, payloadMessage, ipAddress, domain, domainVersion, messageType, retryCount, isScheduled, organisationIdentification, correlationUid, extraData);
final RequestMessage requestMessage = new RequestMessage(correlationUid, organisationIdentification, deviceIdentification, oslpEnvelopeDto);
// Send request message to signing server.
this.signingServerRequestMessageSender.send(requestMessage, SIGNING_REQUEST_MESSAGE_TYPE);
}
use of com.alliander.osgp.shared.infra.jms.RequestMessage in project Protocol-Adapter-OSLP by OSGP.
the class SigningServerRequestMessageListener method onMessage.
@Override
public void onMessage(final Message message) {
try {
final ObjectMessage objectMessage = (ObjectMessage) message;
final Destination replyToQueue = objectMessage.getJMSReplyTo();
final RequestMessage requestMessage = (RequestMessage) objectMessage.getObject();
final UnsignedOslpEnvelopeDto unsignedOslpEnvelopeDto = (UnsignedOslpEnvelopeDto) requestMessage.getRequest();
final String correlationUid = objectMessage.getJMSCorrelationID();
final String deviceIdentification = objectMessage.getStringProperty(Constants.DEVICE_IDENTIFICATION);
LOGGER.info("Received message of type: {}, for device: {} with correlationId: {} and replyToQueue: {}", objectMessage.getJMSType(), deviceIdentification, correlationUid, replyToQueue.toString());
LOGGER.debug("-----------------------------------------------------------------------------");
LOGGER.debug("unsignedOslpEnvelopeDto.getCorrelationUid() : {}", unsignedOslpEnvelopeDto.getCorrelationUid());
LOGGER.debug("unsignedOslpEnvelopeDto.getDeviceId() : {}", unsignedOslpEnvelopeDto.getDeviceId());
LOGGER.debug("unsignedOslpEnvelopeDto.getDomain() : {}", unsignedOslpEnvelopeDto.getDomain());
LOGGER.debug("unsignedOslpEnvelopeDto.getDomainVersion() : {}", unsignedOslpEnvelopeDto.getDomainVersion());
LOGGER.debug("unsignedOslpEnvelopeDto.getIpAddress() : {}", unsignedOslpEnvelopeDto.getIpAddress());
LOGGER.debug("unsignedOslpEnvelopeDto.getMessageType() : {}", unsignedOslpEnvelopeDto.getMessageType());
LOGGER.debug("unsignedOslpEnvelopeDto.getOrganisationIdentification() : {}", unsignedOslpEnvelopeDto.getOrganisationIdentification());
LOGGER.debug("unsignedOslpEnvelopeDto.getPayloadMessage() : {}", unsignedOslpEnvelopeDto.getPayloadMessage().toString());
LOGGER.debug("unsignedOslpEnvelopeDto.getRetryCount() : {}", unsignedOslpEnvelopeDto.getRetryCount());
LOGGER.debug("unsignedOslpEnvelopeDto.getSequenceNumber() : {}", unsignedOslpEnvelopeDto.getSequenceNumber());
LOGGER.debug("unsignedOslpEnvelopeDto.isScheduled() : {}", unsignedOslpEnvelopeDto.isScheduled());
LOGGER.debug("-----------------------------------------------------------------------------");
this.signingService.sign(unsignedOslpEnvelopeDto, correlationUid, deviceIdentification, replyToQueue);
} catch (final JMSException ex) {
LOGGER.error("Exception: {} ", ex.getMessage(), ex);
}
}
Aggregations