Search in sources :

Example 66 with ResponseMessage

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());
}
Also used : ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)

Example 67 with ResponseMessage

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());
}
Also used : SystemEvent(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SystemEvent) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage)

Example 68 with ResponseMessage

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);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage)

Example 69 with ResponseMessage

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);
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) JMSException(javax.jms.JMSException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)

Example 70 with ResponseMessage

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());
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage)

Aggregations

ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)144 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)78 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)66 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)33 JMSException (javax.jms.JMSException)29 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)23 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)20 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)20 ConstraintViolationException (javax.validation.ConstraintViolationException)19 Test (org.junit.jupiter.api.Test)19 CorrelationIds (org.opensmartgridplatform.shared.infra.jms.CorrelationIds)18 ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)16 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)12 ObjectMessage (javax.jms.ObjectMessage)9 ProtocolResponseMessage (org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)8 Transactional (org.springframework.transaction.annotation.Transactional)5 ArrayList (java.util.ArrayList)4 Device (org.opensmartgridplatform.domain.core.entities.Device)4 UnknownEntityException (org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)4 FirmwareVersion (org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)4