@Override public String getMimeType(String resourceName) { return getServlet().getServletContext().getMimeType(resourceName); }
@Override protected LegacyApplication createApplication() { VaadinServlet servlet = VaadinServlet.getCurrent(); if (servlet instanceof LegacyVaadinServlet) { LegacyVaadinServlet legacyServlet = (LegacyVaadinServlet) servlet; HttpServletRequest request = VaadinServletService .getCurrentServletRequest(); try { if (legacyServlet.shouldCreateApplication(request)) { return legacyServlet.getNewApplication(request); } } catch (ServletException e) { throw new RuntimeException(e); } } return null; } };
/** * Called by the servlet container to indicate to a servlet that the servlet * is being placed into service. * * @param servletConfig * the object containing the servlet's configuration and * initialization parameters * @throws ServletException * if an exception has occurred that interferes with the * servlet's normal operation. */ @Override public void init(javax.servlet.ServletConfig servletConfig) throws ServletException { CurrentInstance.clearAll(); super.init(servletConfig); try { servletService = createServletService(); } catch (ServiceException e) { throw new ServletException("Could not initialize VaadinServlet", e); } // Sets current service even though there are no request and response servletService.setCurrentInstances(null, null); servletInitialized(); CurrentInstance.clearAll(); }
/** * Creates a vaadin servlet service. This method functions as a layer of * indirection between {@link #init(ServletConfig)} and * {@link #createServletService(DeploymentConfiguration)} so dependency * injection frameworks can call {@link #createDeploymentConfiguration()} * when creating a vaadin servlet service lazily. * * @return the created vaadin servlet service * * @throws ServletException * if creating a deployment configuration fails * @throws ServiceException * if creating the vaadin servlet service fails * * @since 8.2 */ protected VaadinServletService createServletService() throws ServletException, ServiceException { return createServletService(createDeploymentConfiguration()); }
@Override public File getBaseDirectory() { final String realPath = VaadinServlet .getResourcePath(getServlet().getServletContext(), "/"); if (realPath == null) { return null; } return new File(realPath); }
Properties initParameters = new Properties(); readUiFromEnclosingClass(initParameters); readConfigurationAnnotation(initParameters); final ServletContext context = getServletConfig().getServletContext(); for (final Enumeration<String> e = context.getInitParameterNames(); e .hasMoreElements();) { for (final Enumeration<String> e = getServletConfig() .getInitParameterNames(); e.hasMoreElements();) { final String name = e.nextElement(); initParameters.setProperty(name, getServletConfig().getInitParameter(name)); return createDeploymentConfiguration(initParameters);
@Override protected InputStream getApplicationResourceAsStream(Class<?> contextClass, String fileName) { ServletContext servletContext = VaadinServlet.getCurrent().getServletContext(); return servletContext.getResourceAsStream("/VAADIN/" + fileName); } }
final ServletContext sc = getServletContext(); URL resourceUrl = findResourceURL(filename); if (serveOnTheFlyCompiledScss(filename, request, response, sc)) { return; } else { getLogger().log(Level.INFO, "Requested resource [{0}] not found from filesystem or through class loader." + " Add widgetset and/or theme JAR to your classpath or add files to WebContent/VAADIN folder.", if (!isAllowedVAADINResourceUrl(request, resourceUrl)) { getLogger().log(Level.INFO, "Requested resource [{0}] not accessible in the VAADIN directory or access to it is forbidden.", filename); int resourceCacheTime = getCacheTime(filename); if (resourceCacheTime > 0) { cacheControl = "max-age=" + String.valueOf(resourceCacheTime); if (browserHasNewestVersion(request, lastModifiedTime)) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return; getLogger().log(Level.FINEST, "Failed to find out last modified timestamp. Continuing without it.", e); getLogger().log(Level.INFO,
public void init(javax.servlet.ServletConfig servletConfig) throws ServletException { verifyServletVersion(); CurrentInstance.clearAll(); super.init(servletConfig); Properties initParameters = new Properties(); readUiFromEnclosingClass(initParameters); readConfigurationAnnotation(initParameters); DeploymentConfiguration deploymentConfiguration = createDeploymentConfiguration( initParameters); try { servletService = createServletService(deploymentConfiguration); } catch (ServiceException e) { throw new ServletException("Could not initialize VaadinServlet", e); staticFileServer = createStaticFileServer(); servletInitialized(); CurrentInstance.clearAll();
/** * Finds the given resource from the web content folder or using the class * loader. * * @since 7.7 * @param filename * The file to find, starting with a "/" * @return The URL to the given file, or null if the file was not found * @throws IOException * if there was a problem while locating the file */ public URL findResourceURL(String filename) throws IOException { URL resourceUrl = getServletContext().getResource(filename); if (resourceUrl == null) { // try if requested file is found from class loader // strip leading "/" otherwise stream from JAR wont work if (filename.startsWith("/")) { filename = filename.substring(1); } resourceUrl = getService().getClassLoader().getResource(filename); } return resourceUrl; }
@Override protected void servletInitialized() throws ServletException { super.servletInitialized(); // Make self-internal scssCache dirtily accessible try { Field field = VaadinServlet.class.getDeclaredField("scssCache"); field.setAccessible(true); scssCache = (Map<String, Object>) field.get(this); } catch (ReflectiveOperationException e) { log("Unable to initialize reference to inner Scss cache for the Vaadin servlet; caching won't be disabled.", e); } }
public StubVaadinSession(EventBus eventBus) { this.eventBus = eventBus; final VaadinServlet vaadinServlet = mock(VaadinServlet.class); final ServletConfig servletConfig = mock(ServletConfig.class); this.context = mock(ServletContext.class); doReturn(context).when(servletConfig).getServletContext(); doReturn(servletConfig).when(vaadinServlet).getServletConfig(); doReturn(context).when(vaadinServlet).getServletContext(); this.ui = mock(UI.class); doReturn("foo").when(ui).getEmbedId(); this.vaadinService = mock(VaadinServletService.class); doReturn(vaadinServlet).when(vaadinService).getServlet(); this.vaadinSession = new VaadinSession(vaadinService) { @Override public boolean hasLock() { return true; } }; this.vaadinSession.setAttribute(UI.class, this.ui); this.sessionStore = new SessionStore(vaadinSession, eventBus); this.vaadinSession.setAttribute(SessionStore.class, sessionStore); }
@Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String pathInfo = request.getPathInfo(); if (pathInfo != null && request.getPathInfo().startsWith( "/VAADIN/themes/touchkit/styles.css")) { serveDummyFile(response); } else { super.service(request, response); } }
protected VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration) throws ServiceException { final VaadinServletService service = super.createServletService(deploymentConfiguration); service.addSessionInitListener(new SessionInitListener() { public void sessionInit(SessionInitEvent event) throws ServiceException { event.getSession().addUIProvider(new DevUIProvider(ui, theme)); } }); return service; } }
/** * This method captures the parameters from appropriate methods and sets the servlet parameters accordingly. * <p> * <pre> * vaadin {<br> * version vaadinVersion<br> * widgetset "uk.q3c.krail.demo.widgetset.demoWidgetset"<br> * } * </pre> * <p> * @see <a href="https://github.com/johndevs/gradle-vaadin-plugin"> https://github.com/johndevs/gradle-vaadin-plugin</a> * @see com.vaadin.server.VaadinServlet#createDeploymentConfiguration(java.util.Properties) */ @Override protected DeploymentConfiguration createDeploymentConfiguration(Properties initParameters) { log.debug("creating deployment configuration"); if (!"default".equals(widgetset())) { log.debug("Setting widgetset parameter to '{}'", widgetset()); initParameters.setProperty("widgetset", widgetset()); } else { log.debug("Using default widgetset"); } initParameters.setProperty("productionMode", Boolean.toString(productionMode())); return super.createDeploymentConfiguration(initParameters); }
@Override public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); getService().addSessionInitListener((SessionInitEvent event) -> { try { onVaadinSessionStarted(event.getRequest(), event.getSession()); } catch (ServletException e) { throw new ServiceException(e); } }); }
/** * Allows the only UI's Guice component provider to be injected. */ @Provides GuiceComponentProvider getUiGuiceComponentProvider() { return (GuiceComponentProvider) VaadinServlet.getCurrent().getServletContext().getAttribute("componentProvider"); }
@Override protected void servletInitialized() throws ServletException { super.servletInitialized(); ApplicationContext applicationContext = AppContext.getApplicationContext(); List<BootstrapListener> bootstrapListeners = applicationContext.getBeansOfType(BootstrapListener.class) .values().stream() .sorted(AnnotationAwareOrderComparator.INSTANCE) .collect(Collectors.toList()); getService().addSessionInitListener(event -> bootstrapListeners.forEach(event.getSession()::addBootstrapListener) ); }
@Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String requestURI = ServletUtil.stripPathParameters(request.getRequestURI()); if (StringUtils.endsWith(requestURI, ".css") && scssCache != null) { scssCache.clear(); } super.service(request, response); } }
@Override protected VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration) throws ServiceException { final VaadinServletService service = super.createServletService(deploymentConfiguration); initializePlugin(service); return service; } }