/** * Gets a relative path you can use to refer to the context root. * * @param request * the request for which the location should be determined * @return A relative path to the context root. Never ends with a slash (/). */ public static String getContextRootRelativePath(VaadinRequest request) { VaadinServletRequest servletRequest = (VaadinServletRequest) request; // Generate location from the request by finding how many "../" should // be added to the servlet path before we get to the context root // Should not take pathinfo into account because the base URI refers to // the servlet path String servletPath = servletRequest.getServletPath(); assert servletPath != null; if (!servletPath.endsWith("/")) { servletPath += "/"; } return ServletHelper.getCancelingRelativePath(servletPath); }
/** * 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); } }