filter builder_苹果数据分析代码怎么看

filter builder_苹果数据分析代码怎么看在FilterDispatcher中首先关注的方法是init()和doFilter(),两个有用的局部变量(或者状态)[code="java"]privateFilterConfigfilterConfig;protectedDispatcherdispatcher;[/code]filterConfig用来向filter传递信息,提供了四个方法:[code="java"]…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺
在FilterDispatcher中首先关注的方法是init()和doFilter(),两个有用的局部变量(或者状态)

private FilterConfig filterConfig;
protected Dispatcher dispatcher;

filterConfig用来向filter传递信息,提供了四个方法:

public abstract java.lang.String getFilterName();
public abstract javax.servlet.ServletContext getServletContext();
public abstract java.lang.String getInitParameter(java.lang.String arg0);
public abstract java.util.Enumeration getInitParameterNames();

dispatcher做了FilterDispatcher大部分的工作。

首先来看init方法:


public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
//把filterConfig中的parameters和servletContext传递给new Dispatcher(filterConfig.getServletContext(), params)
dispatcher = createDispatcher(filterConfig);
//加载各种配置
dispatcher.init();

String param = filterConfig.getInitParameter("packages");
String packages = DEFAULT_STATIC_PACKAGES;
if (param != null) {
packages = param + " " + packages;
}
this.pathPrefixes = parse(packages);
}

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {


HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
ServletContext servletContext = getServletContext();

String timerKey = "FilterDispatcher_doFilter: ";
try {
UtilTimerStack.push(timerKey);
request = prepareDispatcherAndWrapRequest(request, response);
ActionMapping mapping;//ActionMapping有四个字段 method, name, namespace,params, result对应着XML配置文件
try {
//装配mappings
mapping = actionMapper.getMapping(request, dispatcher.getConfigurationManager());
} catch (Exception ex) {
LOG.error("error getting ActionMapping", ex);
dispatcher.sendError(request, response, servletContext, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex);
return;
}
// 如果mapping是空的,则去找static的内容
if (mapping == null) {

String resourcePath = RequestUtils.getServletPath(request);

if ("".equals(resourcePath) && null != request.getPathInfo()) {
resourcePath = request.getPathInfo();
}

if (serveStatic && resourcePath.startsWith("/struts")) {
findStaticResource(resourcePath, findAndCheckResources(resourcePath), request, response);
} else {
// this is a normal request, let it pass through
chain.doFilter(request, response);
}
// The framework did its job here
return;
}
//这个方法是关键
dispatcher.serviceAction(request, response, servletContext, mapping);

} finally {
try {
ActionContextCleanUp.cleanUp(req);
} finally {
UtilTimerStack.pop(timerKey);
}
}
}

我们再来查看Dispatcher中的serviceAction。


public void serviceAction(HttpServletRequest request, HttpServletResponse response, ServletContext context,
ActionMapping mapping) throws ServletException {

//创建上下文,extraContext中包括parameterMap, sessionMap, applicationMap, locale, request, response, servletContext等等
Map<String, Object> extraContext = createContextMap(request, response, mapping, context);

//如果request之前有value stack,则复制一个并把它放到上下文中。
ValueStack stack = (ValueStack) request.getAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY);
if (stack != null) {
extraContext.put(ActionContext.VALUE_STACK, ValueStackFactory.getFactory().createValueStack(stack));
}

String timerKey = "Handling request from Dispatcher";
try {
UtilTimerStack.push(timerKey);
String namespace = mapping.getNamespace();
String name = mapping.getName();
String method = mapping.getMethod();

Configuration config = configurationManager.getConfiguration();
//利用工厂方法新建一个ActionProxy,它提供诸多代理方法。
ActionProxy proxy = config.getContainer().getInstance(ActionProxyFactory.class).createActionProxy(
namespace, name, extraContext, true, false);
proxy.setMethod(method);
request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, proxy.getInvocation().getStack());

// 如果mapping中定义了Result,则运行这个Result。Result还是非常值得一讲的
if (mapping.getResult() != null) {
Result result = mapping.getResult();
result.execute(proxy.getInvocation());
} else {
//没有则运行execute,即调用Invocation.invoke()
proxy.execute();
}

// If there was a previous value stack then set it back onto the request
if (stack != null) {
request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, stack);
}
} catch (ConfigurationException e) {
LOG.error("Could not find action or result", e);
sendError(request, response, context, HttpServletResponse.SC_NOT_FOUND, e);
} catch (Exception e) {
throw new ServletException(e);
} finally {
UtilTimerStack.pop(timerKey);
}
}


public interface ActionProxy {

/** 在所有的依赖都配置好调用,在DefaultActionProxyFactory.createActionProxy中使用 */
void prepare() throws Exception;

/** @return 返回所代理的对象 */
Object getAction();

/** @return 返回所代理的对象的名字 */
String getActionName();

/** @return ActionProxy产生所借助的ActionConfig */
ActionConfig getConfig();

/** 设置是否在运行完Action之后运行Action所返回的Result */
void setExecuteResult(boolean executeResult);

/** @return the status of whether the ActionProxy is set to execute the Result after the Action is executed
*/
boolean getExecuteResult();

/** @return the ActionInvocation:表示Action的运行状态,包括Interceptors和Action的实例 */
ActionInvocation getInvocation();

/**
* @return the namespace the ActionConfig for this ActionProxy is mapped to
*/
String getNamespace();

/**
* 运行ActionProxy. 把ActionContext 设置为 ActionInvocation中的 ActionContext
* 关键还是调用ActionInvocation.invoke()。
* DefaultActionProxy中的实现
*public String execute() throws Exception {
* ActionContext nestedContext = ActionContext.getContext();
* ActionContext.setContext(invocation.getInvocationContext());

* String retCode = null;

* String profileKey = "execute: ";
* try {
* UtilTimerStack.push(profileKey);

* retCode = invocation.invoke();
* } finally {
* if (cleanupContext) {
* ActionContext.setContext(nestedContext);
* }
* UtilTimerStack.pop(profileKey);
* }

* return retCode;
*}
*/
String execute() throws Exception;

/** 设置Invocation中的Method的,如果空的话就用execute。 */
void setMethod(String method);

/**
* Returns the method to execute, or null if no method has been specified (meaning "execute" will be invoked)
*/
String getMethod();

}

