Search in sources :

Example 16 with OslpEnvelope

use of com.alliander.osgp.oslp.OslpEnvelope in project Protocol-Adapter-OSLP by OSGP.

the class OslpChannelHandlerServer method processSignedOslpEnvelope.

/**
 * Called when a signed OSLP envelope arrives from signing server. The
 * envelope will be sent to the device which is waiting for a response. The
 * channel for the waiting device should be present in the channelMap.
 *
 * @param signedOslpEnvelopeDto
 *            DTO containing signed OslpEnvelope.
 */
public void processSignedOslpEnvelope(final SignedOslpEnvelopeDto signedOslpEnvelopeDto) {
    // Try to find the channel.
    final Integer channelId = Integer.parseInt(signedOslpEnvelopeDto.getUnsignedOslpEnvelopeDto().getCorrelationUid());
    final Channel channel = this.findChannel(channelId);
    if (channel == null) {
        LOGGER.error("Unable to find channel for channelId: {}. Can't send response message to device.", channelId);
        return;
    }
    // Get signed envelope, log it and send it to device.
    final OslpEnvelope response = signedOslpEnvelopeDto.getOslpEnvelope();
    this.logMessage(response, false);
    channel.write(response);
    LOGGER.info("{} Send OSLP Response: {}", channelId, response.getPayloadMessage());
}
Also used : Channel(org.jboss.netty.channel.Channel) OslpEnvelope(com.alliander.osgp.oslp.OslpEnvelope)

Example 17 with OslpEnvelope

use of com.alliander.osgp.oslp.OslpEnvelope in project Protocol-Adapter-OSLP by OSGP.

the class OslpChannelHandlerServer method messageReceived.

@Override
public void messageReceived(final ChannelHandlerContext ctx, final MessageEvent e) throws Exception {
    final OslpEnvelope message = (OslpEnvelope) e.getMessage();
    this.logMessage(message, true);
    final Integer channelId = e.getChannel().getId();
    if (message.isValid()) {
        if (this.isOslpResponse(message)) {
            LOGGER.warn("{} Received OSLP Response, which is not expected: {}", channelId, message.getPayloadMessage());
        } else {
            LOGGER.info("{} Received OSLP Request: {}", channelId, message.getPayloadMessage());
            // Response pay-load to send to device.
            Message payload = null;
            // Check which request the device has sent and handle it.
            if (message.getPayloadMessage().hasRegisterDeviceRequest()) {
                payload = this.handleRegisterDeviceRequest(message.getDeviceId(), message.getSequenceNumber(), message.getPayloadMessage().getRegisterDeviceRequest());
            } else if (message.getPayloadMessage().hasConfirmRegisterDeviceRequest()) {
                payload = this.handleConfirmRegisterDeviceRequest(message.getDeviceId(), message.getSequenceNumber(), message.getPayloadMessage().getConfirmRegisterDeviceRequest());
            } else if (message.getPayloadMessage().hasEventNotificationRequest()) {
                payload = this.handleEventNotificationRequest(message.getDeviceId(), message.getSequenceNumber(), message.getPayloadMessage().getEventNotificationRequest());
            } else {
                LOGGER.warn("{} Received unknown payload. Received: {}.", channelId, message.getPayloadMessage().toString());
                // Optional extra: return error code to device.
                return;
            }
            // Cache the channel so we can write the response to it later.
            this.cacheChannel(channelId, e.getChannel());
            // Send message to signing server to get our response signed.
            this.oslpSigningService.buildAndSignEnvelope(message.getDeviceId(), message.getSequenceNumber(), payload, channelId, this);
        }
    } else {
        LOGGER.warn("{} Received message wasn't properly secured.", channelId);
    }
}
Also used : Message(com.alliander.osgp.oslp.Oslp.Message) OslpEnvelope(com.alliander.osgp.oslp.OslpEnvelope)

Example 18 with OslpEnvelope

use of com.alliander.osgp.oslp.OslpEnvelope in project Protocol-Adapter-OSLP by OSGP.

the class OslpSigningService method handleSignedOslpResponse.

