Search in sources :

Example 11 with ExchangeMessageException

use of eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException 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 12 with ExchangeMessageException

use of eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException in project UVMS-ExchangeModule-APP by UnionVMS.

the class ExchangeAssetServiceBean method getAsset.

@Override
public Asset getAsset(String assetGuid) throws ExchangeServiceException {
    try {
        String request = AssetModuleRequestMapper.createGetAssetModuleRequest(assetGuid, AssetIdType.GUID);
        String messageId = producer.sendMessageOnQueue(request, MessageQueue.VESSEL);
        TextMessage response = consumer.getMessage(messageId, TextMessage.class);
        return AssetModuleResponseMapper.mapToAssetFromResponse(response, messageId);
    } catch (ExchangeMessageException | MessageException e) {
        LOG.error("Couldn't send message to vessel module");
        throw new ExchangeServiceException("Couldn't send message to vessel module");
    } catch (AssetModelMapperException e) {
        LOG.error("Couldn't map asset object by guid:  {}", assetGuid);
        throw new ExchangeServiceException("Couldn't map asset object by guid:  " + assetGuid);
    }
}
Also used : MessageException(eu.europa.ec.fisheries.uvms.commons.message.api.MessageException) ExchangeMessageException(eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException) AssetModelMapperException(eu.europa.ec.fisheries.uvms.asset.model.exception.AssetModelMapperException) ExchangeMessageException(eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException) TextMessage(javax.jms.TextMessage) ExchangeServiceException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException)

Example 13 with ExchangeMessageException

use of eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException in project UVMS-ExchangeModule-APP by UnionVMS.

the class ExchangeEventIncomingServiceBean method sendSalesReport.

@Override
public void sendSalesReport(@Observes @SendSalesReportEvent ExchangeMessageEvent message) {
    try {
        SendSalesReportRequest request = JAXBMarshaller.unmarshallTextMessage(message.getJmsMessage(), SendSalesReportRequest.class);
        ExchangeLogStatusTypeType validationStatus = request.getValidationStatus();
        exchangeLog.log(request, LogType.SEND_SALES_REPORT, validationStatus, TypeRefType.SALES_REPORT, request.getReport(), false);
        if (validationStatus == ExchangeLogStatusTypeType.SUCCESSFUL || validationStatus == ExchangeLogStatusTypeType.SUCCESSFUL_WITH_WARNINGS) {
            eu.europa.ec.fisheries.schema.exchange.plugin.v1.SendSalesReportRequest pluginRequest = new eu.europa.ec.fisheries.schema.exchange.plugin.v1.SendSalesReportRequest();
            pluginRequest.setRecipient(request.getSenderOrReceiver());
            pluginRequest.setReport(request.getReport());
            if (request.getSenderOrReceiver() != null) {
                pluginRequest.setSenderOrReceiver(request.getSenderOrReceiver());
            }
            pluginRequest.setMethod(ExchangePluginMethod.SEND_SALES_RESPONSE);
            exchangeEventOutgoingService.sendSalesReportToFLUX(pluginRequest);
        } else {
            log.error("Received invalid report from the Sales module: " + request.getReport());
        }
    } catch (ExchangeModelMarshallException | ExchangeMessageException e) {
        fireExchangeFault(message, "Error when sending a Sales response to FLUX", e);
    } catch (ExchangeLogException e) {
        fireExchangeFault(message, "Could not log the outgoing sales report.", e);
    }
}
Also used : ExchangeLogStatusTypeType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusTypeType) SendSalesReportRequest(eu.europa.ec.fisheries.schema.exchange.module.v1.SendSalesReportRequest) ExchangeMessageException(eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException) ExchangeModelMarshallException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMarshallException) ExchangeLogException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException)

Example 14 with ExchangeMessageException

use of eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException in project UVMS-ExchangeModule-APP by UnionVMS.

the class PluginServiceBean method setConfig.

