webwork2.1.7源代码分析之--执行过程(草稿)
讲几个问题:
1. ActionProxy是因为想做一个代理。使得action可以成为一个webservice或soap对象。
2.ActionProxy里有ActionInvocation对象,而ActionInvocation里也有ActionProxy。这很有趣。
3.当一个Action有一组Intecerpter里,它的调用ActionInvocation非常有意思。Intercerpter里注入调用者自己。这里有一个ArroundIntercepter的递归调用,非常有意思:
//invoke interceptors
if (interceptors.hasNext()) {
Interceptor interceptor = (Interceptor) interceptors.next();
resultCode = interceptor.intercept(this);
} else {
resultCode = invokeAction(getAction(), proxy.getConfig());
}
//AroundInterceptor
public String intercept(ActionInvocation invocation) throws Exception {
String result = null;
before(invocation);
result = invocation.invoke();
after(invocation, result);
return result;
}
4.执行过程对异常信息处理的过程。事实上,
//sended error.
try {
ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy(namespace, actionName, extraContext);
request.setAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY, proxy.getInvocation().getStack());
proxy.execute();
// If there was a previous value stack then set it back onto the request
if (stack != null){
request.setAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY,stack);
}
} catch (ConfigurationException e) {
log.error("Could not find action", e);
sendError(request, response, HttpServletResponse.SC_NOT_FOUND, e);
} catch (Exception e) {
log.error("Could not execute action", e);
sendError(request, response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
}
// set to request.
try {
// send a http error response to use the servlet defined error handler
// make the exception availible to the web.xml defined error page
request.setAttribute("javax.servlet.error.exception", e);
// for compatibility
request.setAttribute("javax.servlet.jsp.jspException", e);
// send the error response
response.sendError(code, e.getMessage());
} catch (IOException e1) {
}
5。为什么在web多线程环境下,每个请求的request不会相互冲突?
public class ActionContext {
//~ Static fields/initializers /////////////////////////////////////////////
static ThreadLocal actionContext = new ActionContextThreadLocal();
因为sevlectActionContext继承自ActionContext,而ActionContext有一个静态变量 static ThreadLocal actionContext = new ActionContextThreadLocal()。需要了解为什么,它能保证线程变量安程。因为ThreadLocal就能保证。
发表评论
- 浏览: 26939 次
- 性别:

- 来自: 上海

- 详细资料
搜索本博客
最近加入圈子
链接
最新评论
-
薛林之意
我来焚琴煮鹤一把 看了标题我还以为你说红三连五班那位呢
-- by seen -
管理学书目,觉的有些震动 ...
回yimlin,大杂烩却正是看中这套书目的原因。因为有原书,大多草草看了看序言。 ...
-- by 苏飞 -
管理学书目,觉的有些震动 ...
我就不明白,为什么要把这篇贴子弄为隐藏。这是一种多么可笑的行为。
-- by 苏飞 -
管理学书目,觉的有些震动 ...
得,这东西就是仁者见仁,智者见智。不扯也罢, 庄表伟,是的,确实如你分析的。我 ...
-- by 苏飞 -
管理学书目,觉的有些震动 ...
看了下目录,内容和管理学没啥关系,整一个大杂烩。 我的建议是: 哲学部分不要看, ...
-- by yimlin






评论排行榜