Search in sources :

Example 31 with InitialisationException

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

the class ExtensionPluginMetadataGenerator method createExtensionManager.

/**
 * Creates a {@link ExtensionManager} needed for generating the metadata for an extension. It would be later discarded due to
 * the manager would have references to classes loaded with the launcher class loader instead of the hierarchical class loaders
 * created as result of the classification process.
 *
 * @return an {@link ExtensionManager} that would be used to register the extensions.
 */
private ExtensionManager createExtensionManager() {
    DefaultExtensionManager extensionManager = new DefaultExtensionManager();
    extensionManager.setMuleContext(new DefaultMuleContext() {

        private ErrorTypeRepository errorTypeRepository = createDefaultErrorTypeRepository();

        private ErrorTypeLocator errorTypeLocator = createDefaultErrorTypeLocator(errorTypeRepository);

        @Override
        public MuleRegistry getRegistry() {
            return new MuleRegistryHelper(new DefaultRegistryBroker(this, new MuleLifecycleInterceptor()), this);
        }

        @Override
        public ErrorTypeLocator getErrorTypeLocator() {
            return errorTypeLocator;
        }

        @Override
        public ErrorTypeRepository getErrorTypeRepository() {
            return errorTypeRepository;
        }
    });
    try {
        extensionManager.initialise();
    } catch (InitialisationException e) {
        throw new RuntimeException("Error while initialising the extension manager", e);
    }
    return extensionManager;
}
Also used : ErrorTypeRepository(org.mule.runtime.api.exception.ErrorTypeRepository) ErrorTypeRepositoryFactory.createDefaultErrorTypeRepository(org.mule.runtime.core.internal.exception.ErrorTypeRepositoryFactory.createDefaultErrorTypeRepository) MuleRegistryHelper(org.mule.runtime.core.internal.registry.MuleRegistryHelper) DefaultMuleContext(org.mule.runtime.core.internal.context.DefaultMuleContext) DefaultRegistryBroker(org.mule.runtime.core.internal.registry.DefaultRegistryBroker) ErrorTypeLocatorFactory.createDefaultErrorTypeLocator(org.mule.runtime.core.internal.exception.ErrorTypeLocatorFactory.createDefaultErrorTypeLocator) ErrorTypeLocator(org.mule.runtime.core.privileged.exception.ErrorTypeLocator) MuleRegistry(org.mule.runtime.core.internal.registry.MuleRegistry) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleLifecycleInterceptor(org.mule.runtime.core.internal.lifecycle.MuleLifecycleInterceptor) DefaultExtensionManager(org.mule.runtime.module.extension.internal.manager.DefaultExtensionManager)

Example 32 with InitialisationException

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

the class ParametersResolver method resolveParameters.

/**
 * {@inheritDoc}
 */
@Override
public void resolveParameters(ObjectType objectType, DefaultObjectBuilder builder) {
    final Class<?> objectClass = getType(objectType);
    final boolean isParameterGroup = isFlattenedParameterGroup(objectType);
    objectType.getFields().forEach(field -> {
        final String key = getLocalPart(field);
        ValueResolver<?> valueResolver = null;
        Field objectField = getField(objectClass, key);
        if (parameters.containsKey(key)) {
            valueResolver = toValueResolver(parameters.get(key));
        } else if (!isParameterGroup) {
            valueResolver = getDefaultValue(field).isPresent() ? getFieldDefaultValueValueResolver(field, muleContext) : null;
        }
        Optional<NullSafeTypeAnnotation> nullSafe = field.getAnnotation(NullSafeTypeAnnotation.class);
        if (nullSafe.isPresent()) {
            ValueResolver<?> delegate = valueResolver != null ? valueResolver : new StaticValueResolver<>(null);
            MetadataType type = getMetadataType(nullSafe.get().getType(), ExtensionsTypeLoaderFactory.getDefault().createTypeLoader());
            valueResolver = NullSafeValueResolverWrapper.of(delegate, type, reflectionCache, muleContext, this);
        }
        if (field.getAnnotation(ConfigOverrideTypeAnnotation.class).isPresent()) {
            valueResolver = ConfigOverrideValueResolverWrapper.of(valueResolver != null ? valueResolver : new StaticValueResolver<>(null), key, reflectionCache, muleContext);
        }
        if (valueResolver != null) {
            try {
                initialiseIfNeeded(valueResolver, true, muleContext);
                builder.addPropertyResolver(objectField.getName(), valueResolver);
            } catch (InitialisationException e) {
                throw new MuleRuntimeException(e);
            }
        } else if (field.isRequired() && !isFlattenedParameterGroup(field) && !lazyInitEnabled) {
            throw new RequiredParameterNotSetException(objectField.getName());
        }
    });
}
Also used : RequiredParameterNotSetException(org.mule.runtime.module.extension.internal.runtime.exception.RequiredParameterNotSetException) MetadataType(org.mule.metadata.api.model.MetadataType) IntrospectionUtils.getMetadataType(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getMetadataType) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) NullSafeTypeAnnotation(org.mule.runtime.extension.api.declaration.type.annotation.NullSafeTypeAnnotation) Field(java.lang.reflect.Field) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ConfigOverrideTypeAnnotation(org.mule.runtime.extension.api.declaration.type.annotation.ConfigOverrideTypeAnnotation)

