private boolean pathIsIndefinite() { return !this.jsonPath.isDefinite(); }
@GET @Path("/validate") @Produces(MediaType.APPLICATION_JSON) public Response validate(@QueryParam("path") String path) { int result = -1; try { JsonPath compiled = JsonPath.compile(path); result = compiled.isDefinite() ? 0 : 1; } catch (Exception e) { } return Response.ok(Collections.singletonMap("result", result)).build(); }
/** * @see JsonPath#isDefinite() */ public static boolean isPathDefinite(String path) { return compile(path).isDefinite(); }
@Override public Optional<Multimap<String, String>> validate() { final ArrayListMultimap<String, String> errors = ArrayListMultimap.create(); if (HttpUrl.parse(url()) == null) { errors.put("url", "Invalid URL."); } try { final JsonPath jsonPath = JsonPath.compile(singleValueJSONPath()); if (!jsonPath.isDefinite()) { errors.put("single_value_jsonpath", "JSONPath does not return a single value."); } } catch (InvalidPathException e) { errors.put("single_value_jsonpath", "Invalid JSONPath."); } if (multiValueJSONPath().isPresent()) { try { JsonPath.compile(multiValueJSONPath().get()); } catch (InvalidPathException e) { errors.put("multi_value_jsonpath", "Invalid JSONPath."); } } return errors.isEmpty() ? Optional.empty() : Optional.of(errors); }
@Override protected void doStart() throws Exception { if (isNullOrEmpty(config.url())) { throw new IllegalArgumentException("URL needs to be set"); } if (isNullOrEmpty(config.singleValueJSONPath())) { throw new IllegalArgumentException("Value JSONPath needs to be set"); } this.singleJsonPath = JsonPath.compile(config.singleValueJSONPath()); // The JSONPath for the single value cannot be indefinite. (https://github.com/json-path/JsonPath#what-is-returned-when) if (!singleJsonPath.isDefinite()) { throw new IllegalArgumentException("Single JSONPath <" + config.singleValueJSONPath() + "> cannot return a list"); } if (config.multiValueJSONPath().isPresent() && !isNullOrEmpty(config.multiValueJSONPath().get())) { this.multiJsonPath = JsonPath.compile(config.multiValueJSONPath().get()); } final Headers.Builder headersBuilder = new Headers.Builder() .add(HttpHeaders.USER_AGENT, config.userAgent()) .add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON); if (config.headers() != null) { config.headers().forEach(headersBuilder::set); } this.headers = headersBuilder.build(); }
/** * @see JsonPath#isDefinite() */ public static boolean isPathDefinite(String path) { return compile(path).isDefinite(); }
private boolean isDefinite() { return this.jsonPath.isDefinite(); }
private boolean pathIsIndefinite() { return !this.jsonPath.isDefinite(); }
private boolean pathIsIndefinite() { return !this.jsonPath.isDefinite(); }
/** * @see JsonPath#isDefinite() */ public static boolean isPathDefinite(String path) { return compile(path).isDefinite(); }
object = formatJsonPathResponse(jsonPath.read(jsonStream)); if (object != null) { if (object instanceof List && !jsonPath.isDefinite()) { result = (List) object; } else {
@Override public Optional<Multimap<String, String>> validate() { final ArrayListMultimap<String, String> errors = ArrayListMultimap.create(); if (HttpUrl.parse(url()) == null) { errors.put("url", "Invalid URL."); } try { final JsonPath jsonPath = JsonPath.compile(singleValueJSONPath()); if (!jsonPath.isDefinite()) { errors.put("single_value_jsonpath", "JSONPath does not return a single value."); } } catch (InvalidPathException e) { errors.put("single_value_jsonpath", "Invalid JSONPath."); } if (multiValueJSONPath().isPresent()) { try { JsonPath.compile(multiValueJSONPath().get()); } catch (InvalidPathException e) { errors.put("multi_value_jsonpath", "Invalid JSONPath."); } } return errors.isEmpty() ? Optional.empty() : Optional.of(errors); }
@Override protected void doStart() throws Exception { if (isNullOrEmpty(config.url())) { throw new IllegalArgumentException("URL needs to be set"); } if (isNullOrEmpty(config.singleValueJSONPath())) { throw new IllegalArgumentException("Value JSONPath needs to be set"); } this.singleJsonPath = JsonPath.compile(config.singleValueJSONPath()); // The JSONPath for the single value cannot be indefinite. (https://github.com/json-path/JsonPath#what-is-returned-when) if (!singleJsonPath.isDefinite()) { throw new IllegalArgumentException("Single JSONPath <" + config.singleValueJSONPath() + "> cannot return a list"); } if (config.multiValueJSONPath().isPresent() && !isNullOrEmpty(config.multiValueJSONPath().get())) { this.multiJsonPath = JsonPath.compile(config.multiValueJSONPath().get()); } final Headers.Builder headersBuilder = new Headers.Builder() .add(HttpHeaders.USER_AGENT, config.userAgent()) .add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON); if (config.headers() != null) { config.headers().forEach(headersBuilder::set); } this.headers = headersBuilder.build(); }