Search in sources :

Example 6 with InitializingBean

use of org.springframework.beans.factory.InitializingBean in project HotswapAgent by HotswapProjects.

the class ResetRequestMappingCaches method reset.

public static void reset(DefaultListableBeanFactory beanFactory) {
    Class<?> c = getHandlerMethodMappingClassOrNull();
    if (c == null)
        return;
    Map<String, ?> mappings = BeanFactoryUtils.beansOfTypeIncludingAncestors(beanFactory, c, true, false);
    if (mappings.isEmpty()) {
        LOGGER.trace("Spring: no HandlerMappings found");
    }
    try {
        for (Entry<String, ?> e : mappings.entrySet()) {
            Object am = e.getValue();
            LOGGER.info("Spring: clearing HandlerMapping for {}", am.getClass());
            try {
                Field f = c.getDeclaredField("handlerMethods");
                f.setAccessible(true);
                ((Map<?, ?>) f.get(am)).clear();
                f = c.getDeclaredField("urlMap");
                f.setAccessible(true);
                ((Map<?, ?>) f.get(am)).clear();
                try {
                    f = c.getDeclaredField("nameMap");
                    f.setAccessible(true);
                    ((Map<?, ?>) f.get(am)).clear();
                } catch (NoSuchFieldException nsfe) {
                    LOGGER.trace("Probably using Spring 4.0 or below", nsfe);
                }
            } catch (NoSuchFieldException nsfe) {
                LOGGER.trace("Probably using Spring 4.2+", nsfe);
                Method m = c.getDeclaredMethod("getHandlerMethods", new Class[0]);
                Class<?>[] parameterTypes = new Class[1];
                parameterTypes[0] = Object.class;
                Method u = c.getDeclaredMethod("unregisterMapping", parameterTypes);
                Map<?, ?> unmodifiableHandlerMethods = (Map<?, ?>) m.invoke(am);
                Object[] keys = unmodifiableHandlerMethods.keySet().toArray();
                unmodifiableHandlerMethods = null;
                for (Object key : keys) {
                    LOGGER.trace("Unregistering handler method {}", key);
                    u.invoke(am, key);
                }
            }
            if (am instanceof InitializingBean) {
                ((InitializingBean) am).afterPropertiesSet();
            }
        }
    } catch (Exception e) {
        LOGGER.error("Failed to clear HandlerMappings", e);
    }
}
Also used : Field(java.lang.reflect.Field) Method(java.lang.reflect.Method) InitializingBean(org.springframework.beans.factory.InitializingBean) Map(java.util.Map)

Example 7 with InitializingBean

use of org.springframework.beans.factory.InitializingBean in project cobar by alibaba.

the class AdapterDelegate method createAdapter.

private TimestampPair createAdapter(String ip, int port, String user, String password) {
    CobarAdapter adapter = null;
    try {
        DataSource ds = dsFactory.createDataSource(ip, port, user, password);
        adapter = new CobarAdapter();
        adapter.setDataSource(ds);
        ((InitializingBean) adapter).afterPropertiesSet();
        return new TimestampPair(adapter);
    } catch (Exception exception) {
        logger.error("ip=" + ip + ", port=" + port, exception);
        try {
            adapter.destroy();
        } catch (Exception e) {
        }
        throw new RuntimeException(exception);
    }
}
Also used : InitializingBean(org.springframework.beans.factory.InitializingBean) DataSource(javax.sql.DataSource)

Example 8 with InitializingBean

use of org.springframework.beans.factory.InitializingBean in project spring-framework by spring-projects.

the class JmsListenerEndpointRegistry method createListenerContainer.

/**
 * Create and start a new container using the specified factory.
 */
protected MessageListenerContainer createListenerContainer(JmsListenerEndpoint endpoint, JmsListenerContainerFactory<?> factory) {
    MessageListenerContainer listenerContainer = factory.createListenerContainer(endpoint);
    if (listenerContainer instanceof InitializingBean) {
        try {
            ((InitializingBean) listenerContainer).afterPropertiesSet();
        } catch (Exception ex) {
            throw new BeanInitializationException("Failed to initialize message listener container", ex);
        }
    }
    int containerPhase = listenerContainer.getPhase();
    if (containerPhase < Integer.MAX_VALUE) {
        // a custom phase value
        if (this.phase < Integer.MAX_VALUE && this.phase != containerPhase) {
            throw new IllegalStateException("Encountered phase mismatch between container factory definitions: " + this.phase + " vs " + containerPhase);
        }
        this.phase = listenerContainer.getPhase();
    }
    return listenerContainer;
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) InitializingBean(org.springframework.beans.factory.InitializingBean) MessageListenerContainer(org.springframework.jms.listener.MessageListenerContainer) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException)

Example 9 with InitializingBean

use of org.springframework.beans.factory.InitializingBean in project cas by apereo.

the class CasSamlServiceProvidersConfiguration method coreSamlServiceProvidersInitializingBean.

