@Override @SuppressWarnings("unchecked") public void contextInitialized(ServletContextEvent event) { ApplicationRouteRegistry registry = ApplicationRouteRegistry .getInstance(event.getServletContext()); Stream<Class<? extends Component>> hasErrorComponents = findBySuperType( getErrorParameterPackages(), HasErrorParameter.class) .filter(Component.class::isAssignableFrom) .map(clazz -> (Class<? extends Component>) clazz); registry.setErrorNavigationTargets( hasErrorComponents.collect(Collectors.toSet())); }
@SuppressWarnings("unchecked") @Override public void onStartup(Set<Class<?>> classSet, ServletContext servletContext) throws ServletException { if (classSet == null) { classSet = new HashSet<>(); } Set<Class<? extends Component>> routes = classSet.stream() // Liberty 18 also includes the interface itself in the set... .filter(clazz -> clazz != HasErrorParameter.class) .map(clazz -> (Class<? extends Component>) clazz) .collect(Collectors.toSet()); ApplicationRouteRegistry.getInstance(servletContext) .setErrorNavigationTargets(routes); }
@Override protected RouteRegistry getRouteRegistry() { return ApplicationRouteRegistry.getInstance(getServlet().getServletContext()); }
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"); } }
ApplicationRouteRegistry reg = ApplicationRouteRegistry.getInstance(servletContext);
private void createAppServlet(ServletContext context) { if (!ApplicationRouteRegistry.getInstance(context).hasNavigationTargets()) { getLogger().info( "{} there are no navigation targets registered to the registry", SKIPPING_AUTOMATIC_SERVLET_REGISTRATION_BECAUSE); return; } ServletRegistration vaadinServlet = findVaadinServlet(context); if (vaadinServlet != null) { getLogger().info( "{} there is already a Vaadin servlet with the name {}", SKIPPING_AUTOMATIC_SERVLET_REGISTRATION_BECAUSE, vaadinServlet.getName()); return; } createServletIfNotExists(context, getClass().getName(), "/*"); }
@SuppressWarnings("unchecked") @Override public void contextInitialized(ServletContextEvent event) { ApplicationRouteRegistry registry = ApplicationRouteRegistry .getInstance(event.getServletContext()); if (registry.getRegisteredRoutes().isEmpty()) { try { List<Class<?>> routeClasses = findByAnnotation( getRoutePackages(), Route.class, RouteAlias.class).collect(Collectors.toList()); Set<Class<? extends Component>> navigationTargets = validateRouteClasses( routeClasses.stream()); RouteConfiguration routeConfiguration = RouteConfiguration .forRegistry(registry); routeConfiguration.update(() -> { routeConfiguration.getHandledRegistry().clean(); navigationTargets.forEach(routeConfiguration::setAnnotatedRoute); }); registry.setPwaConfigurationClass(validatePwaClass(routeClasses.stream())); } catch (InvalidRouteConfigurationException e) { throw new IllegalStateException(e); } } }
@Override public void onStartup(Set<Class<?>> classSet, ServletContext servletContext) throws ServletException { try { if (classSet == null) { ApplicationRouteRegistry routeRegistry = ApplicationRouteRegistry .getInstance(servletContext); routeRegistry.clean(); return; } Set<Class<? extends Component>> routes = validateRouteClasses( classSet.stream()); ApplicationRouteRegistry routeRegistry = ApplicationRouteRegistry .getInstance(servletContext); RouteConfiguration routeConfiguration = RouteConfiguration .forRegistry(routeRegistry); routeConfiguration.update(() -> { routeConfiguration.getHandledRegistry().clean(); for (Class<? extends Component> navigationTarget : routes) { routeConfiguration.setAnnotatedRoute(navigationTarget); } }); routeRegistry.setPwaConfigurationClass(validatePwaClass( routes.stream().map(clazz -> (Class<?>) clazz))); } catch (InvalidRouteConfigurationException irce) { throw new ServletException( "Exception while registering Routes on servlet startup", irce); } }
@Override public void onStartup(ServletContext servletContext) throws ServletException { // Verify servlet version also for SpringBoot. ServletVerifier.verifyServletVersion(); ApplicationRouteRegistry registry = ApplicationRouteRegistry .getInstance(servletContext); // If the registry is already initialized then RouteRegistryInitializer // has done its job already, skip the custom routes search if (registry.getRegisteredRoutes().isEmpty()) { /* * Don't rely on RouteRegistry.isInitialized() negative return value * here because it's not known whether RouteRegistryInitializer has * been executed already or not (the order is undefined). Postpone * this to the end of context initialization cycle. At this point * RouteRegistry is either initialized or it's not initialized * because an RouteRegistryInitializer has not been executed (end * never will). */ servletContext.addListener(new RouteServletContextListener()); } servletContext.addListener(new ErrorParameterServletContextListener()); servletContext .addListener(new AnnotationValidatorServletContextListener()); }
private static ApplicationRouteRegistry createRegistry( ServletContext context) { if (context != null && context == OSGiAccess.getInstance() .getOsgiServletContext()) { return new OSGiDataCollector(); } else if (OSGiAccess.getInstance().getOsgiServletContext() == null) { return new ApplicationRouteRegistry(); } OSGiRouteRegistry osgiRouteRegistry = new OSGiRouteRegistry(); OSGiDataCollector osgiDataCollector = (OSGiDataCollector) getInstance( OSGiAccess.getInstance().getOsgiServletContext()); osgiRouteRegistry.setRoutes(osgiDataCollector.getRegisteredRoutes()); osgiRouteRegistry.subscribeToChanges(osgiDataCollector); return osgiRouteRegistry; } }