/** Returns this Web application, or null if not available. * <p>Notice that this method is useful only if ZK libraries are * NOT shared by multiple Web application (in other words, * they are installed under <code>WEB-INF/lib</code>). * If you share ZK libraries among multiple applications (such as * installing them under <code>shared/lib</code>), the returned instance could * be any of them. * * <p>If you share ZK libraries among multiple applications, you could * retrieve the current Web application by one of the following * depending your context. * <ol> * <li>In an event listener:<br/> * <code>Sessions.getCurrent(false).getWebApp();</code><br/> * Note, since {@link Sessions#getCurrent(boolean)} returns null if it executes * in a working thread (without {@link Execution}).</li> * <li>In a working thread (not current execution):<br/> * <code>WebManager.getWebManager(servletContext).getWebApp();</code><br/> * As shown above, {@link org.zkoss.zk.ui.http.WebManager#getWebManager} * requires a servlet context.</li></ol> * @since 5.0.9 */ public static WebApp getCurrent() { final Session sess = Sessions.getCurrent(false); return sess != null ? sess.getWebApp() : _wapp; }
/** Returns the desktop of the specified ID, or null if not found. * If null is returned, {@link #recoverDesktop} will be invoked. * @param sess the session (never null) * @param dtid the desktop ID to look for * @since 5.0.3 */ protected Desktop getDesktop(Session sess, String dtid) { return ((WebAppCtrl) sess.getWebApp()).getDesktopCache(sess).getDesktopIfAny(dtid); }
public DesktopCache getDesktopCache(Session sess) { final WebApp wapp = sess.getWebApp(); DesktopCache dc = (DesktopCache) wapp.getAttribute(ATTR_CACHE); if (dc == null) { synchronized (this) { dc = (DesktopCache) wapp.getAttribute(ATTR_CACHE); if (dc == null) { dc = new SimpleDesktopCache(sess.getWebApp().getConfiguration()); wapp.setAttribute(ATTR_CACHE, dc); } } } return dc; }
/** Called when a servlet/portlet starts to serve a request. * It checks whether the number of concurrent requests per session * exceeds the number specified in * {@link org.zkoss.zk.ui.util.Configuration#getSessionMaxRequests}. * If exceeded, false is returned, and the servlet/portlet shall stop * processing and return an error code back the client. * * <p>If not exceeded, true is returned, and the servlet/portlet * can continue the processing and it shall invoke {@link #requestExit} * in the finally clause. * * @since 3.0.1 */ public static boolean requestEnter(Session sess) { final Integer v = (Integer) sess.getAttribute(ATTR_REQUEST_COUNT); final int i = v != null ? v.intValue() + 1 : 1; final int max = sess.getWebApp().getConfiguration().getSessionMaxRequests(); if (max < 0 || i <= max) { sess.setAttribute(ATTR_REQUEST_COUNT, new Integer(i)); return true; } return false; }
final String errpg = sess.getWebApp().getConfiguration().getErrorPage(sess.getDeviceType(), err); if (errpg != null) { try {
alert = "dtid is required!"; } else { desktop = ((WebAppCtrl) sess.getWebApp()).getDesktopCache(sess).getDesktop(dtid); final Map<String, Object> params = parseRequest(request, desktop, ""); nextURI = (String) params.get("nextURI");
final String errpg = sess.getWebApp().getConfiguration().getErrorPage(sess.getDeviceType(), err); if (errpg != null) { try {
final WebApp wapp = sess.getWebApp(); final WebAppCtrl wappc = (WebAppCtrl) wapp;
final Desktop desktop = ((WebAppCtrl)sess.getWebApp()) .getDesktopCache(sess).getDesktopIfAny(dtid); if (desktop == null) {
final String errpg = sess.getWebApp().getConfiguration().getErrorPage(sess.getDeviceType(), err); if (errpg != null) { try {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request instanceof HttpServletRequest) { HttpServletRequest reg = (HttpServletRequest) request; HttpServletResponse resp = (HttpServletResponse) response; final Session sess = WebManager.getSession(_config.getServletContext(), (HttpServletRequest) request); String path = Https.getThisPathInfo(request); if (path == null) { path = Https.getThisServletPath(request); } try { final Object old = I18Ns.setup(sess, request, response, sess.getWebApp().getConfiguration().getResponseCharset()); try { if (process(sess, reg, resp, path, true)) return; // done } catch (Throwable ex) { // pass } finally { I18Ns.cleanup(request, old); } } finally { SessionsCtrl.requestExit(sess); } } chain.doFilter(request, response); }
private static final Object setup(Object sess, ServletRequest request, ServletResponse response, String charset) { final Object[] old; if (request.getAttribute(ATTR_SETUP) != null) { //has been setup old = null; } else { final HttpSession hsess; if (sess instanceof Session) { final Session se = (Session) sess; //Invoke the request interceptors se.getWebApp().getConfiguration().invokeRequestInterceptors(se, request, response); hsess = (HttpSession) se.getNativeSession(); } else { hsess = (HttpSession) sess; } final Object ol = Charsets.setup(hsess, request, response, charset); //Charsets will handle PREFERRED_LOCALE //time zone final TimeZone tz = getTimeZone(hsess); final Object otz = TimeZones.setThreadLocal(tz); //date format info final DateFormatInfo dfinfo = getDateFormatInfo(hsess); final Object odi = DateFormats.setLocalFormatInfo(dfinfo); request.setAttribute(ATTR_SETUP, Boolean.TRUE); //mark as setup old = new Object[] { ol, otz, odi }; } if (sess instanceof Session) SessionsCtrl.setCurrent((Session) sess); return old; }
public void sessionDidActivate(Session sess) { _sess = sess; _wapp = sess.getWebApp(); Execution exec = Executions.getCurrent(); if (exec != null) { //not possible, but just in case sessDidActivate(); } else { exec = new org.zkoss.zk.ui.impl.PhantomExecution(this); safeActivate(exec); try { sessDidActivate(); if (_spushTemp != null) enableServerPush0(_spushTemp, true); } finally { safeDeactivate(exec); _spushTemp = null; } } }
protected boolean process(Session sess, HttpServletRequest request, HttpServletResponse response, String path, boolean bRichlet) throws ServletException, IOException { final WebApp wapp = sess.getWebApp(); final WebAppCtrl wappc = (WebAppCtrl) wapp; final Configuration config = wapp.getConfiguration();
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String path = Https.getThisPathInfo(request); final boolean bRichlet = path != null && path.length() > 0; if (!bRichlet) path = Https.getThisServletPath(request); // if (log.finerable()) log.finer("Creates from "+path); final Session sess = WebManager.getSession(getServletContext(), request); if (!SessionsCtrl.requestEnter(sess)) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, Messages.get(MZk.TOO_MANY_REQUESTS)); return; } try { final Object old = I18Ns.setup(sess, request, response, sess.getWebApp().getConfiguration().getResponseCharset()); try { if (!process(sess, request, response, path, bRichlet)) handleError(sess, request, response, path, null); } catch (Throwable ex) { handleError(sess, request, response, path, ex); } finally { I18Ns.cleanup(request, old); } } finally { SessionsCtrl.requestExit(sess); } }
public void service(HttpServletRequest request, HttpServletResponse response, String path) throws ServletException, IOException { String resourceCache = Library.getProperty("org.zkoss.zk.ZUML.cache", "true"); if (!Boolean.valueOf(resourceCache)) _cache.clear(); final Session sess = WebManager.getSession(getServletContext(), request); final PageDefinition pagedef = _cache.get(path); if (pagedef == null) { //FUTURE: support the error page (from Configuration) handleError(sess, request, response, path, null); return; } //mimic DHtmlLayoutServlet to process PageDefinition final Object old = I18Ns.setup(sess, request, response, sess.getWebApp().getConfiguration().getResponseCharset()); try { process(sess, request, response, pagedef, path); } catch (Throwable ex) { handleError(sess, request, response, path, ex); } finally { I18Ns.cleanup(request, old); } }
final WebApp wapp = sess.getWebApp(); final WebAppCtrl wappc = (WebAppCtrl) wapp; final Configuration config = wapp.getConfiguration();
HttpServletResponse httpres = RenderHttpServletResponse.getInstance(response); final Object old = I18Ns.setup(httpreq.getSession(), httpreq, httpres, sess.getWebApp().getConfiguration().getResponseCharset()); try { if (!process(sess, request, response, path, bRichlet))
Object old = I18Ns.setup(sess, request, response, "UTF-8"); try { final WebApp wapp = sess.getWebApp(); final WebAppCtrl wappc = (WebAppCtrl)wapp;
final WebApp wapp = sess.getWebApp(); final WebAppCtrl wappc = (WebAppCtrl) wapp; final Object old = I18Ns.setup(sess, request, response, wapp.getConfiguration().getResponseCharset());