@Override public String getRequestPath() { return request.getPathInfo(); }
@Override public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException { String requestUri = request.getPathInfo(); if (pwaRegistry.getPwaConfiguration().isEnabled()) { if (requestHandlerMap.containsKey(requestUri)) { return requestHandlerMap.get(requestUri) .handleRequest(session,request,response); } else if (requestUri.startsWith("/"+PwaRegistry.WORKBOX_FOLDER)) { // allow only files under workbox_folder String resourceName = PwaRegistry.WORKBOX_FOLDER + requestUri // remove the extra '/' .substring(PwaRegistry.WORKBOX_FOLDER.length() + 1) .replaceAll("/", ""); return handleWorkboxResource(resourceName, response); } } return false; }
/** * Gets the service URL as a URL relative to the request URI. * * @param context * the bootstrap context * @return the relative service URL */ protected static String getServiceUrl(BootstrapContext context) { String pathInfo = context.getRequest().getPathInfo(); if (pathInfo == null) { return "."; } else { /* * Make a relative URL to the servlet by adding one ../ for each * path segment in pathInfo (i.e. the part of the requested path * that comes after the servlet mapping) */ return ServletHelper.getCancelingRelativePath(pathInfo); } }
/** * Returns the UI class mapped for servlet that handles the given request. * <p> * This method is protected for testing purposes. * * @param request * the request for the UI * @return the UI class for the request */ protected static Class<? extends UI> getUIClass(VaadinRequest request) { String uiClassName = request.getService().getDeploymentConfiguration() .getUIClassName(); if (uiClassName == null) { throw new BootstrapException( "Could not determine the uiClassName for the request path " + request.getPathInfo()); } ClassLoader classLoader = request.getService().getClassLoader(); try { return Class.forName(uiClassName, true, classLoader) .asSubclass(UI.class); } catch (ClassNotFoundException e) { throw new BootstrapException( "Vaadin Servlet mapped to the request path " + request.getPathInfo() + " cannot find the mapped UI class with name " + uiClassName, e); } }
VaadinResponse response) throws IOException { String pathInfo = request.getPathInfo(); if (pathInfo == null) { return false;
/** * Finds the class on on which page configuration annotation should be * defined. * * @param ui * the UI for which to do the lookup, not <code>null</code> * @param request * the request for which to do the lookup, not <code>null</code> * @return the class for which page configuration annotations should be * defined, or an empty optional if no such class is available */ public static Optional<Class<?>> resolvePageConfigurationHolder(UI ui, VaadinRequest request) { assert ui != null; assert request != null; if (ui.getRouter() == null) { return Optional.empty(); } return ui.getRouter().resolveNavigationTarget(request.getPathInfo(), request.getParameterMap()).map(navigationState -> { Class<? extends RouterLayout> parentLayout = getTopParentLayout( ui.getRouter(), navigationState); if (parentLayout != null) { return parentLayout; } return navigationState.getNavigationTarget(); }); }
private static InitialPageSettings createInitialPageSettingsObject( BootstrapHandler.BootstrapContext context) { UI ui = context.getUI(); VaadinRequest request = context.getRequest(); WebBrowser browser = context.getSession().getBrowser(); String pathInfo = request.getPathInfo(); if (pathInfo == null) { pathInfo = ""; } else { assert pathInfo.startsWith("/"); pathInfo = pathInfo.substring(1); } Router router = ui.getRouter(); NavigationEvent navigationEvent = new NavigationEvent(router, new Location(pathInfo, QueryParameters.full(request.getParameterMap())), ui, NavigationTrigger.PAGE_LOAD); List<HasElement> components = ui.getChildren() .map(component -> (HasElement) component) .collect(Collectors.toList()); AfterNavigationEvent afterNavigationEvent = new AfterNavigationEvent( new LocationChangeEvent(navigationEvent.getSource(), navigationEvent.getUI(), navigationEvent.getTrigger(), navigationEvent.getLocation(), components)); return new InitialPageSettings(request, ui, afterNavigationEvent, browser); }
/** * Enables navigation for a new UI instance. This initializes the UI content * based on the location used for loading the UI and sets up the UI to be * updated when the user navigates to some other location. * * @param ui * the UI that navigation should be set up for * @param initRequest * the Vaadin request that bootstraps the provided UI */ public void initializeUI(UI ui, VaadinRequest initRequest) { Location location = getLocationForRequest(initRequest.getPathInfo(), initRequest.getParameterMap()); ui.getPage().getHistory().setHistoryStateChangeHandler( e -> navigate(ui, e.getLocation(), e.getTrigger())); int statusCode = navigate(ui, location, NavigationTrigger.PAGE_LOAD); VaadinResponse response = VaadinService.getCurrentResponse(); if (response != null) { response.setStatus(statusCode); } }