Search in sources :

Example 21 with OslpEnvelope

use of org.opensmartgridplatform.oslp.OslpEnvelope in project open-smart-grid-platform by OSGP.

the class CommonStopDeviceTestRequestMessageProcessor 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 int messagePriority = unsignedOslpEnvelopeDto.getMessagePriority();
    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) {
            CommonStopDeviceTestRequestMessageProcessor.this.handleEmptyDeviceResponse(deviceResponse, CommonStopDeviceTestRequestMessageProcessor.this.responseMessageSender, domain, domainVersion, messageType, retryCount);
        }

        @Override
        public void handleException(final Throwable t, final DeviceResponse deviceResponse) {
            CommonStopDeviceTestRequestMessageProcessor.this.handleUnableToConnectDeviceResponse(deviceResponse, t, domain, domainVersion, messageType, isScheduled, retryCount);
        }
    };
    final DeviceRequest deviceRequest = new DeviceRequest(organisationIdentification, deviceIdentification, correlationUid, messagePriority);
    try {
        this.deviceService.doStopSelfTest(oslpEnvelope, deviceRequest, deviceResponseHandler, ipAddress);
    } catch (final IOException e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, domain, domainVersion, messageType, messagePriority, retryCount);
    }
}
Also used : UnsignedOslpEnvelopeDto(org.opensmartgridplatform.oslp.UnsignedOslpEnvelopeDto) DeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceResponse) DeviceResponseHandler(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceResponseHandler) DeviceRequest(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceRequest) IOException(java.io.IOException) OslpEnvelope(org.opensmartgridplatform.oslp.OslpEnvelope)

Example 22 with OslpEnvelope

use of org.opensmartgridplatform.oslp.OslpEnvelope in project open-smart-grid-platform by OSGP.

the class OslpDeviceSteps method theDeviceSendsAConfirmRegisterDeviceRequestToThePlatform.

@Given("^the device sends a confirm register device request to the platform over \"([^\"]*)\"$")
public void theDeviceSendsAConfirmRegisterDeviceRequestToThePlatform(final String protocol, final Map<String, String> settings) throws DeviceSimulatorException {
    try {
        final String deviceIdentification = getString(settings, PlatformPubliclightingKeys.KEY_DEVICE_IDENTIFICATION, PlatformPubliclightingDefaults.DEFAULT_DEVICE_IDENTIFICATION);
        final String deviceUid = getString(settings, PlatformPubliclightingKeys.KEY_DEVICE_UID, PlatformPubliclightingDefaults.DEVICE_UID);
        final OslpDevice oslpDevice = this.oslpDeviceRepository.findByDeviceIdentification(deviceIdentification);
        final int randomDevice = oslpDevice.getRandomDevice();
        final int randomPlatform = oslpDevice.getRandomPlatform();
        final Oslp.ConfirmRegisterDeviceRequest confirmRegisterDeviceRequest = Oslp.ConfirmRegisterDeviceRequest.newBuilder().setRandomDevice(randomDevice).setRandomPlatform(randomPlatform).build();
        final Message message = Message.newBuilder().setConfirmRegisterDeviceRequest(confirmRegisterDeviceRequest).build();
        this.oslpMockServer.incrementSequenceNumber(this.getDeviceUid(settings));
        final OslpEnvelope request = this.createEnvelopeBuilder(deviceUid, this.oslpMockServer.getSequenceNumber(this.getDeviceUid(settings))).withPayloadMessage(message).build();
        this.send(request, settings);
    } catch (final IOException | IllegalArgumentException e) {
        ScenarioContext.current().put("Error", e);
    }
}
Also used : Message(org.opensmartgridplatform.oslp.Oslp.Message) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) Oslp(org.opensmartgridplatform.oslp.Oslp) OslpDevice(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice) OslpEnvelope(org.opensmartgridplatform.oslp.OslpEnvelope) Given(io.cucumber.java.en.Given)

Example 23 with OslpEnvelope

use of org.opensmartgridplatform.oslp.OslpEnvelope in project open-smart-grid-platform by OSGP.

the class MockOslpServer method sendRequest.

public Message sendRequest(final String deviceUid, final Message message) throws DeviceSimulatorException, IOException, ParseException {
    final OslpEnvelope envelope = new OslpEnvelope();
    envelope.setPayloadMessage(message);
    return this.channelHandler.handleRequest(envelope, this.getSequenceNumber(deviceUid));
}
Also used : OslpEnvelope(org.opensmartgridplatform.oslp.OslpEnvelope)

Example 24 with OslpEnvelope

use of org.opensmartgridplatform.oslp.OslpEnvelope in project open-smart-grid-platform 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.getMessagePriority() : {}", unsignedOslpEnvelopeDto.getMessagePriority());
    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);
    final MessageType messageType = MessageType.valueOf(unsignedOslpEnvelopeDto.getMessageType());
    // Handle message for message type.
    final OslpEnvelopeProcessor messageProcessor = this.deviceRequestMessageProcessorMap.getOslpEnvelopeProcessor(messageType);
    if (messageProcessor == null) {
        LOGGER.error("No message processor for messageType: {}", unsignedOslpEnvelopeDto.getMessageType());
        return;
    }
    messageProcessor.processSignedOslpEnvelope(deviceIdentification, signedOslpEnvelopeDto);
}
Also used : OslpEnvelopeProcessor(org.opensmartgridplatform.adapter.protocol.oslp.elster.infra.messaging.OslpEnvelopeProcessor) UnsignedOslpEnvelopeDto(org.opensmartgridplatform.oslp.UnsignedOslpEnvelopeDto) MessageType(org.opensmartgridplatform.shared.infra.jms.MessageType) OslpEnvelope(org.opensmartgridplatform.oslp.OslpEnvelope)

Example 25 with OslpEnvelope

use of org.opensmartgridplatform.oslp.OslpEnvelope in project open-smart-grid-platform 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(org.opensmartgridplatform.oslp.UnsignedOslpEnvelopeDto) OslpEnvelope(org.opensmartgridplatform.oslp.OslpEnvelope)

Aggregations

OslpEnvelope (org.opensmartgridplatform.oslp.OslpEnvelope)42 IOException (java.io.IOException)28 UnsignedOslpEnvelopeDto (org.opensmartgridplatform.oslp.UnsignedOslpEnvelopeDto)22 DeviceResponseHandler (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceResponseHandler)20 DeviceResponse (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceResponse)18 DeviceRequest (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceRequest)17 ByteString (com.google.protobuf.ByteString)7 Device (org.opensmartgridplatform.webdevicesimulator.domain.entities.Device)5 DeviceSimulatorException (org.opensmartgridplatform.webdevicesimulator.exceptions.DeviceSimulatorException)4 Given (io.cucumber.java.en.Given)3 Channel (io.netty.channel.Channel)3 ChannelFuture (io.netty.channel.ChannelFuture)3 UnknownHostException (java.net.UnknownHostException)3 GetStatusDeviceRequest (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.requests.GetStatusDeviceRequest)3 GetStatusDeviceResponse (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetStatusDeviceResponse)3 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)3 Oslp (org.opensmartgridplatform.oslp.Oslp)3 Message (org.opensmartgridplatform.oslp.Oslp.Message)3 SocketChannel (io.netty.channel.socket.SocketChannel)2 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)2