use of org.opensmartgridplatform.shared.infra.jms.ResponseMessage in project open-smart-grid-platform by OSGP.
the class ProtocolResponseMessageSendingHandlerTest method sendsProtocolResponseMessageThatAvoidsRetries.
@Test
void sendsProtocolResponseMessageThatAvoidsRetries() {
final ProtocolResponseMessageSendingHandler protocolResponseMessageSendingHandler = this.aProtocolResponseMessageSendingHandler();
protocolResponseMessageSendingHandler.handlePublishedMessage("any/topic", "any-payload".getBytes(StandardCharsets.UTF_8));
verify(this.outboundOsgpCoreResponseMessageSender).send(this.responseMessageCaptor.capture());
final ResponseMessage actualResponseMessage = this.responseMessageCaptor.getValue();
final MessageMetadata actualMessageMetadata = actualResponseMessage.messageMetadata();
assertThat(actualMessageMetadata.isScheduled()).isFalse();
assertThat(actualMessageMetadata.isBypassRetry()).isTrue();
final RetryHeader retryHeader = actualResponseMessage.getRetryHeader();
if (retryHeader != null) {
assertThat(retryHeader.getScheduledRetryTime()).isNull();
assertThat(retryHeader.getMaxRetries()).isZero();
}
}
use of org.opensmartgridplatform.shared.infra.jms.ResponseMessage in project open-smart-grid-platform by OSGP.
the class DeviceManagementService method handleHealthStatusResponse.
public void handleHealthStatusResponse(final GetHealthStatusResponseDto getHealthStatusResponseDto, final String deviceIdentification, final String organisationIdentification, final String correlationUid, final String messageType, final ResponseMessageResultType responseMessageResultType, final OsgpException osgpException) {
LOGGER.info("handleResponse for MessageType: {}", messageType);
ResponseMessageResultType result = ResponseMessageResultType.OK;
GetHealthStatusResponse getHealthStatusResponse = null;
OsgpException exception = null;
try {
if (responseMessageResultType == ResponseMessageResultType.NOT_OK || osgpException != null) {
LOGGER.error("Device Response not ok.", osgpException);
throw osgpException;
}
this.rtuResponseService.handleResponseMessageReceived(LOGGER, deviceIdentification, true);
getHealthStatusResponse = this.mapper.map(getHealthStatusResponseDto, GetHealthStatusResponse.class);
} catch (final Exception e) {
LOGGER.error("Unexpected Exception", e);
result = ResponseMessageResultType.NOT_OK;
exception = this.ensureOsgpException(e, "Exception occurred while getting Health Status Response Data");
}
final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withCorrelationUid(correlationUid).withOrganisationIdentification(organisationIdentification).withDeviceIdentification(deviceIdentification).withMessageType(messageType).withResult(result).withOsgpException(exception).withDataObject(getHealthStatusResponse).build();
this.responseMessageRouter.send(responseMessage, messageType);
}
use of org.opensmartgridplatform.shared.infra.jms.ResponseMessage in project open-smart-grid-platform by OSGP.
the class AdHocManagementService method handleGetStatusResponse.
public void handleGetStatusResponse(final DeviceStatusDto deviceStatusDto, final CorrelationIds ids, final String messageType, final int messagePriority, final ResponseMessageResultType deviceResult, final OsgpException exception) {
LOGGER.info("handleResponse for MessageType: {}", messageType);
final GetStatusResponse response = new GetStatusResponse();
response.setOsgpException(exception);
response.setResult(deviceResult);
if (deviceResult == ResponseMessageResultType.NOT_OK || exception != null) {
LOGGER.error("Device Response not ok.", exception);
} else {
final DeviceStatus status = this.domainCoreMapper.map(deviceStatusDto, DeviceStatus.class);
try {
final Device dev = this.deviceDomainService.searchDevice(ids.getDeviceIdentification());
if (LightMeasurementDevice.LMD_TYPE.equals(dev.getDeviceType())) {
this.handleLmd(status, response);
} else {
this.handleSsld(ids.getDeviceIdentification(), status, DomainType.PUBLIC_LIGHTING, response);
}
} catch (final FunctionalException e) {
LOGGER.error("Caught FunctionalException", e);
}
}
final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(ids).withResult(response.getResult()).withOsgpException(response.getOsgpException()).withDataObject(response.getDeviceStatusMapped()).withMessagePriority(messagePriority).build();
this.webServiceResponseMessageSender.send(responseMessage);
}
use of org.opensmartgridplatform.shared.infra.jms.ResponseMessage in project open-smart-grid-platform by OSGP.
the class PublicLightingDefaultResponseMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) throws JMSException {
LOGGER.debug("Processing public lighting default response message");
String correlationUid = null;
String messageType = null;
int messagePriority = MessagePriorityEnum.DEFAULT.getPriority();
String organisationIdentification = null;
String deviceIdentification = null;
ResponseMessage responseMessage;
ResponseMessageResultType responseMessageResultType = null;
OsgpException osgpException = null;
try {
correlationUid = message.getJMSCorrelationID();
messageType = message.getJMSType();
messagePriority = message.getJMSPriority();
organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
responseMessage = (ResponseMessage) message.getObject();
responseMessageResultType = responseMessage.getResult();
osgpException = responseMessage.getOsgpException();
} catch (final JMSException e) {
LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
LOGGER.debug("correlationUid: {}", correlationUid);
LOGGER.debug("messageType: {}", messageType);
LOGGER.debug("messagePriority: {}", messagePriority);
LOGGER.debug("organisationIdentification: {}", organisationIdentification);
LOGGER.debug("deviceIdentification: {}", deviceIdentification);
LOGGER.debug("responseMessageResultType: {}", responseMessageResultType);
LOGGER.debug("deviceIdentification: {}", deviceIdentification);
LOGGER.debug("osgpException", osgpException);
return;
}
try {
LOGGER.info("Calling application service function to handle response: {}", messageType);
final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
this.defaultDeviceResponseService.handleDefaultDeviceResponse(ids, messageType, messagePriority, responseMessageResultType, osgpException);
} catch (final Exception e) {
this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, messageType, messagePriority);
}
}
use of org.opensmartgridplatform.shared.infra.jms.ResponseMessage in project open-smart-grid-platform by OSGP.
the class PublicLightingGetStatusResponseMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) throws JMSException {
LOGGER.debug("Processing public lighting get status response message");
String correlationUid = null;
String messageType = null;
int messagePriority = MessagePriorityEnum.DEFAULT.getPriority();
String organisationIdentification = null;
String deviceIdentification = null;
ResponseMessage responseMessage;
ResponseMessageResultType responseMessageResultType = null;
OsgpException osgpException = null;
Object dataObject;
try {
correlationUid = message.getJMSCorrelationID();
messageType = message.getJMSType();
messagePriority = message.getJMSPriority();
organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
responseMessage = (ResponseMessage) message.getObject();
responseMessageResultType = responseMessage.getResult();
osgpException = responseMessage.getOsgpException();
dataObject = responseMessage.getDataObject();
} catch (final JMSException e) {
LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
LOGGER.debug("correlationUid: {}", correlationUid);
LOGGER.debug("messageType: {}", messageType);
LOGGER.debug("messagePriority: {}", messagePriority);
LOGGER.debug("organisationIdentification: {}", organisationIdentification);
LOGGER.debug("deviceIdentification: {}", deviceIdentification);
LOGGER.debug("responseMessageResultType: {}", responseMessageResultType);
LOGGER.debug("deviceIdentification: {}", deviceIdentification);
LOGGER.debug("osgpException", osgpException);
return;
}
if (OsgpSystemCorrelationUid.CORRELATION_UID.equals(correlationUid)) {
LOGGER.info("Received message for device: {} of type: {} with correlation UID: {} and result: {}.", deviceIdentification, messageType, correlationUid, responseMessageResultType.name());
this.adHocManagementService.updateLastCommunicationTime(deviceIdentification);
return;
}
try {
LOGGER.info("Calling application service function to handle response: {}", messageType);
final DeviceStatusDto deviceLightStatus = (DeviceStatusDto) dataObject;
final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
this.adHocManagementService.handleGetStatusResponse(deviceLightStatus, ids, messageType, messagePriority, responseMessageResultType, osgpException);
} catch (final Exception e) {
this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, messageType, messagePriority);
}
}
Aggregations