本文整理汇总了Java中com.jayway.jsonpath.PathNotFoundException类的典型用法代码示例。如果您正苦于以下问题:Java PathNotFoundException类的具体用法?Java PathNotFoundException怎么用?Java PathNotFoundException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PathNotFoundException类属于com.jayway.jsonpath包,在下文中一共展示了PathNotFoundException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: element
import com.jayway.jsonpath.PathNotFoundException; //导入依赖的package包/类
public SpinJsonNode element() {
try {
Object result = query.read(spinJsonNode.toString(), dataFormat.getJsonPathConfiguration());
JsonNode node;
if (result != null) {
node = dataFormat.createJsonNode(result);
} else {
node = dataFormat.createNullJsonNode();
}
return dataFormat.createWrapperInstance(node);
} catch(PathNotFoundException pex) {
throw LOG.unableToEvaluateJsonPathExpressionOnNode(spinJsonNode, pex);
} catch (ClassCastException cex) {
throw LOG.unableToCastJsonPathResultTo(SpinJsonNode.class, cex);
} catch(InvalidPathException iex) {
throw LOG.invalidJsonPath(SpinJsonNode.class, iex);
}
}
示例2: assertPaths
import com.jayway.jsonpath.PathNotFoundException; //导入依赖的package包/类
private void assertPaths(JsonNode node, boolean shouldExist, String... paths) {
Object document = Configuration.defaultConfiguration().jsonProvider().parse(node.toString());
for (String path : paths) {
try {
Object object = JsonPath.read(document, path);
if (isIndefinite(path)) {
Collection c = (Collection) object;
assertThat(c.isEmpty()).isNotEqualTo(shouldExist);
} else if (!shouldExist) {
Assert.fail("Expected path not to be found: " + path);
}
} catch (PathNotFoundException e) {
if (shouldExist) {
Assert.fail("Path not found: " + path);
}
}
}
}
示例3: checkArrayModel
import com.jayway.jsonpath.PathNotFoundException; //导入依赖的package包/类
/**
* Check if model is non-null and array.
* @param currentPath
* @param model
* @param ctx
* @return false if current evaluation call must be skipped, true otherwise
* @throws PathNotFoundException if model is null and evaluation must be interrupted
* @throws InvalidPathException if model is not an array and evaluation must be interrupted
*/
protected boolean checkArrayModel(String currentPath, Object model, EvaluationContextImpl ctx) {
if (model == null){
if (! isUpstreamDefinite()) {
return false;
} else {
throw new PathNotFoundException("The path " + currentPath + " is null");
}
}
if (!ctx.jsonProvider().isArray(model)) {
if (! isUpstreamDefinite()) {
return false;
} else {
throw new PathNotFoundException(format("Filter: %s can only be applied to arrays. Current context is: %s", toString(), model));
}
}
return true;
}
示例4: getValue
import com.jayway.jsonpath.PathNotFoundException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> T getValue(boolean unwrap) {
if (path.isDefinite()) {
if(resultIndex == 0){
throw new PathNotFoundException("No results for path: " + path.toString());
}
int len = jsonProvider().length(valueResult);
Object value = (len > 0) ? jsonProvider().getArrayIndex(valueResult, len-1) : null;
if (value != null && unwrap){
value = jsonProvider().unwrap(value);
}
return (T) value;
}
return (T)valueResult;
}
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:17,代码来源:EvaluationContextImpl.java
示例5: evaluate
import com.jayway.jsonpath.PathNotFoundException; //导入依赖的package包/类
@Override
public void evaluate(String currentPath, PathRef parent, Object model, EvaluationContextImpl ctx) {
if (ctx.jsonProvider().isMap(model)) {
for (String property : ctx.jsonProvider().getPropertyKeys(model)) {
handleObjectProperty(currentPath, model, ctx, asList(property));
}
} else if (ctx.jsonProvider().isArray(model)) {
for (int idx = 0; idx < ctx.jsonProvider().length(model); idx++) {
try {
handleArrayIndex(idx, currentPath, model, ctx);
} catch (PathNotFoundException p){
if(ctx.options().contains(Option.REQUIRE_PROPERTIES)){
throw p;
}
}
}
}
}
示例6: completeBasedOnJsonpathMatches
import com.jayway.jsonpath.PathNotFoundException; //导入依赖的package包/类
private void completeBasedOnJsonpathMatches(String kind, List<String> words,
List<Candidate> candidates) {
if (ctx != null) {
try {
List<String> names = ctx.read(String.format("$.%s[*].name", kind));
Optional<String> name = names.stream().filter(words::contains).map(String::toString)
.findFirst();
if (name.isPresent()) {
List<String> parameterNames = ctx.read(String
.format("$.%s[?(@.name=='%s')].parameters[*].name", kind, name.get()));
completeParameters(kind, words, candidates, parameterNames);
parameterNames = ctx.read(String
.format("$.%s[?(@.name=='%s')].mapped_parameters[*].local_key", kind, name.get()));
completeParameters(kind, words, candidates, parameterNames);
}
else {
names.forEach(n -> candidates.add(new Candidate(n)));
}
}
catch (PathNotFoundException e) {
// This is ok as it means we don't have the matching operation in the cache
}
}
}
示例7: addFieldToSolrString
import com.jayway.jsonpath.PathNotFoundException; //导入依赖的package包/类
private String addFieldToSolrString(JsonPath jp, Object sourceProfile) {
String fields = "";
try {
Object field = jp.read(sourceProfile);
if (!(field instanceof List)) {
if (!(field instanceof String)) {
field = field.toString();
}
fields += (String) field + " ";
} else {
for (Object field1 : (List)field) {
if (!(field1 instanceof String)) {
field1 = field1.toString();
}
fields += (String)field1 + " ";
}
}
} catch (PathNotFoundException pnfe) {
logger.debug("Path not found in profile " + pnfe.getMessage());
}
return fields;
}
示例8: poll
import com.jayway.jsonpath.PathNotFoundException; //导入依赖的package包/类
/**
* Polls the base URL for the DDI API interface.
*/
@Override
public void poll() {
if (!removed) {
final String basePollJson = controllerResource.get(getTenant(), getId());
try {
final String href = JsonPath.parse(basePollJson).read("_links.deploymentBase.href");
final long actionId = Long.parseLong(href.substring(href.lastIndexOf('/') + 1, href.indexOf('?')));
if (currentActionId == null) {
final String deploymentJson = controllerResource.getDeployment(getTenant(), getId(), actionId);
final String swVersion = JsonPath.parse(deploymentJson).read("deployment.chunks[0].version");
currentActionId = actionId;
startDdiUpdate(actionId, swVersion);
}
} catch (final PathNotFoundException e) {
// href might not be in the json response, so ignore
// exception here.
LOGGER.trace("Response does not contain a deploymentbase href link, ignoring.", e);
}
}
}
示例9: hello
import com.jayway.jsonpath.PathNotFoundException; //导入依赖的package包/类
@Test
public void hello() throws URISyntaxException, IOException {
String jsonString = FileUtils.readFirstLine("general/test.json");
Object jsonDocument = Configuration.defaultConfiguration().jsonProvider().parse(jsonString);
for (JsonBranch collectionBranch : schema.getCollectionPaths()) {
Object rawCollection = null;
try {
rawCollection = JsonPath.read(jsonDocument, collectionBranch.getJsonPath());
} catch (PathNotFoundException e) {}
if (rawCollection != null) {
if (rawCollection instanceof JSONArray) {
JSONArray collection = (JSONArray)rawCollection;
collection.forEach(
node -> {
processNode(node, collectionBranch.getChildren());
}
);
} else {
processNode(rawCollection, collectionBranch.getChildren());
}
}
}
}
示例10: readRegenerateFlagFrom
import com.jayway.jsonpath.PathNotFoundException; //导入依赖的package包/类
private boolean readRegenerateFlagFrom(String requestString) {
boolean isRegenerateRequest;
try {
isRegenerateRequest = JsonPath.read(requestString, "$.regenerate");
} catch (PathNotFoundException e) {
// could have just returned null, that would have been pretty useful
isRegenerateRequest = false;
}
return isRegenerateRequest;
}
示例11: read
import com.jayway.jsonpath.PathNotFoundException; //导入依赖的package包/类
/**
* Reads the given 'responseElements' and extracts information based on given 'pattern'.<br/>
* If 'responseElements' is null or empty you can handle the {@link IllegalArgumentException} raised or got an empty
* list.
*/
public static List<String> read(final String responseElements, final String pattern,
final boolean emptyListOnNullOrEmptyResponse) {
if (isNullOrEmpty(responseElements) && emptyListOnNullOrEmptyResponse) {
return emptyList();
}
try {
return JsonPath.read(responseElements, pattern);
} catch (final PathNotFoundException e) {
if (emptyListOnNullOrEmptyResponse) {
return emptyList();
} else {
throw e;
}
}
}
示例12: getRequestField
import com.jayway.jsonpath.PathNotFoundException; //导入依赖的package包/类
private String getRequestField(DataAccessRequest request, String fieldPath) {
String rawContent = request.getContent();
if(!Strings.isNullOrEmpty(fieldPath) && !Strings.isNullOrEmpty(rawContent)) {
Object content = Configuration.defaultConfiguration().jsonProvider().parse(rawContent);
List<Object> values = null;
try {
values = JsonPath.using(conf).parse(content).read(fieldPath);
} catch(PathNotFoundException ex) {
//ignore
} catch(InvalidPathException e) {
log.warn("Invalid jsonpath {}", fieldPath);
}
if(values != null) {
return values.get(0).toString();
}
}
return null;
}
示例13: isSafe
import com.jayway.jsonpath.PathNotFoundException; //导入依赖的package包/类
@Override
public final boolean isSafe(final String url) {
boolean safe = true;
try {
final MultiValueMap<String, String> formParameters = this.config.getParameters();
formParameters.add(PARAMETER_URL, url);
final ResponseEntity<String> response = this.client.postForEntity(this.config.getApiUrl(), formParameters, String.class);
if (response.getStatusCode() == HttpStatus.OK) {
final boolean phish = JsonPath.parse(response.getBody()).read(IN_DATABASE_PARSE_EXPRESSION);
if (phish) {
LOGGER.warn("Possible malicious link posted: {}", url);
LOGGER.debug("PhishTank response: {}", response);
safe = false;
}
} else {
LOGGER.warn("Request for PhishTank API failed with status: {} - : {}", response.getStatusCode(), response);
}
} catch (final RestClientException | PathNotFoundException exception) {
LOGGER.warn("Something went wrong while processing PhishTank API: {}", exception);
}
return safe;
}
示例14: testNoJoinIdsAtPath
import com.jayway.jsonpath.PathNotFoundException; //导入依赖的package包/类
@Test(expected=PathNotFoundException.class)
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testNoJoinIdsAtPath() throws IOException {
NamedList args = new NamedList();
args.add(SimpleXJoinResultsFactory.INIT_PARAM_TYPE, SimpleXJoinResultsFactory.Type.JSON.toString());
args.add(SimpleXJoinResultsFactory.INIT_PARAM_ROOT_URL, getClass().getResource("results.json").toString());
NamedList globalPaths = new NamedList();
args.add(SimpleXJoinResultsFactory.INIT_PARAM_GLOBAL_FIELD_PATHS, globalPaths);
globalPaths.add("total", "$.count");
args.add(SimpleXJoinResultsFactory.INIT_PARAM_JOIN_ID_PATH, "$.no.ids.at.this.path");
SimpleXJoinResultsFactory factory = new SimpleXJoinResultsFactory();
factory.init(args);
SolrParams params = new ModifiableSolrParams();
XJoinResults<String> results = factory.getResults(params);
assertEquals(0, IteratorUtils.toArray(results.getJoinIds().iterator()).length);
}
示例15: mapJson
import com.jayway.jsonpath.PathNotFoundException; //导入依赖的package包/类
public void mapJson(FieldMapContext context, Object jsonObject, IndexDocument target)
throws SearchLibException, IOException, ParseException, SyntaxError, URISyntaxException,
ClassNotFoundException, InterruptedException, InstantiationException, IllegalAccessException {
for (GenericLink<SourceField, CommonFieldTarget> link : getList()) {
String jsonPath = link.getSource().getUniqueName();
try {
Object jsonContent = JsonPath.read(jsonObject, jsonPath);
if (jsonContent == null)
continue;
if (jsonContent instanceof JSONArray) {
JSONArray jsonArray = (JSONArray) jsonContent;
for (Object content : jsonArray) {
if (content != null)
mapFieldTarget(context, link.getTarget(), false, content.toString(), target, null);
}
} else
mapFieldTarget(context, link.getTarget(), false, jsonContent.toString(), target, null);
} catch (PathNotFoundException | IllegalArgumentException e) {
Logging.warn(e);
}
}
}