Search in sources :

Example 76 with OsgpException

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

the class DeviceResponseMessageServiceTest method testProcessScheduledMessageRetry.

private void testProcessScheduledMessageRetry(final String exceptionMessage, final String expectedMessage) {
    final ResponseMessageResultType result = ResponseMessageResultType.NOT_OK;
    final Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, 1);
    final Date scheduledRetryTime = calendar.getTime();
    // since the retryCount is smaller than the maxRetries, the message
    // should be retried
    final RetryHeader retryHeader = new RetryHeader(0, 1, scheduledRetryTime);
    final OsgpException exception = new OsgpException(ComponentType.OSGP_CORE, exceptionMessage);
    final ProtocolResponseMessage message = new ProtocolResponseMessage.Builder().messageMetadata(MESSAGE_METADATA.builder().withScheduled(true).build()).result(result).dataObject(DATA_OBJECT).retryHeader(retryHeader).osgpException(exception).build();
    final ScheduledTask scheduledTask = new ScheduledTask(MESSAGE_METADATA, DOMAIN, DOMAIN_VERSION, DATA_OBJECT, SCHEDULED_TIME);
    when(this.scheduledTaskService.findByCorrelationUid(anyString())).thenReturn(scheduledTask);
    this.deviceResponseMessageService.processMessage(message);
    // check if the message is not send and the task is not deleted
    verify(this.domainResponseMessageSender, never()).send(message);
    verify(this.scheduledTaskService, never()).deleteScheduledTask(scheduledTask);
    verify(this.scheduledTaskService).saveScheduledTask(scheduledTask);
    // check if the scheduled time is updated to the message retry time
    assertThat(scheduledTask.getScheduledTime()).isEqualTo(new Timestamp(scheduledRetryTime.getTime()));
    assertThat(scheduledTask.getErrorLog()).contains(expectedMessage);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) Calendar(java.util.Calendar) ScheduledTask(org.opensmartgridplatform.domain.core.entities.ScheduledTask) RetryHeader(org.opensmartgridplatform.shared.infra.jms.RetryHeader) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Example 77 with OsgpException

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

the class DlmsConnectionMessageProcessor method createAndHandleConnectionForDevice.

public void createAndHandleConnectionForDevice(final DlmsDevice device, final MessageMetadata messageMetadata, final Consumer<DlmsConnectionManager> taskForConnectionManager) throws OsgpException {
    Permit permit = null;
    if (this.throttlingClientConfig.clientEnabled()) {
        permit = this.throttlingClientConfig.throttlingClient().requestPermitUsingNetworkSegmentIfIdsAreAvailable(messageMetadata.getBaseTransceiverStationId(), messageMetadata.getCellId());
    } else {
        this.throttlingService.openConnection();
    }
    final DlmsMessageListener dlmsMessageListener = this.createMessageListenerForDeviceConnection(device, messageMetadata);
    try {
        this.dlmsConnectionHelper.createAndHandleConnectionForDevice(messageMetadata, device, dlmsMessageListener, permit, taskForConnectionManager);
    } catch (final ConnectionTaskException e) {
        /*
       * Exceptions thrown by the tasks working with the DlmsConnectionManager are wrapped in
       * ConnectionTaskException in the ThrowingConsumer.
       */
        throw e.getOsgpException();
    } catch (final Exception e) {
        /*
       * Throttling permit is released in this catch block to make sure that it is made available
       * again when there were problems setting up the connection and only then (exceptions thrown
       * by the tasks working with the DlmsConnectionManager are wrapped as ConnectionTaskException
       * and are caught in the previous catch block, so they don't end up here).
       *
       * If there are no problems in setting up the connection, releasing the throttling permit is
       * the responsibility of the tasks for the DlmsConnectionManager, as seen in
       * DeviceRequestMessageProcessor.processMessageTasks(), where
       * this.doConnectionPostProcessing() is called in a finally block.
       */
        if (this.throttlingClientConfig.clientEnabled()) {
            this.throttlingClientConfig.throttlingClient().releasePermit(permit);
        } else {
            this.throttlingService.closeConnection();
        }
        throw e;
    }
}
Also used : Permit(org.opensmartgridplatform.throttling.api.Permit) ConnectionTaskException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionTaskException) ConnectionTaskException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionTaskException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException) NonRetryableException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.NonRetryableException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 78 with OsgpException

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

