Search in sources :

Example 11 with OsgpException

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

Example 12 with OsgpException

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

Example 13 with OsgpException

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

Example 14 with OsgpException

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;
}
Also used : GetKeysResponseData(org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.GetKeysResponseData) ResponseData(org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData) SetSpecialDaysResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.SetSpecialDaysResponse) IOException(java.io.IOException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 15 with OsgpException

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;
}
Also used : GetKeysResponseData(org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.GetKeysResponseData) ResponseData(org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData) SetPushSetupSmsResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.SetPushSetupSmsResponse) IOException(java.io.IOException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Aggregations

OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)235 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)153 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)153 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)128 ConstraintViolationException (javax.validation.ConstraintViolationException)98 ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)75 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)67 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)64 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)54 ResponseData (org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData)51 JMSException (javax.jms.JMSException)40 IOException (java.io.IOException)30 GetKeysResponseData (org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.GetKeysResponseData)23 CorrelationIds (org.opensmartgridplatform.shared.infra.jms.CorrelationIds)18 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)17 AsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.common.AsyncResponse)15 ProtocolResponseMessage (org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)15 ResponseNotFoundException (org.opensmartgridplatform.adapter.ws.da.application.exceptionhandling.ResponseNotFoundException)10 Device (org.opensmartgridplatform.domain.core.entities.Device)10 ArrayList (java.util.ArrayList)9