private void validate(final String identifier, final OgnlCommand command, final Map<String, String> results) { try { command.validate(); } catch (OgnlException e) { log.info("OgnlException during validation " + e.getMessage(), e); results.put(identifier, e.getMessage()); } }
public Object getValue(String expression, Object obj) { Object value = null; try { value = Ognl.getValue(expression, newDefaultContext(), obj); } catch (OgnlException ex) { String message = ex.getMessage(); // MS: This is SUPER SUPER LAME, but I don't see any other way in OGNL to // make keypaths with null components behave like NSKVC (i.e. returning null // vs throwing an exception). They have something called nullHandlers // in OGNL, but it appears that you have to register it per-class and you // can't override the factory. if (message == null || !message.startsWith("source is null for getProperty(null, ")) { throw new RuntimeException("Failed to get value '" + expression + "' on " + obj, ex); } } return value; }
throwMBeanException(ognle.getReason()); } else { String message = ognle.getMessage(); if (e instanceof NoSuchPropertyException) { message = "No such property: " + message;
private void throwMBeanException(Throwable e) throws MBeanException { if (e instanceof OgnlException) { OgnlException ognle = (OgnlException) e; if (ognle.getReason() != null) { throwMBeanException(ognle.getReason()); } else { String message = ognle.getMessage(); if (e instanceof NoSuchPropertyException) { message = "No such property: " + message; } else if (e instanceof ExpressionSyntaxException) { message = "Illegal expression syntax: " + message; } else if (e instanceof InappropriateExpressionException) { message = "Inappropriate expression: " + message; } e = new IllegalArgumentException(message); e.setStackTrace(ognle.getStackTrace()); } } if (e instanceof InvocationTargetException) { throwMBeanException(e.getCause()); } LOGGER.warn("Unexpected exception.", e); if (e.getClass().getPackage().getName().matches("javax?\\..+")) { if (e instanceof Exception) { throw new MBeanException((Exception) e, e.getMessage()); } throw new MBeanException(new RuntimeException(e), e.getMessage()); } throw new MBeanException(new RuntimeException(e.getClass().getName() + ": " + e.getMessage()), e.getMessage()); }
private InvalidExpressionException invalidExpressionException(OgnlException e) { Throwable cause = e; String message = e.getMessage(); if (e.getReason() != null) { message = e.getReason().getMessage(); cause = e.getReason(); } if (message == null) { message = ""; } if (e instanceof MethodFailedException) { MethodFailedException ex = ((MethodFailedException) e); Throwable realReason = ex.getReason(); if (realReason != null) { if (realReason instanceof NullPointerException) { message = "NullPointerException"; } else { message = realReason.getClass().getName() + ": " + message; } } message = message.replaceAll("java\\.lang\\.", ""); } return new InvalidExpressionException(message, cause); }
private InvalidExpressionException invalidExpressionException(OgnlException e) { Throwable cause = e; String message = e.getMessage(); if (e.getReason() != null) { message = e.getReason().getMessage(); cause = e.getReason(); } if (message == null) { message = ""; } if (e instanceof MethodFailedException) { MethodFailedException ex = ((MethodFailedException) e); Throwable realReason = ex.getReason(); if (realReason != null) { if (realReason instanceof NullPointerException) { message = "NullPointerException"; } else { message = realReason.getClass().getName() + ": " + message; } } message = message.replaceAll("java\\.lang\\.", ""); } return new InvalidExpressionException(message, cause); }
public static Object eval(String expr, Map<String, Object> mergeProperties, Map<Object, Map<String, Object>> cachedProperties) { Exception ex = null; try { val nestedExpr = new NestedExpr(expr); if (nestedExpr.isNested()) { Object map = evalNested(nestedExpr, mergeProperties, cachedProperties); if (map != null) return map; } return Ognl.getValue(expr, new OgRoot(mergeProperties)); } catch (NoSuchPropertyException e) { // ignore } catch (OgnlException e) { if (!e.getMessage().contains("source is null for getProperty")) ex = e; } catch (Exception e) { ex = e; } if (ex != null) log.warn("error while eval " + expr, ex); return null; }