use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class SmartMeteringBundleEndpoint method bundleRequest.
@PayloadRoot(localPart = "BundleRequest", namespace = NAMESPACE)
@ResponsePayload
public BundleAsyncResponse bundleRequest(@ResponseUrl final String responseUrl, @MessageMetadata final org.opensmartgridplatform.shared.infra.jms.MessageMetadata messageMetadata, @RequestPayload final BundleRequest request) throws OsgpException {
final String organisationIdentification = messageMetadata.getOrganisationIdentification();
final String deviceIdentification = request.getDeviceIdentification();
log.info("Incoming BundleRequest with responseUrl {} and {} actions. [deviceId={} | organisationId={}]", responseUrl, request.getActions().getActionList().size(), deviceIdentification, organisationIdentification);
BundleAsyncResponse response = null;
try {
response = new BundleAsyncResponse();
final List<ActionRequest> actionRequestList = this.actionMapperService.mapAllActions(request.getActions().getActionList());
final String correlationUid = this.bundleService.enqueueBundleRequest(messageMetadata.builder().withDeviceIdentification(deviceIdentification).withMessageType(MessageType.HANDLE_BUNDLED_ACTIONS.name()).build(), actionRequestList);
log.info("BundleRequest placed on queue [correlationId={} | deviceId={} | organisationId={}]", correlationUid, deviceIdentification, organisationIdentification);
response.setCorrelationUid(correlationUid);
response.setDeviceIdentification(request.getDeviceIdentification());
this.saveResponseUrlIfNeeded(correlationUid, responseUrl);
} catch (final Exception e) {
this.handleException(e);
}
return response;
}
use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class SmartMeteringConfigurationEndpoint method getGetMBusEncryptionKeyStatusByChannelResponse.
@PayloadRoot(localPart = "GetMbusEncryptionKeyStatusByChannelAsyncRequest", namespace = SMARTMETER_CONFIGURATION_NAMESPACE)
@ResponsePayload
public GetMbusEncryptionKeyStatusByChannelResponse getGetMBusEncryptionKeyStatusByChannelResponse(@RequestPayload final GetMbusEncryptionKeyStatusByChannelAsyncRequest request) throws OsgpException {
GetMbusEncryptionKeyStatusByChannelResponse response = null;
try {
final ResponseData responseData = this.responseDataService.get(request.getCorrelationUid(), ComponentType.WS_SMART_METERING);
this.throwExceptionIfResultNotOk(responseData, "retrieving the M-Bus encryption key status by channel.");
response = new GetMbusEncryptionKeyStatusByChannelResponse();
response.setResult(OsgpResultType.fromValue(responseData.getResultType().getValue()));
response.setEncryptionKeyStatus(EncryptionKeyStatus.fromValue(((EncryptionKeyStatusType) responseData.getMessageData()).name()));
} catch (final Exception e) {
this.handleException(e);
}
return response;
}
use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class SmartMeteringManagementEndpoint method getEnableDebuggingResponse.
@PayloadRoot(localPart = "EnableDebuggingAsyncRequest", namespace = NAMESPACE)
@ResponsePayload
public EnableDebuggingResponse getEnableDebuggingResponse(@OrganisationIdentification final String organisationIdentification, @RequestPayload final EnableDebuggingAsyncRequest request) throws OsgpException {
log.info("EnableDebugging response for organisation: {} and device: {}.", organisationIdentification, request.getDeviceIdentification());
EnableDebuggingResponse response = null;
try {
response = new EnableDebuggingResponse();
final ResponseData responseData = this.responseDataService.get(request.getCorrelationUid(), ComponentType.WS_SMART_METERING);
this.throwExceptionIfResultNotOk(responseData, "Enable Debugging");
response.setResult(OsgpResultType.fromValue(responseData.getResultType().getValue()));
if (responseData.getMessageData() instanceof String) {
response.setDescription((String) responseData.getMessageData());
}
} catch (final ConstraintViolationException e) {
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.WS_SMART_METERING, new ValidationException(e.getConstraintViolations()));
} catch (final Exception e) {
this.handleException(e);
}
return response;
}
use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class CommonGetConfigurationRequestMessageProcessor method handleGetConfigurationDeviceResponse.
private void handleGetConfigurationDeviceResponse(final DeviceResponse deviceResponse, final ResponseMessageSender responseMessageSender, final DomainInformation domainInformation, final String messageType, final int retryCount, final boolean isScheduled) {
ResponseMessageResultType result = ResponseMessageResultType.OK;
OsgpException osgpException = null;
ConfigurationDto configuration = null;
try {
final GetConfigurationDeviceResponse response = (GetConfigurationDeviceResponse) deviceResponse;
configuration = response.getConfiguration();
} catch (final Exception e) {
LOGGER.error("Device Response Exception", e);
result = ResponseMessageResultType.NOT_OK;
osgpException = new TechnicalException(ComponentType.PROTOCOL_IEC61850, "Unexpected exception while retrieving response message", e);
}
final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withDeviceIdentification(deviceResponse.getDeviceIdentification()).withOrganisationIdentification(deviceResponse.getOrganisationIdentification()).withCorrelationUid(deviceResponse.getCorrelationUid()).withMessageType(messageType).withDomain(domainInformation.getDomain()).withDomainVersion(domainInformation.getDomainVersion()).withMessagePriority(deviceResponse.getMessagePriority()).withScheduled(isScheduled).withRetryCount(retryCount).build();
final ProtocolResponseMessage responseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(messageMetadata).result(result).osgpException(osgpException).dataObject(configuration).build();
responseMessageSender.send(responseMessage);
}
use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class OsgpResponseMessageListener method onMessage.
@Override
public void onMessage(final Message message) {
try {
LOGGER.info("Received message of type: {}", message.getJMSType());
final ObjectMessage objectMessage = (ObjectMessage) message;
final String messageType = objectMessage.getJMSType();
final String deviceIdentification = objectMessage.getStringProperty(Constants.DEVICE_IDENTIFICATION);
final ResponseMessage responseMessage = (ResponseMessage) objectMessage.getObject();
final String result = responseMessage == null ? null : responseMessage.getResult().toString();
final OsgpException osgpException = responseMessage == null ? null : responseMessage.getOsgpException();
if (MessageType.valueOf(messageType) == (MessageType.REGISTER_DEVICE)) {
handleDeviceRegistration(result, deviceIdentification, messageType, osgpException);
} else {
throw new UnknownMessageTypeException("Unknown JMSType: " + messageType);
}
} catch (final JMSException ex) {
LOGGER.error("Exception: {} ", ex.getMessage(), ex);
} catch (final ProtocolAdapterException e) {
LOGGER.error("ProtocolAdapterException", e);
} catch (final UnknownMessageTypeException e) {
LOGGER.error("UnknownMessageTypeException", e);
}
}
Aggregations