use of com.alliander.osgp.oslp.UnsignedOslpEnvelopeDto 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.oslp.UnsignedOslpEnvelopeDto 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);
}
use of com.alliander.osgp.oslp.UnsignedOslpEnvelopeDto in project Protocol-Adapter-OSLP by OSGP.
the class OslpSigningService method handleError.
/**
* Handle an error from the signing server.
*/
public void handleError(final String deviceIdentification, final ResponseMessage responseMessage) {
final UnsignedOslpEnvelopeDto unsignedOslpEnvelopeDto = (UnsignedOslpEnvelopeDto) responseMessage.getDataObject();
final DeviceMessageMetadata deviceMessageMetadata = new DeviceMessageMetadata(deviceIdentification, unsignedOslpEnvelopeDto.getOrganisationIdentification(), unsignedOslpEnvelopeDto.getCorrelationUid(), unsignedOslpEnvelopeDto.getMessageType(), MessagePriorityEnum.DEFAULT.getPriority());
final ProtocolResponseMessage protocolResponseMessage = ProtocolResponseMessage.newBuilder().domain(unsignedOslpEnvelopeDto.getDomain()).domainVersion(unsignedOslpEnvelopeDto.getDomainVersion()).deviceMessageMetadata(deviceMessageMetadata).result(responseMessage.getResult()).osgpException(responseMessage.getOsgpException()).scheduled(unsignedOslpEnvelopeDto.isScheduled()).build();
this.deviceResponseMessageSender.send(protocolResponseMessage);
}
use of com.alliander.osgp.oslp.UnsignedOslpEnvelopeDto 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);
}
}
use of com.alliander.osgp.oslp.UnsignedOslpEnvelopeDto in project Protocol-Adapter-OSLP by OSGP.
the class CommonGetStatusRequestMessageProcessor 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) {
CommonGetStatusRequestMessageProcessor.this.handleGetStatusDeviceResponse(deviceResponse, CommonGetStatusRequestMessageProcessor.this.responseMessageSender, domain, domainVersion, messageType, retryCount);
}
@Override
public void handleException(final Throwable t, final DeviceResponse deviceResponse) {
CommonGetStatusRequestMessageProcessor.this.handleUnableToConnectDeviceResponse(deviceResponse, t, null, CommonGetStatusRequestMessageProcessor.this.responseMessageSender, deviceResponse, domain, domainVersion, messageType, isScheduled, retryCount);
}
};
final GetStatusDeviceRequest deviceRequest = new GetStatusDeviceRequest(organisationIdentification, deviceIdentification, correlationUid, null);
try {
this.deviceService.doGetStatus(oslpEnvelope, deviceRequest, deviceResponseHandler, ipAddress);
} catch (final IOException e) {
this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, domain, domainVersion, messageType, retryCount);
}
}
Aggregations