Search in sources :

Example 36 with OsgpException

use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.

the class SmartMeteringBundleEndpoint method bundleRequest.

@PayloadRoot(localPart = "BundleRequest", namespace = NAMESPACE)
@ResponsePayload
public BundleAsyncResponse bundleRequest(@ResponseUrl final String responseUrl, @MessageMetadata final org.opensmartgridplatform.shared.infra.jms.MessageMetadata messageMetadata, @RequestPayload final BundleRequest request) throws OsgpException {
    final String organisationIdentification = messageMetadata.getOrganisationIdentification();
    final String deviceIdentification = request.getDeviceIdentification();
    log.info("Incoming BundleRequest with responseUrl {} and {} actions. [deviceId={} | organisationId={}]", responseUrl, request.getActions().getActionList().size(), deviceIdentification, organisationIdentification);
    BundleAsyncResponse response = null;
    try {
        response = new BundleAsyncResponse();
        final List<ActionRequest> actionRequestList = this.actionMapperService.mapAllActions(request.getActions().getActionList());
        final String correlationUid = this.bundleService.enqueueBundleRequest(messageMetadata.builder().withDeviceIdentification(deviceIdentification).withMessageType(MessageType.HANDLE_BUNDLED_ACTIONS.name()).build(), actionRequestList);
        log.info("BundleRequest placed on queue [correlationId={} | deviceId={} | organisationId={}]", correlationUid, deviceIdentification, organisationIdentification);
        response.setCorrelationUid(correlationUid);
        response.setDeviceIdentification(request.getDeviceIdentification());
        this.saveResponseUrlIfNeeded(correlationUid, responseUrl);
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : ActionRequest(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ActionRequest) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) BundleAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.bundle.BundleAsyncResponse) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 37 with OsgpException

use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.

the class SmartMeteringConfigurationEndpoint method getGetMBusEncryptionKeyStatusByChannelResponse.

