Search in sources :

Example 26 with TechnicalException

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

the class DeviceRequestMessageProcessor method handleScheduledEmptyDeviceResponse.

protected void handleScheduledEmptyDeviceResponse(final DeviceResponse deviceResponse, final ResponseMessageSender responseMessageSender, final String domain, final String domainVersion, final String messageType, final boolean isScheduled, final int retryCount) {
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    TechnicalException ex = null;
    try {
        final EmptyDeviceResponse response = (EmptyDeviceResponse) deviceResponse;
        this.deviceResponseService.handleDeviceMessageStatus(response.getStatus());
    } catch (final TechnicalException e) {
        LOGGER.error("Device Response Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        ex = e;
    }
    final MessageMetadata messageMetadata = MessageMetadataFactory.from(deviceResponse, messageType).builder().withDomain(domain).withDomainVersion(domainVersion).withScheduled(isScheduled).withRetryCount(retryCount).build();
    final ProtocolResponseMessage responseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(messageMetadata).result(result).osgpException(ex).build();
    responseMessageSender.send(responseMessage);
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) EmptyDeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.EmptyDeviceResponse)

Example 27 with TechnicalException

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

the class DeviceRequestMessageProcessor method handleUnableToConnectDeviceResponse.

public void handleUnableToConnectDeviceResponse(final DeviceResponse deviceResponse, final Throwable t, final String domain, final String domainVersion, final String messageType, final boolean isScheduled, final int retryCount) {
    LOGGER.error("Error while connecting to or communicating with device", t);
    final ResponseMessageResultType result = ResponseMessageResultType.NOT_OK;
    // Set the exception to a class known by all OSGP components
    final TechnicalException ex = new TechnicalException(ComponentType.PROTOCOL_OSLP, StringUtils.isBlank(t.getMessage()) ? UNEXPECTED_EXCEPTION : t.getMessage());
    final MessageMetadata messageMetadata = MessageMetadataFactory.from(deviceResponse, messageType).builder().withDomain(domain).withDomainVersion(domainVersion).withScheduled(isScheduled).withRetryCount(retryCount).build();
    final ProtocolResponseMessage responseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(messageMetadata).result(result).osgpException(ex).build();
    this.responseMessageSender.send(responseMessage);
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)

Example 28 with TechnicalException

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

the class DeviceRequestMessageProcessor method handleError.

protected void handleError(final RuntimeException e, final MessageMetadata messageMetadata) {
    LOGGER.error("Error while processing message, using MessageMetadata to create error response", e);
    // Set the exception to a class known by all OSGP components
    final TechnicalException ex = new TechnicalException(ComponentType.PROTOCOL_OSLP, UNEXPECTED_EXCEPTION);
    final ProtocolResponseMessage protocolResponseMessage = this.createProtocolResponseMessage(messageMetadata, ex);
    this.responseMessageSender.send(protocolResponseMessage);
}
Also used : TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)

Example 29 with TechnicalException

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

the class DeviceRequestMessageProcessor method handleError.

protected void handleError(final IOException e, final String correlationUid, final String organisationIdentification, final String deviceIdentification, final String domain, final String domainVersion, final String messageType, final int messagePriority, final int retryCount) {
    LOGGER.error("Error while processing message", e);
    // Set the exception to a class known by all OSGP components
    final TechnicalException ex = new TechnicalException(ComponentType.PROTOCOL_OSLP, UNEXPECTED_EXCEPTION);
    final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withDeviceIdentification(deviceIdentification).withOrganisationIdentification(organisationIdentification).withCorrelationUid(correlationUid).withMessageType(messageType).withDomain(domain).withDomainVersion(domainVersion).withMessagePriority(messagePriority).withRetryCount(retryCount).build();
    final ProtocolResponseMessage protocolResponseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(messageMetadata).result(ResponseMessageResultType.NOT_OK).osgpException(ex).build();
    this.responseMessageSender.send(protocolResponseMessage);
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)

Example 30 with TechnicalException

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

the class DeviceManagementService method updateKey.

// === UPDATE KEY ===
public void updateKey(final MessageMetadata messageMetadata, final DeviceResponseMessageSender responseMessageSender, final String publicKey) {
    final String deviceIdentification = messageMetadata.getDeviceIdentification();
    final String organisationIdentification = messageMetadata.getOrganisationIdentification();
    LOGGER.info("updateKey called for device: {} for organisation: {} with new publicKey: {}", deviceIdentification, organisationIdentification, publicKey);
    try {
        OslpDevice oslpDevice = this.oslpDeviceSettingsService.getDeviceByDeviceIdentification(deviceIdentification);
        if (oslpDevice == null) {
            // Device not found, create new device
            LOGGER.debug("Device [{}] does not exist, creating new device", deviceIdentification);
            oslpDevice = new OslpDevice(deviceIdentification);
            oslpDevice = this.oslpDeviceSettingsService.addDevice(oslpDevice);
        }
        oslpDevice.updatePublicKey(publicKey);
        this.oslpDeviceSettingsService.updateDevice(oslpDevice);
        this.sendResponseMessage(messageMetadata, ResponseMessageResultType.OK, null, responseMessageSender);
    } catch (final Exception e) {
        LOGGER.error("Unexpected exception during updateKey", e);
        final TechnicalException ex = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while updating key", e);
        this.sendResponseMessage(messageMetadata, ResponseMessageResultType.NOT_OK, ex, responseMessageSender);
    }
}
Also used : TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) OslpDevice(org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)

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