/** * 在指定的request context及其级联的request context中找到一个指定类型的request context。 * * @param webContext 要搜索的request context * @param webContextInterface 要查找的类 * @return <code>WebContext</code>对象,如果没找到,则返回<code>null</code> */ public static <R extends WebContext> R findWebContext(WebContext webContext, Class<R> webContextInterface) { do { if (webContextInterface.isInstance(webContext)) { break; } webContext = webContext.getWrappedWebContext(); } while (webContext != null); return webContextInterface.cast(webContext); }
/** * 在指定的request context及其级联的request context中找到一个指定类型的request context。 * * @param webContext 要搜索的request context * @param webContextInterface 要查找的类 * @return <code>WebContext</code>对象,如果没找到,则返回<code>null</code> */ public static <R extends WebContext> R findWebContext(WebContext webContext, Class<R> webContextInterface) { do { if (webContextInterface.isInstance(webContext)) { break; } webContext = webContext.getWrappedWebContext(); } while (webContext != null); return webContextInterface.cast(webContext); }
protected <T> T getFromWrapperContext(String name, WebContext webContext) { T result = getFromSubContext(name, webContext); if (result != null) { return result; } if (webContext.getWrappedWebContext() != null) { result = getFromWrapperContext(name, webContext.getWrappedWebContext()); if (result != null) { return result; } } return null; }
protected boolean existFromWrapperContext(String name, WebContext webContext) { boolean exist = existFromSubContext(name, webContext); if (exist) { return true; } if (webContext.getWrappedWebContext() != null) { exist = existFromWrapperContext(name, webContext.getWrappedWebContext()); if (exist) { return true; } } return false; }
/** * 判断请求是否已经结束。如果请求被重定向了,则表示请求已经结束。 * * @param webContext * @return */ private boolean isRequestFinished(int filterSize, WebContext webContext) { WebContext wrapContext = webContext; for (int i = 0; i < filterSize; i++) { if (wrapContext != null) { if (wrapContext.isRequestFinished()) { return true; } wrapContext = wrapContext.getWrappedWebContext(); } } return false; }
protected <T> T getFromWrapperContext(String name, WebContext webContext) { T result = (T) getFromSubContext(name, webContext); if (!ObjectUtil.isEmptyObject(result)) return result; if (webContext.getWrappedWebContext() != null) { result = (T) getFromWrapperContext(name, webContext.getWrappedWebContext()); if (!ObjectUtil.isEmptyObject(result)) { return result; } } return null; }
/** * 头部提交,保证内容只提交一次 * * @param wrapperedContext */ public void commitHeaders(WebContext wrapperedContext) { CommitMonitor monitor = getCommitMonitor(wrapperedContext); synchronized (monitor) { if (!monitor.isHeadersCommitted()) { monitor.setHeadersCommitted(true); for (WebContext rc = wrapperedContext; rc != null; rc = rc .getWrappedWebContext()) { if (rc instanceof TwoPhaseCommitWebContext) { TwoPhaseCommitWebContext tpc = (TwoPhaseCommitWebContext) rc; logger.logMessage(LogLevel.TRACE, "Committing headers: {}", tpc.getClass() .getSimpleName()); tpc.commitHeaders(); } } } } }
/** * * 头部提交,保证内容只提交一次 * * @param wrapperedContext */ public void commitHeaders(WebContext wrapperedContext) { CommitMonitor monitor = getCommitMonitor(wrapperedContext); synchronized (monitor) { if (!monitor.isHeadersCommitted()) { monitor.setHeadersCommitted(true); for (WebContext rc = wrapperedContext; rc != null; rc = rc .getWrappedWebContext()) { if (rc instanceof TwoPhaseCommitWebContext) { TwoPhaseCommitWebContext tpc = (TwoPhaseCommitWebContext) rc; logger.logMessage(LogLevel.TRACE, "Committing headers: {}", tpc.getClass() .getSimpleName()); tpc.commitHeaders(); } } } } }
wrapperedContext = wrapperedContext.getWrappedWebContext();
wrapperedContext = wrapperedContext.getWrappedWebContext();