Search in sources :

Example 16 with InitialisationException

use of org.mule.runtime.api.lifecycle.InitialisationException in project mule by mulesoft.

the class ResolverUtils method getExpressionBasedValueResolver.

private static ValueResolver<?> getExpressionBasedValueResolver(String expression, BooleanSupplier isTypedValue, BooleanSupplier isParameterResolver, Optional<StackedTypesModelProperty> stackedTypesModelProperty, MetadataType type, MuleContext muleContext) {
    try {
        ValueResolver resolver;
        if (stackedTypesModelProperty.isPresent()) {
            resolver = stackedTypesModelProperty.get().getValueResolverFactory().getExpressionBasedValueResolver(expression, getType(type));
        // TODO MULE-13518: Add support for stacked value resolvers for @Parameter inside pojos // The following "IFs" should be removed once implemented
        } else if (isTypedValue.getAsBoolean()) {
            ExpressionTypedValueValueResolver<Object> valueResolver = new ExpressionTypedValueValueResolver<>(expression, getType(type));
            valueResolver.setTransformationService(muleContext.getTransformationService());
            valueResolver.setExtendedExpressionManager(muleContext.getExpressionManager());
            resolver = valueResolver;
        } else if (isParameterResolver.getAsBoolean()) {
            ExpressionBasedParameterResolverValueResolver<Object> valueResolver = new ExpressionBasedParameterResolverValueResolver<>(expression, getType(type), type);
            valueResolver.setTransformationService(muleContext.getTransformationService());
            valueResolver.setExtendedExpressionManager(muleContext.getExpressionManager());
            resolver = valueResolver;
        } else if (muleContext.getExpressionManager().isExpression(expression)) {
            TypeSafeExpressionValueResolver<Object> valueResolver = new TypeSafeExpressionValueResolver<>(expression, getType(type), type);
            valueResolver.setTransformationService(muleContext.getTransformationService());
            valueResolver.setExtendedExpressionManager(muleContext.getExpressionManager());
            resolver = valueResolver;
        } else {
            TypeSafeValueResolverWrapper typeSafeValueResolverWrapper = new TypeSafeValueResolverWrapper<>(new StaticValueResolver<>(expression), getType(type));
            typeSafeValueResolverWrapper.setTransformationService(muleContext.getTransformationService());
            resolver = typeSafeValueResolverWrapper;
        }
        initialiseIfNeeded(resolver, muleContext);
        return resolver;
    } catch (InitialisationException e) {
        throw new MuleRuntimeException(e);
    }
}
Also used : InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException)

Example 17 with InitialisationException

use of org.mule.runtime.api.lifecycle.InitialisationException in project mule by mulesoft.

the class AbstractFlowConstruct method initialise.

@Override
public final void initialise() throws InitialisationException {
    try {
        lifecycleManager.fireInitialisePhase((phaseName, object) -> {
            initialiseIfNeeded(exceptionListener, muleContext);
            validateConstruct();
            doInitialise();
        });
    } catch (InitialisationException e) {
        safely(() -> dispose());
        throw e;
    } catch (MuleException e) {
        safely(() -> dispose());
        throw new InitialisationException(e, this);
    }
}
Also used : InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleException(org.mule.runtime.api.exception.MuleException)

Example 18 with InitialisationException

use of org.mule.runtime.api.lifecycle.InitialisationException in project mule by mulesoft.

the class AbstractRegistryBootstrap method createTransactionFactoryBootstrapProperty.

private TransactionFactoryBootstrapProperty createTransactionFactoryBootstrapProperty(BootstrapService bootstrapService, Properties bootstrapProperties, String propertyKey, String propertyValue) throws InitialisationException {
    String transactionResourceKey = propertyKey.replace(".transaction.factory", TRANSACTION_RESOURCE_SUFFIX);
    String transactionResource = bootstrapProperties.getProperty(transactionResourceKey);
    if (transactionResource == null) {
        throw new InitialisationException(createStaticMessage(format("There is no transaction resource specified for transaction factory %s", propertyKey)), this);
    }
    String transactionResourceClassNameProperties = transactionResource;
    boolean optional = false;
    int index = transactionResourceClassNameProperties.indexOf(",");
    if (index > -1) {
        Properties p = PropertiesUtils.getPropertiesFromString(transactionResourceClassNameProperties.substring(index + 1), ',');
        optional = p.containsKey(OPTIONAL_ATTRIBUTE);
    }
    final String transactionResourceClassName = (index == -1 ? transactionResourceClassNameProperties : transactionResourceClassNameProperties.substring(0, index));
    return new TransactionFactoryBootstrapProperty(bootstrapService, singleton(APP), optional, propertyValue, transactionResourceClassName);
}
Also used : ArtifactType.createFromString(org.mule.runtime.core.api.config.bootstrap.ArtifactType.createFromString) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) Properties(java.util.Properties)