the class DlmsConnectionMessageProcessor method sendResponseMessage.

protected void sendResponseMessage(final MessageMetadata messageMetadata, final ResponseMessageResultType result, final Exception exception, final DeviceResponseMessageSender responseMessageSender, final Serializable responseObject) {
    OsgpException osgpException = null;
    if (exception != null) {
        osgpException = this.osgpExceptionConverter.ensureOsgpOrTechnicalException(exception);
    }
    final RetryHeader retryHeader;
    if (this.shouldRetry(result, exception, responseObject)) {
        retryHeader = this.retryHeaderFactory.createRetryHeader(messageMetadata.getRetryCount());
    } else {
        retryHeader = this.retryHeaderFactory.createEmptyRetryHeader();
    }
    final ProtocolResponseMessage responseMessage = new ProtocolResponseMessage.Builder().messageMetadata(messageMetadata).result(result).osgpException(osgpException).dataObject(responseObject).retryHeader(retryHeader).build();
    responseMessageSender.send(responseMessage);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) RetryHeader(org.opensmartgridplatform.shared.infra.jms.RetryHeader)

Example 79 with OsgpException

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

the class TariffSwitchingGetStatusRequestMessageProcessor method handleGetStatusDeviceResponse.

private void handleGetStatusDeviceResponse(final DeviceResponse deviceResponse, final ResponseMessageSender responseMessageSender, final String domain, final String domainVersion, final String messageType, final int retryCount) {
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    OsgpException osgpException = null;
    DeviceStatusDto status = null;
    try {
        final GetStatusDeviceResponse response = (GetStatusDeviceResponse) deviceResponse;
        status = response.getDeviceStatus();
    } catch (final Exception e) {
        LOGGER.error("Device Response Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        osgpException = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while getting device status", e);
    }
    final MessageMetadata messageMetadata = MessageMetadataFactory.from(deviceResponse, messageType).builder().withDomain(domain).withDomainVersion(domainVersion).withRetryCount(retryCount).build();
    final ProtocolResponseMessage responseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(messageMetadata).result(result).osgpException(osgpException).dataObject(status).build();
    responseMessageSender.send(responseMessage);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) GetStatusDeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetStatusDeviceResponse) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) DeviceStatusDto(org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) IOException(java.io.IOException) JMSException(javax.jms.JMSException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)

Example 80 with OsgpException

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

the class CommonGetFirmwareRequestMessageProcessor method handleGetFirmwareVersionDeviceResponse.

private void handleGetFirmwareVersionDeviceResponse(final DeviceResponse deviceResponse, final ResponseMessageSender responseMessageSender, final String domain, final String domainVersion, final String messageType, final int retryCount) {
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    final String firmwareVersion;
    OsgpException osgpException = null;
    final List<FirmwareVersionDto> firmwareVersions = new ArrayList<>();
    try {
        final GetFirmwareVersionDeviceResponse response = (GetFirmwareVersionDeviceResponse) deviceResponse;
        firmwareVersion = response.getFirmwareVersion();
        firmwareVersions.add(new FirmwareVersionDto(FirmwareModuleType.FUNCTIONAL, firmwareVersion));
    } catch (final Exception e) {
        LOGGER.error("Device Response Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        osgpException = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while getting device firmware version", e);
    }
    final ProtocolResponseMessage responseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(MessageMetadataFactory.from(deviceResponse, messageType).builder().withDomain(domain).withDomainVersion(domainVersion).withRetryCount(retryCount).build()).result(result).osgpException(osgpException).dataObject((Serializable) firmwareVersions).build();
    responseMessageSender.send(responseMessage);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) Serializable(java.io.Serializable) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) GetFirmwareVersionDeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetFirmwareVersionDeviceResponse) ArrayList(java.util.ArrayList) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) IOException(java.io.IOException) JMSException(javax.jms.JMSException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)

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