public CdiVaadinServlet getServlet() { return (CdiVaadinServlet) super.getServlet(); }
@Override public CdiVaadinServlet getServlet() { return (CdiVaadinServlet) super.getServlet(); }
public CdiVaadinServlet getServlet() { return (CdiVaadinServlet) super.getServlet(); }
@Override protected PwaRegistry getPwaRegistry() { return Optional.ofNullable(getServlet()) .map(GenericServlet::getServletContext) .map(PwaRegistry::getInstance).orElse(null); }
@Override public String getServiceName() { return getServlet().getServletName(); }
@Override public String getMimeType(String resourceName) { return getServlet().getServletContext().getMimeType(resourceName); }
@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; }
/** * Gets the currently used Vaadin servlet. The current servlet is * automatically defined when initializing the servlet and when processing * requests to the server (see {@link ThreadLocal}) and in * {@link VaadinSession#access(Command)} and {@link UI#access(Command)}. In * other cases, (e.g. from background threads), the current servlet is not * automatically defined. * <p> * The current servlet is derived from the current service using * {@link VaadinService#getCurrent()} * * @return the current Vaadin servlet instance if available, otherwise * <code>null</code> * */ public static VaadinServlet getCurrent() { VaadinService vaadinService = CurrentInstance.get(VaadinService.class); if (vaadinService instanceof VaadinServletService) { VaadinServletService vss = (VaadinServletService) vaadinService; return vss.getServlet(); } else { return null; } }
/** * Finds a resource for the given path inside a webjar. * * @param path * the resource path * @return the path to the resource inside a webjar or <code>null</code> if * the resource was not found in a webjar */ private Optional<String> getWebJarPath(String path) { return getServlet().getWebJarServer() .flatMap(server -> server.getWebJarResourcePath(path)); }
@Override public String getMainDivId(VaadinSession session, VaadinRequest request) { String appId = null; try { @SuppressWarnings("deprecation") URL appUrl = getServlet() .getApplicationUrl((VaadinServletRequest) request); appId = appUrl.getPath(); } catch (MalformedURLException e) { // Just ignore problem here } if (appId == null || "".equals(appId) || "/".equals(appId)) { appId = "ROOT"; } appId = appId.replaceAll("[^a-zA-Z0-9]", ""); // Add hashCode to the end, so that it is still (sort of) // predictable, but indicates that it should not be used in CSS // and // such: int hashCode = appId.hashCode(); if (hashCode < 0) { hashCode = -hashCode; } appId = appId + "-" + hashCode; return appId; }
@Override protected RouteRegistry getRouteRegistry() { return ApplicationRouteRegistry.getInstance(getServlet().getServletContext()); }
/** * 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; }
private static RouteRegistry getApplicationRegistry() { VaadinService service = VaadinService.getCurrent(); if (service instanceof VaadinServletService) { return ApplicationRouteRegistry .getInstance(((VaadinServletService) service).getServlet() .getServletContext()); } else { // TODO Once we have PortletService, this will explode // we will need route registry for portlet context throw new IllegalStateException("Cannot access " + ApplicationRouteRegistry.class.getName() + ", because no " + "VaadinServletService available for " + "fetching ServletContext"); } }
/** * 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 destroy event observer. * * During application shutdown it is container specific whether * this observer being called, or not. * Application context destroy may happen earlier, and cleanup * done by {@link #destroyAll()}. * * @param event service destroy event */ private void onServiceDestroy(@Observes(notifyObserver = IF_EXISTS) ServiceDestroyEvent event) { if (!(event.getSource() instanceof VaadinServletService)) { return; } VaadinServletService service = (VaadinServletService) event.getSource(); String servletName = service.getServlet().getServletName(); destroy(servletName); }
/** * Service destroy event observer. * * During application shutdown it is container specific whether * this observer being called, or not. * Application context destroy may happen earlier, and cleanup * done by {@link #destroyAll()}. * * @param event service destroy event */ private void onServiceDestroy(@Observes(notifyObserver = IF_EXISTS) ServiceDestroyEvent event) { if (!(event.getSource() instanceof VaadinServletService)) { return; } VaadinServletService service = (VaadinServletService) event.getSource(); String servletName = service.getServlet().getServletName(); destroy(servletName); }
/** * Service destroy event observer. * * During application shutdown it is container specific whether * this observer being called, or not. * Application context destroy may happen earlier, and cleanup * done by {@link #destroyAll()}. * * @param event service destroy event */ private void onServiceDestroy(@Observes(notifyObserver = IF_EXISTS) ServiceDestroyEvent event) { if (!(event.getSource() instanceof VaadinServletService)) { return; } VaadinServletService service = (VaadinServletService) event.getSource(); String servletName = service.getServlet().getServletName(); destroy(servletName); }
final ServletConfig vaadinServletConfig = service.getServlet() .getServletConfig(); throw new ServiceException( "Failed to initialize Atmosphere for " + service.getServlet().getServletName() + ". Push will not work.", e);