@Override public void describeTo(Description description) { description.appendText("without json path ").appendValue(jsonPath.getPath()); } }
public void describeTo(Description description) { description .appendText("with json path ") .appendValue(jsonPath.getPath()) .appendText(" evaluated to ") .appendDescriptionOf(resultMatcher); }
@VisibleForTesting protected String buildShortMessage(Map<String, Object> fields) { final StringBuilder shortMessage = new StringBuilder(); shortMessage.append("JSON API poll result: "); shortMessage.append(jsonPath.getPath()).append(" -> "); if (fields.toString().length() > 50) { shortMessage.append(fields.toString().substring(0, 50)).append("[...]"); } else { shortMessage.append(fields.toString()); } return shortMessage.toString(); }
@Override protected boolean matchesSafely(ReadContext actual, Description mismatchDescription) { try { Object value = actual.read(jsonPath); mismatchDescription .appendText(jsonPath.getPath()) .appendText(" was evaluated to ") .appendValue(value); return false; } catch (JsonPathException e) { return true; } }
@Override protected void describeMismatchSafely(ReadContext context, Description mismatchDescription) { try { T value = jsonPath.read(context.json()); mismatchDescription .appendText("json path ") .appendValue(jsonPath.getPath()) .appendText(" was evaluated to ") .appendValue(value); } catch (PathNotFoundException e) { mismatchDescription .appendText("json path ") .appendValue(jsonPath.getPath()) .appendText(" was not found in ") .appendValue(context.json()); } catch (JsonPathException e) { mismatchDescription .appendText("was ") .appendValue(context.json()); } }
public static Matcher<? super ReadContext> withJsonPath(JsonPath jsonPath) { return describedAs("with json path %0", withJsonPath(jsonPath, anything()), jsonPath.getPath()); }
if (returnType.equals(RETURN_TYPE_SCALAR) && !isJsonScalar(potentialResult)) { logger.error("Unable to return a scalar value for the expression {} for FlowFile {}. Evaluated value was {}. Transferring to {}.", new Object[]{jsonPathExp.getPath(), flowFile.getId(), potentialResult.toString(), REL_FAILURE.getName()}); processSession.transfer(flowFile, REL_FAILURE); return; if (pathNotFound.equals(PATH_NOT_FOUND_WARN)) { logger.warn("FlowFile {} could not find path {} for attribute key {}.", new Object[]{flowFile.getId(), jsonPathExp.getPath(), jsonPathAttrKey}, e); processSession.getProvenanceReporter().modifyContent(flowFile, "Replaced content with result of expression " + jsonPathExp.getPath());
jsonPathResult = documentContext.read(jsonPath); } catch (PathNotFoundException e) { logger.warn("JsonPath {} could not be found for FlowFile {}", new Object[]{jsonPath.getPath(), original}); processSession.transfer(original, REL_FAILURE); return; logger.error("The evaluated value {} of {} was not a JSON Array compatible type and cannot be split.", new Object[]{jsonPathResult, jsonPath.getPath()}); processSession.transfer(original, REL_FAILURE); return;
@Override public void describeTo(Description description) { description.appendText("without json path ").appendValue(jsonPath.getPath()); } }
public void describeTo(Description description) { description .appendText("with json path ") .appendValue(jsonPath.getPath()) .appendText(" evaluated to ") .appendDescriptionOf(resultMatcher); }
@VisibleForTesting protected String buildShortMessage(Map<String, Object> fields) { final StringBuilder shortMessage = new StringBuilder(); shortMessage.append("JSON API poll result: "); shortMessage.append(jsonPath.getPath()).append(" -> "); if (fields.toString().length() > 50) { shortMessage.append(fields.toString().substring(0, 50)).append("[...]"); } else { shortMessage.append(fields.toString()); } return shortMessage.toString(); }
@VisibleForTesting protected String buildShortMessage(Map<String, Object> fields) { final StringBuilder shortMessage = new StringBuilder(); shortMessage.append("JSON API poll result: "); shortMessage.append(jsonPath.getPath()).append(" -> "); if (fields.toString().length() > 50) { shortMessage.append(fields.toString().substring(0, 50)).append("[...]"); } else { shortMessage.append(fields.toString()); } return shortMessage.toString(); }
@Override protected boolean matchesSafely(ReadContext actual, Description mismatchDescription) { try { Object value = actual.read(jsonPath); mismatchDescription .appendText(jsonPath.getPath()) .appendText(" was evaluated to ") .appendValue(value); return value == null || empty().matches(value); } catch (JsonPathException e) { return true; } }
public <T> T parseValue(final JsonPath path) { final T value = (T) path.read(json); if (value == null) { log.debug( String.format("Expected value at %s was missing in response from Bitbucket Server %s.", path.getPath(), stashLink.getName())); } return value; }
public SynapseJsonPath(String jsonPathExpression) throws JaxenException { super(jsonPathExpression, SynapsePath.JSON_PATH, log); // Set default configuration for Jayway JsonPath setJsonPathConfiguration(); this.contentAware = true; this.expression = jsonPathExpression; // Though SynapseJsonPath support "$.", the JSONPath implementation does not support it if (expression.endsWith(".")) { expression = expression.substring(0, expression.length() - 1); } jsonPath = JsonPath.compile(expression); // Check if the JSON path expression evaluates to the whole payload. If so no point in evaluating the path. if ("$".equals(jsonPath.getPath().trim()) || "$.".equals(jsonPath.getPath().trim())) { isWholeBody = true; } this.setPathType(SynapsePath.JSON_PATH); }
public static Matcher<? super ReadContext> withJsonPath(JsonPath jsonPath) { return describedAs("with json path %0", withJsonPath(jsonPath, not(anyOf(nullValue(), empty()))), jsonPath.getPath()); }
@Override protected void describeMismatchSafely(ReadContext context, Description mismatchDescription) { try { T value = jsonPath.read(context.json()); mismatchDescription .appendText("json path ") .appendValue(jsonPath.getPath()) .appendText(" was evaluated to ") .appendValue(value); } catch (PathNotFoundException e) { mismatchDescription .appendText("json path ") .appendValue(jsonPath.getPath()) .appendText(" was not found in ") .appendValue(context.json()); } catch (JsonPathException e) { mismatchDescription .appendText("was ") .appendValue(context.json()); } }
public URI interpolate(EndpointAddress endpoint, Message message) throws InterpolationException { UriTemplate template = templateCache.getUnchecked(endpoint.getEndpoint()); String[] variables = template.getVariables(); if (variables.length > 0) { Map<String, Object> values = Maps.newHashMap(); String payload = new String(message.getData(), Charsets.UTF_8); for (String variable : variables) { JsonPath path = variableCompiler.getUnchecked(variable); try { values.put(variable, path.read(payload)); } catch (InvalidPathException e) { throw new InterpolationException(String.format("Missing variable on path %s", path.getPath()), e); } } try { return URI.create(template.expand(values)); } catch (VariableExpansionException e) { throw new InterpolationException("Cannot expand template", e); } } return endpoint.getUri(); }
public URI interpolate(EndpointAddress endpoint, Message message) throws InterpolationException { UriTemplate template = templateCache.getUnchecked(endpoint.getEndpoint()); String[] variables = template.getVariables(); if (variables.length > 0) { Map<String, Object> values = Maps.newHashMap(); String payload = new String(message.getData(), Charsets.UTF_8); for (String variable : variables) { JsonPath path = variableCompiler.getUnchecked(variable); try { values.put(variable, path.read(payload)); } catch (InvalidPathException e) { throw new InterpolationException(String.format("Missing variable on path %s", path.getPath()), e); } } try { return URI.create(template.expand(values)); } catch (VariableExpansionException e) { throw new InterpolationException("Cannot expand template", e); } } return endpoint.getUri(); }