/** * Asserts that the given language name and predicate expression evaluates * to the expected value on the message exchange */ protected void assertPredicate(String languageName, String expressionText, Exchange exchange, boolean expected) { Language language = assertResolveLanguage(languageName); Predicate predicate = language.createPredicate(expressionText); assertNotNull("No Predicate could be created for text: " + expressionText + " language: " + language, predicate); assertPredicate(predicate, exchange, expected); }
protected Predicate getMandatoryPredicate(Step step, String expression, String language) { Objects.requireNonNull(expression, "No expression specified for step " + step); Language jsonpath = getLanguage(language); Predicate answer = jsonpath.createPredicate(expression); Objects.requireNonNull(answer, "No predicate created from: " + expression); return answer; }
public JsonSimplePredicate(String expression, CamelContext context) { Language language = ObjectHelper.notNull(context.resolveLanguage("simple"), "simple language"); String ognlExpression = convertSimpleToOGNLForMaps(expression); this.predicate = language.createPredicate(expression); this.ognlPredicate = language.createPredicate(ognlExpression); }
public JsonSimplePredicate(final String expression, final CamelContext context) { final Language language = ObjectHelper.notNull(context.resolveLanguage("simple"), "simple language"); final String ognlExpression = convertSimpleToOGNLForMaps(expression); predicate = language.createPredicate(expression); ognlPredicate = language.createPredicate(ognlExpression); final Registry registry = context.getRegistry(); final Set<ObjectMapper> mappers = registry.findByType(ObjectMapper.class); if (mappers.size() != 1) { mapper = MAPPER; } else { mapper = mappers.iterator().next(); } }
@Override public Predicate getObject() throws Exception { Language languageImpl = validateLanguage(); return languageImpl.createPredicate(getExpression()); }
/** * Parses a string of the form "languageName.remaining = expression" returning the Predicate and the remaining text */ protected Pair<Predicate, String> parsePredicateAndRemaining(CamelContextService camelContextService, String key, String expression) { // lets assume no dots in language names int idx = key.indexOf('.'); if (idx > 0) { String languageName = key.substring(0, idx); String remaining = key.substring(idx + 1); Language language = camelContextService.getCamelContext().resolveLanguage(languageName); if (languageName == null) { LOG.error("Could not resolve language '" + languageName + "' with expression '" + expression + "'"); } else { try { Predicate predicate = language.createPredicate(expression); if (predicate == null) { LOG.error("Could not create predicate for language " + language + " and expression '" + expression + "'"); } else { return new Pair<Predicate, String>(predicate, remaining); } } catch (Exception e) { LOG.error("Failed to parse " + language + " expression '" + expression + "'. Reason: " + e); } } } return null; }
@Override public boolean matches(Exchange exchange) { Object msgBody = exchange.getIn().getBody(); // TODO: Maybe check for content-type, too ? // String contentType = exchange.getIn().getHeader(Exchange.CONTENT_TYPE, String.class); // if ("application/json".equals(contentType)) { ... } // ??? if (!(msgBody instanceof String)) { return language.createPredicate(expression).matches(exchange); } Exchange exchangeToCheck = exchange; // If it is a json document , suppose that this is a document which needs to be parsed as JSON // Therefor we set a map instead of the string Map jsonDocument = jsonStringAsMap((String) msgBody, exchange); if (jsonDocument != null) { // Clone the exchange and set the JSON message converted to a Map / List as in message. // The intention is that only this predicate acts on the converted value, // but the original in-message still continues to carry the same format // The predicated is supposed to be read only with respect to the incoming messaeg. exchangeToCheck = ExchangeHelper.createCopy(exchange, true); exchangeToCheck.getIn().setBody(jsonDocument); } return language.createPredicate(convertSimpleToOGNLForMaps(expression)).matches(exchangeToCheck); }