private void handleSignedOslpResponse(final SignedOslpEnvelopeDto signedOslpEnvelopeDto) {
    final OslpEnvelope oslpEnvelope = signedOslpEnvelopeDto.getOslpEnvelope();
    final UnsignedOslpEnvelopeDto unsignedOslpEnvelopeDto = signedOslpEnvelopeDto.getUnsignedOslpEnvelopeDto();
    // Handle OSLP response message.
    LOGGER.debug(LINES);
    LOGGER.info("oslpEnvelope.size: {} for message type: {}", oslpEnvelope.getSize(), unsignedOslpEnvelopeDto.getMessageType());
    LOGGER.debug(LINES);
    LOGGER.debug("unsignedOslpEnvelopeDto.getCorrelationUid() : {}", unsignedOslpEnvelopeDto.getCorrelationUid());
    LOGGER.debug("unsignedOslpEnvelopeDto.getDeviceId() : {}", unsignedOslpEnvelopeDto.getDeviceId());
    LOGGER.debug("unsignedOslpEnvelopeDto.getSequenceNumber() : {}", unsignedOslpEnvelopeDto.getSequenceNumber());
    LOGGER.debug("unsignedOslpEnvelopeDto.getPayloadMessage() : {}", unsignedOslpEnvelopeDto.getPayloadMessage().toString());
    // Send the signed OSLP envelope to the channel handler server.
    this.oslpChannelHandlerServer.processSignedOslpEnvelope(signedOslpEnvelopeDto);
}
Also used : UnsignedOslpEnvelopeDto(com.alliander.osgp.oslp.UnsignedOslpEnvelopeDto) OslpEnvelope(com.alliander.osgp.oslp.OslpEnvelope)

Example 19 with OslpEnvelope

use of com.alliander.osgp.oslp.OslpEnvelope in project Protocol-Adapter-OSLP by OSGP.

the class OslpSigningService method handleSignedOslpRequest.

private void handleSignedOslpRequest(final SignedOslpEnvelopeDto signedOslpEnvelopeDto, final String deviceIdentification) {
    final OslpEnvelope oslpEnvelope = signedOslpEnvelopeDto.getOslpEnvelope();
    final UnsignedOslpEnvelopeDto unsignedOslpEnvelopeDto = signedOslpEnvelopeDto.getUnsignedOslpEnvelopeDto();
    // Handle OSLP request message.
    LOGGER.debug(LINES);
    LOGGER.info("oslpEnvelope.size: {} for message type: {}", oslpEnvelope.getSize(), unsignedOslpEnvelopeDto.getMessageType());
    LOGGER.debug(LINES);
    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(LINES);
    // Try to convert message type to DeviceRequestMessageType member.
    final DeviceRequestMessageType deviceRequestMessageType = DeviceRequestMessageType.valueOf(unsignedOslpEnvelopeDto.getMessageType());
    // Handle message for message type.
    final OslpEnvelopeProcessor messageProcessor = this.deviceRequestMessageProcessorMap.getOslpEnvelopeProcessor(deviceRequestMessageType);
    if (messageProcessor == null) {
        LOGGER.error("No message processor for messageType: {}", unsignedOslpEnvelopeDto.getMessageType());
        return;
    }
    messageProcessor.processSignedOslpEnvelope(deviceIdentification, signedOslpEnvelopeDto);
}
Also used : OslpEnvelopeProcessor(com.alliander.osgp.adapter.protocol.oslp.elster.infra.messaging.OslpEnvelopeProcessor) UnsignedOslpEnvelopeDto(com.alliander.osgp.oslp.UnsignedOslpEnvelopeDto) DeviceRequestMessageType(com.alliander.osgp.adapter.protocol.oslp.elster.infra.messaging.DeviceRequestMessageType) OslpEnvelope(com.alliander.osgp.oslp.OslpEnvelope)

Example 20 with OslpEnvelope

use of com.alliander.osgp.oslp.OslpEnvelope in project Protocol-Adapter-OSLP by OSGP.

the class CommonGetFirmwareRequestMessageProcessor method processSignedOslpEnvelope.