@Override
public void setConfig(@Observes @ConfigSettingUpdatedEvent ConfigSettingEvent settingEvent) {
    switch(settingEvent.getType()) {
        case STORE:
            // ConfigModule and/or Exchange module deployed
            break;
        case UPDATE:
            LOG.info("ConfigModule updated parameter table with settings of plugins");
            try {
                String key = settingEvent.getKey();
                String value = parameterService.getStringValue(key);
                String settingKey;
                String[] splittedKey = key.split(PARAMETER_DELIMETER);
                if (splittedKey.length > 2) {
                    settingKey = key;
                    String serviceClassName = "";
                    for (int i = 0; i < splittedKey.length - 2; i++) {
                        serviceClassName += splittedKey[i] + ".";
                    }
                    serviceClassName += splittedKey[splittedKey.length - 2];
                    SettingType settingType = new SettingType();
                    settingType.setKey(key);
                    settingType.setValue(value);
                    updatePluginSetting(serviceClassName, settingType, "UVMS");
                } else {
                    LOG.error("No key or malformed key sent in settingEvent: key: {}, value: {}", key, value);
                }
            } catch (ConfigServiceException e) {
                LOG.error("Couldn't get updated parameter table value");
            } catch (ExchangeServiceException e) {
                LOG.error("Couldn't upsert settings in exchange");
            } catch (ExchangeModelMarshallException e) {
                LOG.error("Couldn't create plugin set config request");
            } catch (ExchangeMessageException e) {
                LOG.error("Couldn't send message to plugin");
            }
            break;
        case DELETE:
            LOG.info("ConfigModule removed parameter setting");
            break;
    }
}
Also used : ExchangeModelMarshallException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMarshallException) ConfigServiceException(eu.europa.ec.fisheries.uvms.config.exception.ConfigServiceException) ExchangeMessageException(eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException) SettingType(eu.europa.ec.fisheries.schema.exchange.service.v1.SettingType) ExchangeServiceException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException)

Example 15 with ExchangeMessageException

use of eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException in project UVMS-ExchangeModule-APP by UnionVMS.

the class PluginServiceBean method ping.

@Override
public boolean ping(String serviceClassName) throws ExchangeServiceException {
    if (serviceClassName == null) {
        throw new InputArgumentException("No service to ping");
    }
    try {
        String text = ExchangePluginRequestMapper.createPingRequest();
        producer.sendEventBusMessage(text, serviceClassName);
        return true;
    } catch (ExchangeModelMarshallException e) {
        throw new ExchangeServiceException("[ Couldn't map ping request for " + serviceClassName + " ]");
    } catch (ExchangeMessageException e) {
        throw new ExchangeServiceException("[ Couldn't send ping request for " + serviceClassName + " ]");
    }
}
Also used : ExchangeModelMarshallException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMarshallException) InputArgumentException(eu.europa.ec.fisheries.uvms.exchange.service.exception.InputArgumentException) ExchangeMessageException(eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException) ExchangeServiceException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException)

Aggregations

ExchangeMessageException (eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException)15 ExchangeModelMarshallException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMarshallException)13 ExchangeLogException (eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException)7 ExchangeServiceException (eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException)6 TextMessage (javax.jms.TextMessage)4 InputArgumentException (eu.europa.ec.fisheries.uvms.exchange.service.exception.InputArgumentException)3 RegisterServiceRequest (eu.europa.ec.fisheries.schema.exchange.registry.v1.RegisterServiceRequest)2 ExchangeLogStatusTypeType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusTypeType)2 PluginMessageEvent (eu.europa.ec.fisheries.uvms.exchange.message.event.carrier.PluginMessageEvent)2 ReceiveInvalidSalesMessage (eu.europa.ec.fisheries.schema.exchange.module.v1.ReceiveInvalidSalesMessage)1 SendSalesReportRequest (eu.europa.ec.fisheries.schema.exchange.module.v1.SendSalesReportRequest)1 SendSalesResponseRequest (eu.europa.ec.fisheries.schema.exchange.module.v1.SendSalesResponseRequest)1 SetFAQueryMessageRequest (eu.europa.ec.fisheries.schema.exchange.module.v1.SetFAQueryMessageRequest)1 SetFLUXFAReportMessageRequest (eu.europa.ec.fisheries.schema.exchange.module.v1.SetFLUXFAReportMessageRequest)1 SetFLUXFAResponseMessageRequest (eu.europa.ec.fisheries.schema.exchange.module.v1.SetFLUXFAResponseMessageRequest)1 UpdatePluginSettingRequest (eu.europa.ec.fisheries.schema.exchange.module.v1.UpdatePluginSettingRequest)1 ExchangeRegistryBaseRequest (eu.europa.ec.fisheries.schema.exchange.registry.v1.ExchangeRegistryBaseRequest)1 UnregisterServiceRequest (eu.europa.ec.fisheries.schema.exchange.registry.v1.UnregisterServiceRequest)1 ServiceType (eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceType)1 SettingType (eu.europa.ec.fisheries.schema.exchange.service.v1.SettingType)1