Search in sources :

Example 1 with PropertiesBootstrapService

use of org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapService in project mule by mulesoft.

the class TestBootstrapServiceDiscovererConfigurationBuilder method getArtifactBootstrapService.

private List<BootstrapService> getArtifactBootstrapService(Object artifactClassLoader) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, IOException {
    // Uses reflection to access the class loader as classes were loaded from different class loaders so they cannot be casted
    ClassLoader classLoader = (ClassLoader) artifactClassLoader.getClass().getMethod("getClassLoader").invoke(artifactClassLoader);
    final Enumeration<URL> resources = (Enumeration<URL>) classLoader.getClass().getMethod("findResources", String.class).invoke(classLoader, BOOTSTRAP_PROPERTIES);
    final List<BootstrapService> bootstrapServices = new ArrayList<>();
    if (resources.hasMoreElements()) {
        while (resources.hasMoreElements()) {
            final URL localResource = resources.nextElement();
            final Properties properties = PropertiesUtils.loadProperties(localResource);
            final PropertiesBootstrapService propertiesBootstrapService = new PropertiesBootstrapService(classLoader, properties);
            bootstrapServices.add(propertiesBootstrapService);
        }
    }
    return bootstrapServices;
}
Also used : PropertiesBootstrapService(org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapService) Enumeration(java.util.Enumeration) ArrayList(java.util.ArrayList) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) Properties(java.util.Properties) URL(java.net.URL) BootstrapService(org.mule.runtime.core.api.config.bootstrap.BootstrapService) PropertiesBootstrapService(org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapService)

Example 2 with PropertiesBootstrapService

use of org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapService in project mule by mulesoft.

the class ArtifactBootstrapServiceDiscovererConfigurationBuilder method doConfigure.

@Override
protected void doConfigure(MuleContext muleContext) throws Exception {
    final PropertiesBootstrapServiceDiscoverer propertiesBootstrapServiceDiscoverer = new PropertiesBootstrapServiceDiscoverer(this.getClass().getClassLoader());
    List<BootstrapService> bootstrapServices = new LinkedList<>();
    bootstrapServices.addAll(propertiesBootstrapServiceDiscoverer.discover());
    for (ArtifactPlugin artifactPlugin : artifactPlugins) {
        final Enumeration<URL> resources = artifactPlugin.getArtifactClassLoader().findResources(BOOTSTRAP_PROPERTIES);
        while (resources.hasMoreElements()) {
            final URL localResource = resources.nextElement();
            final Properties properties = PropertiesUtils.loadProperties(localResource);
            final BootstrapService pluginBootstrapService = new PropertiesBootstrapService(artifactPlugin.getArtifactClassLoader().getClassLoader(), properties);
            bootstrapServices.add(pluginBootstrapService);
        }
    }
    muleContext.setBootstrapServiceDiscoverer(() -> bootstrapServices);
}
Also used : PropertiesBootstrapServiceDiscoverer(org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapServiceDiscoverer) PropertiesBootstrapService(org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapService) Properties(java.util.Properties) LinkedList(java.util.LinkedList) URL(java.net.URL) BootstrapService(org.mule.runtime.core.api.config.bootstrap.BootstrapService) PropertiesBootstrapService(org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapService) ArtifactPlugin(org.mule.runtime.deployment.model.api.plugin.ArtifactPlugin)

Aggregations

URL (java.net.URL)2 Properties (java.util.Properties)2 BootstrapService (org.mule.runtime.core.api.config.bootstrap.BootstrapService)2 PropertiesBootstrapService (org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapService)2 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 LinkedList (java.util.LinkedList)1 PropertiesBootstrapServiceDiscoverer (org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapServiceDiscoverer)1 ArtifactPlugin (org.mule.runtime.deployment.model.api.plugin.ArtifactPlugin)1 ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)1