本文整理汇总了Java中com.github.fge.jsonschema.core.exceptions.ProcessingException类的典型用法代码示例。如果您正苦于以下问题:Java ProcessingException类的具体用法?Java ProcessingException怎么用?Java ProcessingException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProcessingException类属于com.github.fge.jsonschema.core.exceptions包,在下文中一共展示了ProcessingException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateJSonSchema
import com.github.fge.jsonschema.core.exceptions.ProcessingException; //导入依赖的package包/类
private static SwaggerModelInfo validateJSonSchema(final String specification, final Swagger model) {
try {
final JsonNode specRoot = convertToJson(specification);
final ProcessingReport report = SWAGGER_2_0_SCHEMA.validate(specRoot);
final List<Violation> errors = new ArrayList<>();
final List<Violation> warnings = new ArrayList<>();
for (final ProcessingMessage message : report) {
final boolean added = append(errors, message, Optional.of("error"));
if (!added) {
append(warnings, message, Optional.empty());
}
}
return new SwaggerModelInfo.Builder().errors(errors).warnings(warnings).model(model).resolvedSpecification(specification)
.build();
} catch (IOException | ProcessingException ex) {
LOG.error("Unable to load the schema file embedded in the artifact", ex);
return new SwaggerModelInfo.Builder().addError(new Violation.Builder().error("error").property("")
.message("Unable to load the swagger schema file embedded in the artifact").build()).build();
}
}
示例2: isValid
import com.github.fge.jsonschema.core.exceptions.ProcessingException; //导入依赖的package包/类
public boolean isValid(JsonNode jsonNode) {
final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
log.verboseOutput("Checking against schema. Available at 'https://raw.githubusercontent.com/pivio/pivio-client/master/src/main/resources/pivio-schema.json'.", configuration.isVerbose());
try {
String schemaContent = readFromJARFile("/pivio-schema.json");
JsonNode schemaNode = new ObjectMapper().readTree(schemaContent);
final JsonSchema jsonSchema = factory.getJsonSchema(schemaNode);
ProcessingReport processingReport = jsonSchema.validate(jsonNode);
for (ProcessingMessage processingMessage : processingReport) {
String pointer = processingMessage.asJson().get("instance").get("pointer").asText();
log.output(pointer + " : " + processingMessage.getMessage());
}
return processingReport.isSuccess();
} catch (ProcessingException | IOException e ) {
log.output("Error processing Json. "+e.getMessage());
return false;
}
}
示例3: doValidate
import com.github.fge.jsonschema.core.exceptions.ProcessingException; //导入依赖的package包/类
private static void doValidate(final Map<String, JsonNode> schemas,
final int i)
throws ProcessingException
{
String name;
JsonNode value;
ProcessingReport report;
for (final Map.Entry<String, JsonNode> entry: schemas.entrySet()) {
name = entry.getKey();
value = entry.getValue();
report = SCHEMA.validate(value);
if (!report.isSuccess()) {
System.err.println("ERROR: schema " + name + " did not "
+ "validate (iteration " + i + ')');
System.exit(1);
}
}
}
示例4: execute
import com.github.fge.jsonschema.core.exceptions.ProcessingException; //导入依赖的package包/类
@Override
protected ExecuteResult execute(final WebServiceConnector connector) {
final String body = connector.getBody();
final ObjectMapper mapper = new ObjectMapper();
try {
final JsonNode obj = mapper.readTree(body);
final JsonNode schema = mapper.readTree(this.schema);
final ProcessingReport report = JsonSchemaFactory.byDefault()
.getJsonSchema(schema)
.validate(obj);
return report.isSuccess() ? getSuccessOutput() : getFailedOutput();
} catch (IOException | ProcessingException e) {
return getFailedOutput();
}
}
示例5: getSchema
import com.github.fge.jsonschema.core.exceptions.ProcessingException; //导入依赖的package包/类
/**
* Get the {@link SchemaTree} for the given {@code uri}.
*
* This is similar to {@link SchemaLoader#get(URI)}, but allows {@code uri} to contain a fragment.
*
* @param uri
* @return
* @throws ProcessingException
*/
// XXX: Should this be the default behavior of SchemaLoader#get()?
@VisibleForTesting
protected SchemaTree getSchema(SchemaLoader schemaLoader, URI uri) throws ProcessingException {
String fragment = uri.getFragment();
if (fragment == null) {
return schemaLoader.get(uri);
} else {
try {
URI schemaTreeUri = new URI(uri.getScheme(), uri.getSchemeSpecificPart(), null);
JsonPointer pointer = new JsonPointer(fragment);
SchemaTree schema = schemaLoader.get(schemaTreeUri);
return schema.setPointer(pointer);
} catch (URISyntaxException|JsonPointerException e) {
assert false : "Was a valid before, we split things up!";
throw new RuntimeException(e);
}
}
}
示例6: populateHiddenFields
import com.github.fge.jsonschema.core.exceptions.ProcessingException; //导入依赖的package包/类
@Test
public void populateHiddenFields() throws IOException, ProcessingException {
// use a different md for this test
TestCRUDOperationContext ctx = new TestCRUDOperationContext(CRUDOperation.FIND);
md = getMd("./testMetadata_index.json");
ctx.add(md);
docTranslator = new DocTranslator(ctx, nodeFactory);
ObjectNode obj = JsonNodeFactory.instance.objectNode();
obj.put(DocTranslator.OBJECT_TYPE_STR, "test")
.put("field1", "testField1")
.put("field2", "testField2");
DBObject bson = docTranslator.toBson(new JsonDoc(obj)).doc;
DocTranslator.populateDocHiddenFields(bson, md);
DBObject hidden = (DBObject) bson.get(DocTranslator.HIDDEN_SUB_PATH.toString());
Assert.assertEquals("TESTFIELD1", hidden.get("field1"));
Assert.assertNull("testField2", hidden.get("field2"));
Assert.assertEquals(null, hidden.get("field3"));
}
示例7: assertMatchesJsonSchema
import com.github.fge.jsonschema.core.exceptions.ProcessingException; //导入依赖的package包/类
private void assertMatchesJsonSchema(final String json) {
try {
final ObjectNode rootNode = (ObjectNode) JsonLoader.fromString(json);
final ObjectNode contextNode = (ObjectNode) rootNode.get("context");
if (contextNode != null) {
contextNode.remove("logger");
contextNode.remove("MDC_KEY");
contextNode.remove("CONTEXT_KEY1");
contextNode.remove("CONTEXT_KEY2");
contextNode.remove("CONTEXT_KEY3");
contextNode.remove("CONTEXT_KEY4");
contextNode.remove("CONTEXT_KEY5");
contextNode.remove("CONTEXT_KEY6");
}
final ProcessingReport report = _validator.validate(STENO_SCHEMA, rootNode);
Assert.assertTrue(report.toString(), report.isSuccess());
} catch (final IOException | ProcessingException e) {
Assert.fail("Failed with exception: " + e);
}
}
示例8: _validate
import com.github.fge.jsonschema.core.exceptions.ProcessingException; //导入依赖的package包/类
protected ProcessingReport _validate(JsonNode json) throws IOException {
final JsonNode belSchema = JsonLoader.fromResource("/bel-json-graph.schema.json");
final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
final JsonSchema schema;
try {
schema = factory.getJsonSchema(belSchema);
return schema.validate(json, true);
} catch (ProcessingException e) {
throw new IOException(e);
}
}
示例9: validateSchema
import com.github.fge.jsonschema.core.exceptions.ProcessingException; //导入依赖的package包/类
private JsonSchema validateSchema(JsonNode jsonSchema)
throws UnRAVLException {
try {
final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
final JsonSchema schema = factory.getJsonSchema(jsonSchema);
SyntaxValidator syntaxValidator = factory.getSyntaxValidator();
if (!syntaxValidator.schemaIsValid(jsonSchema)) {
throw new UnRAVLException("JSON schema is invalid");
}
ProcessingReport report = syntaxValidator
.validateSchema(jsonSchema);
boolean success = report.isSuccess();
if (!success) {
throw new UnRAVLAssertionException(report.toString());
}
return schema;
} catch (ProcessingException e) {
throw new UnRAVLException(e);
}
}
示例10: testResource
import com.github.fge.jsonschema.core.exceptions.ProcessingException; //导入依赖的package包/类
private void testResource(String resource) throws IOException, JSONException, ProcessingException {
// verify json is schema compliant
runValidJsonTest("json-schema/metadata/metadata.json", resource);
JsonNode object = loadJsonNode(resource);
// json to java
EntityMetadata em = parser.parseEntityMetadata(object);
// verify got something
Assert.assertNotNull(em);
// java back to json
JsonNode converted = parser.convert(em);
String original = loadResource(resource);
String before = object.toString();
String after = converted.toString();
JSONAssert.assertEquals(original, before, false);
JSONAssert.assertEquals(original, after, false);
}
示例11: testExtraFieldNoHooks
import com.github.fge.jsonschema.core.exceptions.ProcessingException; //导入依赖的package包/类
@Test
public void testExtraFieldNoHooks() throws IOException, ParseException, JSONException, ProcessingException {
JsonNode object = loadJsonNode("JSONMetadataParserTest-object-everything-no-hooks-extra-field.json");
EntityMetadata em = parser.parseEntityMetadata(object);
Assert.assertNotNull(em);
Assert.assertNotNull(em.getEntitySchema());
Map<String, Object> properties = em.getEntitySchema().getProperties();
Assert.assertNotNull(properties);
Assert.assertFalse("Empty 'properties' (it should contain rdbms)", properties.isEmpty());
Assert.assertTrue("More than a single property (it should contain just rdbms)", properties.size() == 1);
Object rdbms = properties.get("rdbms");
Assert.assertNotNull(rdbms);
Assert.assertEquals("42", ((Map<String, Object>) rdbms).get("answer"));
JsonNode c = parser.convert(em);
Assert.assertEquals(object.get("schema").get("rdbms"), c.get("schema").get("rdbms"));
}
示例12: loadSchema
import com.github.fge.jsonschema.core.exceptions.ProcessingException; //导入依赖的package包/类
/**
* Load a schema from given resourceName.
*
* @param resourceName
* @return the schema
* @throws ProcessingException
* @throws IOException
*/
public static JsonSchema loadSchema(String resourceName) throws ProcessingException, IOException {
JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
SyntaxValidator validator = factory.getSyntaxValidator();
JsonNode node = loadJsonNode(resourceName);
ProcessingReport report = validator.validateSchema(node);
if (!report.isSuccess()) {
throw Error.get(UtilConstants.ERR_JSON_SCHEMA_INVALID);
}
JsonSchema schema = factory.getJsonSchema("resource:/" + resourceName);
if (null == schema) {
throw Error.get(UtilConstants.ERR_JSON_SCHEMA_INVALID);
}
return schema;
}
示例13: jsonSchemaValidation
import com.github.fge.jsonschema.core.exceptions.ProcessingException; //导入依赖的package包/类
/**
* Validates input node against given schema. Returns NULL if no errors
* reported, else returns string representing violations.
*
* @param schema the json schema (see #loadSchema)
* @param node the json node to validate
* @return null if there are no errors, else string with all errors and
* warnings
* @throws ProcessingException
*/
public static String jsonSchemaValidation(JsonSchema schema, JsonNode node) throws ProcessingException, JsonProcessingException {
ProcessingReport report = schema.validate(node);
Iterator<ProcessingMessage> i = report.iterator();
StringBuilder buff = new StringBuilder();
while (!report.isSuccess() && i != null && i.hasNext()) {
ProcessingMessage pm = i.next();
// attempting to pretty print the json
ObjectMapper mapper = new ObjectMapper();
String prettyPrintJson = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(pm.asJson());
buff.append(prettyPrintJson).append("\n\n");
}
return report.isSuccess() ? null : buff.toString();
}
示例14: buildResult
import com.github.fge.jsonschema.core.exceptions.ProcessingException; //导入依赖的package包/类
@Override
protected JsonNode buildResult(final String input)
throws IOException, ProcessingException
{
final ObjectNode ret = FACTORY.objectNode();
final boolean invalidSchema = fillWithData(ret, INPUT, INVALID_INPUT,
input);
final JsonNode schemaNode = ret.remove(INPUT);
if (invalidSchema)
return ret;
final ProcessingReport report = VALIDATOR.validateSchema(schemaNode);
final boolean success = report.isSuccess();
ret.put(VALID, success);
ret.put(RESULTS, JacksonUtils.prettyPrint(buildReport(report)));
return ret;
}
示例15: GenericOpenRtbValidator
import com.github.fge.jsonschema.core.exceptions.ProcessingException; //导入依赖的package包/类
/**
* Constructs a JSON validator using the given schema read as a resource.
*
* @param schemaResource
* the schema resource
*/
GenericOpenRtbValidator(String schemaResource) {
try {
JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
JsonNode jsonNode = JsonLoader.fromResource(schemaResource);
schema = factory.getJsonSchema(jsonNode);
} catch (IOException | ProcessingException e) {
throw new IllegalStateException("could not initialize validator due to previous exception", e);
}
}