@Test public void shouldFilterByDefaultForJavaBeanInput() { final JsonSimplePredicate predicate = new JsonSimplePredicate("${body.prop} == 1", CONTEXT); assertThat(predicate.matches(exchangeWith(new Bean()))).isEqualTo(true); }
@Override @SuppressFBWarnings({"NP_LOAD_OF_KNOWN_NULL_VALUE", "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", "RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE"}) public boolean matches(final Exchange exchange) { final Exchange exchangeForProcessing = ExchangeHelper.createCopy(exchange, true); final Message payload = exchangeForProcessing.getIn(); if (payload.getBody() instanceof List) { List<?> jsonBeans = payload.getBody(List.class); payload.setBody("[" + jsonBeans.stream().map(Object::toString).collect(Collectors.joining(",")) + "]"); } try (InputStream stream = payload.getBody(InputStream.class)) { if (stream == null) { return predicate.matches(exchange); } ResetAfterCloseInputStream resetAfterCloseInputStream = new ResetAfterCloseInputStream(stream); if (exchange.getIn().getBody() instanceof InputStream) { exchange.getIn().setBody(resetAfterCloseInputStream); } final JsonNode json = mapper.readTree(resetAfterCloseInputStream); if (json != null) { if (json.isArray()) { payload.setBody(mapper.convertValue(json, List.class)); try { return ognlPredicate.matches(exchangeForProcessing); } catch (RuntimeBeanExpressionException e) { if (Optional.ofNullable(e.getCause()) .map(Object::getClass) .map(IndexOutOfBoundsException.class::equals) .orElse(false)) { LOG.debug("Try to match array item out of bounds"); LOG.trace("Try to match array item out of bounds ", e); return false; } throw e; } } else if (json.isObject()) { payload.setBody(mapper.convertValue(json, Map.class)); return ognlPredicate.matches(exchangeForProcessing); } } } catch (final JsonParseException e) { LOG.debug("Incoming message is not a json, try to match using simple language"); LOG.trace("Unable to parse incoming message body as JSON ", e); } catch (final IOException e) { LOG.warn("Unable to apply simple filter to the given payload"); LOG.debug("Unable to parse incoming message body as JSON needed for simple filtering", e); } return predicate.matches(exchange); }
JsonSimplePredicate implements Predicate { @Override @SuppressFBWarnings({"NP_LOAD_OF_KNOWN_NULL_VALUE", "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", "RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE"}) public boolean matches(final Exchange exchange) { final Exchange exchangeForProcessing = ExchangeHelper.createCopy(exchange, true); final Message payload = exchangeForProcessing.getIn(); if (payload.getBody() instanceof List) { List<?> jsonBeans = payload.getBody(List.class); payload.setBody("[" + jsonBeans.stream().map(Object::toString).collect(Collectors.joining(",")) + "]"); } try (InputStream stream = payload.getBody(InputStream.class)) { if (stream == null) { return predicate.matches(exchange); } ResetAfterCloseInputStream resetAfterCloseInputStream = new ResetAfterCloseInputStream(stream); if (exchange.getIn().getBody() instanceof InputStream) { exchange.getIn().setBody(resetAfterCloseInputStream); } final JsonNode json = mapper.readTree(resetAfterCloseInputStream); if (json != null) { if (json.isArray()) { payload.setBody(mapper.convertValue(json, List.class)); try { return ognlPredicate.matches(exchangeForProcessing); } catch (RuntimeBeanExpressionException e) { if (Optional.ofNullable(e.getCause()) .map(Object::getClass) .map(IndexOutOfBoundsException.class::equals) .orElse(false)) { LOG.debug("Try to match array item out of bounds"); LOG.trace("Try to match array item out of bounds ", e); return false; } throw e; } } else if (json.isObject()) { payload.setBody(mapper.convertValue(json, Map.class)); return ognlPredicate.matches(exchangeForProcessing); } } } catch (final JsonParseException e) { LOG.debug("Incoming message is not a json, try to match using simple language"); LOG.trace("Unable to parse incoming message body as JSON ", e); } catch (final IOException e) { LOG.warn("Unable to apply simple filter to the given payload"); LOG.debug("Unable to parse incoming message body as JSON needed for simple filtering", e); } return predicate.matches(exchange); } }
JsonSimplePredicate implements Predicate { @Override @SuppressFBWarnings({"NP_LOAD_OF_KNOWN_NULL_VALUE", "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", "RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE"}) public boolean matches(final Exchange exchange) { final Exchange exchangeForProcessing = ExchangeHelper.createCopy(exchange, true); final Message payload = exchangeForProcessing.getIn(); if (payload.getBody() instanceof List) { List<?> jsonBeans = payload.getBody(List.class); payload.setBody("[" + jsonBeans.stream().map(Object::toString).collect(Collectors.joining(",")) + "]"); } try (InputStream stream = payload.getBody(InputStream.class)) { if (stream == null) { return predicate.matches(exchange); } ResetAfterCloseInputStream resetAfterCloseInputStream = new ResetAfterCloseInputStream(stream); if (exchange.getIn().getBody() instanceof InputStream) { exchange.getIn().setBody(resetAfterCloseInputStream); } final JsonNode json = mapper.readTree(resetAfterCloseInputStream); if (json != null) { if (json.isArray()) { payload.setBody(mapper.convertValue(json, List.class)); try { return ognlPredicate.matches(exchangeForProcessing); } catch (RuntimeBeanExpressionException e) { if (Optional.ofNullable(e.getCause()) .map(Object::getClass) .map(IndexOutOfBoundsException.class::equals) .orElse(false)) { LOG.debug("Try to match array item out of bounds"); LOG.trace("Try to match array item out of bounds ", e); return false; } throw e; } } else if (json.isObject()) { payload.setBody(mapper.convertValue(json, Map.class)); return ognlPredicate.matches(exchangeForProcessing); } } } catch (final JsonParseException e) { LOG.debug("Incoming message is not a json, try to match using simple language"); LOG.trace("Unable to parse incoming message body as JSON ", e); } catch (final IOException e) { LOG.warn("Unable to apply simple filter to the given payload"); LOG.debug("Unable to parse incoming message body as JSON needed for simple filtering", e); } return predicate.matches(exchange); } JsonSimplePredicate(final String expression, final CamelContext context); }
JsonSimplePredicate implements Predicate { @Override @SuppressFBWarnings({"NP_LOAD_OF_KNOWN_NULL_VALUE", "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", "RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE"}) public boolean matches(final Exchange exchange) { final Exchange exchangeForProcessing = ExchangeHelper.createCopy(exchange, true); final Message payload = exchangeForProcessing.getIn(); if (payload.getBody() instanceof List) { List<?> jsonBeans = payload.getBody(List.class); payload.setBody("[" + jsonBeans.stream().map(Object::toString).collect(Collectors.joining(",")) + "]"); } try (InputStream stream = payload.getBody(InputStream.class)) { if (stream == null) { return predicate.matches(exchange); } ResetAfterCloseInputStream resetAfterCloseInputStream = new ResetAfterCloseInputStream(stream); if (exchange.getIn().getBody() instanceof InputStream) { exchange.getIn().setBody(resetAfterCloseInputStream); } final JsonNode json = mapper.readTree(resetAfterCloseInputStream); if (json != null) { if (json.isArray()) { payload.setBody(mapper.convertValue(json, List.class)); try { return ognlPredicate.matches(exchangeForProcessing); } catch (RuntimeBeanExpressionException e) { if (Optional.ofNullable(e.getCause()) .map(Object::getClass) .map(IndexOutOfBoundsException.class::equals) .orElse(false)) { LOG.debug("Try to match array item out of bounds"); LOG.trace("Try to match array item out of bounds ", e); return false; } throw e; } } else if (json.isObject()) { payload.setBody(mapper.convertValue(json, Map.class)); return ognlPredicate.matches(exchangeForProcessing); } } } catch (final JsonParseException e) { LOG.debug("Incoming message is not a json, try to match using simple language"); LOG.trace("Unable to parse incoming message body as JSON ", e); } catch (final IOException e) { LOG.warn("Unable to apply simple filter to the given payload"); LOG.debug("Unable to parse incoming message body as JSON needed for simple filtering", e); } return predicate.matches(exchange); } JsonSimplePredicate(final String expression, final CamelContext context); @Override @SuppressFBWarnings({"NP_LOAD_OF_KNOWN_NULL_VALUE", "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", "RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE"}) // https://github.com/spotbugs/spotbugs/issues/868 though this code is fishy (TODO) boolean matches(final Exchange exchange); }
JsonSimplePredicate implements Predicate { @Override @SuppressFBWarnings({"NP_LOAD_OF_KNOWN_NULL_VALUE", "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", "RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE"}) public boolean matches(final Exchange exchange) { final Exchange exchangeForProcessing = ExchangeHelper.createCopy(exchange, true); final Message payload = exchangeForProcessing.getIn(); if (payload.getBody() instanceof List) { List<?> jsonBeans = payload.getBody(List.class); payload.setBody("[" + jsonBeans.stream().map(Object::toString).collect(Collectors.joining(",")) + "]"); } try (InputStream stream = payload.getBody(InputStream.class)) { if (stream == null) { return predicate.matches(exchange); } ResetAfterCloseInputStream resetAfterCloseInputStream = new ResetAfterCloseInputStream(stream); if (exchange.getIn().getBody() instanceof InputStream) { exchange.getIn().setBody(resetAfterCloseInputStream); } final JsonNode json = mapper.readTree(resetAfterCloseInputStream); if (json != null) { if (json.isArray()) { payload.setBody(mapper.convertValue(json, List.class)); try { return ognlPredicate.matches(exchangeForProcessing); } catch (RuntimeBeanExpressionException e) { if (Optional.ofNullable(e.getCause()) .map(Object::getClass) .map(IndexOutOfBoundsException.class::equals) .orElse(false)) { LOG.debug("Try to match array item out of bounds"); LOG.trace("Try to match array item out of bounds ", e); return false; } throw e; } } else if (json.isObject()) { payload.setBody(mapper.convertValue(json, Map.class)); return ognlPredicate.matches(exchangeForProcessing); } } } catch (final JsonParseException e) { LOG.debug("Incoming message is not a json, try to match using simple language"); LOG.trace("Unable to parse incoming message body as JSON ", e); } catch (final IOException e) { LOG.warn("Unable to apply simple filter to the given payload"); LOG.debug("Unable to parse incoming message body as JSON needed for simple filtering", e); } return predicate.matches(exchange); } JsonSimplePredicate(final String expression, final CamelContext context); @Override @SuppressFBWarnings({"NP_LOAD_OF_KNOWN_NULL_VALUE", "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", "RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE"}) // https://github.com/spotbugs/spotbugs/issues/868 though this code is fishy (TODO) boolean matches(final Exchange exchange);  }