use of ognl.OgnlException in project pentaho-kettle by pentaho.
the class PropertySetter method setOgnlProperty.
private Object setOgnlProperty(String[] expression, String value) throws KettleConfigException {
if (expression.length >= 2) {
OgnlExpression expr = ognlExpressions.get(value);
if (expr == null) {
synchronized (ognlExpressions) {
try {
expr = new OgnlExpression(expression[1]);
ognlExpressions.put(value, expr);
} catch (OgnlException e) {
throw new KettleConfigException("Unable to parse expression [" + expression[1] + "] with Ognl", e);
}
}
}
// evaluate
try {
return expr.getValue(octx, this);
} catch (OgnlException e) {
throw new KettleConfigException("Unable to get value for expression [" + expression[1] + "] with Ognl", e);
}
} else {
throw new KettleConfigException("the ognl, directive need at least 2 parameters: ongl and the expression but " + expression.length + " parameters were found in [" + value + "]");
}
}
use of ognl.OgnlException in project stdlib by petergeneric.
the class RulesEngineImpl method run.
@Override
public void run(final Rules rules, boolean ignoreMethodErrors) throws OgnlException {
Map<String, Object> vars = prepare(rules);
for (RuleSet rs : rules.ruleSets) {
try {
log.debug("Assessing input for ruleset : " + rs.id);
OgnlContext rsContext = createContext(vars);
rs.runInput(rsContext);
for (Rule rule : rs.rules) {
if (StringUtils.isEmpty(rule.id)) {
throw new IllegalArgumentException("Rule with condition " + rule.condition + " has no id!");
}
final RuleProcessTask task = new RuleProcessTask(this, rs, rule, rsContext);
synchronized (activeTasks) {
// if not currently being processed
if (!activeTasks.containsKey(rule.id)) {
try {
activeTasks.put(rule.id, task);
task.submit(executorService);
} catch (Exception e) {
log.error("Error submitting rule for execution ", e);
activeTasks.remove(rule.id);
}
}
}
}
} catch (MethodFailedException mfe) {
if (!ignoreMethodErrors) {
throw mfe;
}
log.warn("Method failed for ruleset " + rs.id, mfe);
}
}
}
use of ognl.OgnlException in project thymeleaf by thymeleaf.
the class OGNLContextPropertyAccessor method getProperty.
public Object getProperty(final Map ognlContext, final Object target, final Object name) throws OgnlException {
if (!(target instanceof IContext)) {
throw new IllegalStateException("Wrong target type. This property accessor is only usable for " + IContext.class.getName() + " implementations, and " + "in this case the target object is " + (target == null ? "null" : ("of class " + target.getClass().getName())));
}
if (REQUEST_PARAMETERS_RESTRICTED_VARIABLE_NAME.equals(name) && ognlContext != null && ognlContext.containsKey(RESTRICT_REQUEST_PARAMETERS)) {
throw new OgnlException("Access to variable \"" + name + "\" is forbidden in this context. Note some restrictions apply to " + "variable access. For example, direct access to request parameters is forbidden in preprocessing and " + "unescaped expressions, in TEXT template mode, in fragment insertion specifications and " + "in some specific attribute processors.");
}
final String propertyName = (name == null ? null : name.toString());
// 'execInfo' translation from context variable to expression object - deprecated and to be removed in 3.1
final Object execInfoResult = checkExecInfo(propertyName, ognlContext);
if (execInfoResult != null) {
return execInfoResult;
}
/*
* NOTE we do not check here whether we are being asked for the 'locale', 'request', 'response', etc.
* because there already are specific expression objects for the most important of them, which should
* be used instead: #locale, #httpServletRequest, #httpSession, etc.
* The variables maps should just be used as a map, without exposure of its more-internal methods...
*/
final IContext context = (IContext) target;
return context.getVariable(propertyName);
}
use of ognl.OgnlException in project thymeleaf by thymeleaf.
the class OGNLShortcutExpression method evaluate.
Object evaluate(final IEngineConfiguration configuration, final Map<String, Object> context, final Object root) throws Exception {
final ICacheManager cacheManager = configuration.getCacheManager();
final ICache<ExpressionCacheKey, Object> expressionCache = (cacheManager == null ? null : cacheManager.getExpressionCache());
Object target = root;
for (final String propertyName : this.expressionLevels) {
// If target is null, we will mimic what OGNL does in these cases...
if (target == null) {
throw new OgnlException("source is null for getProperty(null, \"" + propertyName + "\")");
}
// For the best integration possible, we will ask OGNL which property accessor it would use for
// this target object, and then depending on the result apply our equivalent or just default to
// OGNL evaluation if it is a custom property accessor we do not implement.
final Class<?> targetClass = OgnlRuntime.getTargetClass(target);
final PropertyAccessor ognlPropertyAccessor = OgnlRuntime.getPropertyAccessor(targetClass);
// Depending on the returned OGNL property accessor, we will try to apply ours
if (target instanceof Class<?>) {
// Because of the way OGNL works, the "OgnlRuntime.getTargetClass(...)" of a Class object is the class
// object itself, so we might be trying to apply a PropertyAccessor to a Class instead of a real object,
// something we avoid by means of this shortcut
target = getObjectProperty(expressionCache, propertyName, target);
} else if (OGNLContextPropertyAccessor.class.equals(ognlPropertyAccessor.getClass())) {
target = getContextProperty(propertyName, context, target);
} else if (ObjectPropertyAccessor.class.equals(ognlPropertyAccessor.getClass())) {
target = getObjectProperty(expressionCache, propertyName, target);
} else if (MapPropertyAccessor.class.equals(ognlPropertyAccessor.getClass())) {
target = getMapProperty(propertyName, (Map<?, ?>) target);
} else if (ListPropertyAccessor.class.equals(ognlPropertyAccessor.getClass())) {
target = getListProperty(expressionCache, propertyName, (List<?>) target);
} else if (SetPropertyAccessor.class.equals(ognlPropertyAccessor.getClass())) {
target = getSetProperty(expressionCache, propertyName, (Set<?>) target);
} else if (IteratorPropertyAccessor.class.equals(ognlPropertyAccessor.getClass())) {
target = getIteratorProperty(expressionCache, propertyName, (Iterator<?>) target);
} else if (EnumerationPropertyAccessor.class.equals(ognlPropertyAccessor.getClass())) {
target = getEnumerationProperty(expressionCache, propertyName, (Enumeration<?>) target);
} else if (ArrayPropertyAccessor.class.equals(ognlPropertyAccessor.getClass())) {
target = getArrayProperty(expressionCache, propertyName, (Object[]) target);
} else {
// default to normal OGNL evaluation.
throw new OGNLShortcutExpressionNotApplicableException();
}
}
return target;
}
use of ognl.OgnlException in project camel by apache.
the class OgnlExpression method evaluate.
public <T> T evaluate(Exchange exchange, Class<T> tClass) {
OgnlContext oglContext = new OgnlContext();
// setup the class resolver from camel
oglContext.setClassResolver(new CamelClassResolver(exchange.getContext().getClassResolver()));
try {
Object value = Ognl.getValue(expression, oglContext, new RootObject(exchange));
return exchange.getContext().getTypeConverter().convertTo(tClass, value);
} catch (OgnlException e) {
throw new ExpressionEvaluationException(this, exchange, e);
}
}
Aggregations