Search in sources :

Example 1 with PluginMessageEvent

use of eu.europa.ec.fisheries.uvms.exchange.message.event.carrier.PluginMessageEvent in project UVMS-ExchangeModule-APP by UnionVMS.

the class ExchangeEventIncomingServiceBean method validate.

private boolean validate(SetReportMovementType setReport, ServiceResponseType service, TextMessage origin) {
    if (setReport == null) {
        String faultMessage = "No setReport request";
        pluginErrorEvent.fire(new PluginMessageEvent(origin, service, ExchangePluginResponseMapper.mapToPluginFaultResponse(FaultCode.PLUGIN_VALIDATION.getCode(), faultMessage)));
        return false;
    } else if (setReport.getMovement() == null) {
        String faultMessage = "No movement in setReport request";
        pluginErrorEvent.fire(new PluginMessageEvent(origin, service, ExchangePluginResponseMapper.mapToPluginFaultResponse(FaultCode.PLUGIN_VALIDATION.getCode(), faultMessage)));
        return false;
    } else if (setReport.getPluginType() == null) {
        String faultMessage = "No pluginType in setReport request";
        pluginErrorEvent.fire(new PluginMessageEvent(origin, service, ExchangePluginResponseMapper.mapToPluginFaultResponse(FaultCode.PLUGIN_VALIDATION.getCode(), faultMessage)));
        return false;
    } else if (setReport.getPluginName() == null || setReport.getPluginName().isEmpty()) {
        String faultMessage = "No pluginName in setReport request";
        pluginErrorEvent.fire(new PluginMessageEvent(origin, service, ExchangePluginResponseMapper.mapToPluginFaultResponse(FaultCode.PLUGIN_VALIDATION.getCode(), faultMessage)));
        return false;
    } else if (setReport.getTimestamp() == null) {
        String faultMessage = "No timestamp in setReport request";
        pluginErrorEvent.fire(new PluginMessageEvent(origin, service, ExchangePluginResponseMapper.mapToPluginFaultResponse(FaultCode.PLUGIN_VALIDATION.getCode(), faultMessage)));
        return false;
    }
    return true;
}
Also used : PluginMessageEvent(eu.europa.ec.fisheries.uvms.exchange.message.event.carrier.PluginMessageEvent)

Example 2 with PluginMessageEvent

use of eu.europa.ec.fisheries.uvms.exchange.message.event.carrier.PluginMessageEvent in project UVMS-ExchangeModule-APP by UnionVMS.

the class ExchangeEventIncomingServiceBean method firePluginFault.

private void firePluginFault(ExchangeMessageEvent messageEvent, String errorMessage, Throwable exception) {
    log.error(errorMessage, exception);
    PluginFault fault = ExchangePluginResponseMapper.mapToPluginFaultResponse(FaultCode.EXCHANGE_PLUGIN_EVENT.getCode(), errorMessage);
    pluginErrorEvent.fire(new PluginMessageEvent(messageEvent.getJmsMessage(), null, fault));
}
Also used : PluginFault(eu.europa.ec.fisheries.schema.exchange.plugin.types.v1.PluginFault) PluginMessageEvent(eu.europa.ec.fisheries.uvms.exchange.message.event.carrier.PluginMessageEvent)

Example 3 with PluginMessageEvent

use of eu.europa.ec.fisheries.uvms.exchange.message.event.carrier.PluginMessageEvent in project UVMS-ExchangeModule-APP by UnionVMS.

the class PluginServiceBean method registerService.

@Override
public void registerService(@Observes @RegisterServiceEvent PluginMessageEvent event) {
    LOG.info("register service:{}", event);
    TextMessage textMessage = event.getJmsMessage();
    RegisterServiceRequest register = null;
    try {
        register = JAXBMarshaller.unmarshallTextMessage(textMessage, RegisterServiceRequest.class);
        String messageId = textMessage.getJMSMessageID();
        boolean sendMessage = true;
        if (register.getService() != null) {
            sendMessage = checkPluginType(register.getService().getPluginType(), register.getService().getServiceResponseMessageName(), messageId);
            if (sendMessage) {
                registerService(register, messageId);
            }
        }
    } catch (ExchangeModelMarshallException | ExchangeMessageException | JMSException e) {
        LOG.error("Register service exception {} {}", event, e.getMessage());
        errorEvent.fire(new PluginMessageEvent(textMessage, register.getService(), ExchangePluginResponseMapper.mapToPluginFaultResponse(FaultCode.EXCHANGE_PLUGIN_EVENT.getCode(), "Exception when register service")));
    }
}
Also used : ExchangeModelMarshallException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMarshallException) RegisterServiceRequest(eu.europa.ec.fisheries.schema.exchange.registry.v1.RegisterServiceRequest) ExchangeMessageException(eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException) JMSException(javax.jms.JMSException) PluginMessageEvent(eu.europa.ec.fisheries.uvms.exchange.message.event.carrier.PluginMessageEvent) TextMessage(javax.jms.TextMessage)

Example 4 with PluginMessageEvent

use of eu.europa.ec.fisheries.uvms.exchange.message.event.carrier.PluginMessageEvent in project UVMS-ExchangeModule-APP by UnionVMS.

the class RegistryBusEventListener method onMessage.

