Search in sources :

Example 16 with VaadinServletContext

use of com.vaadin.flow.server.VaadinServletContext in project flow by vaadin.

the class DevModeBrowserLauncher method isProductionMode.

private static boolean isProductionMode(GenericWebApplicationContext app) {
    ServletContext servletContext = app.getServletContext();
    VaadinContext context = new VaadinServletContext(servletContext);
    ApplicationConfiguration applicationConfiguration = ApplicationConfiguration.get(context);
    return applicationConfiguration.isProductionMode();
}
Also used : VaadinServletContext(com.vaadin.flow.server.VaadinServletContext) VaadinContext(com.vaadin.flow.server.VaadinContext) VaadinServletContext(com.vaadin.flow.server.VaadinServletContext) ServletContext(javax.servlet.ServletContext) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration)

Example 17 with VaadinServletContext

use of com.vaadin.flow.server.VaadinServletContext in project flow by vaadin.

the class SpringLookupInitializer method initialize.

@Override
public void initialize(VaadinContext context, Map<Class<?>, Collection<Class<?>>> services, VaadinApplicationInitializationBootstrap bootstrap) throws ServletException {
    VaadinServletContext servletContext = (VaadinServletContext) context;
    boolean isContextAvailable = false;
    synchronized (LOCK) {
        ApplicationContext appContext = getApplicationContext(context);
        isContextAvailable = appContext != null;
        if (!isContextAvailable) {
            context.setAttribute(BootstrapCallable.class, () -> doInitialize(servletContext, services, bootstrap));
        }
    }
    if (isContextAvailable) {
        doInitialize(servletContext, services, bootstrap);
    }
}
Also used : VaadinServletContext(com.vaadin.flow.server.VaadinServletContext) WebApplicationContext(org.springframework.web.context.WebApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext)

Example 18 with VaadinServletContext

use of com.vaadin.flow.server.VaadinServletContext in project flow by vaadin.

the class VaadinServletContextInitializer method onStartup.

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    // Verify servlet version also for SpringBoot.
    ServletVerifier.verifyServletVersion();
    VaadinServletContext vaadinContext = new VaadinServletContext(servletContext);
    servletContext.addListener(createCompositeListener(vaadinContext));
}
Also used : VaadinServletContext(com.vaadin.flow.server.VaadinServletContext)

Example 19 with VaadinServletContext

use of com.vaadin.flow.server.VaadinServletContext in project flow by vaadin.

the class LookupServletContainerInitializer method process.

@Override
public void process(Set<Class<?>> classSet, ServletContext servletContext) throws ServletException {
    if (classSet == null) {
        throw new ServletException(ServletContainerInitializer.class.getSimpleName() + " is called but the " + "provided set of classes is 'null'. " + LookupInitializer.class + " always presents " + "and has to be passed to the 'onStartup' method as an argument " + "in the set of classes if the servlet container supports Servlet 3.0 specification. " + "The propject configuration is broken somehow or you are using Servlet 3.0 incompatible container.");
    }
    if (!classSet.contains(LookupInitializer.class)) {
        // executed at all.
        return;
    }
    VaadinServletContext vaadinContext = new VaadinServletContext(servletContext);
    Map<Class<?>, Collection<Class<?>>> services = new HashMap<>();
    collectSubclasses(AbstractLookupInitializer.class, classSet, services);
    AbstractLookupInitializer initializer = getLookupInitializer(services);
    services.remove(AbstractLookupInitializer.class);
    collectServiceImplementations(classSet, services);
    initializer.initialize(vaadinContext, services, lookup -> {
        vaadinContext.setAttribute(Lookup.class, lookup);
        DeferredServletContextInitializers deferredInitializers;
        synchronized (servletContext) {
            deferredInitializers = vaadinContext.getAttribute(DeferredServletContextInitializers.class);
            vaadinContext.removeAttribute(DeferredServletContextInitializers.class);
        }
        if (deferredInitializers != null) {
            deferredInitializers.runInitializers(servletContext);
        }
    });
}
Also used : ServletException(javax.servlet.ServletException) VaadinServletContext(com.vaadin.flow.server.VaadinServletContext) HashMap(java.util.HashMap) Collection(java.util.Collection) AbstractLookupInitializer(com.vaadin.flow.di.AbstractLookupInitializer) AbstractLookupInitializer(com.vaadin.flow.di.AbstractLookupInitializer) LookupInitializer(com.vaadin.flow.di.LookupInitializer)

Example 20 with VaadinServletContext

use of com.vaadin.flow.server.VaadinServletContext in project flow by vaadin.

the class ServletDeployer method contextInitialized.

@Override
public void contextInitialized(ServletContextEvent sce) {
    ServletContext context = sce.getServletContext();
    Collection<DeploymentConfiguration> servletConfigurations = getServletConfigurations(context);
    VaadinServletContext vaadinContext = new VaadinServletContext(context);
    ApplicationConfiguration config = ApplicationConfiguration.get(vaadinContext);
    boolean enableServlets = !config.disableAutomaticServletRegistration();
    boolean productionMode = false;
    for (DeploymentConfiguration configuration : servletConfigurations) {
        productionMode = productionMode || configuration.isProductionMode();
    }
    VaadinServletCreation servletCreation = enableServlets ? createAppServlet(context) : null;
    logServletCreation(servletCreation, context, productionMode);
}
Also used : VaadinServletContext(com.vaadin.flow.server.VaadinServletContext) VaadinServletContext(com.vaadin.flow.server.VaadinServletContext) ServletContext(javax.servlet.ServletContext) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration)

Aggregations

VaadinServletContext (com.vaadin.flow.server.VaadinServletContext)20 Lookup (com.vaadin.flow.di.Lookup)8 ServletContext (javax.servlet.ServletContext)8 VaadinService (com.vaadin.flow.server.VaadinService)4 ApplicationConfiguration (com.vaadin.flow.server.startup.ApplicationConfiguration)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 ResourceProvider (com.vaadin.flow.di.ResourceProvider)3 ServletException (javax.servlet.ServletException)3 Before (org.junit.Before)3 WebApplicationContext (org.springframework.web.context.WebApplicationContext)3 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)2 HasErrorParameter (com.vaadin.flow.router.HasErrorParameter)2 NotFoundException (com.vaadin.flow.router.NotFoundException)2 MockServletServiceSessionSetup (com.vaadin.flow.server.MockServletServiceSessionSetup)2 StaticFileServer (com.vaadin.flow.server.StaticFileServer)2 VaadinSession (com.vaadin.flow.server.VaadinSession)2 ApplicationRouteRegistry (com.vaadin.flow.server.startup.ApplicationRouteRegistry)2 Properties (java.util.Properties)2 Set (java.util.Set)2