use of org.opensmartgridplatform.shared.exceptionhandling.TechnicalException in project open-smart-grid-platform by OSGP.
the class DefaultDeviceResponseService method handleDefaultDeviceResponse.
public void handleDefaultDeviceResponse(final CorrelationIds ids, final String messageType, final int messagePriority, final ResponseMessageResultType deviceResult, final OsgpException exception) {
LOGGER.info("handleDefaultDeviceResponse for MessageType: {}", messageType);
ResponseMessageResultType result = deviceResult;
OsgpException osgpException = exception;
if (deviceResult == ResponseMessageResultType.NOT_OK && exception == null) {
LOGGER.error("Incorrect response received, exception should not be null when result is not ok");
osgpException = new TechnicalException(ComponentType.DOMAIN_TARIFF_SWITCHING, "An unknown error occurred");
}
if (deviceResult == ResponseMessageResultType.OK && exception != null) {
LOGGER.error("Incorrect response received, result should be set to not ok when exception is not null");
result = ResponseMessageResultType.NOT_OK;
}
final MessageMetadata metaData = new MessageMetadata.Builder().withCorrelationUid(ids.getCorrelationUid()).withDeviceIdentification(ids.getDeviceIdentification()).withOrganisationIdentification(ids.getOrganisationIdentification()).withMessageType(messageType).build();
final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withMessageMetadata(metaData).withResult(result).withOsgpException(osgpException).withMessagePriority(messagePriority).build();
this.webServiceResponseMessageSender.send(responseMessage);
}
use of org.opensmartgridplatform.shared.exceptionhandling.TechnicalException in project open-smart-grid-platform by OSGP.
the class BundleResponseMessageProcessorTest method technicalExceptionDetailsWithoutCauseOrMessageInFaultResponse.
@Test
public void technicalExceptionDetailsWithoutCauseOrMessageInFaultResponse() throws Exception {
final ComponentType component = ComponentType.PROTOCOL_DLMS;
final Exception exception = new TechnicalException(component, null, null);
final FaultResponseDto faultResponse = this.processor.faultResponseForException(exception, this.parameters, this.defaultMessage);
this.assertResponse(faultResponse, null, this.defaultMessage, component.name(), null, null, this.parameters);
}
use of org.opensmartgridplatform.shared.exceptionhandling.TechnicalException in project open-smart-grid-platform by OSGP.
the class DetailSoapFaultMappingExceptionResolver method customizeFault.
@Override
protected void customizeFault(final Object endpoint, final Exception ex, final SoapFault fault) {
final SoapFaultDetail detail = fault.addFaultDetail();
final Result result = detail.getResult();
FunctionalException fex = null;
TechnicalException tex = null;
if (ex instanceof FunctionalException) {
fex = (FunctionalException) ex;
} else if (ex instanceof TechnicalException) {
tex = (TechnicalException) ex;
}
if (fex != null) {
try {
this.marshalFunctionalException(fex, result);
} catch (final JAXBException e) {
LOGGER.error("Unable to marshal the Functional Exception", e);
}
}
if (tex != null) {
try {
this.marshalTechnicalException(tex, result);
} catch (final JAXBException e) {
LOGGER.error("Unable to marshal the Technical Exception", e);
}
}
}
use of org.opensmartgridplatform.shared.exceptionhandling.TechnicalException in project open-smart-grid-platform by OSGP.
the class SmartMeteringAdhocEndpoint method getScanMbusChannelsResponse.
@PayloadRoot(localPart = "ScanMbusChannelsAsyncRequest", namespace = SMARTMETER_ADHOC_NAMESPACE)
@ResponsePayload
public ScanMbusChannelsResponse getScanMbusChannelsResponse(@RequestPayload final ScanMbusChannelsAsyncRequest request) throws OsgpException {
ScanMbusChannelsResponse response = null;
try {
response = new ScanMbusChannelsResponse();
final ResponseData responseData = this.responseDataService.get(request.getCorrelationUid(), ComponentType.WS_SMART_METERING);
this.throwExceptionIfResultNotOk(responseData, "retrieving the scan m-bus channels response");
response.setResult(OsgpResultType.fromValue(responseData.getResultType().getValue()));
final ScanMbusChannelsResponseData scanMbusChannelsResponse = (ScanMbusChannelsResponseData) responseData.getMessageData();
if (ResponseMessageResultType.OK == responseData.getResultType()) {
final List<MbusChannelShortEquipmentIdentifier> channelShortIds = response.getChannelShortIds();
channelShortIds.addAll(this.adhocMapper.mapAsList(scanMbusChannelsResponse.getChannelShortIds(), MbusChannelShortEquipmentIdentifier.class));
} else if (responseData.getMessageData() instanceof OsgpException) {
throw (OsgpException) responseData.getMessageData();
} else if (responseData.getMessageData() instanceof Exception) {
throw new TechnicalException(ComponentType.WS_SMART_METERING, "An exception occurred: Scan M-Bus Channels", (Exception) responseData.getMessageData());
} else {
throw new TechnicalException(ComponentType.WS_SMART_METERING, "An exception occurred: Scan M-Bus Channels", null);
}
} catch (final Exception e) {
this.handleException(e);
}
return response;
}
use of org.opensmartgridplatform.shared.exceptionhandling.TechnicalException in project open-smart-grid-platform by OSGP.
the class ManagementService method findEventsByCorrelationUid.
public List<Event> findEventsByCorrelationUid(final String organisationIdentification, final String correlationUid) throws OsgpException {
log.info("findEventsByCorrelationUid called with organisation {}}", organisationIdentification);
this.domainHelperService.findOrganisation(organisationIdentification);
final ResponseData responseData = this.responseDataRepository.findByCorrelationUid(correlationUid);
final List<Event> events = new ArrayList<>();
final Serializable messageData = responseData.getMessageData();
if (messageData instanceof EventMessagesResponse) {
events.addAll(((EventMessagesResponse) messageData).getEvents());
log.info("deleting ResponseData for correlation uid {}.", correlationUid);
this.responseDataRepository.delete(responseData);
} else {
/**
* If the returned data is not an EventMessageContainer but a String, there has been an
* exception. The exception message has been put in the messageData.
*
* <p>As there is no way of knowing what the type of the exception was (because it is passed
* as a String) it is thrown as a TechnicalException because the user is most probably not to
* blame for the exception.
*/
if (messageData instanceof String) {
throw new TechnicalException(ComponentType.UNKNOWN, (String) messageData);
}
log.info("findEventsByCorrelationUid found other type of meter response data: {} for correlation UID: {}", messageData.getClass().getName(), correlationUid);
}
log.info("returning a list containing {} events", events.size());
return events;
}
Aggregations