Search in sources :

Example 6 with RequestMessage

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;
        }
    });
}
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 7 with RequestMessage

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());
}
Also used : RequestMessage(com.alliander.osgp.shared.infra.jms.RequestMessage) ArrayList(java.util.ArrayList) EventNotificationDto(com.alliander.osgp.dto.valueobjects.EventNotificationDto) Oslp(com.alliander.osgp.oslp.Oslp) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) OslpDevice(com.alliander.osgp.adapter.protocol.oslp.elster.domain.entities.OslpDevice)

Example 8 with RequestMessage

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);
}
Also used : UnsignedOslpEnvelopeDto(com.alliander.osgp.oslp.UnsignedOslpEnvelopeDto) RequestMessage(com.alliander.osgp.shared.infra.jms.RequestMessage)

Example 9 with RequestMessage

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);
}
Also used : UnsignedOslpEnvelopeDto(com.alliander.osgp.oslp.UnsignedOslpEnvelopeDto) RequestMessage(com.alliander.osgp.shared.infra.jms.RequestMessage)

Example 10 with RequestMessage

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);
    }
}
Also used : Destination(javax.jms.Destination) UnsignedOslpEnvelopeDto(com.alliander.osgp.oslp.UnsignedOslpEnvelopeDto) ObjectMessage(javax.jms.ObjectMessage) RequestMessage(com.alliander.osgp.shared.infra.jms.RequestMessage) JMSException(javax.jms.JMSException)

Aggregations

RequestMessage (com.alliander.osgp.shared.infra.jms.RequestMessage)10 JMSException (javax.jms.JMSException)4 ObjectMessage (javax.jms.ObjectMessage)4 UnsignedOslpEnvelopeDto (com.alliander.osgp.oslp.UnsignedOslpEnvelopeDto)3 Message (javax.jms.Message)3 Session (javax.jms.Session)3 MessageCreator (org.springframework.jms.core.MessageCreator)3 DeviceRegistrationDataDto (com.alliander.osgp.dto.valueobjects.DeviceRegistrationDataDto)2 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)1 IED (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.IED)1 OslpDevice (com.alliander.osgp.adapter.protocol.oslp.elster.domain.entities.OslpDevice)1 Ssld (com.alliander.osgp.core.db.api.iec61850.entities.Ssld)1 EventNotificationDto (com.alliander.osgp.dto.valueobjects.EventNotificationDto)1 Oslp (com.alliander.osgp.oslp.Oslp)1 ArrayList (java.util.ArrayList)1 Destination (javax.jms.Destination)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1