defaultremoter.java

来自「反向的AJAX。最大的特性是我们成为反向的Ajax。DWR1.x允许你用java」· Java 代码 · 共 562 行 · 第 1/2 页

JAVA
562
字号
            Call call = calls.getCall(callNum);            Reply reply = execute(call);            replies.addReply(reply);        }        return replies;    }    /**     * Execute a single call object     * @param call The call to execute     * @return A Reply to the Call     */    public Reply execute(Call call)    {        try        {            Method method = call.getMethod();            if (method == null || call.getException() != null)            {                return new Reply(call.getCallId(), null, call.getException());            }            // Get a list of the available matching methods with the coerced            // parameters that we will use to call it if we choose to use that            // method.            Creator creator = creatorManager.getCreator(call.getScriptName());            // We don't need to check accessControl.getReasonToNotExecute()            // because the checks are made by the doExec method, but we do check            // if we can display it            accessControl.assertExecutionIsPossible(creator, call.getScriptName(), method);            // Get ourselves an object to execute a method on unless the            // method is static            Object object = null;            String scope = creator.getScope();            boolean create = false;            if (!Modifier.isStatic(method.getModifiers()))            {                WebContext webcx = WebContextFactory.get();                // Check the various scopes to see if it is there                if (scope.equals(Creator.APPLICATION))                {                    object = webcx.getServletContext().getAttribute(call.getScriptName());                }                else if (scope.equals(Creator.SESSION))                {                    object = webcx.getSession().getAttribute(call.getScriptName());                }                else if (scope.equals(Creator.SCRIPT))                {                    object = webcx.getScriptSession().getAttribute(call.getScriptName());                }                else if (scope.equals(Creator.REQUEST))                {                    object = webcx.getHttpServletRequest().getAttribute(call.getScriptName());                }                // Creator.PAGE scope means we create one every time anyway                // If we don't have an object the call the creator                if (object == null)                {                    create = true;                    object = creator.getInstance();                }                // Remember it for next time                if (create)                {                    if (scope.equals(Creator.APPLICATION))                    {                        // This might also be done at application startup by                        // DefaultCreatorManager.addCreator(String, Creator)                        webcx.getServletContext().setAttribute(call.getScriptName(), object);                    }                    else if (scope.equals(Creator.SESSION))                    {                        webcx.getSession().setAttribute(call.getScriptName(), object);                    }                    else if (scope.equals(Creator.SCRIPT))                    {                        webcx.getScriptSession().setAttribute(call.getScriptName(), object);                    }                    else if (scope.equals(Creator.REQUEST))                    {                        webcx.getHttpServletRequest().setAttribute(call.getScriptName(), object);                    }                    // Creator.PAGE scope means we create one every time anyway                }            }            // Some debug            log.info("Exec: " + call.getScriptName() + "." + call.getMethodName() + "()");            if (log.isDebugEnabled())            {                StringBuffer buffer = new StringBuffer();                if (create)                {                    buffer.append("--Object created, ");                    if (!scope.equals(Creator.PAGE))                    {                        buffer.append(" stored in ");                        buffer.append(scope);                    }                    else                    {                        buffer.append(" not stored");                    }                }                else                {                    buffer.append("--Object found in ");                    buffer.append(scope);                }                buffer.append(". ");                // It would be good to debug the params but it's not easy                //buffer.append("Call params (");                //for (int j = 0; j < inctx.getParameterCount(callNum); j++)                //{                //    if (j != 0)                //    {                //        buffer.append(", ");                //    }                //    InboundVariable param = inctx.getParameter(callNum, j);                //    buffer.append(param.toString());                //}                //buffer.append(") ");                buffer.append("id=");                buffer.append(call.getCallId());                log.debug(buffer.toString());            }            // Execute the filter chain method.toString()            final Iterator it = ajaxFilterManager.getAjaxFilters(call.getScriptName());            AjaxFilterChain chain = new AjaxFilterChain()            {                public Object doFilter(Object obj, Method meth, Object[] p) throws Exception                {                    AjaxFilter next = (AjaxFilter) it.next();                    return next.doFilter(obj, meth, p, this);                }            };            Object reply = chain.doFilter(object, method, call.getParameters());            return new Reply(call.getCallId(), reply);        }        catch (InvocationTargetException ex)        {            // Allow Jetty RequestRetry exception to propogate to container            Continuation.rethrowIfContinuation(ex);            log.warn("Method execution failed: ", ex.getTargetException());            return new Reply(call.getCallId(), null, ex.getTargetException());        }        catch (Exception ex)        {            // Allow Jetty RequestRetry exception to propogate to container            Continuation.rethrowIfContinuation(ex);            log.warn("Method execution failed: ", ex);            return new Reply(call.getCallId(), null, ex);        }    }    /**     * Accessor for the CreatorManager that we configure     * @param creatorManager The new ConverterManager     */    public void setCreatorManager(CreatorManager creatorManager)    {        this.creatorManager = creatorManager;    }    /**     * Accessor for the ConverterManager that we configure     * @param converterManager The new ConverterManager     */    public void setConverterManager(ConverterManager converterManager)    {        this.converterManager = converterManager;    }    /**     * Accessor for the security manager     * @param accessControl The accessControl to set.     */    public void setAccessControl(AccessControl accessControl)    {        this.accessControl = accessControl;    }    /**     * Accessor for the AjaxFilterManager     * @param ajaxFilterManager The AjaxFilterManager to set.     */    public void setAjaxFilterManager(AjaxFilterManager ajaxFilterManager)    {        this.ajaxFilterManager = ajaxFilterManager;    }    /**     * If we need to override the default path     * @param overridePath The new override path     */    public void setOverridePath(String overridePath)    {        this.overridePath = overridePath;    }    /**     * Do we allow impossible tests for debug purposes     * @param allowImpossibleTests The allowImpossibleTests to set.     */    public void setAllowImpossibleTests(boolean allowImpossibleTests)    {        this.allowImpossibleTests = allowImpossibleTests;    }    /**     * To prevent a DoS attack we limit the max number of calls that can be     * made in a batch     * @param maxCallCount the maxCallCount to set     */    public void setMaxCallCount(int maxCallCount)    {        this.maxCallCount = maxCallCount;    }    /**     * What AjaxFilters apply to which Ajax calls?     */    private AjaxFilterManager ajaxFilterManager = null;    /**     * How we create new beans     */    protected CreatorManager creatorManager = null;    /**     * How we convert beans - or in this case create client side classes     */    protected ConverterManager converterManager = null;    /**     * The security manager     */    protected AccessControl accessControl = null;    /**     * If we need to override the default path     */    private String overridePath = null;    /**     * This helps us test that access rules are being followed     */    private boolean allowImpossibleTests = false;    /**     * To prevent a DoS attack we limit the max number of calls that can be     * made in a batch     */    private int maxCallCount = 20;    /**     * Generated Javascript cache     */    private Map methodCache = Collections.synchronizedMap(new HashMap());    /**     * The log stream     */    private static final Logger log = Logger.getLogger(DefaultRemoter.class);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?