@Override
public void processSignedOslpEnvelope(final String deviceIdentification, final SignedOslpEnvelopeDto signedOslpEnvelopeDto) {
    final UnsignedOslpEnvelopeDto unsignedOslpEnvelopeDto = signedOslpEnvelopeDto.getUnsignedOslpEnvelopeDto();
    final OslpEnvelope oslpEnvelope = signedOslpEnvelopeDto.getOslpEnvelope();
    final String correlationUid = unsignedOslpEnvelopeDto.getCorrelationUid();
    final String organisationIdentification = unsignedOslpEnvelopeDto.getOrganisationIdentification();
    final String domain = unsignedOslpEnvelopeDto.getDomain();
    final String domainVersion = unsignedOslpEnvelopeDto.getDomainVersion();
    final String messageType = unsignedOslpEnvelopeDto.getMessageType();
    final String ipAddress = unsignedOslpEnvelopeDto.getIpAddress();
    final int retryCount = unsignedOslpEnvelopeDto.getRetryCount();
    final boolean isScheduled = unsignedOslpEnvelopeDto.isScheduled();
    final DeviceResponseHandler deviceResponseHandler = new DeviceResponseHandler() {

        @Override
        public void handleResponse(final DeviceResponse deviceResponse) {
            CommonGetFirmwareRequestMessageProcessor.this.handleGetFirmwareVersionDeviceResponse(deviceResponse, CommonGetFirmwareRequestMessageProcessor.this.responseMessageSender, domain, domainVersion, messageType, retryCount);
        }

        @Override
        public void handleException(final Throwable t, final DeviceResponse deviceResponse) {
            CommonGetFirmwareRequestMessageProcessor.this.handleUnableToConnectDeviceResponse(deviceResponse, t, null, CommonGetFirmwareRequestMessageProcessor.this.responseMessageSender, deviceResponse, domain, domainVersion, messageType, isScheduled, retryCount);
        }
    };
    final DeviceRequest deviceRequest = new DeviceRequest(organisationIdentification, deviceIdentification, correlationUid);
    try {
        this.deviceService.doGetFirmwareVersion(oslpEnvelope, deviceRequest, deviceResponseHandler, ipAddress);
    } catch (final IOException e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, domain, domainVersion, messageType, retryCount);
    }
}
Also used : UnsignedOslpEnvelopeDto(com.alliander.osgp.oslp.UnsignedOslpEnvelopeDto) GetFirmwareVersionDeviceResponse(com.alliander.osgp.adapter.protocol.oslp.elster.device.responses.GetFirmwareVersionDeviceResponse) DeviceResponse(com.alliander.osgp.adapter.protocol.oslp.elster.device.DeviceResponse) DeviceResponseHandler(com.alliander.osgp.adapter.protocol.oslp.elster.device.DeviceResponseHandler) DeviceRequest(com.alliander.osgp.adapter.protocol.oslp.elster.device.DeviceRequest) IOException(java.io.IOException) OslpEnvelope(com.alliander.osgp.oslp.OslpEnvelope)

Aggregations

OslpEnvelope (com.alliander.osgp.oslp.OslpEnvelope)40 IOException (java.io.IOException)25 UnsignedOslpEnvelopeDto (com.alliander.osgp.oslp.UnsignedOslpEnvelopeDto)23 DeviceResponseHandler (com.alliander.osgp.adapter.protocol.oslp.elster.device.DeviceResponseHandler)21 DeviceResponse (com.alliander.osgp.adapter.protocol.oslp.elster.device.DeviceResponse)20 DeviceRequest (com.alliander.osgp.adapter.protocol.oslp.elster.device.DeviceRequest)15 GetStatusDeviceRequest (com.alliander.osgp.adapter.protocol.oslp.elster.device.requests.GetStatusDeviceRequest)4 DeviceSimulatorException (com.alliander.osgp.webdevicesimulator.exceptions.DeviceSimulatorException)4 GetStatusDeviceResponse (com.alliander.osgp.adapter.protocol.oslp.elster.device.responses.GetStatusDeviceResponse)3 Device (com.alliander.osgp.webdevicesimulator.domain.entities.Device)3 UnknownHostException (java.net.UnknownHostException)3 SetScheduleDeviceRequest (com.alliander.osgp.adapter.protocol.oslp.elster.device.requests.SetScheduleDeviceRequest)2 ScheduleMessageDataContainerDto (com.alliander.osgp.dto.valueobjects.ScheduleMessageDataContainerDto)2 Message (com.alliander.osgp.oslp.Oslp.Message)2 GetPowerUsageHistoryDeviceRequest (com.alliander.osgp.adapter.protocol.oslp.elster.device.requests.GetPowerUsageHistoryDeviceRequest)1 ResumeScheduleDeviceRequest (com.alliander.osgp.adapter.protocol.oslp.elster.device.requests.ResumeScheduleDeviceRequest)1 SetConfigurationDeviceRequest (com.alliander.osgp.adapter.protocol.oslp.elster.device.requests.SetConfigurationDeviceRequest)1 SetDeviceVerificationKeyDeviceRequest (com.alliander.osgp.adapter.protocol.oslp.elster.device.requests.SetDeviceVerificationKeyDeviceRequest)1 SetEventNotificationsDeviceRequest (com.alliander.osgp.adapter.protocol.oslp.elster.device.requests.SetEventNotificationsDeviceRequest)1 SetLightDeviceRequest (com.alliander.osgp.adapter.protocol.oslp.elster.device.requests.SetLightDeviceRequest)1