Example 19 with InitialisationException

use of org.mule.runtime.api.lifecycle.InitialisationException in project mule by mulesoft.

the class OnErrorContinueHandler method doInitialise.

@Override
protected void doInitialise(MuleContext muleContext) throws InitialisationException {
    super.doInitialise(muleContext);
    ErrorTypeRepository errorTypeRepository = muleContext.getErrorTypeRepository();
    sourceErrorMatcher = new SingleErrorTypeMatcher(errorTypeRepository.getSourceResponseErrorType());
    if (errorType != null) {
        String[] errors = errorType.split(",");
        for (String error : errors) {
            // Since the partial initialisation was successful, we know this error ids are safe
            String sanitizedError = error.trim();
            ErrorType errorType = errorTypeRepository.lookupErrorType(buildFromStringRepresentation(sanitizedError)).get();
            if (sourceErrorMatcher.match(errorType)) {
                throw new InitialisationException(getInitialisationError(sanitizedError), this);
            }
        }
    } else if (when == null) {
        // No error type and no expression, force ANY matcher
        errorTypeMatcher = new SingleErrorTypeMatcher(errorTypeRepository.getAnyErrorType());
    }
}
Also used : ErrorTypeRepository(org.mule.runtime.api.exception.ErrorTypeRepository) ErrorType(org.mule.runtime.api.message.ErrorType) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) SingleErrorTypeMatcher(org.mule.runtime.core.api.exception.SingleErrorTypeMatcher)

Example 20 with InitialisationException

use of org.mule.runtime.api.lifecycle.InitialisationException in project mule by mulesoft.

the class AsyncDelegateMessageProcessor method initialise.

@Override
public void initialise() throws InitialisationException {
    Object rootContainer = getFromAnnotatedObject(componentLocator, this).orElse(null);
    if (rootContainer instanceof FlowConstruct) {
        if (maxConcurrency != null && rootContainer instanceof Pipeline) {
            ProcessingStrategyFactory flowPsFactory = ((Pipeline) rootContainer).getProcessingStrategyFactory();
            if (flowPsFactory instanceof AsyncProcessingStrategyFactory) {
                ((AsyncProcessingStrategyFactory) flowPsFactory).setMaxConcurrency(maxConcurrency);
            } else {
                logger.warn("{} does not support 'maxConcurrency'. Ignoring the value.", flowPsFactory.getClass().getSimpleName());
            }
            processingStrategy = flowPsFactory.create(muleContext, getLocation().getLocation());
            ownProcessingStrategy = true;
        } else {
            processingStrategy = ((FlowConstruct) rootContainer).getProcessingStrategy();
        }
    } else {
        processingStrategy = DIRECT_PROCESSING_STRATEGY_INSTANCE;
    }
    if (delegateBuilder == null) {
        throw new InitialisationException(objectIsNull("delegate message processor"), this);
    }
    delegateBuilder.setProcessingStrategy(processingStrategy);
    delegate = delegateBuilder.build();
    initialiseIfNeeded(delegate, muleContext);
    super.initialise();
}
Also used : FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) ProcessingStrategyFactory(org.mule.runtime.core.api.processor.strategy.ProcessingStrategyFactory) AsyncProcessingStrategyFactory(org.mule.runtime.core.api.processor.strategy.AsyncProcessingStrategyFactory) ComponentUtils.getFromAnnotatedObject(org.mule.runtime.core.internal.component.ComponentUtils.getFromAnnotatedObject) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) AsyncProcessingStrategyFactory(org.mule.runtime.core.api.processor.strategy.AsyncProcessingStrategyFactory) Pipeline(org.mule.runtime.core.api.construct.Pipeline)

Aggregations

InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)36 MuleException (org.mule.runtime.api.exception.MuleException)14 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)12 HashMap (java.util.HashMap)5 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)3 Map (java.util.Map)3 Properties (java.util.Properties)3 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)3 ConfigurationException (org.mule.runtime.core.api.config.ConfigurationException)3 RegistrationException (org.mule.runtime.core.privileged.registry.RegistrationException)3 Arrays.asList (java.util.Arrays.asList)2 List (java.util.List)2 Optional (java.util.Optional)2 Optional.empty (java.util.Optional.empty)2 ErrorTypeRepository (org.mule.runtime.api.exception.ErrorTypeRepository)2 ArtifactDeclaration (org.mule.runtime.app.declaration.api.ArtifactDeclaration)2 FlowConstruct (org.mule.runtime.core.api.construct.FlowConstruct)2 ComponentUtils.getFromAnnotatedObject (org.mule.runtime.core.internal.component.ComponentUtils.getFromAnnotatedObject)2 MuleRegistry (org.mule.runtime.core.internal.registry.MuleRegistry)2