Search in sources :

Example 1 with ConfigurationException

use of cn.taketoday.core.ConfigurationException in project today-framework by TAKETODAY.

the class TomcatServer method doPrepareContext.

protected void doPrepareContext(Host host) {
    try {
        // 
        ServletWebServerApplicationLoader starter = new ServletWebServerApplicationLoader(obtainApplicationContext(), this::getMergedInitializers);
        TomcatEmbeddedContext context = new TomcatEmbeddedContext(sessionIdGenerator);
        context.setFailCtxIfServletStartFails(true);
        context.setName(getContextPath());
        context.setDisplayName(getDisplayName());
        context.setPath(getContextPath());
        WebDocumentConfiguration webDocumentConfiguration = getWebDocumentConfiguration();
        if (webDocumentConfiguration != null) {
            Resource validDocBase = webDocumentConfiguration.getValidDocumentDirectory();
            if (validDocBase != null && validDocBase.exists() && validDocBase.isDirectory()) {
                context.setDocBase(validDocBase.getFile().getAbsolutePath());
            }
        }
        context.addLifecycleListener(new FixContextListener());
        context.setParentClassLoader(ClassUtils.getDefaultClassLoader());
        resetDefaultLocaleMapping(context);
        addLocaleMappings(context);
        context.setUseRelativeRedirects(useRelativeRedirects);
        WebappLoader loader = new WebappLoader();
        loader.setLoaderClass(WebappClassLoader.class.getName());
        loader.setDelegate(true);
        context.setLoader(loader);
        configureJasperInitializer(context);
        host.addChild(context);
        context.addServletContainerInitializer(starter, Collections.emptySet());
        configureTomcatContext(context);
    } catch (IOException e) {
        throw new ConfigurationException(e);
    }
}
Also used : WebappClassLoader(org.apache.catalina.loader.WebappClassLoader) ConfigurationException(cn.taketoday.core.ConfigurationException) WebDocumentConfiguration(cn.taketoday.web.framework.config.WebDocumentConfiguration) Resource(cn.taketoday.core.io.Resource) IOException(java.io.IOException) WebappLoader(org.apache.catalina.loader.WebappLoader) FixContextListener(org.apache.catalina.startup.Tomcat.FixContextListener)

Example 2 with ConfigurationException

use of cn.taketoday.core.ConfigurationException in project today-framework by TAKETODAY.

the class AspectAutoProxyCreator method getInterceptor.

private MethodInterceptor getInterceptor(BeanDefinition aspectDef, @Nullable Method aspectMethod, MergedAnnotation<Advice> advice) {
    BeanFactory beanFactory = getFactory();
    if (aspectMethod == null) {
        // method interceptor
        if (!beanFactory.isTypeMatch(aspectDef.getBeanName(), MethodInterceptor.class)) {
            throw new ConfigurationException('[' + aspectDef.getBeanClassName() + "] must be implement: [" + MethodInterceptor.class.getName() + ']');
        }
        // aspect is a method interceptor
        return getMethodInterceptor(beanFactory, aspectDef);
    }
    // -----------------
    // invoke advice method that annotated: @AfterReturning @Around @Before @After @AfterThrowing
    Class<? extends MethodInterceptor> interceptor = advice.getClass("interceptor");
    if (interceptor == AbstractAnnotationMethodInterceptor.class || !MethodInterceptor.class.isAssignableFrom(interceptor)) {
        throw new ConfigurationException(interceptor + " must be implement: [" + AbstractAnnotationMethodInterceptor.class.getName() + "] or [" + MethodInterceptor.class.getName() + "]");
    }
    // exist in bean factory ?
    if (AnnotatedElementUtils.hasAnnotation(interceptor, Component.class)) {
        if (beanFactory instanceof BeanDefinitionRegistry) {
            BeanDefinition interceptorDef = ((BeanDefinitionRegistry) beanFactory).getBeanDefinition(interceptor);
            if (interceptorDef != null) {
                // exist in bean factory
                return getMethodInterceptor(beanFactory, interceptorDef);
            }
        } else {
            // just get bean
            MethodInterceptor ret = beanFactory.getBean(interceptor);
            if (ret != null) {
                return ret;
            }
        }
    }
    // dynamic parameters -> aspectMethod, beanName, beanFactory
    MethodInterceptor ret = DependencyInjectorAwareInstantiator.instantiate(interceptor, beanFactory, new Object[] { aspectMethod, aspectDef.getBeanName(), beanFactory });
    if (beanFactory instanceof AutowireCapableBeanFactory) {
        ((AutowireCapableBeanFactory) beanFactory).autowireBean(ret);
    }
    return ret;
}
Also used : SuppliedMethodInterceptor(cn.taketoday.aop.support.SuppliedMethodInterceptor) MethodInterceptor(org.aopalliance.intercept.MethodInterceptor) ConfigurationException(cn.taketoday.core.ConfigurationException) BeanFactory(cn.taketoday.beans.factory.BeanFactory) AutowireCapableBeanFactory(cn.taketoday.beans.factory.config.AutowireCapableBeanFactory) BeanDefinitionRegistry(cn.taketoday.beans.factory.support.BeanDefinitionRegistry) BeanDefinition(cn.taketoday.beans.factory.config.BeanDefinition) AnnotatedBeanDefinition(cn.taketoday.beans.factory.annotation.AnnotatedBeanDefinition) AutowireCapableBeanFactory(cn.taketoday.beans.factory.config.AutowireCapableBeanFactory)

