Search in sources :

Example 56 with MuleRuntimeException

use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.

the class ApplicationModel method validateNamedTopLevelElementsHaveName.

private void validateNamedTopLevelElementsHaveName(ComponentBuildingDefinitionRegistry componentBuildingDefinitionRegistry) throws ConfigurationException {
    try {
        List<ComponentModel> topLevelComponents = muleComponentModels.get(0).getInnerComponents();
        topLevelComponents.stream().forEach(topLevelComponent -> {
            final ComponentIdentifier identifier = topLevelComponent.getIdentifier();
            componentBuildingDefinitionRegistry.getBuildingDefinition(identifier).filter(ComponentBuildingDefinition::isNamed).ifPresent(buildingDefinition -> {
                if (isBlank(topLevelComponent.getNameAttribute())) {
                    throw new MuleRuntimeException(createStaticMessage(format("Global element %s:%s does not provide a name attribute.", identifier.getNamespace(), identifier.getName())));
                }
            });
        });
    } catch (Exception e) {
        throw new ConfigurationException(e);
    }
}
Also used : RuntimeConfigurationException(org.mule.runtime.config.internal.dsl.model.config.RuntimeConfigurationException) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) TypedComponentIdentifier(org.mule.runtime.api.component.TypedComponentIdentifier) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) RuntimeConfigurationException(org.mule.runtime.config.internal.dsl.model.config.RuntimeConfigurationException) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException)

Example 57 with MuleRuntimeException

use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.

the class ApplicationModel method validateFlowRefPointsToExistingFlow.

private void validateFlowRefPointsToExistingFlow() {
    executeOnEveryMuleComponentTree(componentModel -> {
        if (componentModel.getIdentifier().equals(FLOW_REF_IDENTIFIER)) {
            String nameAttribute = componentModel.getNameAttribute();
            if (nameAttribute != null && !nameAttribute.startsWith(DEFAULT_EXPRESSION_PREFIX)) {
                Optional<ComponentModel> referencedFlow = findTopLevelNamedComponent(nameAttribute);
                referencedFlow.orElseThrow(() -> new MuleRuntimeException(createStaticMessage("flow-ref at %s:%s is pointing to %s which does not exist", componentModel.getConfigFileName().orElse("unknown"), componentModel.getLineNumber().orElse(-1), nameAttribute)));
            }
        }
    });
}
Also used : MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException)

Example 58 with MuleRuntimeException

use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.

the class ApplicationModel method validateSingleElementExistence.

private void validateSingleElementExistence(ComponentIdentifier componentIdentifier) {
    Map<String, Map<ComponentIdentifier, ComponentModel>> existingComponentsPerFile = new HashMap<>();
    executeOnEveryMuleComponentTree(componentModel -> {
        String configFileName = componentModel.getConfigFileName().get();
        ComponentIdentifier identifier = componentModel.getIdentifier();
        if (componentIdentifier.getNamespace().equals(identifier.getNamespace()) && componentIdentifier.getName().equals(identifier.getName())) {
            if (existingComponentsPerFile.containsKey(configFileName) && existingComponentsPerFile.get(configFileName).containsKey(identifier)) {
                throw new MuleRuntimeException(createStaticMessage("Two configuration elements %s have been defined. Element [%s] must be unique. Clashing components are %s and %s", identifier.getNamespace() + ":" + identifier.getName(), identifier.getNamespace() + ":" + identifier.getName(), componentModel.getNameAttribute(), existingComponentsPerFile.get(configFileName).get(identifier).getNameAttribute()));
            }
            Map<ComponentIdentifier, ComponentModel> existingComponentWithName = new HashMap<>();
            existingComponentWithName.put(identifier, componentModel);
            existingComponentsPerFile.put(configFileName, existingComponentWithName);
        }
    });
}
Also used : HashMap(java.util.HashMap) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) TypedComponentIdentifier(org.mule.runtime.api.component.TypedComponentIdentifier) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Collections.emptyMap(java.util.Collections.emptyMap)

Example 59 with MuleRuntimeException

use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.

the class SpringPostProcessorIocHelper method toBeanDefinitions.

@Override
public List toBeanDefinitions(List<ComponentConfiguration> components) {
    ManagedList responseMessageProcessorsBeanList = new ManagedList();
    components.forEach(responseProcessorComponentModel -> {
        SpringComponentModel springComponentModel = (SpringComponentModel) responseProcessorComponentModel.getProperty(COMPONENT_MODEL_KEY).orElseThrow(() -> new MuleRuntimeException(createStaticMessage("Component configuration is expected to have the component model at this point.")));
        BeanDefinition beanDefinition = springComponentModel.getBeanDefinition();
        responseMessageProcessorsBeanList.add(beanDefinition != null ? beanDefinition : springComponentModel.getBeanReference());
    });
    return responseMessageProcessorsBeanList;
}
Also used : SpringComponentModel(org.mule.runtime.config.internal.dsl.model.SpringComponentModel) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ManagedList(org.springframework.beans.factory.support.ManagedList) BeanDefinitionBuilder.genericBeanDefinition(org.springframework.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) BeanDefinitionBuilder.rootBeanDefinition(org.springframework.beans.factory.support.BeanDefinitionBuilder.rootBeanDefinition)

Example 60 with MuleRuntimeException

use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.

the class BasicRuntimeServicesConfigurationBuilder method doConfigure.

@Override
protected void doConfigure(MuleContext muleContext) throws Exception {
    new SpiServiceRegistry().lookupProviders(Service.class, BasicRuntimeServicesConfigurationBuilder.class.getClassLoader()).forEach(service -> {
        try {
            startIfNeeded(service);
            registerObject(muleContext, service.getName(), service);
        } catch (MuleException e) {
            throw new MuleRuntimeException(e);
        }
    });
    DefaultExpressionLanguageFactoryService weaveExpressionExecutor = new WeaveDefaultExpressionLanguageFactoryService();
    registerObject(muleContext, weaveExpressionExecutor.getName(), weaveExpressionExecutor);
}
Also used : WeaveDefaultExpressionLanguageFactoryService(org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) DefaultExpressionLanguageFactoryService(org.mule.runtime.api.el.DefaultExpressionLanguageFactoryService) WeaveDefaultExpressionLanguageFactoryService(org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService) Service(org.mule.runtime.api.service.Service) DefaultExpressionLanguageFactoryService(org.mule.runtime.api.el.DefaultExpressionLanguageFactoryService) WeaveDefaultExpressionLanguageFactoryService(org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) MuleException(org.mule.runtime.api.exception.MuleException)

Aggregations

MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)123 IOException (java.io.IOException)22 List (java.util.List)22 MuleException (org.mule.runtime.api.exception.MuleException)22 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)22 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)22 Map (java.util.Map)20 Optional (java.util.Optional)20 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)18 ArrayList (java.util.ArrayList)17 String.format (java.lang.String.format)16 File (java.io.File)15 HashMap (java.util.HashMap)15 HashSet (java.util.HashSet)13 Set (java.util.Set)13 Collectors.toList (java.util.stream.Collectors.toList)12 ConfigurationException (org.mule.runtime.core.api.config.ConfigurationException)12 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)10 Collections.emptyMap (java.util.Collections.emptyMap)9 Optional.empty (java.util.Optional.empty)9