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