Search in sources :

Example 21 with ProtocolResponseMessage

use of org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage 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 22 with ProtocolResponseMessage

use of org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage 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 23 with ProtocolResponseMessage

use of org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage 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 24 with ProtocolResponseMessage

use of org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage 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 25 with ProtocolResponseMessage

use of org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage in project open-smart-grid-platform by OSGP.

the class DeviceRequestMessageProcessor method handleFunctionalException.

protected void handleFunctionalException(final FunctionalException e, final MessageMetadata messageMetadata) {
    LOGGER.error("Functional error while processing message, using MessageMetadata to create error response", e);
    final ProtocolResponseMessage protocolResponseMessage = this.createProtocolResponseMessage(messageMetadata, e);
    this.responseMessageSender.send(protocolResponseMessage);
}
Also used : ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)

Aggregations

ProtocolResponseMessage (org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)47 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)18 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)17 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)14 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)13 JMSException (javax.jms.JMSException)12 Serializable (java.io.Serializable)6 IOException (java.io.IOException)5 Test (org.junit.jupiter.api.Test)5 DeviceStatusDto (org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto)4 GetStatusDeviceResponse (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetStatusDeviceResponse)3 ScheduledTask (org.opensmartgridplatform.domain.core.entities.ScheduledTask)3 NotSupportedException (org.opensmartgridplatform.shared.exceptionhandling.NotSupportedException)3 RetryHeader (org.opensmartgridplatform.shared.infra.jms.RetryHeader)3 Calendar (java.util.Calendar)2 Date (java.util.Date)2 EmptyDeviceResponse (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.EmptyDeviceResponse)2 ConfigurationDto (org.opensmartgridplatform.dto.valueobjects.ConfigurationDto)2 FirmwareFileDto (org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto)2 FirmwareVersionDto (org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto)2