Search in sources :

Example 16 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;
    ConnectionFailureException cex = null;
    if (ex instanceof FunctionalException) {
        fex = (FunctionalException) ex;
    } else if (ex instanceof TechnicalException) {
        tex = (TechnicalException) ex;
    } else if (ex instanceof ConnectionFailureException) {
        cex = (ConnectionFailureException) 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);
        }
    }
    if (cex != null) {
        try {
            this.marshalConnectionFailureException(cex, result);
        } catch (final JAXBException e) {
            LOGGER.error("Unable to marshal the Connection Failure Exception", e);
        }
    }
}
Also used : TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) SoapFaultDetail(org.springframework.ws.soap.SoapFaultDetail) ConnectionFailureException(org.opensmartgridplatform.shared.exceptionhandling.ConnectionFailureException) JAXBException(javax.xml.bind.JAXBException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) Result(javax.xml.transform.Result)

Example 17 with TechnicalException

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

the class DeviceInstallationServiceTest method testHandleGetStatusResponseOkLmdStatusNull.

@Test
public void testHandleGetStatusResponseOkLmdStatusNull() throws FunctionalException {
    when(this.domainCoreMapper.map(null, DeviceStatus.class)).thenReturn(null);
    final Device mockedDevice = Mockito.mock(Device.class);
    when(mockedDevice.getDeviceType()).thenReturn(LightMeasurementDevice.LMD_TYPE);
    when(this.deviceDomainService.searchDevice(TEST_DEVICE)).thenReturn(mockedDevice);
    this.deviceInstallationService.handleGetStatusResponse(null, CORRELATION_IDS, TEST_MESSAGE_TYPE, MESSAGE_PRIORITY, ResponseMessageResultType.OK, null);
    verify(this.webServiceResponseMessageSender).send(this.argumentResponseMessage.capture());
    assertThat(this.argumentResponseMessage.getValue()).usingRecursiveComparison().isEqualTo(this.createNewResponseMessage(ResponseMessageResultType.NOT_OK, new TechnicalException(ComponentType.DOMAIN_CORE, "Light measurement device was not able to report light sensor status", new NoDeviceResponseException()), null));
}
Also used : TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) NoDeviceResponseException(org.opensmartgridplatform.shared.exceptionhandling.NoDeviceResponseException) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) Device(org.opensmartgridplatform.domain.core.entities.Device) Test(org.junit.jupiter.api.Test)

Example 18 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 19 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 20 with TechnicalException

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

the class Hls5Connector method connect.

@Override
public DlmsConnection connect(final MessageMetadata messageMetadata, final DlmsDevice device, final DlmsMessageListener dlmsMessageListener) throws OsgpException {
    // Make sure neither device or device.getIpAddress() is null.
    this.checkDevice(device);
    this.checkIpAddress(device);
    try {
        return this.createConnection(messageMetadata, device, dlmsMessageListener, this.secretManagementService::getKeys);
    } catch (final UnknownHostException e) {
        // Unknown IP, unrecoverable.
        LOGGER.error("The IP address is not found: {}", device.getIpAddress(), e);
        throw new TechnicalException(ComponentType.PROTOCOL_DLMS, "The IP address is not found: " + device.getIpAddress());
    } catch (final IOException e) {
        // Queue key recovery process
        if (this.secretManagementService.hasNewSecret(messageMetadata, device.getDeviceIdentification())) {
            this.recoverKeyProcessInitiator.initiate(messageMetadata, device.getDeviceIdentification());
        }
        final String msg = String.format("Error creating connection for device %s with Ip address:%s Port:%d UseHdlc:%b UseSn:%b " + "Message:%s", device.getDeviceIdentification(), device.getIpAddress(), device.getPort(), device.isUseHdlc(), device.isUseSn(), e.getMessage());
        LOGGER.error(msg);
        throw new ConnectionException(msg, e);
    } catch (final EncrypterException e) {
        throw new FunctionalException(FunctionalExceptionType.INVALID_DLMS_KEY_FORMAT, ComponentType.PROTOCOL_DLMS, e);
    }
}
Also used : TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) UnknownHostException(java.net.UnknownHostException) EncrypterException(org.opensmartgridplatform.shared.exceptionhandling.EncrypterException) IOException(java.io.IOException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)

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