@PayloadRoot(localPart = "GetMbusEncryptionKeyStatusByChannelAsyncRequest", namespace = SMARTMETER_CONFIGURATION_NAMESPACE)
@ResponsePayload
public GetMbusEncryptionKeyStatusByChannelResponse getGetMBusEncryptionKeyStatusByChannelResponse(@RequestPayload final GetMbusEncryptionKeyStatusByChannelAsyncRequest request) throws OsgpException {
    GetMbusEncryptionKeyStatusByChannelResponse response = null;
    try {
        final ResponseData responseData = this.responseDataService.get(request.getCorrelationUid(), ComponentType.WS_SMART_METERING);
        this.throwExceptionIfResultNotOk(responseData, "retrieving the M-Bus encryption key status by channel.");
        response = new GetMbusEncryptionKeyStatusByChannelResponse();
        response.setResult(OsgpResultType.fromValue(responseData.getResultType().getValue()));
        response.setEncryptionKeyStatus(EncryptionKeyStatus.fromValue(((EncryptionKeyStatusType) responseData.getMessageData()).name()));
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : GetKeysResponseData(org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.GetKeysResponseData) ResponseData(org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData) EncryptionKeyStatusType(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EncryptionKeyStatusType) GetMbusEncryptionKeyStatusByChannelResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.GetMbusEncryptionKeyStatusByChannelResponse) IOException(java.io.IOException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 38 with OsgpException

use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.

the class SmartMeteringManagementEndpoint method getEnableDebuggingResponse.

@PayloadRoot(localPart = "EnableDebuggingAsyncRequest", namespace = NAMESPACE)
@ResponsePayload
public EnableDebuggingResponse getEnableDebuggingResponse(@OrganisationIdentification final String organisationIdentification, @RequestPayload final EnableDebuggingAsyncRequest request) throws OsgpException {
    log.info("EnableDebugging response for organisation: {} and device: {}.", organisationIdentification, request.getDeviceIdentification());
    EnableDebuggingResponse response = null;
    try {
        response = new EnableDebuggingResponse();
        final ResponseData responseData = this.responseDataService.get(request.getCorrelationUid(), ComponentType.WS_SMART_METERING);
        this.throwExceptionIfResultNotOk(responseData, "Enable Debugging");
        response.setResult(OsgpResultType.fromValue(responseData.getResultType().getValue()));
        if (responseData.getMessageData() instanceof String) {
            response.setDescription((String) responseData.getMessageData());
        }
    } catch (final ConstraintViolationException e) {
        throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.WS_SMART_METERING, new ValidationException(e.getConstraintViolations()));
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) EnableDebuggingResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.EnableDebuggingResponse) SetDeviceLifecycleStatusByChannelResponseData(org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.SetDeviceLifecycleStatusByChannelResponseData) ResponseData(org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData) GetGsmDiagnosticResponseData(org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.GetGsmDiagnosticResponseData) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 39 with OsgpException

use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.

the class CommonGetConfigurationRequestMessageProcessor method handleGetConfigurationDeviceResponse.

private void handleGetConfigurationDeviceResponse(final DeviceResponse deviceResponse, final ResponseMessageSender responseMessageSender, final DomainInformation domainInformation, final String messageType, final int retryCount, final boolean isScheduled) {
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    OsgpException osgpException = null;
    ConfigurationDto configuration = null;
    try {
        final GetConfigurationDeviceResponse response = (GetConfigurationDeviceResponse) deviceResponse;
        configuration = response.getConfiguration();
    } catch (final Exception e) {
        LOGGER.error("Device Response Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        osgpException = new TechnicalException(ComponentType.PROTOCOL_IEC61850, "Unexpected exception while retrieving response message", e);
    }
    final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withDeviceIdentification(deviceResponse.getDeviceIdentification()).withOrganisationIdentification(deviceResponse.getOrganisationIdentification()).withCorrelationUid(deviceResponse.getCorrelationUid()).withMessageType(messageType).withDomain(domainInformation.getDomain()).withDomainVersion(domainInformation.getDomainVersion()).withMessagePriority(deviceResponse.getMessagePriority()).withScheduled(isScheduled).withRetryCount(retryCount).build();
    final ProtocolResponseMessage responseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(messageMetadata).result(result).osgpException(osgpException).dataObject(configuration).build();
    responseMessageSender.send(responseMessage);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) ConfigurationDto(org.opensmartgridplatform.dto.valueobjects.ConfigurationDto) GetConfigurationDeviceResponse(org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.responses.GetConfigurationDeviceResponse) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)

Example 40 with OsgpException

use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.

the class OsgpResponseMessageListener method onMessage.

@Override
public void onMessage(final Message message) {
    try {
        LOGGER.info("Received message of type: {}", message.getJMSType());
        final ObjectMessage objectMessage = (ObjectMessage) message;
        final String messageType = objectMessage.getJMSType();
        final String deviceIdentification = objectMessage.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        final ResponseMessage responseMessage = (ResponseMessage) objectMessage.getObject();
        final String result = responseMessage == null ? null : responseMessage.getResult().toString();
        final OsgpException osgpException = responseMessage == null ? null : responseMessage.getOsgpException();
        if (MessageType.valueOf(messageType) == (MessageType.REGISTER_DEVICE)) {
            handleDeviceRegistration(result, deviceIdentification, messageType, osgpException);
        } else {
            throw new UnknownMessageTypeException("Unknown JMSType: " + messageType);
        }
    } catch (final JMSException ex) {
        LOGGER.error("Exception: {} ", ex.getMessage(), ex);
    } catch (final ProtocolAdapterException e) {
        LOGGER.error("ProtocolAdapterException", e);
    } catch (final UnknownMessageTypeException e) {
        LOGGER.error("UnknownMessageTypeException", e);
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) UnknownMessageTypeException(org.opensmartgridplatform.shared.infra.jms.UnknownMessageTypeException)

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