Search in sources :

Example 51 with OsgpException

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;
}
Also used : AssociationLnListType(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AssociationLnListType) ScanMbusChannelsResponseData(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ScanMbusChannelsResponseData) ResponseData(org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData) GetAssociationLnObjectsResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.GetAssociationLnObjectsResponse) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 52 with OsgpException

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);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) Message(org.opensmartgridplatform.oslp.Oslp.Message) SignedOslpEnvelopeDto(org.opensmartgridplatform.oslp.SignedOslpEnvelopeDto) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) RetryHeader(org.opensmartgridplatform.shared.infra.jms.RetryHeader) OslpEnvelope(org.opensmartgridplatform.oslp.OslpEnvelope)

Example 53 with OsgpException

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);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) Test(org.junit.jupiter.api.Test)

Example 54 with OsgpException

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);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) Test(org.junit.jupiter.api.Test)

Example 55 with OsgpException

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);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) Test(org.junit.jupiter.api.Test)

Aggregations

OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)235 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)153 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)153 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)128 ConstraintViolationException (javax.validation.ConstraintViolationException)98 ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)75 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)67 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)64 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)54 ResponseData (org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData)51 JMSException (javax.jms.JMSException)40 IOException (java.io.IOException)30 GetKeysResponseData (org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.GetKeysResponseData)23 CorrelationIds (org.opensmartgridplatform.shared.infra.jms.CorrelationIds)18 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)17 AsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.common.AsyncResponse)15 ProtocolResponseMessage (org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)15 ResponseNotFoundException (org.opensmartgridplatform.adapter.ws.da.application.exceptionhandling.ResponseNotFoundException)10 Device (org.opensmartgridplatform.domain.core.entities.Device)10 ArrayList (java.util.ArrayList)9