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);
}
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"));
}
}
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;
}
Aggregations