再来看一下ActionInvocation.invoke()的实现:


public String invoke() throws Exception {
String profileKey = "invoke: ";
try {
UtilTimerStack.push(profileKey);
//如果运行过了,就抛出异常
if (executed) {
throw new IllegalStateException("Action has already executed");
}
//运行Interceptor
if (interceptors.hasNext()) {
final InterceptorMapping interceptor = (InterceptorMapping) interceptors.next();
//UtilTimerStack.profile()即
/*public static <T> T profile(String name, ProfilingBlock<T> block) throws Exception {
UtilTimerStack.push(name);
try {
return block.doProfiling();
}
finally {
UtilTimerStack.pop(name);
}
}*/
UtilTimerStack.profile("interceptor: "+interceptor.getName(),
new UtilTimerStack.ProfilingBlock<String>() {
public String doProfiling() throws Exception {
resultCode = interceptor.getInterceptor().intercept(DefaultActionInvocation.this);
return null;
}
});
} else {
resultCode = invokeActionOnly();
}

// this is needed because the result will be executed, then control will return to the Interceptor, which will
// return above and flow through again

[color=red]没看懂,好像是由于在下面还要调用result.execute(ActionInvocation),那么还是有可能再次调用这个地方?[/color]
if (!executed) {
if (preResultListeners != null) {
for (Iterator iterator = preResultListeners.iterator();
iterator.hasNext();) {
PreResultListener listener = (PreResultListener) iterator.next();

String _profileKey="preResultListener: ";
try {
UtilTimerStack.push(_profileKey);
listener.beforeResult(this, resultCode);
}
finally {
UtilTimerStack.pop(_profileKey);
}
}
}

// now execute the result, if we're supposed to
if (proxy.getExecuteResult()) {
//调用result.execute(ActionInvocation);
executeResult();
}

executed = true;
}

return resultCode;
}
finally {
UtilTimerStack.pop(profileKey);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/170656.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 《JavaScript 模式》读书笔记(6)— 代码复用模式1

    我们有开始进入新篇章了。这篇内容主要讲代码复用模式,实际上代码复用,就是继承啊,原型啊,构造函数啊等等这一类的内容。对于前端进阶来说,是很重要的基础知识。这一篇内容会对原型、继承有很深入的讲解。我也

    2022年3月25日
    38
  • 有名的博客网站「建议收藏」

    有名的博客网站「建议收藏」 根据自身特殊的定位和客户群,不同的网站有着不同的表现手法,所强调的功能和服务也有很大的区别,有的是独立托管网站,有的依附于门户或专业、行业网站,这种多样化的博客托管形成丰富多彩的博客内容和广泛的接触面及影响力,多样化产生了精彩,而这正是值得我们去深入研究并借鉴的地方。下文的点评即是基于大众对各博客托管网站的认识,力求从客观公正的角度加以整体分析。No.1:博客网——http://

    2022年7月12日
    13
  • html5 模拟scrollview,horizontalScrollView

    html5 模拟scrollview,horizontalScrollViewhorizontalScrollView资源下载此资源下载价格为2D币,请先登录资源文件列表zhy_horizontalScrollView/.classpath,475zhy_horizontalScrollView/.project,860zhy_horizontalScrollView/.settings/org.eclipse.jdt.core.prefs,177zhy_hor…

    2022年7月26日
    4
  • java 实现 按位异或_Java 按位异或的性质及其妙用

    java 实现 按位异或_Java 按位异或的性质及其妙用文章摘要:1、按位异或,可以简单理解成:不进位加法。即:1+1=0;0+0=0;1+0=1;2、任何数和自己异或结果为零。3、按位异或自反性。两次运算操作,可以将最后的结果还原。4、任何数和0做异或值不变,和1异或结果为原操作数取反。5、交换律。不使用中间变量,交换两个数。一、按位异或具有自反性。即:对同一个数据,进行两次按位异或操作,等于数据本身。intdisplayOptions=0x…

    2022年6月6日
    94
  • Vue 子组件调用父组件的属性,方法「建议收藏」

    Vue 子组件调用父组件的属性,方法「建议收藏」一、子组件调用父组件的方法子组件里用$emit向父组件触发一个事件,父组件监听这个事件就行了//父组件<template><div><label>我是父组件</label><child@fatherMethod=”test”></child>&…

    2022年9月27日
    0
  • 根据IP地址和子网掩码求网络号、主机号

    根据IP地址和子网掩码求网络号、主机号一、理论阐述目前,IP地址主要使用32位的二进制来表示,即IPv4地址。由于32位二进制不容易记忆和书写,故采用点分十进制形式来表示IP地址。IP地址由两部分组成{<网络号>,<主机号>},网络号表示计算机所在的网络,供路由器在进行路由选择时使用;主机号是计算机在该网络中的唯一标识。IP地址分为A、B、C、D、E五类,其中:A类IP地址第一个字节的范围是:1~126…

    2022年6月24日
    29

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号