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);
}
}
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;
}
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);
}
}
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'");
}
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);
}
}
}
}
Aggregations