Search in sources :

Example 6 with TechnicalException

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

the class DefaultDeviceResponseService method handleDefaultDeviceResponse.

public void handleDefaultDeviceResponse(final CorrelationIds ids, final String messageType, final int messagePriority, final ResponseMessageResultType deviceResult, final OsgpException exception) {
    LOGGER.info("handleDefaultDeviceResponse for MessageType: {}", messageType);
    ResponseMessageResultType result = deviceResult;
    OsgpException osgpException = exception;
    if (deviceResult == ResponseMessageResultType.NOT_OK && exception == null) {
        LOGGER.error("Incorrect response received, exception should not be null when result is not ok");
        osgpException = new TechnicalException(ComponentType.DOMAIN_TARIFF_SWITCHING, "An unknown error occurred");
    }
    if (deviceResult == ResponseMessageResultType.OK && exception != null) {
        LOGGER.error("Incorrect response received, result should be set to not ok when exception is not null");
        result = ResponseMessageResultType.NOT_OK;
    }
    final MessageMetadata metaData = new MessageMetadata.Builder().withCorrelationUid(ids.getCorrelationUid()).withDeviceIdentification(ids.getDeviceIdentification()).withOrganisationIdentification(ids.getOrganisationIdentification()).withMessageType(messageType).build();
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withMessageMetadata(metaData).withResult(result).withOsgpException(osgpException).withMessagePriority(messagePriority).build();
    this.webServiceResponseMessageSender.send(responseMessage);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)

Example 7 with TechnicalException

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

the class BundleResponseMessageProcessorTest method technicalExceptionDetailsWithoutCauseOrMessageInFaultResponse.

@Test
public void technicalExceptionDetailsWithoutCauseOrMessageInFaultResponse() throws Exception {
    final ComponentType component = ComponentType.PROTOCOL_DLMS;
    final Exception exception = new TechnicalException(component, null, null);
    final FaultResponseDto faultResponse = this.processor.faultResponseForException(exception, this.parameters, this.defaultMessage);
    this.assertResponse(faultResponse, null, this.defaultMessage, component.name(), null, null, this.parameters);
}
Also used : ComponentType(org.opensmartgridplatform.shared.exceptionhandling.ComponentType) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) FaultResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.FaultResponseDto) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) Test(org.junit.jupiter.api.Test)

Example 8 with TechnicalException

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

the class DetailSoapFaultMappingExceptionResolver method customizeFault.

@Override
protected void customizeFault(final Object endpoint, final Exception ex, final SoapFault fault) {
    final SoapFaultDetail detail = fault.addFaultDetail();
    final Result result = detail.getResult();
    FunctionalException fex = null;
    TechnicalException tex = null;
    if (ex instanceof FunctionalException) {
        fex = (FunctionalException) ex;
    } else if (ex instanceof TechnicalException) {
        tex = (TechnicalException) ex;
    }
    if (fex != null) {
        try {
            this.marshalFunctionalException(fex, result);
        } catch (final JAXBException e) {
            LOGGER.error("Unable to marshal the Functional Exception", e);
        }
    }
    if (tex != null) {
        try {
            this.marshalTechnicalException(tex, result);
        } catch (final JAXBException e) {
            LOGGER.error("Unable to marshal the Technical Exception", e);
        }
    }
}
Also used : TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) SoapFaultDetail(org.springframework.ws.soap.SoapFaultDetail) JAXBException(javax.xml.bind.JAXBException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) Result(javax.xml.transform.Result)

Example 9 with TechnicalException

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

the class SmartMeteringAdhocEndpoint method getScanMbusChannelsResponse.

