use of org.opensmartgridplatform.shared.infra.jms.CorrelationIds in project open-smart-grid-platform by OSGP.
the class CommonDefaultResponseMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) throws JMSException {
LOGGER.debug("Processing common 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.CorrelationIds in project open-smart-grid-platform by OSGP.
the class MonitoringService method handleGetPQValuesResponse.
public void handleGetPQValuesResponse(final GetPQValuesResponseDto getPQValuesResponseDto, final CorrelationIds ids, final String messageType, final ResponseMessageResultType responseMessageResultType, final OsgpException osgpException) {
LOGGER.info("handleResponse for MessageType: {}", messageType);
final String deviceIdentification = ids.getDeviceIdentification();
final String organisationIdentification = ids.getOrganisationIdentification();
ResponseMessageResultType result = ResponseMessageResultType.OK;
GetPQValuesResponse getPQValuesResponse = null;
OsgpException exception = osgpException;
try {
if (responseMessageResultType == ResponseMessageResultType.NOT_OK || osgpException != null) {
LOGGER.error("Device Response not ok.", osgpException);
throw osgpException;
}
this.rtuResponseService.handleResponseMessageReceived(LOGGER, deviceIdentification, true);
getPQValuesResponse = this.mapper.map(getPQValuesResponseDto, GetPQValuesResponse.class);
} catch (final Exception e) {
LOGGER.error("Unexpected Exception", e);
result = ResponseMessageResultType.NOT_OK;
exception = this.ensureOsgpException(e, "Exception occurred while getting PQ Values Response Data");
}
// Support for Push messages, generate correlationUid
String actualCorrelationUid = ids.getCorrelationUid();
if ("no-correlationUid".equals(actualCorrelationUid)) {
actualCorrelationUid = getCorrelationId("DeviceGenerated", deviceIdentification);
}
final CorrelationIds actualIds = new CorrelationIds(organisationIdentification, deviceIdentification, actualCorrelationUid);
final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(actualIds).withResult(result).withOsgpException(exception).withDataObject(getPQValuesResponse).build();
this.responseMessageRouter.send(responseMessage, messageType);
}
use of org.opensmartgridplatform.shared.infra.jms.CorrelationIds in project open-smart-grid-platform by OSGP.
the class FirmwareManagementServiceTest method testHandleGetFirmwareVersionResponseVersionNotInHistoryButNoCorrespondingFirmwareFile.
@Test
void testHandleGetFirmwareVersionResponseVersionNotInHistoryButNoCorrespondingFirmwareFile() {
// Arrange
// Mock that FUNCTIONAL VERSION 3 and SECURITY VERSION 1 is now
// installed,
// no firmware file will hold this combination, so it will fail to save
final FirmwareVersionDto firmwareVersionDto1 = new FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareModuleType.SECURITY, VERSION_3);
final FirmwareVersionDto firmwareVersionDto2 = new FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareModuleType.FUNCTIONAL, VERSION_3);
final List<FirmwareVersionDto> versionsOnDeviceDtos = Arrays.asList(firmwareVersionDto1, firmwareVersionDto2);
final FirmwareVersion firmwareVersion1 = new FirmwareVersion(FirmwareModuleType.SECURITY, VERSION_1);
final FirmwareVersion firmwareVersion3 = new FirmwareVersion(FirmwareModuleType.FUNCTIONAL, VERSION_3);
final List<FirmwareVersion> versionsOnDevice = Arrays.asList(firmwareVersion1, firmwareVersion3);
final FirmwareFile firmwareFile = new FirmwareFile.Builder().withFilename("filename").withDescription("description").withPushToNewDevices(false).build();
final FirmwareModule firmwareModule1 = new FirmwareModule(FirmwareModuleType.SECURITY.getDescription().toLowerCase());
firmwareFile.addFirmwareModule(firmwareModule1, VERSION_3);
final FirmwareModule firmwareModule2 = new FirmwareModule(FirmwareModuleType.FUNCTIONAL.getDescription().toLowerCase());
firmwareFile.addFirmwareModule(firmwareModule2, VERSION_3);
when(this.domainCoreMapper.mapAsList(versionsOnDeviceDtos, FirmwareVersion.class)).thenReturn(versionsOnDevice);
when(this.ssldPendingFirmwareUpdateRepository.findByDeviceIdentification("DVC")).thenReturn(Collections.emptyList());
when(this.firmwareFileRepository.findByDeviceModel(any(DeviceModel.class))).thenReturn(Collections.singletonList(firmwareFile));
final CorrelationIds ids = new CorrelationIds("ORG", "DVC", "CORR");
// Act
this.firmwareManagementService.handleGetFirmwareVersionResponse(versionsOnDeviceDtos, ids, "FW", 0, ResponseMessageResultType.OK, null);
// Validate
verify(this.deviceFirmwareFileRepository, never()).save(any(DeviceFirmwareFile.class));
}
use of org.opensmartgridplatform.shared.infra.jms.CorrelationIds in project open-smart-grid-platform by OSGP.
the class GetPQValuesRequestMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) {
LOGGER.info("Processing DA Get PQ Values request message");
String correlationUid = null;
String messageType = null;
String organisationIdentification = null;
String deviceIdentification = null;
GetPQValuesRequest getPQValuesRequest = null;
try {
correlationUid = message.getJMSCorrelationID();
messageType = message.getJMSType();
organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
if (message.getObject() instanceof GetPQValuesRequest) {
getPQValuesRequest = (GetPQValuesRequest) message.getObject();
}
} 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("organisationIdentification: {}", organisationIdentification);
LOGGER.debug("deviceIdentification: {}", deviceIdentification);
return;
}
try {
LOGGER.info("Calling application service function: {}", messageType);
final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
this.monitoringService.getPQValues(ids, messageType, getPQValuesRequest);
} catch (final Exception e) {
this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, messageType);
}
}
use of org.opensmartgridplatform.shared.infra.jms.CorrelationIds in project open-smart-grid-platform by OSGP.
the class WebServiceMonitorInterceptor method createAndSendLoggingRequestMessage.
/**
* Create the logging Request Message and send it using {@link
* WebServiceMonitorInterceptor#loggingMessageSender}.
*
* @param messageContext The messageContext.
* @param endpoint The endpoint.
* @param overrideResult When set, use this value as result for the {@link LoggingRequestMessage}.
* @throws WebServiceMonitorInterceptorException
*/
private void createAndSendLoggingRequestMessage(final MessageContext messageContext, final Object endpoint, final String overrideResult) throws WebServiceMonitorInterceptorException {
if (!this.soapMessageLoggingEnabled) {
return;
}
// Get the current time.
final Date now = new Date();
// Get EndPointClass and EndPointMethod.
final EndpointClassAndMethod classAndMethod = this.getEndPointClassAndMethod(endpoint);
// Get the request.
final SoapMessage request = this.getSoapRequest(messageContext);
final SoapHeader soapHeader = request.getSoapHeader();
// Read OrganisationIdentification, UserName and ApplicationName from
// header from request.
final String organisationIdentification = this.getHeaderValue(soapHeader, this.organisationIdentificationHeader);
final String userName = this.getHeaderValue(soapHeader, this.userNameHeader);
final String appName = this.getHeaderValue(soapHeader, this.applicationNameHeader);
// Read correlationUid and deviceId from request.
final Map<String, Object> requestData = this.parseSoapMessage(request);
if (requestData == null) {
throw new WebServiceMonitorInterceptorException("unable to get correlationUid or deviceId from request");
}
// Get the response.
final SoapMessage response = this.getSoapResponse(messageContext);
// Read correlationUid and deviceId and result and data size from
// response.
final Map<String, Object> responseData = this.parseSoapMessage(response);
if (responseData == null) {
throw new WebServiceMonitorInterceptorException("unable to get correlationUid or deviceId or result from response");
}
// Check response for correlationId, otherwise request.
String correlationUid = (String) responseData.get(CORRELATION_UID);
if (StringUtils.isEmpty(correlationUid)) {
correlationUid = (String) requestData.get(CORRELATION_UID);
}
// Creating the logging request message.
final String deviceIdentification = (String) requestData.get(DEVICE_ID);
final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
final ResponseResultAndDataSize responseResultAndDataSize = this.resultAndDataSizeFrom(responseData);
final LoggingRequestMessage loggingRequestMessage = new LoggingRequestMessage(now, ids, userName, appName, classAndMethod, responseResultAndDataSize);
if (!StringUtils.isEmpty(overrideResult)) {
loggingRequestMessage.setResponseResult(overrideResult);
}
this.loggingMessageSender.send(loggingRequestMessage);
}
Aggregations