Search in sources :

Example 16 with WebContext

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

the class TranslationsFilter method doFilter.

public Object doFilter(Object obj, Method method, Object[] params, AjaxFilterChain chain) throws Exception {
    WebContext webContext = WebContextFactory.get();
    WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(webContext.getServletContext());
    MessageSource messageSource = (MessageSource) wac.getBean(messageSourceKey);
    JstlUtils.exposeLocalizationContext(webContext.getHttpServletRequest(), messageSource);
    return chain.doFilter(obj, method, params);
}
Also used : WebContext(org.directwebremoting.WebContext) MessageSource(org.springframework.context.MessageSource) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 17 with WebContext

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

the class ScriptedCreator method getInstance.

/* (non-Javadoc)
     * @see org.directwebremoting.Creator#getInstance()
     */
public Object getInstance() throws InstantiationException {
    try {
        if (useDynamicClasses && clazz != null) {
            return clazz.newInstance();
        }
        BSFManager bsfman = new BSFManager();
        try {
            WebContext context = WebContextFactory.get();
            bsfman.declareBean("context", context, context.getClass());
        } catch (BSFException ex) {
            log.warn("Failed to register WebContext with scripting engine: " + ex.getMessage());
        }
        return bsfman.eval(language, (null == scriptPath ? "dwr.xml" : scriptPath), 0, 0, getScript());
    } catch (Exception ex) {
        log.error("Error executing script", ex);
        throw new InstantiationException(Messages.getString("Creator.IllegalAccess"));
    }
}
Also used : WebContext(org.directwebremoting.WebContext) BSFException(org.apache.bsf.BSFException) BSFManager(org.apache.bsf.BSFManager) BSFException(org.apache.bsf.BSFException)

Example 18 with WebContext

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

the class BaseCallMarshaller method marshallInbound.

/* (non-Javadoc)
     * @see org.directwebremoting.extend.Marshaller#marshallInbound(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
public Calls marshallInbound(HttpServletRequest request, HttpServletResponse response) throws IOException, ServerException {
    // We must parse the parameters before we setup the conduit because it's
    // only after doing this that we know the scriptSessionId
    WebContext webContext = WebContextFactory.get();
    Batch batch = (Batch) request.getAttribute(ATTRIBUTE_BATCH);
    if (batch == null) {
        batch = new Batch(request, crossDomainSessionSecurity, allowGetForSafariButMakeForgeryEasier, sessionCookieName);
        // Save calls for retry exception
        request.setAttribute(ATTRIBUTE_BATCH, batch);
    }
    // Various bits of the Batch need to be stashed away places
    storeParsedRequest(request, webContext, batch);
    Calls calls = batch.getCalls();
    // Debug the environment
    if (log.isDebugEnabled() && calls.getCallCount() > 0) {
        // We can just use 0 because they are all shared
        InboundContext inctx = (InboundContext) batch.getInboundContexts().get(0);
        StringBuffer buffer = new StringBuffer();
        for (Iterator it = inctx.getInboundVariableNames(); it.hasNext(); ) {
            String key = (String) it.next();
            InboundVariable value = inctx.getInboundVariable(key);
            if (key.startsWith(ProtocolConstants.INBOUND_CALLNUM_PREFIX) && key.indexOf(ProtocolConstants.INBOUND_CALLNUM_SUFFIX + ProtocolConstants.INBOUND_KEY_ENV) != -1) {
                buffer.append(key);
                buffer.append('=');
                buffer.append(value.toString());
                buffer.append(", ");
            }
        }
        if (buffer.length() > 0) {
            log.debug("Environment:  " + buffer.toString());
        }
    }
    callLoop: for (int callNum = 0; callNum < calls.getCallCount(); callNum++) {
        Call call = calls.getCall(callNum);
        InboundContext inctx = (InboundContext) batch.getInboundContexts().get(callNum);
        // 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());
        // Which method are we using?
        Method method = findMethod(call, inctx);
        if (method == null) {
            String name = call.getScriptName() + '.' + call.getMethodName();
            String error = Messages.getString("BaseCallMarshaller.UnknownMethod", name);
            log.warn("Marshalling exception: " + error);
            call.setMethod(null);
            call.setParameters(null);
            call.setException(new IllegalArgumentException(error));
            continue callLoop;
        }
        call.setMethod(method);
        // Check this method is accessible
        accessControl.assertExecutionIsPossible(creator, call.getScriptName(), method);
        // Convert all the parameters to the correct types
        Object[] params = new Object[method.getParameterTypes().length];
        for (int j = 0; j < method.getParameterTypes().length; j++) {
            try {
                Class paramType = method.getParameterTypes()[j];
                InboundVariable param = inctx.getParameter(callNum, j);
                TypeHintContext incc = new TypeHintContext(converterManager, method, j);
                params[j] = converterManager.convertInbound(paramType, param, inctx, incc);
            } catch (MarshallException ex) {
                log.warn("Marshalling exception", ex);
                call.setMethod(null);
                call.setParameters(null);
                call.setException(ex);
                continue callLoop;
            }
        }
        call.setParameters(params);
    }
    return calls;
}
Also used : Call(org.directwebremoting.extend.Call) WebContext(org.directwebremoting.WebContext) TypeHintContext(org.directwebremoting.extend.TypeHintContext) InboundContext(org.directwebremoting.extend.InboundContext) Calls(org.directwebremoting.extend.Calls) InboundVariable(org.directwebremoting.extend.InboundVariable) Creator(org.directwebremoting.extend.Creator) Method(java.lang.reflect.Method) MarshallException(org.directwebremoting.extend.MarshallException) Iterator(java.util.Iterator)

Aggregations

WebContext (org.directwebremoting.WebContext)18 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)4 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)3 Iterator (java.util.Iterator)3 Creator (org.directwebremoting.extend.Creator)3 ReportVO (com.serotonin.m2m2.reports.vo.ReportVO)2 Method (java.lang.reflect.Method)2 MarshallException (org.directwebremoting.extend.MarshallException)2 InvalidArgumentException (com.serotonin.InvalidArgumentException)1 IMangoLifecycle (com.serotonin.m2m2.IMangoLifecycle)1 CompoundChild (com.serotonin.m2m2.gviews.component.CompoundChild)1 CompoundComponent (com.serotonin.m2m2.gviews.component.CompoundComponent)1 ImageChartComponent (com.serotonin.m2m2.gviews.component.ImageChartComponent)1 PointComponent (com.serotonin.m2m2.gviews.component.PointComponent)1 SimpleCompoundComponent (com.serotonin.m2m2.gviews.component.SimpleCompoundComponent)1 SimplePointComponent (com.serotonin.m2m2.gviews.component.SimplePointComponent)1 ViewComponent (com.serotonin.m2m2.gviews.component.ViewComponent)1 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 ReportDao (com.serotonin.m2m2.reports.ReportDao)1