use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class SmartMeteringAdhocEndpoint method getAssociationLnObjectsResponse.
@PayloadRoot(localPart = "GetAssociationLnObjectsAsyncRequest", namespace = SMARTMETER_ADHOC_NAMESPACE)
@ResponsePayload
public GetAssociationLnObjectsResponse getAssociationLnObjectsResponse(@RequestPayload final GetAssociationLnObjectsAsyncRequest request) throws OsgpException {
GetAssociationLnObjectsResponse response = null;
try {
response = new GetAssociationLnObjectsResponse();
final ResponseData responseData = this.responseDataService.get(request.getCorrelationUid(), ComponentType.WS_SMART_METERING);
response.setResult(OsgpResultType.fromValue(responseData.getResultType().getValue()));
if (responseData.getMessageData() instanceof AssociationLnListType) {
response.setAssociationLnList(this.adhocMapper.map(responseData.getMessageData(), org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.AssociationLnListType.class));
}
} catch (final Exception e) {
this.handleException(e);
}
return response;
}
use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class SigningService method doSignMessage.
private void doSignMessage(final UnsignedOslpEnvelopeDto unsignedOslpEnvelopeDto, final String correlationUid, final String deviceIdentification, final Destination replyToQueue) {
final byte[] deviceId = unsignedOslpEnvelopeDto.getDeviceId();
final byte[] sequenceNumber = unsignedOslpEnvelopeDto.getSequenceNumber();
final Message payloadMessage = unsignedOslpEnvelopeDto.getPayloadMessage();
final String organisationIdentification = unsignedOslpEnvelopeDto.getOrganisationIdentification();
final int messagePriority = unsignedOslpEnvelopeDto.getMessagePriority();
final boolean scheduled = unsignedOslpEnvelopeDto.isScheduled();
final OslpEnvelope oslpEnvelope = new OslpEnvelope.Builder().withDeviceId(deviceId).withSequenceNumber(sequenceNumber).withPrimaryKey(this.privateKey).withSignature(this.signature).withProvider(this.signatureProvider).withPayloadMessage(payloadMessage).build();
ResponseMessage responseMessage;
if (oslpEnvelope == null) {
LOGGER.error("Message for device: {} with correlationId: {} NOT SIGNED, sending error to protocol-adapter", deviceIdentification, correlationUid);
responseMessage = ResponseMessage.newResponseMessageBuilder().withCorrelationUid(correlationUid).withOrganisationIdentification(organisationIdentification).withDeviceIdentification(deviceIdentification).withResult(ResponseMessageResultType.NOT_OK).withOsgpException(new OsgpException(ComponentType.UNKNOWN, "Failed to build signed OslpEnvelope", null)).withDataObject(unsignedOslpEnvelopeDto).withMessagePriority(messagePriority).withScheduled(scheduled).withRetryHeader(new RetryHeader()).build();
} else {
LOGGER.info("Message for device: {} with correlationId: {} signed, sending response to protocol-adapter", deviceIdentification, correlationUid);
final SignedOslpEnvelopeDto signedOslpEnvelopeDto = new SignedOslpEnvelopeDto(oslpEnvelope, unsignedOslpEnvelopeDto);
responseMessage = ResponseMessage.newResponseMessageBuilder().withCorrelationUid(correlationUid).withOrganisationIdentification(organisationIdentification).withDeviceIdentification(deviceIdentification).withResult(ResponseMessageResultType.OK).withDataObject(signedOslpEnvelopeDto).withMessagePriority(messagePriority).withScheduled(scheduled).withRetryHeader(new RetryHeader()).build();
}
this.signingServerResponseMessageSender.send(responseMessage, "SIGNING_RESPONSE", replyToQueue);
}
use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class DefaultDeviceResponseServiceTest method testDefaultDeviceResponseWithOkTypeAndNoException.
@Test
public void testDefaultDeviceResponseWithOkTypeAndNoException() {
// Arrange
final ResponseMessageResultType deviceResult = ResponseMessageResultType.OK;
final OsgpException exception = null;
final ResponseMessage expectedResponseMessage = ResponseMessage.newResponseMessageBuilder().withIds(IDS).withResult(ResponseMessageResultType.OK).withOsgpException(exception).withMessagePriority(MESSAGE_PRIORITY).withMessageType(MESSAGE_TYPE).build();
// Act
this.defaultDeviceResponseService.handleDefaultDeviceResponse(IDS, MESSAGE_TYPE, MESSAGE_PRIORITY, deviceResult, exception);
final ArgumentCaptor<ResponseMessage> argument = ArgumentCaptor.forClass(ResponseMessage.class);
verify(this.webServiceResponseMessageSender).send(argument.capture());
// Assert
assertThat(argument.getValue()).usingRecursiveComparison().isEqualTo(expectedResponseMessage);
}
use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class DefaultDeviceResponseServiceTest method testDefaultDeviceResponseWithOkTypeAndException.
@Test
public void testDefaultDeviceResponseWithOkTypeAndException() {
// Arrange
final ResponseMessageResultType deviceResult = ResponseMessageResultType.OK;
final OsgpException exception = new OsgpException(ComponentType.DOMAIN_CORE, "There was an exception");
final ResponseMessage expectedResponseMessage = ResponseMessage.newResponseMessageBuilder().withIds(IDS).withResult(ResponseMessageResultType.NOT_OK).withOsgpException(exception).withMessagePriority(MESSAGE_PRIORITY).withMessageType(MESSAGE_TYPE).build();
// Act
this.defaultDeviceResponseService.handleDefaultDeviceResponse(IDS, MESSAGE_TYPE, MESSAGE_PRIORITY, deviceResult, exception);
final ArgumentCaptor<ResponseMessage> argument = ArgumentCaptor.forClass(ResponseMessage.class);
verify(this.webServiceResponseMessageSender).send(argument.capture());
// Assert
assertThat(argument.getValue()).usingRecursiveComparison().isEqualTo(expectedResponseMessage);
}
use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class DefaultDeviceResponseServiceTest method testDefaultDeviceResponseWithNotOkTypeAndNoException.
@Test
public void testDefaultDeviceResponseWithNotOkTypeAndNoException() {
// Arrange
final ResponseMessageResultType deviceResult = ResponseMessageResultType.NOT_OK;
final OsgpException exception = null;
final OsgpException osgpException = new TechnicalException(ComponentType.DOMAIN_CORE, "An unknown error occurred");
final ResponseMessage expectedResponseMessage = ResponseMessage.newResponseMessageBuilder().withIds(IDS).withResult(ResponseMessageResultType.NOT_OK).withOsgpException(osgpException).withMessagePriority(MESSAGE_PRIORITY).withMessageType(MESSAGE_TYPE).build();
this.defaultDeviceResponseService.handleDefaultDeviceResponse(IDS, MESSAGE_TYPE, MESSAGE_PRIORITY, deviceResult, exception);
// Act
final ArgumentCaptor<ResponseMessage> argument = ArgumentCaptor.forClass(ResponseMessage.class);
verify(this.webServiceResponseMessageSender).send(argument.capture());
// Assert
assertThat(argument.getValue()).usingRecursiveComparison().isEqualTo(expectedResponseMessage);
}
Aggregations