use of org.opensmartgridplatform.shared.infra.jms.ResponseMessage in project open-smart-grid-platform by OSGP.
the class ManagementService method handleMetadataOnlyResponseMessage.
private void handleMetadataOnlyResponseMessage(final MessageMetadata messageMetadata, final ResponseMessageResultType deviceResult, final OsgpException exception) {
ResponseMessageResultType result = deviceResult;
if (exception != null) {
LOGGER.error(DEVICE_RESPONSE_NOT_OK_LOG_MSG, exception);
result = ResponseMessageResultType.NOT_OK;
}
final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withMessageMetadata(messageMetadata).withResult(result).withOsgpException(exception).build();
this.webServiceResponseMessageSender.send(responseMessage, messageMetadata.getMessageType());
}
use of org.opensmartgridplatform.shared.infra.jms.ResponseMessage in project open-smart-grid-platform by OSGP.
the class NotificationService method handleSystemEvent.
public void handleSystemEvent(final MessageMetadata messageMetadata, final SystemEventDto systemEventDto) {
LOGGER.info("handleSystemEvent for MessageType: {}", messageMetadata.getMessageType());
final SystemEvent systemEvent = this.mapperFactory.getMapperFacade().map(systemEventDto, SystemEvent.class);
/*
* Send the systemEvent as a response message to the web service, so
* it can be handled similar to response messages based on earlier web service
* requests.
*/
final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withMessageMetadata(messageMetadata).withResult(ResponseMessageResultType.OK).withDataObject(systemEvent).build();
this.webServiceResponseMessageSender.send(responseMessage, messageMetadata.getMessageType());
}
use of org.opensmartgridplatform.shared.infra.jms.ResponseMessage in project open-smart-grid-platform by OSGP.
the class AbstractRequestMessageProcessor 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 messageMetadata The metadata for the message for which an error is handled.
*/
protected void handleError(final Exception e, final MessageMetadata messageMetadata) {
final String messageType = messageMetadata.getMessageType();
LOGGER.error("handling error: {} for message type: {}", e.getMessage(), messageType, e);
OsgpException osgpException = null;
if (e instanceof OsgpException) {
osgpException = (OsgpException) e;
} else {
osgpException = new TechnicalException(this.componentType, String.format("An unknown error of type %s occurred.", e.getClass().getName()), e);
}
final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withMessageMetadata(messageMetadata).withResult(ResponseMessageResultType.NOT_OK).withOsgpException(osgpException).build();
this.responseMessageSender.send(responseMessage, messageType);
}
use of org.opensmartgridplatform.shared.infra.jms.ResponseMessage in project open-smart-grid-platform by OSGP.
the class OsgpCoreResponseMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) throws JMSException {
LOGGER.debug("Processing response message");
final MessageMetadata messageMetadata = MessageMetadata.fromMessage(message);
final ResponseMessage responseMessage;
OsgpException osgpException = null;
try {
responseMessage = (ResponseMessage) message.getObject();
osgpException = responseMessage.getOsgpException();
} catch (final JMSException e) {
LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
LOGGER.debug(messageMetadata.toString());
LOGGER.debug("osgpException", osgpException);
return;
}
try {
if (osgpException != null) {
this.handleError(osgpException, messageMetadata, responseMessage);
} else if (this.hasRegularResponseObject(responseMessage)) {
LOGGER.info("Calling application service function to handle response: {} with correlationUid: {}", messageMetadata.getMessageType(), messageMetadata.getCorrelationUid());
this.handleMessage(messageMetadata, responseMessage, osgpException);
} else {
LOGGER.error("No osgpException, yet dataObject ({}) is not of the regular type for handling response: {}", responseMessage.getDataObject() == null ? null : responseMessage.getDataObject().getClass().getName(), messageMetadata.getMessageType());
this.handleError(new TechnicalException(ComponentType.DOMAIN_SMART_METERING, "Unexpected response data handling request.", null), messageMetadata);
}
} catch (final Exception e) {
this.handleError(e, messageMetadata);
}
}
use of org.opensmartgridplatform.shared.infra.jms.ResponseMessage in project open-smart-grid-platform by OSGP.
the class OsgpCoreResponseMessageProcessor 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 messageMetadata the device message metadata.
*/
protected void handleError(final Exception e, final MessageMetadata messageMetadata) {
LOGGER.info("handeling error: {} for message type: {}", e.getMessage(), messageMetadata.getMessageType());
final OsgpException osgpException = this.ensureOsgpException(e);
final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withMessageMetadata(messageMetadata).withResult(ResponseMessageResultType.NOT_OK).withOsgpException(osgpException).build();
this.webServiceResponseMessageSender.send(responseMessage, messageMetadata.getMessageType());
}
Aggregations