Example 33 with InitialisationException

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

the class FunctionalTestProcessor method initialise.

@Override
public void initialise() throws InitialisationException {
    if (enableMessageHistory) {
        messageHistory = new CopyOnWriteArrayList<>();
    }
    for (LifecycleCallback callback : lifecycleCallbacks) {
        callback.onTransition(id, Initialisable.PHASE_NAME);
    }
    if (processorClass != null) {
        try {
            processor = (Processor) instantiateClass(processorClass);
            initialiseIfNeeded(processor, true, muleContext);
        } catch (Exception e) {
            throw new InitialisationException(e, this);
        }
    }
}
Also used : InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleException(org.mule.runtime.api.exception.MuleException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) FunctionalTestException(org.mule.functional.api.exception.FunctionalTestException)

Example 34 with InitialisationException

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

the class DefaultExtensionManagerFactory method create.

/**
 * {@inheritDoc}
 */
@Override
public ExtensionManager create(MuleContext muleContext) {
    ExtensionManager extensionManager = new DefaultExtensionManager();
    muleContext.setExtensionManager(extensionManager);
    try {
        initialiseIfNeeded(extensionManager, false, muleContext);
    } catch (InitialisationException e) {
        throw new MuleRuntimeException(createStaticMessage("Could not initialise extension manager"), e);
    }
    return extensionManager;
}
Also used : ExtensionManager(org.mule.runtime.core.api.extension.ExtensionManager) DefaultExtensionManager(org.mule.runtime.module.extension.internal.manager.DefaultExtensionManager) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) DefaultExtensionManager(org.mule.runtime.module.extension.internal.manager.DefaultExtensionManager)

Example 35 with InitialisationException

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

the class ServerNotificationManagerConfigurator method populateNotificationTypeMappings.

public ServerNotificationManager populateNotificationTypeMappings(Map<String, Class<? extends Notification>> eventMap, Map<String, Class<? extends NotificationListener>> interfaceMap) throws InitialisationException {
    Map<String, NotificationsProvider> providersMap = new HashMap<>();
    for (NotificationsProvider provider : registry.lookupAllByType(NotificationsProvider.class)) {
        for (Entry<String, Pair<Class<? extends Notification>, Class<? extends NotificationListener>>> entry : provider.getEventListenerMapping().entrySet()) {
            final String notificationType = entry.getKey();
            if (!notificationType.matches("[a-zA-Z]+:[A-Z\\-]+")) {
                throw new InitialisationException(createStaticMessage("Notification '%s' declared in '%s' doesn't comply with the '[artifactID]:[NOTIFICATION-ID]' format", notificationType, provider.toString()), this);
            }
            if (eventMap.containsKey(notificationType)) {
                throw new InitialisationException(createStaticMessage("Notification '%s' declared in '%s' is already declared for another artifact in provider '%s'.", notificationType, provider.toString(), eventMap.get(notificationType)), this);
            }
            eventMap.put(notificationType, entry.getValue().getFirst());
            interfaceMap.put(notificationType, entry.getValue().getSecond());
            providersMap.put(notificationType, provider);
        }
    }
    ServerNotificationManager notificationManager = muleContext.getNotificationManager();
    if (dynamic != null) {
        notificationManager.setNotificationDynamic(dynamic.booleanValue());
    }
    return notificationManager;
}
Also used : HashMap(java.util.HashMap) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) ServerNotificationManager(org.mule.runtime.core.api.context.notification.ServerNotificationManager) NotificationsProvider(org.mule.runtime.core.api.context.notification.NotificationsProvider) ListenerSubscriptionPair(org.mule.runtime.core.api.context.notification.ListenerSubscriptionPair) Pair(org.mule.runtime.api.util.Pair)

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