use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class BaseMessageProcessor method handleError.
/**
* In case of an error, this function can be used to send a response containing the exception to
* the web-service-adapter.
*
* @param e The exception.
* @param correlationUid The correlation UID.
* @param organisationIdentification The organisation identification.
* @param deviceIdentification The device identification.
* @param messageType The message type.
* @param messagePriority The priority of the message.
*/
protected void handleError(final Exception e, final String correlationUid, final String organisationIdentification, final String deviceIdentification, final String messageType, final int messagePriority) {
LOGGER.info("handling error: {} for message type: {}", e.getMessage(), messageType);
final OsgpException osgpException = this.osgpExceptionOf(e);
final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withCorrelationUid(correlationUid).withOrganisationIdentification(organisationIdentification).withDeviceIdentification(deviceIdentification).withResult(ResponseMessageResultType.NOT_OK).withOsgpException(osgpException).withDataObject(e).withMessagePriority(messagePriority).withMessageType(messageType).build();
this.responseMessageSender.send(responseMessage);
}
use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class BaseNotificationMessageProcessor method handleError.
/**
* In case of an error, this function can be used to send a response containing the exception to
* the web-service-adapter.
*
* @param e The exception.
* @param correlationUid The correlation UID.
* @param organisationIdentification The organisation identification.
* @param deviceIdentification The device identification.
* @param messageType The message type.
*/
protected void handleError(final Exception e, final String correlationUid, final String organisationIdentification, final String deviceIdentification, final String messageType) {
LOGGER.info("handeling error: {} for message type: {}", e.getMessage(), messageType);
final OsgpException osgpException = this.osgpExceptionOf(e);
final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withCorrelationUid(correlationUid).withOrganisationIdentification(organisationIdentification).withDeviceIdentification(deviceIdentification).withResult(ResponseMessageResultType.NOT_OK).withOsgpException(osgpException).withDataObject(e).build();
this.responseMessageSender.send(responseMessage, messageType);
}
use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class WebServiceResponseMessageSender method makeObjectMessage.
private ObjectMessage makeObjectMessage(final Session session, final ResponseMessage responseMessage, final String messageType) throws JMSException {
final ObjectMessage objectMessage = session.createObjectMessage(responseMessage);
responseMessage.messageMetadata().applyTo(objectMessage);
objectMessage.setJMSType(messageType);
objectMessage.setStringProperty(Constants.RESULT, responseMessage.getResult().toString());
if (responseMessage.getOsgpException() == null) {
objectMessage.setObject(responseMessage.getDataObject());
} else {
String description;
// If an exception had a cause, get the message of the
// cause. If not, get the message of the exception itself
final OsgpException osgpException = responseMessage.getOsgpException();
if (osgpException.getCause() != null) {
description = osgpException.getCause().getMessage();
} else {
description = osgpException.getMessage();
}
objectMessage.setStringProperty(Constants.DESCRIPTION, description);
objectMessage.setObject(osgpException);
}
return objectMessage;
}
use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class SmartMeteringConfigurationEndpoint method getSetSpecialDaysResponse.
@PayloadRoot(localPart = "SetSpecialDaysAsyncRequest", namespace = SMARTMETER_CONFIGURATION_NAMESPACE)
@ResponsePayload
public SetSpecialDaysResponse getSetSpecialDaysResponse(@RequestPayload final SetSpecialDaysAsyncRequest request) throws OsgpException {
SetSpecialDaysResponse response = null;
try {
response = new SetSpecialDaysResponse();
final ResponseData responseData = this.responseDataService.get(request.getCorrelationUid(), ComponentType.WS_SMART_METERING);
response.setResult(OsgpResultType.fromValue(responseData.getResultType().getValue()));
if (responseData.getMessageData() instanceof String) {
response.setDescription((String) responseData.getMessageData());
}
} 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 getSetPushSetupSmsResponse.
@PayloadRoot(localPart = "SetPushSetupSmsAsyncRequest", namespace = SMARTMETER_CONFIGURATION_NAMESPACE)
@ResponsePayload
public SetPushSetupSmsResponse getSetPushSetupSmsResponse(@OrganisationIdentification final String organisationIdentification, @RequestPayload final SetPushSetupSmsAsyncRequest request) throws OsgpException {
log.info("Incoming SetPushSetupAlarmAsyncRequest for organisation {} for meter: {}.", organisationIdentification, request.getDeviceIdentification());
SetPushSetupSmsResponse response = null;
try {
response = new SetPushSetupSmsResponse();
final ResponseData meterResponseData = this.responseDataService.get(request.getCorrelationUid(), ComponentType.WS_SMART_METERING);
response.setResult(OsgpResultType.fromValue(meterResponseData.getResultType().getValue()));
if (meterResponseData.getMessageData() instanceof String) {
response.setDescription((String) meterResponseData.getMessageData());
}
} catch (final Exception e) {
this.handleException(e);
}
return response;
}
Aggregations