@Override
public void onMessage(Message message) {
    TextMessage textMessage = (TextMessage) message;
    ServiceType settings = null;
    try {
        ExchangeRegistryBaseRequest request = JAXBMarshaller.unmarshallTextMessage(textMessage, ExchangeRegistryBaseRequest.class);
        LOG.info("Eventbus listener for Exchange Registry (ExchangeModelConstants.EXCHANGE_REGISTER_SERVICE): {} {}", ExchangeModelConstants.EXCHANGE_REGISTER_SERVICE, request);
        switch(request.getMethod()) {
            case REGISTER_SERVICE:
                RegisterServiceRequest regReq = JAXBMarshaller.unmarshallTextMessage(textMessage, RegisterServiceRequest.class);
                settings = regReq.getService();
                registerServiceEvent.fire(new PluginMessageEvent(textMessage));
                break;
            case UNREGISTER_SERVICE:
                UnregisterServiceRequest unRegReq = JAXBMarshaller.unmarshallTextMessage(textMessage, UnregisterServiceRequest.class);
                settings = unRegReq.getService();
                unregisterServiceEvent.fire(new PluginMessageEvent(textMessage));
                break;
            default:
                LOG.error("[ Not implemented method consumed: {} ]", request.getMethod());
                throw new ExchangeMessageException("[ Not implemented method consumed: " + request.getMethod() + " ]");
        }
    } catch (ExchangeMessageException | ExchangeModelMarshallException | NullPointerException e) {
        LOG.error("[ Error when receiving message on topic in exchange: {}] {}", message, e);
        errorEvent.fire(new PluginMessageEvent(textMessage, settings, ExchangePluginResponseMapper.mapToPluginFaultResponse(FaultCode.EXCHANGE_TOPIC_MESSAGE.getCode(), "Error when receiving message in exchange " + e.getMessage())));
    }
}
Also used : ExchangeModelMarshallException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMarshallException) ServiceType(eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceType) UnregisterServiceRequest(eu.europa.ec.fisheries.schema.exchange.registry.v1.UnregisterServiceRequest) RegisterServiceRequest(eu.europa.ec.fisheries.schema.exchange.registry.v1.RegisterServiceRequest) ExchangeMessageException(eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException) PluginMessageEvent(eu.europa.ec.fisheries.uvms.exchange.message.event.carrier.PluginMessageEvent) TextMessage(javax.jms.TextMessage) ExchangeRegistryBaseRequest(eu.europa.ec.fisheries.schema.exchange.registry.v1.ExchangeRegistryBaseRequest)

Example 5 with PluginMessageEvent

use of eu.europa.ec.fisheries.uvms.exchange.message.event.carrier.PluginMessageEvent in project UVMS-ExchangeModule-APP by UnionVMS.

the class PluginServiceBean method unregisterService.

@Override
public void unregisterService(@Observes @UnRegisterServiceEvent PluginMessageEvent event) {
    LOG.info("unregister service:{}", event);
    TextMessage textMessage = event.getJmsMessage();
    ServiceResponseType service = null;
    try {
        UnregisterServiceRequest unregister = JAXBMarshaller.unmarshallTextMessage(textMessage, UnregisterServiceRequest.class);
        service = exchangeService.unregisterService(unregister.getService(), unregister.getService().getName());
        String serviceClassName = service.getServiceClassName();
    // NO ack back to plugin
    // TODO log to exchange log
    } catch (ExchangeModelMarshallException | ExchangeServiceException e) {
        LOG.error("Unregister service exception " + e.getMessage());
        errorEvent.fire(new PluginMessageEvent(textMessage, service, ExchangePluginResponseMapper.mapToPluginFaultResponse(FaultCode.EXCHANGE_PLUGIN_EVENT.getCode(), "Exception when unregister service")));
    }
}
Also used : ExchangeModelMarshallException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMarshallException) ServiceResponseType(eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceResponseType) UnregisterServiceRequest(eu.europa.ec.fisheries.schema.exchange.registry.v1.UnregisterServiceRequest) PluginMessageEvent(eu.europa.ec.fisheries.uvms.exchange.message.event.carrier.PluginMessageEvent) TextMessage(javax.jms.TextMessage) ExchangeServiceException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException)

Aggregations

PluginMessageEvent (eu.europa.ec.fisheries.uvms.exchange.message.event.carrier.PluginMessageEvent)5 ExchangeModelMarshallException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMarshallException)3 TextMessage (javax.jms.TextMessage)3 RegisterServiceRequest (eu.europa.ec.fisheries.schema.exchange.registry.v1.RegisterServiceRequest)2 UnregisterServiceRequest (eu.europa.ec.fisheries.schema.exchange.registry.v1.UnregisterServiceRequest)2 ExchangeMessageException (eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException)2 PluginFault (eu.europa.ec.fisheries.schema.exchange.plugin.types.v1.PluginFault)1 ExchangeRegistryBaseRequest (eu.europa.ec.fisheries.schema.exchange.registry.v1.ExchangeRegistryBaseRequest)1 ServiceResponseType (eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceResponseType)1 ServiceType (eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceType)1 ExchangeServiceException (eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException)1 JMSException (javax.jms.JMSException)1