/** * 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); }
@Override protected boolean canHandleRequest(VaadinRequest request) { return ServletHelper.isRequestType(request, RequestType.HEARTBEAT); }
if (ServletHelper.isRequestType(request, RequestType.UIDL)) { ServletHelper.findLocale(null, request), request); getService().writeUncachedStringResponse(response, JsonConstants.JSON_CONTENT_TYPE,
Locale locale = ServletHelper.findLocale(session, request); String contextRoot = ServletHelper.getContextRootRelativePath(request) + "/"; appConfig.put(ApplicationConstants.CONTEXT_ROOT_URL, contextRoot);
private static Element getPushScript(BootstrapContext context) { VaadinRequest request = context.getRequest(); // Parameter appended to JS to bypass caches after version upgrade. String versionQueryParam = "?v=" + Version.getFullVersion(); // Load client-side dependencies for push support String pushJSPath = ServletHelper.getContextRootRelativePath(request) + "/"; if (request.getService().getDeploymentConfiguration() .isProductionMode()) { pushJSPath += ApplicationConstants.VAADIN_PUSH_JS; } else { pushJSPath += ApplicationConstants.VAADIN_PUSH_DEBUG_JS; } pushJSPath += versionQueryParam; return createJavaScriptElement(pushJSPath); }
ServletHelper.findLocale(null, request), request); String sessionExpiredURL = systemMessages.getSessionExpiredURL(); if (sessionExpiredURL != null
@Override public boolean synchronizedHandleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException { // Find UI class Class<? extends UI> uiClass = getUIClass(request); BootstrapContext context = createAndInitUI(uiClass, request, response, session); ServletHelper.setResponseNoCacheHeaders(response::setHeader, response::setDateHeader); Document document = getBootstrapPage(context); writeBootstrapPage(response, document.outerHtml()); return true; }
if (ServletHelper.isRequestType(request, RequestType.UIDL)) { SystemMessages ci = getSystemMessages( ServletHelper.findLocale(vaadinSession, request), request); try {
UI ui = ReflectTools.createInstance(uiClass); ui.getInternals().setContextRoot( ServletHelper.getContextRootRelativePath(request) + "/");
} catch (final Exception e) { SystemMessages msg = service.getSystemMessages( ServletHelper.findLocale(null, vaadinRequest), vaadinRequest);
@Override protected boolean canHandleRequest(VaadinRequest request) { return ServletHelper.isRequestType(request, RequestType.UIDL); }
/** * 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); } }
@Override public boolean handleSessionExpired(VaadinRequest request, VaadinResponse response) throws IOException { if (!ServletHelper.isRequestType(request, RequestType.HEARTBEAT)) { return false; } response.sendError(HttpServletResponse.SC_GONE, "Session expired"); return true; } }
@Override public boolean handleSessionExpired(VaadinRequest request, VaadinResponse response) throws IOException { if (!ServletHelper.isRequestType(request, RequestType.UIDL)) { return false; } VaadinService service = request.getService(); service.writeUncachedStringResponse(response, JsonConstants.JSON_CONTENT_TYPE, VaadinService.createSessionExpiredJSON()); return true; }
@Override public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException { if (!ServletHelper.isRequestType(request, RequestType.PUSH)) { return false; } if (request instanceof VaadinServletRequest) { if (atmosphere == null) { response.sendError(500, "Atmosphere initialization failed. No push available."); return true; } try { atmosphere.doCometSupport( AtmosphereRequestImpl .wrap((VaadinServletRequest) request), AtmosphereResponseImpl .wrap((VaadinServletResponse) response)); } catch (ServletException e) { // TODO PUSH decide how to handle throw new RuntimeException(e); } } else { throw new IllegalArgumentException( "Only VaadinServletRequests are supported"); } return true; }