public CdiVaadinServlet getServlet() { return (CdiVaadinServlet) super.getServlet(); }
/** * Creates a vaadin servlet service. * * @param deploymentConfiguration * the deployment configuration to be used * * @return the created vaadin servlet service * * @throws ServiceException * if creating the vaadin servlet service fails */ protected VaadinServletService createServletService( DeploymentConfiguration deploymentConfiguration) throws ServiceException { VaadinServletService service = new VaadinServletService(this, deploymentConfiguration); service.init(); return service; }
@Override public URL getStaticResource(String path) { URL resource = super.getStaticResource(path); if (resource == null) { resource = getResourceURL(path); } return resource; }
@Override public URL getStaticResource(String path) { try { return getServlet().getServletContext().getResource(path); } catch (MalformedURLException e) { getLogger().warn("Error finding resource for '{}'", path, e); } return null; }
/** * Finds the given resource in the servlet context or in a webjar. * * @param path * the path inside servlet context, automatically translated as * needed for webjars * @return a URL for the resource or <code>null</code> if no resource was * found */ private URL getResourceInServletContextOrWebJar(String path) { ServletContext servletContext = getServlet().getServletContext(); try { URL url = servletContext.getResource(path); if (url != null) { return url; } Optional<String> webJarPath = getWebJarPath(path); if (webJarPath.isPresent()) { return servletContext.getResource(webJarPath.get()); } } catch (MalformedURLException e) { getLogger().warn("Error finding resource for '{}'", path, e); } return null; }
service.requestStart(vaadinRequest, null); session = service.findVaadinSession(vaadinRequest); assert VaadinSession.getCurrent() == session; } catch (SessionExpiredException e) { session.lock(); try { ui = service.findUI(vaadinRequest); assert UI.getCurrent() == ui; callErrorHandler(session, e); } catch (final Exception e) { SystemMessages msg = service.getSystemMessages( ServletHelper.findLocale(null, vaadinRequest), vaadinRequest); try { if (websocket) { service.requestEnd(vaadinRequest, null, session);
@Override public void init() throws ServiceException { addSessionDestroyListener(new Listener()); addServiceDestroyListener(this::fireCdiDestroyEvent); super.init(); }
/** * Opens a stream for the given resource found in the servlet context or in * a webjar. * * @param path * the path inside servlet context, automatically translated as * needed for webjars * @return a URL for the resource or <code>null</code> if no resource was * found */ private InputStream getResourceInServletContextOrWebJarAsStream( String path) { ServletContext servletContext = getServlet().getServletContext(); InputStream stream = servletContext.getResourceAsStream(path); if (stream != null) { return stream; } Optional<String> webJarPath = getWebJarPath(path); if (webJarPath.isPresent()) { return servletContext.getResourceAsStream(webJarPath.get()); } return null; }
throws ServiceException { service.addServiceDestroyListener(event -> destroy()); final ServletConfig vaadinServletConfig = service.getServlet() .getServletConfig(); throw new ServiceException( "Failed to initialize Atmosphere for " + service.getServlet().getServletName() + ". Push will not work.", e);
@Override protected Optional<Instantiator> loadInstantiators() throws ServiceException { Optional<Instantiator> spiInstantiator = super.loadInstantiators(); List<Instantiator> springInstantiators = context .getBeansOfType(Instantiator.class).values().stream() .filter(instantiator -> instantiator.init(this)) .collect(Collectors.toList()); if (spiInstantiator.isPresent() && !springInstantiators.isEmpty()) { throw new ServiceException( "Cannot init VaadinService because there are multiple eligible " + "instantiator implementations: Java SPI registered instantiator " + spiInstantiator.get() + " and Spring instantiator beans: " + springInstantiators); } if (!spiInstantiator.isPresent() && springInstantiators.isEmpty()) { Instantiator defaultInstantiator = new SpringInstantiator(this, context); defaultInstantiator.init(this); return Optional.of(defaultInstantiator); } return spiInstantiator.isPresent() ? spiInstantiator : springInstantiators.stream().findFirst(); }
session = service.findVaadinSession(vaadinRequest); } catch (SessionExpiredException e) { VaadinSession.setCurrent(session); ui = service.findUI(vaadinRequest); if (ui == null) {
@Override public void destroy() { super.destroy(); getService().destroy(); }
@Override public void init() throws ServiceException { lookup(SystemMessagesProvider.class) .ifPresent(this::setSystemMessagesProvider); addUIInitListener(beanManager::fireEvent); addSessionInitListener(this::sessionInit); addSessionDestroyListener(this::sessionDestroy); addServiceDestroyListener(this::fireCdiDestroyEvent); super.init(); }
@Override protected Optional<Instantiator> loadInstantiators() throws ServiceException { Optional<Instantiator> spiInstantiator = super.loadInstantiators(); List<Instantiator> springInstantiators = context .getBeansOfType(Instantiator.class).values().stream() .filter(instantiator -> instantiator.init(this)) .collect(Collectors.toList()); if (spiInstantiator.isPresent() && !springInstantiators.isEmpty()) { throw new ServiceException( "Cannot init VaadinService because there are multiple eligible " + "instantiator implementations: Java SPI registered instantiator " + spiInstantiator.get() + " and Spring instantiator beans: " + springInstantiators); } if (!spiInstantiator.isPresent() && springInstantiators.isEmpty()) { Instantiator defaultInstantiator = new SpringInstantiator(this, context); defaultInstantiator.init(this); return Optional.of(defaultInstantiator); } return spiInstantiator.isPresent() ? spiInstantiator : springInstantiators.stream().findFirst(); }
@Override public CdiVaadinServlet getServlet() { return (CdiVaadinServlet) super.getServlet(); }
@Override public void init() throws ServiceException { lookup(SystemMessagesProvider.class) .ifPresent(this::setSystemMessagesProvider); addUIInitListener(beanManager::fireEvent); addSessionInitListener(this::sessionInit); addSessionDestroyListener(this::sessionDestroy); addServiceDestroyListener(this::fireCdiDestroyEvent); super.init(); }
@Override public boolean isStaticResourceRequest(HttpServletRequest request) { URL resource; String requestFilename = getRequestFilename(request); if (requestFilename.endsWith("/")) { // Directories are not static resources although // servletContext.getResource will return a URL for them, at // least with Jetty return false; } if (requestFilename.startsWith( "/" + ApplicationConstants.VAADIN_STATIC_FILES_PATH)) { // The path is reserved for internal static resources only // We rather serve 404 than let it fall through return true; } resource = servletService.getStaticResource(requestFilename); return resource != null; }
public CdiVaadinServlet getServlet() { return (CdiVaadinServlet) super.getServlet(); }
@Override public boolean serveStaticResource(HttpServletRequest request, HttpServletResponse response) throws IOException { String filenameWithPath = getRequestFilename(request); URL resourceUrl = servletService.getStaticResource(filenameWithPath); if (resourceUrl == null) { // Not found in webcontent or in META-INF/resources in some JAR response.sendError(HttpServletResponse.SC_NOT_FOUND); return true; } // There is a resource! // Intentionally writing cache headers also for 304 responses writeCacheHeaders(filenameWithPath, response); long timestamp = writeModificationTimestamp(resourceUrl, request, response); if (browserHasNewestVersion(request, timestamp)) { // Browser is up to date, nothing further to do than set the // response code response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return true; } responseWriter.writeResponseContents(filenameWithPath, resourceUrl, request, response); return true; }
@Override protected PwaRegistry getPwaRegistry() { return Optional.ofNullable(getServlet()) .map(GenericServlet::getServletContext) .map(PwaRegistry::getInstance).orElse(null); }