Example 3 with ConfigurationException

use of cn.taketoday.core.ConfigurationException in project today-framework by TAKETODAY.

the class LightWebServer method contextInitialized.

@Override
protected void contextInitialized() {
    super.contextInitialized();
    try {
        final WebServerApplicationLoader loader = new WebServerApplicationLoader(this::getMergedInitializers);
        loader.setDispatcher(httpHandler);
        loader.setApplicationContext(obtainApplicationContext());
        loader.onStartup(obtainApplicationContext());
    } catch (Throwable e) {
        throw new ConfigurationException(e);
    }
}
Also used : WebServerApplicationLoader(cn.taketoday.web.framework.server.WebServerApplicationLoader) ConfigurationException(cn.taketoday.core.ConfigurationException)

Example 4 with ConfigurationException

use of cn.taketoday.core.ConfigurationException in project today-framework by TAKETODAY.

the class AbstractWebServer method getStoreDirectory.

/**
 * get session store directory
 */
public File getStoreDirectory(@Nullable Class<?> startupClass) throws IOException {
    Assert.state(sessionConfig != null, "Please enable web session");
    Resource storeDirectory = sessionConfig.getStoreDirectory();
    if (storeDirectory == null || !storeDirectory.exists()) {
        return ApplicationUtils.getTemporalDirectory(startupClass, "web-app-sessions");
    }
    if (storeDirectory.isDirectory()) {
        LoggerFactory.getLogger(getClass()).info("Use directory: [{}] to store sessions", storeDirectory);
        return storeDirectory.getFile();
    }
    throw new ConfigurationException("Store directory must be a 'directory'");
}
Also used : ConfigurationException(cn.taketoday.core.ConfigurationException) Resource(cn.taketoday.core.io.Resource)

Example 5 with ConfigurationException

use of cn.taketoday.core.ConfigurationException in project today-framework by TAKETODAY.

the class AbstractServletWebServer method addJspServlet.

/**
 * Add jsp to context
 */
protected void addJspServlet() {
    JspServletConfiguration jspServletConfiguration = this.jspServletConfiguration;
    if (jspServletConfiguration != null) {
        // config jsp servlet
        getWebApplicationConfiguration().configureJspServlet(jspServletConfiguration);
        if (jspServletConfiguration.isEnabled()) {
            try {
                Servlet jspServlet = BeanUtils.newInstance(jspServletConfiguration.getClassName());
                log.info("Jsp is enabled, use jsp servlet: [{}]", jspServlet.getServletInfo());
                WebServletInitializer<Servlet> initializer = new WebServletInitializer<>(jspServlet);
                initializer.setName(jspServletConfiguration.getName());
                initializer.setOrder(Ordered.HIGHEST_PRECEDENCE);
                initializer.addUrlMappings(jspServletConfiguration.getUrlMappings());
                initializer.setInitParameters(jspServletConfiguration.getInitParameters());
                getContextInitializers().add(initializer);
            } catch (ClassNotFoundException e) {
                throw new ConfigurationException("jsp servlet class not found", e);
            }
        }
    }
}
Also used : ConfigurationException(cn.taketoday.core.ConfigurationException) Servlet(jakarta.servlet.Servlet) JspServletConfiguration(cn.taketoday.web.framework.config.JspServletConfiguration) WebServletInitializer(cn.taketoday.web.servlet.initializer.WebServletInitializer)

Aggregations

ConfigurationException (cn.taketoday.core.ConfigurationException)9 Resource (cn.taketoday.core.io.Resource)2 IOException (java.io.IOException)2 SuppliedMethodInterceptor (cn.taketoday.aop.support.SuppliedMethodInterceptor)1 BeanDefinitionStoreException (cn.taketoday.beans.factory.BeanDefinitionStoreException)1 BeanFactory (cn.taketoday.beans.factory.BeanFactory)1 AnnotatedBeanDefinition (cn.taketoday.beans.factory.annotation.AnnotatedBeanDefinition)1 AutowireCapableBeanFactory (cn.taketoday.beans.factory.config.AutowireCapableBeanFactory)1 BeanDefinition (cn.taketoday.beans.factory.config.BeanDefinition)1 BeanDefinitionRegistry (cn.taketoday.beans.factory.support.BeanDefinitionRegistry)1 BeanDefinitionRegistrar (cn.taketoday.context.loader.BeanDefinitionRegistrar)1 JspServletConfiguration (cn.taketoday.web.framework.config.JspServletConfiguration)1 WebDocumentConfiguration (cn.taketoday.web.framework.config.WebDocumentConfiguration)1 AbstractWebServer (cn.taketoday.web.framework.server.AbstractWebServer)1 ConfigurableWebServer (cn.taketoday.web.framework.server.ConfigurableWebServer)1 WebServer (cn.taketoday.web.framework.server.WebServer)1 WebServerApplicationLoader (cn.taketoday.web.framework.server.WebServerApplicationLoader)1 ResolvableMethodParameter (cn.taketoday.web.handler.method.ResolvableMethodParameter)1 HandlerInterceptor (cn.taketoday.web.interceptor.HandlerInterceptor)1 WebServletInitializer (cn.taketoday.web.servlet.initializer.WebServletInitializer)1