@SuppressWarnings("PMD.AvoidReassigningParameters") @Override public boolean matches(Exchange exchange) { Object msgBody = exchange.getIn().getBody(); Predicate predicate = this.predicate; // 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) { // 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<String, Object> 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. exchange = ExchangeHelper.createCopy(exchange, true); exchange.getIn().setBody(jsonDocument); predicate = this.ognlPredicate; } } return predicate.matches(exchange); }
final Exchange exchangeForProcessing = ExchangeHelper.createCopy(exchange, true); exchangeForProcessing.getIn().setBody(json);
@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); }