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);
}
}
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)));
}
}
});
}
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);
}
});
}
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;
}
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);
}
Aggregations