@PayloadRoot(localPart = "ScanMbusChannelsAsyncRequest", namespace = SMARTMETER_ADHOC_NAMESPACE)
@ResponsePayload
public ScanMbusChannelsResponse getScanMbusChannelsResponse(@RequestPayload final ScanMbusChannelsAsyncRequest request) throws OsgpException {
    ScanMbusChannelsResponse response = null;
    try {
        response = new ScanMbusChannelsResponse();
        final ResponseData responseData = this.responseDataService.get(request.getCorrelationUid(), ComponentType.WS_SMART_METERING);
        this.throwExceptionIfResultNotOk(responseData, "retrieving the scan m-bus channels response");
        response.setResult(OsgpResultType.fromValue(responseData.getResultType().getValue()));
        final ScanMbusChannelsResponseData scanMbusChannelsResponse = (ScanMbusChannelsResponseData) responseData.getMessageData();
        if (ResponseMessageResultType.OK == responseData.getResultType()) {
            final List<MbusChannelShortEquipmentIdentifier> channelShortIds = response.getChannelShortIds();
            channelShortIds.addAll(this.adhocMapper.mapAsList(scanMbusChannelsResponse.getChannelShortIds(), MbusChannelShortEquipmentIdentifier.class));
        } else if (responseData.getMessageData() instanceof OsgpException) {
            throw (OsgpException) responseData.getMessageData();
        } else if (responseData.getMessageData() instanceof Exception) {
            throw new TechnicalException(ComponentType.WS_SMART_METERING, "An exception occurred: Scan M-Bus Channels", (Exception) responseData.getMessageData());
        } else {
            throw new TechnicalException(ComponentType.WS_SMART_METERING, "An exception occurred: Scan M-Bus Channels", null);
        }
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) MbusChannelShortEquipmentIdentifier(org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.MbusChannelShortEquipmentIdentifier) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ScanMbusChannelsResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.ScanMbusChannelsResponse) ScanMbusChannelsResponseData(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ScanMbusChannelsResponseData) ResponseData(org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData) ScanMbusChannelsResponseData(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ScanMbusChannelsResponseData) 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 10 with TechnicalException

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

the class ManagementService method findEventsByCorrelationUid.

public List<Event> findEventsByCorrelationUid(final String organisationIdentification, final String correlationUid) throws OsgpException {
    log.info("findEventsByCorrelationUid called with organisation {}}", organisationIdentification);
    this.domainHelperService.findOrganisation(organisationIdentification);
    final ResponseData responseData = this.responseDataRepository.findByCorrelationUid(correlationUid);
    final List<Event> events = new ArrayList<>();
    final Serializable messageData = responseData.getMessageData();
    if (messageData instanceof EventMessagesResponse) {
        events.addAll(((EventMessagesResponse) messageData).getEvents());
        log.info("deleting ResponseData for correlation uid {}.", correlationUid);
        this.responseDataRepository.delete(responseData);
    } else {
        /**
         * If the returned data is not an EventMessageContainer but a String, there has been an
         * exception. The exception message has been put in the messageData.
         *
         * <p>As there is no way of knowing what the type of the exception was (because it is passed
         * as a String) it is thrown as a TechnicalException because the user is most probably not to
         * blame for the exception.
         */
        if (messageData instanceof String) {
            throw new TechnicalException(ComponentType.UNKNOWN, (String) messageData);
        }
        log.info("findEventsByCorrelationUid found other type of meter response data: {} for correlation UID: {}", messageData.getClass().getName(), correlationUid);
    }
    log.info("returning a list containing {} events", events.size());
    return events;
}
Also used : Serializable(java.io.Serializable) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ResponseData(org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData) ArrayList(java.util.ArrayList) Event(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.Event) EventMessagesResponse(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventMessagesResponse)

Aggregations

TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)62 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)26 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)20 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)18 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)15 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)13 ProtocolResponseMessage (org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)13 JMSException (javax.jms.JMSException)10 IOException (java.io.IOException)9 SoapFaultDetail (org.springframework.ws.soap.SoapFaultDetail)8 JAXBException (javax.xml.bind.JAXBException)7 Result (javax.xml.transform.Result)7 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)7 NoDeviceResponseException (org.opensmartgridplatform.shared.exceptionhandling.NoDeviceResponseException)7 ResponseData (org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData)6 Test (org.junit.jupiter.api.Test)5 Serializable (java.io.Serializable)4 Device (org.opensmartgridplatform.domain.core.entities.Device)4 DeviceStatusMapped (org.opensmartgridplatform.domain.core.valueobjects.DeviceStatusMapped)4 DeviceStatusDto (org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto)4