Search in sources :

Example 1 with WebServerApplicationContext

use of cn.taketoday.web.framework.WebServerApplicationContext in project today-framework by TAKETODAY.

the class AbstractServletWebServer method prepareInitialize.

@Override
protected void prepareInitialize() {
    super.prepareInitialize();
    WebServerApplicationContext context = obtainApplicationContext();
    Class<?> mainApplicationClass = getMainApplicationClass();
    if (mainApplicationClass != null) {
        ServletSecurity servletSecurity = mainApplicationClass.getAnnotation(ServletSecurity.class);
        if (servletSecurity != null) {
            BeanDefinitionRegistry registry = context.unwrapFactory(BeanDefinitionRegistry.class);
            if (registry.containsBeanDefinition(ServletSecurityElement.class)) {
                log.info("Multiple: [{}] Overriding its bean definition", ServletSecurityElement.class.getName());
            }
            context.unwrap(BeanDefinitionRegistrar.class).registerSingleton(new ServletSecurityElement(servletSecurity));
        }
    }
    addDefaultServlet();
    addJspServlet();
}
Also used : WebServerApplicationContext(cn.taketoday.web.framework.WebServerApplicationContext) ServletSecurity(jakarta.servlet.annotation.ServletSecurity) BeanDefinitionRegistrar(cn.taketoday.context.loader.BeanDefinitionRegistrar) BeanDefinitionRegistry(cn.taketoday.beans.factory.support.BeanDefinitionRegistry) ServletSecurityElement(jakarta.servlet.ServletSecurityElement)

Example 2 with WebServerApplicationContext

use of cn.taketoday.web.framework.WebServerApplicationContext in project today-framework by TAKETODAY.

the class AbstractWebServer method prepareInitialize.

protected void prepareInitialize() {
    log.info("Prepare initialize web server");
    WebServerApplicationContext context = obtainApplicationContext();
    Environment environment = context.getEnvironment();
    TodayStrategies.setProperty(WebApplicationLoader.ENABLE_WEB_STARTED_LOG, Boolean.FALSE.toString());
    String webMvcConfigLocation = environment.getProperty(WebApplicationLoader.WEB_MVC_CONFIG_LOCATION);
    if (StringUtils.isNotEmpty(webMvcConfigLocation)) {
        TodayStrategies.setProperty(WebApplicationLoader.ENABLE_WEB_MVC_XML, Boolean.TRUE.toString());
    }
}
Also used : WebServerApplicationContext(cn.taketoday.web.framework.WebServerApplicationContext) Environment(cn.taketoday.core.env.Environment)

Example 3 with WebServerApplicationContext

use of cn.taketoday.web.framework.WebServerApplicationContext in project today-framework by TAKETODAY.

the class NettyWebServer method preBootstrap.

/**
 * before bootstrap
 *
 * @param bootstrap netty ServerBootstrap
 */
protected void preBootstrap(ServerBootstrap bootstrap) {
    ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.DISABLED);
    // adjust context path
    WebServerApplicationContext context = obtainApplicationContext();
    NettyRequestContextConfig contextConfig = context.getBean(NettyRequestContextConfig.class);
    Assert.state(contextConfig != null, "No NettyRequestContextConfig");
    String contextPath = contextConfig.getContextPath();
    String serverContextPath = getContextPath();
    if (contextPath == null) {
        contextConfig.setContextPath(serverContextPath);
    } else {
        if (serverContextPath != null) {
            if (!Objects.equals(serverContextPath, contextPath)) {
                log.info("Using NettyRequestContextConfig 'contextPath' -> '{}'", contextPath);
                setContextPath(contextPath);
                // reset contextPath
                applyContextPath(context);
            }
        } else {
            setContextPath(contextPath);
        }
    }
}
Also used : StandardWebServerApplicationContext(cn.taketoday.web.framework.StandardWebServerApplicationContext) WebServerApplicationContext(cn.taketoday.web.framework.WebServerApplicationContext)

Example 4 with WebServerApplicationContext

use of cn.taketoday.web.framework.WebServerApplicationContext in project today-framework by TAKETODAY.

the class NettyWebServer method getNettyServerInitializer.

protected NettyServerInitializer getNettyServerInitializer() {
    NettyServerInitializer serverInitializer = this.nettyServerInitializer;
    if (serverInitializer == null) {
        WebServerApplicationContext context = obtainApplicationContext();
        serverInitializer = context.getBean(NettyServerInitializer.class);
        if (serverInitializer == null) {
            ReactiveChannelHandler reactiveDispatcher = context.getBean(ReactiveChannelHandler.class);
            serverInitializer = new NettyServerInitializer(reactiveDispatcher);
        }
    }
    return serverInitializer;
}
Also used : StandardWebServerApplicationContext(cn.taketoday.web.framework.StandardWebServerApplicationContext) WebServerApplicationContext(cn.taketoday.web.framework.WebServerApplicationContext)

Example 5 with WebServerApplicationContext

use of cn.taketoday.web.framework.WebServerApplicationContext in project today-framework by TAKETODAY.

the class NettyWebServer method contextInitialized.

@Override
protected void contextInitialized() {
    super.contextInitialized();
    WebServerApplicationContext context = obtainApplicationContext();
    try {
        WebServerApplicationLoader loader = new WebServerApplicationLoader(this::getMergedInitializers);
        loader.setApplicationContext(context);
        loader.onStartup(context);
    } catch (Throwable e) {
        throw ExceptionUtils.sneakyThrow(e);
    }
}
Also used : WebServerApplicationLoader(cn.taketoday.web.framework.server.WebServerApplicationLoader) StandardWebServerApplicationContext(cn.taketoday.web.framework.StandardWebServerApplicationContext) WebServerApplicationContext(cn.taketoday.web.framework.WebServerApplicationContext)

Aggregations

WebServerApplicationContext (cn.taketoday.web.framework.WebServerApplicationContext)5 StandardWebServerApplicationContext (cn.taketoday.web.framework.StandardWebServerApplicationContext)3 BeanDefinitionRegistry (cn.taketoday.beans.factory.support.BeanDefinitionRegistry)1 BeanDefinitionRegistrar (cn.taketoday.context.loader.BeanDefinitionRegistrar)1 Environment (cn.taketoday.core.env.Environment)1 WebServerApplicationLoader (cn.taketoday.web.framework.server.WebServerApplicationLoader)1 ServletSecurityElement (jakarta.servlet.ServletSecurityElement)1 ServletSecurity (jakarta.servlet.annotation.ServletSecurity)1