Search in sources :

Example 1 with InitialisationException

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

the class DefaultMuleContextFactory method doCreateMuleContext.

private MuleContext doCreateMuleContext(MuleContextBuilder muleContextBuilder, ContextConfigurator configurator) throws InitialisationException, ConfigurationException {
    MuleContext muleContext = buildMuleContext(muleContextBuilder);
    listeners.forEach(l -> l.onCreation(muleContext));
    try {
        configurator.configure(muleContext);
        muleContext.initialise();
    } catch (ConfigurationException e) {
        if (muleContext != null && !muleContext.isDisposed()) {
            try {
                muleContext.dispose();
            } catch (Exception e1) {
                logger.warn("Can not dispose context. " + getMessage(e1));
                if (logger.isDebugEnabled()) {
                    logger.debug("Can not dispose context. " + getStackTrace(e1));
                }
            }
        }
        throw e;
    }
    return muleContext;
}
Also used : MuleContext(org.mule.runtime.core.api.MuleContext) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException)

Example 2 with InitialisationException

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

the class AbstractSecurityFilter method initialise.

@Override
public final void initialise() throws InitialisationException {
    if (securityManager == null) {
        securityManager = (SecurityManager) registry.lookupByName(OBJECT_SECURITY_MANAGER).get();
    }
    if (securityManager == null) {
        throw new InitialisationException(authSecurityManagerNotSet(), this);
    }
    // security providers
    if (securityProviders != null) {
        SecurityManager localManager = new DefaultMuleSecurityManager();
        String[] securityProviders = splitAndTrim(this.securityProviders, ",");
        for (String sp : securityProviders) {
            SecurityProvider provider = securityManager.getProvider(sp);
            if (provider != null) {
                localManager.addProvider(provider);
            } else {
                throw new InitialisationException(objectNotRegistered("Security Provider", sp), this);
            }
        }
        securityManager = localManager;
    }
    doInitialise();
}
Also used : DefaultMuleSecurityManager(org.mule.runtime.core.internal.security.DefaultMuleSecurityManager) DefaultMuleSecurityManager(org.mule.runtime.core.internal.security.DefaultMuleSecurityManager) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException)

Example 3 with InitialisationException

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

the class LifecycleUtils method initialiseIfNeeded.

/**
 * The same as {@link #initialiseIfNeeded(Object)}, only that before checking for {@code object} being {@link Initialisable}, it
 * uses the given {@code muleContext} to perform further initialization.
 * <p>
 * It checks if the {@code object} implements {@link MuleContextAware}, in which case it will invoke
 * {@link MuleContextAware#setMuleContext(MuleContext)} with the given {@code muleContext}.
 * <p>
 * Also depending on the value of the {@code inject} argument, it will perform dependency injection on the {@code object}
 *
 * @param object the object you're trying to initialise
 * @param inject whether it should perform dependency injection on the {@code object} before actually initialising it
 * @param muleContext a {@link MuleContext}
 * @throws InitialisationException
 * @throws IllegalArgumentException if {@code MuleContext} is {@code null}
 */
public static void initialiseIfNeeded(Object object, boolean inject, MuleContext muleContext) throws InitialisationException {
    checkArgument(muleContext != null, "muleContext cannot be null");
    object = unwrap(object);
    if (object == null) {
        return;
    }
    if (object instanceof MuleContextAware) {
        ((MuleContextAware) object).setMuleContext(muleContext);
    }
    if (inject) {
        try {
            muleContext.getInjector().inject(object);
        } catch (MuleException e) {
            I18nMessage message = createStaticMessage(format("Found exception trying to inject object of type '%s' on initialising phase", object.getClass().getName()));
            if (object instanceof Initialisable) {
                throw new InitialisationException(message, e, (Initialisable) object);
            }
            throw new MuleRuntimeException(message, e);
        }
    }
    initialiseIfNeeded(object);
}
Also used : MuleContextAware(org.mule.runtime.core.api.context.MuleContextAware) Initialisable(org.mule.runtime.api.lifecycle.Initialisable) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) I18nMessage(org.mule.runtime.api.i18n.I18nMessage) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleException(org.mule.runtime.api.exception.MuleException)

Example 4 with InitialisationException

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

the class DefaultMuleContext method initialise.

@Override
public void initialise() throws InitialisationException {
    synchronized (lifecycleStateLock) {
        lifecycleManager.checkPhase(Initialisable.PHASE_NAME);
        if (getNotificationManager() == null) {
            throw new MuleRuntimeException(objectIsNull(OBJECT_NOTIFICATION_MANAGER));
        }
        try {
            JdkVersionUtils.validateJdk();
        } catch (RuntimeException e) {
            throw new InitialisationException(invalidJdk(JAVA_VERSION, getSupportedJdks()), this);
        }
        try {
            id = getConfiguration().getDomainId() + "." + getClusterId() + "." + getConfiguration().getId();
            // Initialize the helper, this only initialises the helper class and does not call the registry lifecycle manager
            // The registry lifecycle is called below using 'getLifecycleManager().fireLifecycle(Initialisable.PHASE_NAME);'
            getRegistry().initialise();
            fireNotification(new MuleContextNotification(this, CONTEXT_INITIALISING));
            getLifecycleManager().fireLifecycle(Initialisable.PHASE_NAME);
            fireNotification(new MuleContextNotification(this, CONTEXT_INITIALISED));
            listeners.forEach(l -> l.onInitialization(this, getApiRegistry()));
            initialiseIfNeeded(getExceptionListener(), true, this);
            getNotificationManager().initialise();
            // refresh object serializer reference in case a default one was redefined in the config.
            objectSerializer = registryBroker.get(DEFAULT_OBJECT_SERIALIZER_NAME);
        } catch (InitialisationException e) {
            dispose();
            throw e;
        } catch (Exception e) {
            dispose();
            throw new InitialisationException(e, this);
        }
    }
}
Also used : MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleContextNotification(org.mule.runtime.core.api.context.notification.MuleContextNotification) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MuleException(org.mule.runtime.api.exception.MuleException) ConnectException(org.mule.runtime.core.api.connector.ConnectException) LifecycleException(org.mule.runtime.api.lifecycle.LifecycleException) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException)

Example 5 with InitialisationException

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

the class InvokerMessageProcessor method resolveMethodToInvoke.

protected void resolveMethodToInvoke() throws InitialisationException {
    if (argumentTypes != null) {
        method = ClassUtils.getMethod(object.getClass(), methodName, argumentTypes);
        if (method == null) {
            throw new InitialisationException(methodWithParamsNotFoundOnObject(methodName, argumentTypes, object.getClass()), this);
        }
    } else {
        List<Method> matchingMethods = new ArrayList<>();
        int argSize = arguments != null ? arguments.size() : 0;
        for (Method methodCandidate : object.getClass().getMethods()) {
            if (methodCandidate.getName().equals(methodName) && methodCandidate.getParameterTypes().length == argSize)
                matchingMethods.add(methodCandidate);
        }
        if (matchingMethods.size() == 1) {
            method = matchingMethods.get(0);
            argumentTypes = method.getParameterTypes();
        } else {
            throw new InitialisationException(methodWithNumParamsNotFoundOnObject(methodName, arguments.size(), object), this);
        }
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(format("Initialised %s to use method: '%s'", this, method));
    }
}
Also used : ArrayList(java.util.ArrayList) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) Method(java.lang.reflect.Method)

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