Search in sources :

Example 26 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project pentaho-platform by pentaho.

the class PentahoSystemPluginManager method unloadPlugins.

private void unloadPlugins() {
    // is called within the synchronized block in reload
    for (IPlatformPlugin plugin : PentahoSystem.getAll(IPlatformPlugin.class)) {
        try {
            plugin.unLoaded();
            // if a spring app context was registered for this plugin, remove and close it
            final GenericApplicationContext appContext = PentahoSystem.get(GenericApplicationContext.class, null, Collections.singletonMap(PLUGIN_ID, plugin.getId()));
            if (appContext != null) {
                final StandaloneSpringPentahoObjectFactory pentahoObjectFactory = StandaloneSpringPentahoObjectFactory.getInstance(appContext);
                if (pentahoObjectFactory != null) {
                    PentahoSystem.deregisterObjectFactory(pentahoObjectFactory);
                }
                appContext.close();
            }
        } catch (Throwable t) {
            // we do not want any type of exception to leak out and cause a problem here
            // A plugin unload should not adversely affect anything downstream, it should
            // log an error and otherwise fail silently
            String msg = Messages.getInstance().getErrorString("PluginManager.ERROR_0014_PLUGIN_FAILED_TO_PROPERLY_UNLOAD", // $NON-NLS-1$
            plugin.getId());
            logger.error(getClass().toString(), msg, t);
            PluginMessageLogger.add(msg);
        }
        final ClassLoader classLoader = PentahoSystem.get(ClassLoader.class, null, Collections.singletonMap(PLUGIN_ID, plugin.getId()));
        if (classLoader != null) {
            try {
                ((PluginClassLoader) classLoader).close();
            } catch (IOException e) {
                logger.error("errror closing plugin clasloader", e);
            }
        }
    }
    for (Map.Entry<String, IPentahoObjectRegistration> entry : handleRegistry.entries()) {
        entry.getValue().remove();
    }
    handleRegistry.clear();
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) IOException(java.io.IOException) IPentahoObjectRegistration(org.pentaho.platform.api.engine.IPentahoObjectRegistration) Map(java.util.Map) HashMap(java.util.HashMap) IPlatformPlugin(org.pentaho.platform.api.engine.IPlatformPlugin) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)

Example 27 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project pentaho-platform by pentaho.

the class StandaloneSpringPentahoObjectFactoryTest method testInitFromObject.

public void testInitFromObject() throws Exception {
    StandaloneSession session = new StandaloneSession();
    StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
    File f = new File("src/test/resources/solution/system/pentahoObjects.spring.xml");
    FileSystemResource fsr = new FileSystemResource(f);
    GenericApplicationContext appCtx = new GenericApplicationContext();
    appCtx.refresh();
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(appCtx);
    xmlReader.loadBeanDefinitions(fsr);
    factory.init("src/test/resources/solution/system/pentahoObjects.spring.xml", appCtx);
    GoodObject obj = factory.get(GoodObject.class, session);
    assertNotNull(obj);
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)

Example 28 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project wso2-synapse by wso2.

the class SpringMediator method buildAppContext.

private synchronized void buildAppContext(MessageContext synCtx, SynapseLog synLog) {
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Creating Spring ApplicationContext from key : " + configKey);
    }
    GenericApplicationContext appContext = new GenericApplicationContext();
    XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(appContext);
    xbdr.setValidating(false);
    Object springConfig = synCtx.getEntry(configKey);
    if (springConfig == null) {
        String errorMessage = "Cannot look up Spring configuration " + configKey;
        log.error(errorMessage);
        // throw new SynapseException(errorMessage);
        return;
    }
    xbdr.loadBeanDefinitions(new InputStreamResource(SynapseConfigUtils.getStreamSource(springConfig).getInputStream()));
    appContext.refresh();
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Spring ApplicationContext from key : " + configKey + " created");
    }
    this.appContext = appContext;
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) InputStreamResource(org.springframework.core.io.InputStreamResource)

Example 29 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project pentaho-platform by pentaho.

the class SystemResourceIT method getSpringApplicationContext.

/**
 * Make spring configs available for test
 *
 * @return ApplicationContext
 */
private ApplicationContext getSpringApplicationContext() {
    String[] fns = { "pentahoObjects.spring.xml", "adminPlugins.xml", "sessionStartupActions.xml", "systemListeners.xml", "pentahoSystemConfig.xml", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
    "repository.spring.xml" };
    GenericApplicationContext appCtx = new GenericApplicationContext();
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(appCtx);
    for (String fn : fns) {
        // $NON-NLS-1$
        File f = new File(getSolutionPath() + SYSTEM_FOLDER + "/" + fn);
        if (f.exists()) {
            FileSystemResource fsr = new FileSystemResource(f);
            xmlReader.loadBeanDefinitions(fsr);
        }
    }
    return appCtx;
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File)

Example 30 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project wildfly-camel by wildfly-extras.

the class SpringCamelContextBootstrap method loadBeanDefinitions.

private void loadBeanDefinitions(Resource resource, ClassLoader classLoader) {
    applicationContext = new GenericApplicationContext();
    applicationContext.setClassLoader(classLoader);
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(applicationContext) {

        @Override
        protected NamespaceHandlerResolver createDefaultNamespaceHandlerResolver() {
            NamespaceHandlerResolver defaultResolver = super.createDefaultNamespaceHandlerResolver();
            return new SpringCamelContextBootstrap.CamelNamespaceHandlerResolver(defaultResolver);
        }
    };
    xmlReader.loadBeanDefinitions(resource);
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) NamespaceHandlerResolver(org.springframework.beans.factory.xml.NamespaceHandlerResolver) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader)

Aggregations

GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)378 Test (org.junit.jupiter.api.Test)193 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)106 Test (org.junit.Test)74 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)72 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)50 ClassPathResource (org.springframework.core.io.ClassPathResource)36 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)16 QueueChannel (org.springframework.integration.channel.QueueChannel)16 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)15 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)15 GenericMessage (org.springframework.messaging.support.GenericMessage)14 Properties (java.util.Properties)13 DefaultAdvisorAutoProxyCreator (org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator)13 File (java.io.File)12 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)12 Message (org.springframework.messaging.Message)12 InputStreamResource (org.springframework.core.io.InputStreamResource)11 MBeanExporter (org.springframework.jmx.export.MBeanExporter)11 BeforeEach (org.junit.jupiter.api.BeforeEach)10