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就能保证。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值