@Bean
public InitializingBean coreSamlServiceProvidersInitializingBean(@Qualifier(ServicesManager.BEAN_NAME) final ServicesManager servicesManager, final CasConfigurationProperties casProperties, @Qualifier(SamlRegisteredServiceCachingMetadataResolver.DEFAULT_BEAN_NAME) final SamlRegisteredServiceCachingMetadataResolver samlRegisteredServiceCachingMetadataResolver) {
    return () -> {
        val preloadMetadata = (Function<SamlRegisteredService, Void>) service -> {
            LOGGER.info("Launching background thread to load the metadata. This might take a while...");
            new Thread(() -> {
                LOGGER.debug("Loading metadata at [{}]...", service.getMetadataLocation());
                samlRegisteredServiceCachingMetadataResolver.resolve(service, new CriteriaSet());
            }, getClass().getSimpleName()).start();
            return null;
        };
        val samlSp = casProperties.getSamlSp();
        processSamlServiceProvider(samlSp.getAcademicHealthPlans(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getAcademicWorks(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getAdobeCloud(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getAmazon(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getAppDynamics(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getArcGIS(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getArmsSoftware(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getAsana(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getBenefitFocus(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getBlackBaud(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getBox(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getBynder(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getCccco(), servicesManager, samlRegisteredServiceCachingMetadataResolver, preloadMetadata);
        processSamlServiceProvider(samlSp.getCherWell(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getConcurSolutions(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getConfluence(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getCraniumCafe(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getCrashPlan(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getDocuSign(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getDropbox(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getEasyIep(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getEgnyte(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getEmma(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getEverBridge(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getEvernote(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getFamis(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getGartner(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getGitlab(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getGiveCampus(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getInCommon(), servicesManager, samlRegisteredServiceCachingMetadataResolver, preloadMetadata);
        processSamlServiceProvider(samlSp.getInfiniteCampus(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getJira(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getNeoGov(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getNetPartner(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getNewRelic(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getOffice365(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getOpenAthens(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getPagerDuty(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getPollEverywhere(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getQualtrics(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getRocketChat(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getSafariOnline(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getSalesforce(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getSaManage(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getSansSth(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getServiceNow(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getSlack(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getTopHat(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getSserca(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getSymplicity(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getTableau(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getWarpWire(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getWebAdvisor(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getWebex(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getWorkday(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getYuja(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getZendesk(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getZimbra(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
        processSamlServiceProvider(samlSp.getZoom(), servicesManager, samlRegisteredServiceCachingMetadataResolver);
    };
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) SamlRegisteredServiceCachingMetadataResolver(org.apereo.cas.support.saml.services.idp.metadata.cache.SamlRegisteredServiceCachingMetadataResolver) lombok.val(lombok.val) SamlSPUtils(org.apereo.cas.util.SamlSPUtils) Function(java.util.function.Function) InitializingBean(org.springframework.beans.factory.InitializingBean) Configuration(org.springframework.context.annotation.Configuration) Slf4j(lombok.extern.slf4j.Slf4j) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) AbstractSamlSPProperties(org.apereo.cas.configuration.model.support.saml.sps.AbstractSamlSPProperties) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) Qualifier(org.springframework.beans.factory.annotation.Qualifier) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) Bean(org.springframework.context.annotation.Bean) ServicesManager(org.apereo.cas.services.ServicesManager) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) InitializingBean(org.springframework.beans.factory.InitializingBean) Bean(org.springframework.context.annotation.Bean)

Example 10 with InitializingBean

use of org.springframework.beans.factory.InitializingBean in project paascloud-master by paascloud.

the class ExceptionHandlingAsyncTaskExecutor method afterPropertiesSet.

/**
 * After properties set.
 *
 * @throws Exception the exception
 */
@Override
public void afterPropertiesSet() throws Exception {
    if (executor instanceof InitializingBean) {
        InitializingBean bean = (InitializingBean) executor;
        bean.afterPropertiesSet();
    }
}
Also used : InitializingBean(org.springframework.beans.factory.InitializingBean)

Aggregations

InitializingBean (org.springframework.beans.factory.InitializingBean)27 ApplicationContextAware (org.springframework.context.ApplicationContextAware)8 AutowireCapableBeanFactory (org.springframework.beans.factory.config.AutowireCapableBeanFactory)6 Bean (org.springframework.context.annotation.Bean)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 MessageChannel (org.springframework.messaging.MessageChannel)4 Function (java.util.function.Function)3 DisposableBean (org.springframework.beans.factory.DisposableBean)3 AbstractMessageChannel (org.springframework.integration.channel.AbstractMessageChannel)3 FluxMessageChannel (org.springframework.integration.channel.FluxMessageChannel)3 DevelopmentException (com.haulmont.cuba.core.global.DevelopmentException)2 IOException (java.io.IOException)2 Field (java.lang.reflect.Field)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Supplier (java.util.function.Supplier)2 BeansException (org.springframework.beans.BeansException)2 BeanFactoryAware (org.springframework.beans.factory.BeanFactoryAware)2