@Test(expected = InvalidParseOperationException.class) public void givenJsonWhenValueIsTooBigORContainXMLTag() throws InvalidParseOperationException, IOException { final File file = PropertiesUtils.findFile(JSON_TEST_FILE); final JsonNode json = JsonHandler.getFromFile(file); assertNotNull(json); SanityChecker.checkJsonSanity(json); }
protected static final void checkJsonSanity(JsonNode json) throws InvalidParseOperationException { if (json.isArray()) { ArrayNode nodes = (ArrayNode) json; for (JsonNode element : nodes) { checkJsonSanity(element); } } else { final Iterator<Map.Entry<String, JsonNode>> fields = json.fields(); while (fields.hasNext()) { final Map.Entry<String, JsonNode> entry = fields.next(); final String key = entry.getKey(); checkSanityTags(key, getLimitFieldSize()); final JsonNode value = entry.getValue(); if (value.isArray()) { ArrayNode nodes = (ArrayNode) value; for (JsonNode jsonNode : nodes) { if (!jsonNode.isValueNode()) { checkJsonSanity(jsonNode); } else { validateJSONField(value); } } } else if (!value.isValueNode()) { checkJsonSanity(value); } else { validateJSONField(value); } } } }
SanityChecker { protected static final void checkJsonSanity(JsonNode json) throws InvalidParseOperationException { if (json.isArray()) { ArrayNode nodes = (ArrayNode) json; for (JsonNode element : nodes) { checkJsonSanity(element); } } else { final Iterator<Map.Entry<String, JsonNode>> fields = json.fields(); while (fields.hasNext()) { final Map.Entry<String, JsonNode> entry = fields.next(); final String key = entry.getKey(); checkSanityTags(key, getLimitFieldSize()); final JsonNode value = entry.getValue(); if (value.isArray()) { ArrayNode nodes = (ArrayNode) value; for (JsonNode jsonNode : nodes) { if (!jsonNode.isValueNode()) { checkJsonSanity(jsonNode); } else { validateJSONField(value); } } } else if (!value.isValueNode()) { checkJsonSanity(value); } else { validateJSONField(value); } } } } }
SanityChecker { protected static final void checkJsonSanity(JsonNode json) throws InvalidParseOperationException { if (json.isArray()) { ArrayNode nodes = (ArrayNode) json; for (JsonNode element : nodes) { checkJsonSanity(element); } } else { final Iterator<Map.Entry<String, JsonNode>> fields = json.fields(); while (fields.hasNext()) { final Map.Entry<String, JsonNode> entry = fields.next(); final String key = entry.getKey(); checkSanityTags(key, getLimitFieldSize()); final JsonNode value = entry.getValue(); if (value.isArray()) { ArrayNode nodes = (ArrayNode) value; for (JsonNode jsonNode : nodes) { if (!jsonNode.isValueNode()) { checkJsonSanity(jsonNode); } else { validateJSONField(value); } } } else if (!value.isValueNode()) { checkJsonSanity(value); } else { validateJSONField(value); } } } } private  SanityChecker(); }
SanityChecker { protected static final void checkJsonSanity(JsonNode json) throws InvalidParseOperationException { if (json.isArray()) { ArrayNode nodes = (ArrayNode) json; for (JsonNode element : nodes) { checkJsonSanity(element); } } else { final Iterator<Map.Entry<String, JsonNode>> fields = json.fields(); while (fields.hasNext()) { final Map.Entry<String, JsonNode> entry = fields.next(); final String key = entry.getKey(); checkSanityTags(key, getLimitFieldSize()); final JsonNode value = entry.getValue(); if (value.isArray()) { ArrayNode nodes = (ArrayNode) value; for (JsonNode jsonNode : nodes) { if (!jsonNode.isValueNode()) { checkJsonSanity(jsonNode); } else { validateJSONField(value); } } } else if (!value.isValueNode()) { checkJsonSanity(value); } else { validateJSONField(value); } } } } private  SanityChecker(); static boolean isValidFileName(String value); static final void checkXmlAll(File xmlFile); static final String sanitizeJson(JsonNode json); static final void checkJsonAll(JsonNode json); static final void checkJsonAll(String json); static final void checkParameter(String... params); static final void checkHTMLFile(File file); static final void checkHeaders(final HttpHeaders headers); static final void checkHeadersMap(MultivaluedMap<String, String> requestHeaders); static final void checkUriParametersMap(MultivaluedMap<String, String> uriParameters); static final long getLimitFileSize(); static final void setLimitFileSize(long limitFileSize); static final long getLimitJsonSize(); static final void setLimitJsonSize(long limitJsonSize); static final int getLimitFieldSize(); static final void setLimitFieldSize(int limitFieldSize); static final int getLimitParamSize(); static final void setLimitParamSize(int limitParamSize); }
SanityChecker { protected static final void checkJsonSanity(JsonNode json) throws InvalidParseOperationException { if (json.isArray()) { ArrayNode nodes = (ArrayNode) json; for (JsonNode element : nodes) { checkJsonSanity(element); } } else { final Iterator<Map.Entry<String, JsonNode>> fields = json.fields(); while (fields.hasNext()) { final Map.Entry<String, JsonNode> entry = fields.next(); final String key = entry.getKey(); checkSanityTags(key, getLimitFieldSize()); final JsonNode value = entry.getValue(); if (value.isArray()) { ArrayNode nodes = (ArrayNode) value; for (JsonNode jsonNode : nodes) { if (!jsonNode.isValueNode()) { checkJsonSanity(jsonNode); } else { validateJSONField(value); } } } else if (!value.isValueNode()) { checkJsonSanity(value); } else { validateJSONField(value); } } } } private  SanityChecker(); static boolean isValidFileName(String value); static final void checkXmlAll(File xmlFile); static final String sanitizeJson(JsonNode json); static final void checkJsonAll(JsonNode json); static final void checkJsonAll(String json); static final void checkParameter(String... params); static final void checkHTMLFile(File file); static final void checkHeaders(final HttpHeaders headers); static final void checkHeadersMap(MultivaluedMap<String, String> requestHeaders); static final void checkUriParametersMap(MultivaluedMap<String, String> uriParameters); static final long getLimitFileSize(); static final void setLimitFileSize(long limitFileSize); static final long getLimitJsonSize(); static final void setLimitJsonSize(long limitJsonSize); static final int getLimitFieldSize(); static final void setLimitFieldSize(int limitFieldSize); static final int getLimitParamSize(); static final void setLimitParamSize(int limitParamSize); static final String HTTP_PARAMETER_VALUE; }