@Override public KeywordValidator getKeywordValidator(JsonNode node) throws ProcessingException { try { return constructor.newInstance(node); } catch (InstantiationException e) { throw new ProcessingException(ERRMSG, e); } catch (IllegalAccessException e) { throw new ProcessingException(ERRMSG, e); } catch (InvocationTargetException e) { throw new ProcessingException(ERRMSG, e); } }
public ProcessingReport validate(String jsonText) throws IOException { ProcessingReport report; JsonNode toValidate = JsonLoader.fromString(jsonText); try { report = this.schema.validate(toValidate); } catch (ProcessingException e) { throw new IOException("Error validating json text : " + e.getMessage()); } return report; } }
/** * Add a {@code $schema} and matching library to this configuration * * @param uri the value for {@code $schema} * @param library the library * @return this * @throws NullPointerException URI us null or library is null * @throws IllegalArgumentException string is not a URI, or not an absolute * JSON Reference; or a library already exists at this URI. */ public ValidationConfigurationBuilder addLibrary(final String uri, final Library library) { final JsonRef ref; try { ref = JsonRef.fromString(uri); } catch (JsonReferenceException e) { throw new IllegalArgumentException(e.getMessage()); } BUNDLE.checkArgumentPrintf(ref.isAbsolute(), "refProcessing.uriNotAbsolute", ref); BUNDLE.checkNotNull(library, "nullLibrary"); BUNDLE.checkArgumentPrintf(libraries.put(ref, library) == null, "dupLibrary", ref); return this; }
@Test(timeOut = 1000) public void circularReferencingDuringValidationIsDetected() throws IOException, ProcessingException, JsonPointerException { final JsonNode schemaNode = JsonLoader.fromResource("/other/issue102.json"); final JsonSchemaFactory factory = JsonSchemaFactory.byDefault(); final JsonValidator validator = factory.getValidator(); final MessageBundle bundle = MessageBundles.getBundle(JsonSchemaValidationBundle.class); try { validator.validate(schemaNode, JacksonUtils.nodeFactory().nullNode()); fail("No exception thrown!"); } catch (ProcessingException e) { final URI uri = URI.create("#/oneOf/1"); final ProcessingMessage message = e.getProcessingMessage(); final String expectedMessage = bundle.printf("err.common.validationLoop", uri, ""); assertMessage(message) .hasMessage(expectedMessage) .hasField("alreadyVisited", uri) .hasField("instancePointer", JsonPointer.empty().toString()) .hasField("validationPath", Arrays.asList("#", "#/oneOf/1")); } assertTrue(true); }
throw new InvalidSchemaException(message);
/** * Build an exception out of this message * * <p>This uses the {@link ExceptionProvider} built into the message and * invokes {@link ExceptionProvider#doException(ProcessingMessage)} with * {@code this} as an argument.</p> * * @return an exception * @see #setExceptionProvider(ExceptionProvider) */ public ProcessingException asException() { return exceptionProvider.doException(this); }
/** * Build a {@link JsonSchema} instance * * @param schema the schema * @param pointer the pointer into the schema * @return a new {@link JsonSchema} * @throws ProcessingException resolving the pointer against the schema * leads to a {@link MissingNode} * @throws NullPointerException the schema or pointer is null */ JsonSchema buildJsonSchema(final JsonNode schema, final JsonPointer pointer) throws ProcessingException { final SchemaTree tree = loader.load(schema).setPointer(pointer); if (tree.getNode().isMissingNode()) throw new JsonReferenceException(new ProcessingMessage() .setMessage(BUNDLE.getMessage("danglingRef"))); return new JsonSchemaImpl(processor, tree, reportProvider); }
@Override void doIt(final ProcessingReport report) throws ProcessingException { throw new ProcessingException(); } };
@Override public ProcessingException doException(final ProcessingMessage message) { return new InvalidSchemaException(message); } };
/** * Build an exception out of this message * * <p>This uses the {@link ExceptionProvider} built into the message and * invokes {@link ExceptionProvider#doException(ProcessingMessage)} with * {@code this} as an argument.</p> * * @return an exception * @see #setExceptionProvider(ExceptionProvider) */ public ProcessingException asException() { return exceptionProvider.doException(this); }
/** * Build a {@link JsonSchema} instance * * @param uri the URI to load the schema from * @return a {@link JsonSchema} * @throws ProcessingException invalid URI, or URI did not resolve to a * JSON Schema * @throws NullPointerException URI is null */ JsonSchema buildJsonSchema(final String uri) throws ProcessingException { final JsonRef ref = JsonRef.fromString(uri); if (!ref.isLegal()) throw new JsonReferenceException(new ProcessingMessage() .setMessage(BUNDLE.getMessage("illegalJsonRef"))); final SchemaTree tree = loader.get(ref.getLocator()).setPointer(ref.getPointer()); if (tree.getNode().isMissingNode()) throw new JsonReferenceException(new ProcessingMessage() .setMessage(BUNDLE.getMessage("danglingRef"))); return new JsonSchemaImpl(processor, tree, reportProvider); }
@Override void doIt(final ProcessingReport report, final ProcessingMessage message) throws ProcessingException { throw new ProcessingException(); } };
@Override public ProcessingException doException(final ProcessingMessage message) { return new InvalidSchemaException(message); } };
/** * Build an exception out of this message * * <p>This uses the {@link ExceptionProvider} built into the message and * invokes {@link ExceptionProvider#doException(ProcessingMessage)} with * {@code this} as an argument.</p> * * @return an exception * @see #setExceptionProvider(ExceptionProvider) */ public ProcessingException asException() { return exceptionProvider.doException(this); }
@Override void doIt(final ProcessingReport report) throws ProcessingException { throw new ProcessingException(); } };
@Override public ProcessingException doException(final ProcessingMessage message) { return new InvalidSchemaException(message); } };
throw new ProcessingException(validationLoopMessage(data)); schemaURIs.addLast(schemaURI); return;
@Override public ProcessingException doException(final ProcessingMessage message) { return new ProcessingException(message); } }
@Override public ProcessingException doException(final ProcessingMessage message) { return new ProcessingException(message); } }
@Override public ProcessingException doException(final ProcessingMessage message) { return new ProcessingException(message); } }