Search in sources :

Example 6 with AjaxFilter

use of org.directwebremoting.AjaxFilter in project ma-core-public by infiniteautomation.

the class DwrXmlConfigurator method processAjaxFilters.

/**
 * J2EE role based method level security added here.
 * @param javascript The name of the creator
 * @param parent The container of the include and exclude elements.
 */
private void processAjaxFilters(String javascript, Element parent) {
    NodeList nodes = parent.getElementsByTagName(ELEMENT_FILTER);
    for (int i = 0; i < nodes.getLength(); i++) {
        Element include = (Element) nodes.item(i);
        String type = include.getAttribute(ATTRIBUTE_CLASS);
        AjaxFilter filter = (AjaxFilter) LocalUtil.classNewInstance(javascript, type, AjaxFilter.class);
        if (filter != null) {
            LocalUtil.setParams(filter, createSettingMap(include), ignore);
            ajaxFilterManager.addAjaxFilter(filter, javascript);
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) AjaxFilter(org.directwebremoting.AjaxFilter)

Example 7 with AjaxFilter

use of org.directwebremoting.AjaxFilter in project ma-core-public by infiniteautomation.

the class DefaultRemoter method execute.

/**
 * 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());
            }
            // 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);
    }
}
Also used : WebContext(org.directwebremoting.WebContext) Method(java.lang.reflect.Method) Creator(org.directwebremoting.extend.Creator) AjaxFilterChain(org.directwebremoting.AjaxFilterChain) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Iterator(java.util.Iterator) Reply(org.directwebremoting.extend.Reply) AjaxFilter(org.directwebremoting.AjaxFilter)

Aggregations

AjaxFilter (org.directwebremoting.AjaxFilter)7 Iterator (java.util.Iterator)3 AjaxFilterManager (org.directwebremoting.extend.AjaxFilterManager)3 Creator (org.directwebremoting.extend.Creator)2 SignatureParser (org.directwebremoting.impl.SignatureParser)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 List (java.util.List)1 Map (java.util.Map)1 Properties (java.util.Properties)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 AjaxFilterChain (org.directwebremoting.AjaxFilterChain)1 WebContext (org.directwebremoting.WebContext)1 AccessControl (org.directwebremoting.extend.AccessControl)1 ConverterManager (org.directwebremoting.extend.ConverterManager)1 CreatorManager (org.directwebremoting.extend.CreatorManager)1 Reply (org.directwebremoting.extend.Reply)1 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1