Change cache lookup logic in XML and JSON response handlers

This commit is contained in:
Mikhail Golubev
2013-10-10 18:18:43 +04:00
parent 4ce5dec98e
commit a47f9d3eaf
2 changed files with 10 additions and 7 deletions
@@ -114,6 +114,7 @@ public final class JsonPathResponseHandler extends SelectorBasedResponseHandler
return extractValueAndCheckType(selector, (String)context, Boolean.class);
}
@SuppressWarnings("UnusedDeclaration")
@Nullable
private Long selectLong(@NotNull Selector selector, @NotNull String source) throws Exception {
return extractValueAndCheckType(selector, source, Long.class);
@@ -121,16 +122,17 @@ public final class JsonPathResponseHandler extends SelectorBasedResponseHandler
@NotNull
private JsonPath lazyCompile(@NotNull String path) throws Exception {
if (!myCompiledCache.containsKey(path)) {
JsonPath jsonPath = myCompiledCache.get(path);
if (jsonPath == null) {
try {
final JsonPath jsonPath = JsonPath.compile(path);
jsonPath = JsonPath.compile(path);
myCompiledCache.put(path, jsonPath);
}
catch (InvalidPathException e) {
throw new Exception(String.format("Malformed JsonPath expression '%s'", path));
}
}
return myCompiledCache.get(path);
return jsonPath;
}
@NotNull
@@ -65,16 +65,17 @@ public final class XPathResponseHandler extends SelectorBasedResponseHandler {
@NotNull
private XPath lazyCompile(@NotNull String path) throws Exception {
if (!myCompiledCache.containsKey(path)) {
XPath xPath = myCompiledCache.get(path);
if (xPath == null) {
try {
final XPath compiled = XPath.newInstance(path);
myCompiledCache.put(path, compiled);
xPath = XPath.newInstance(path);
myCompiledCache.put(path, xPath);
}
catch (JDOMException e) {
throw new Exception(String.format("Malformed XPath expression '%s'", path));
}
}
return myCompiledCache.get(path);
return xPath;
}
@NotNull