• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ValidationException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.everit.json.schema.ValidationException的典型用法代码示例。如果您正苦于以下问题:Java ValidationException类的具体用法?Java ValidationException怎么用?Java ValidationException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ValidationException类属于org.everit.json.schema包,在下文中一共展示了ValidationException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: validate

import org.everit.json.schema.ValidationException; //导入依赖的package包/类
/**
 * Validates a given JSON Object against the default profile schema.
 * @param jsonObjectToValidate
 * @throws IOException
 * @throws DataPackageException
 * @throws ValidationException 
 */
public void validate(JSONObject jsonObjectToValidate) throws IOException, DataPackageException, ValidationException{
    
    // If a profile value is provided.
    if(jsonObjectToValidate.has(Package.JSON_KEY_PROFILE)){
        String profile = jsonObjectToValidate.getString(Package.JSON_KEY_PROFILE);
        
        String[] schemes = {"http", "https"};
        UrlValidator urlValidator = new UrlValidator(schemes);
        
        if (urlValidator.isValid(profile)) {
            this.validate(jsonObjectToValidate, new URL(profile));
        }else{
            this.validate(jsonObjectToValidate, profile);
        }
        
    }else{
        // If no profile value is provided, use default value.
        this.validate(jsonObjectToValidate, Profile.PROFILE_DEFAULT);
    }   
}
 
开发者ID:frictionlessdata,项目名称:datapackage-java,代码行数:28,代码来源:Validator.java


示例2: check

import org.everit.json.schema.ValidationException; //导入依赖的package包/类
@Override
public boolean check(
        HttpServerExchange exchange,
        RequestContext context,
        BsonDocument contentToCheck,
        BsonValue args) {
    if (contentToCheck == null) {
        return false;
    }

    try {
        schema.validate(new JSONObject(contentToCheck.toString()));
    } catch (ValidationException ve) {
        context.addWarning(ve.getMessage());
        ve.getCausingExceptions().stream()
                .map(ValidationException::getMessage)
                .forEach(context::addWarning);

        return false;
    }

    return true;
}
 
开发者ID:SoftInstigate,项目名称:restheart,代码行数:24,代码来源:JsonMetaSchemaChecker.java


示例3: validateGeoJsonSchema

import org.everit.json.schema.ValidationException; //导入依赖的package包/类
/**
 * We only want to go through this initialization if we have to because it's a
 * performance issue the first time it is executed.
 * Because of this, so we don't include this logic in the constructor and only
 * call it when it is actually required after trying all other type inferral.
 * @param geoJson
 * @throws ValidationException 
 */
private void validateGeoJsonSchema(JSONObject geoJson) throws ValidationException{
    if(this.getGeoJsonSchema() == null){
        // FIXME: Maybe this infering against geojson scheme is too much.
        // Grabbed geojson schema from here: https://github.com/fge/sample-json-schemas/tree/master/geojson
        InputStream geoJsonSchemaInputStream = TypeInferrer.class.getResourceAsStream("/schemas/geojson/geojson.json");
        JSONObject rawGeoJsonSchema = new JSONObject(new JSONTokener(geoJsonSchemaInputStream));
        this.setGeoJsonSchema(SchemaLoader.load(rawGeoJsonSchema));
    }
    this.getGeoJsonSchema().validate(geoJson);
}
 
开发者ID:frictionlessdata,项目名称:tableschema-java,代码行数:19,代码来源:TypeInferrer.java


示例4: Schema

import org.everit.json.schema.ValidationException; //导入依赖的package包/类
/**
 * Read, create, and validate a table schema with local descriptor.
 * @param schemaFilePath
 * @param strict
 * @throws ValidationException
 * @throws PrimaryKeyException
 * @throws ForeignKeyException
 * @throws Exception 
 */
public Schema(String schemaFilePath, boolean strict) throws ValidationException, PrimaryKeyException, ForeignKeyException, Exception{
    this.strictValidation = strict;
    this.initValidator(); 
    InputStream is = new FileInputStream(schemaFilePath);
    InputStreamReader inputStreamReader = new InputStreamReader(is);
    this.initSchemaFromStream(inputStreamReader);
    
    this.validate();
}
 
开发者ID:frictionlessdata,项目名称:tableschema-java,代码行数:19,代码来源:Schema.java


示例5: isValid

import org.everit.json.schema.ValidationException; //导入依赖的package包/类
/**
 * Check if schema is valid or not.
 * @return 
 */
public boolean isValid(){
    try{
        validate();
        return true;
        
    }catch(ValidationException ve){
        return false;
    }
}
 
开发者ID:frictionlessdata,项目名称:tableschema-java,代码行数:14,代码来源:Schema.java


示例6: validate

import org.everit.json.schema.ValidationException; //导入依赖的package包/类
/**
 * Validate the loaded Schema.
 * Validation is strict or unstrict depending on how the package was
 * instanciated with the strict flag.
 * @throws ValidationException 
 */
public final void validate() throws ValidationException{
    try{
         this.tableJsonSchema.validate(this.getJson());
        
    }catch(ValidationException ve){
        if(this.strictValidation){
            throw ve;
        }else{
            this.getErrors().add(ve);
        }
    }
}
 
开发者ID:frictionlessdata,项目名称:tableschema-java,代码行数:19,代码来源:Schema.java


示例7: testCreateSchemaFromInvalidSchemaJson

import org.everit.json.schema.ValidationException; //导入依赖的package包/类
@Test
public void testCreateSchemaFromInvalidSchemaJson() throws PrimaryKeyException, ForeignKeyException{  
    JSONObject schemaJsonObj = new JSONObject();
   
    schemaJsonObj.put("fields", new JSONArray());
    Field nameField = new Field("id", Field.FIELD_TYPE_INTEGER);
    Field invalidField = new Field("coordinates", "invalid");
    schemaJsonObj.getJSONArray("fields").put(nameField.getJson());
    schemaJsonObj.getJSONArray("fields").put(invalidField.getJson());
    
    exception.expect(ValidationException.class);
    Schema invalidSchema = new Schema(schemaJsonObj, true);
    
}
 
开发者ID:frictionlessdata,项目名称:tableschema-java,代码行数:15,代码来源:SchemaTest.java


示例8: testInvalidForeignKeyString

import org.everit.json.schema.ValidationException; //导入依赖的package包/类
@Test
public void testInvalidForeignKeyString() throws PrimaryKeyException, ForeignKeyException, Exception{
    String sourceFileAbsPath = SchemaTest.class.getResource("/fixtures/foreignkeys/schema_invalid_fk_string.json").getPath();
    
    exception.expect(ValidationException.class);
    Schema schema = new Schema(sourceFileAbsPath, true);
}
 
开发者ID:frictionlessdata,项目名称:tableschema-java,代码行数:8,代码来源:SchemaTest.java


示例9: Package

import org.everit.json.schema.ValidationException; //导入依赖的package包/类
/**
 * Load from String representation of JSON object or from a zip file path.
 * @param jsonStringSource
 * @param strict
 * @throws IOException
 * @throws DataPackageException
 * @throws ValidationException
 */
public Package(String jsonStringSource, boolean strict) throws IOException, DataPackageException, ValidationException{
    this.strictValidation = strict;
    
    // If zip file is given.
    if(jsonStringSource.toLowerCase().endsWith(".zip")){
        // Read in memory the file inside the zip.
        ZipFile zipFile = new ZipFile(jsonStringSource);
        ZipEntry entry = zipFile.getEntry(DATAPACKAGE_FILENAME);
        
        // Throw exception if expected datapackage.json file not found.
        if(entry == null){
            throw new DataPackageException("The zip file does not contain the expected file: " + DATAPACKAGE_FILENAME);
        }
        
        // Read the datapackage.json file inside the zip
        try(InputStream is = zipFile.getInputStream(entry)){
            StringBuilder out = new StringBuilder();
            try(BufferedReader reader = new BufferedReader(new InputStreamReader(is))){
                String line = null;
                while ((line = reader.readLine()) != null) {
                    out.append(line);
                }
            }
            
            // Create and set the JSONObject for the datapackage.json that was read from inside the zip file.
            this.setJson(new JSONObject(out.toString()));  
            
            // Validate.
            this.validate();
        }
   
    }else{
        // Create and set the JSONObject fpr the String representation of desriptor JSON object.
        this.setJson(new JSONObject(jsonStringSource)); 
        
        // If String representation of desriptor JSON object is provided.
        this.validate(); 
    }
}
 
开发者ID:frictionlessdata,项目名称:datapackage-java,代码行数:48,代码来源:Package.java


示例10: validate

import org.everit.json.schema.ValidationException; //导入依赖的package包/类
/**
 * Validation is strict or unstrict depending on how the package was
 * instanciated with the strict flag.
 * @throws IOException
 * @throws DataPackageException
 * @throws ValidationException 
 */
public final void validate() throws IOException, DataPackageException, ValidationException{
    try{
        this.validator.validate(this.getJson());
        
    }catch(ValidationException ve){
        if(this.strictValidation){
            throw ve;
        }else{
            errors.add(ve);
        }
    }
}
 
开发者ID:frictionlessdata,项目名称:datapackage-java,代码行数:20,代码来源:Package.java


示例11: testLoadInvalidJsonObject

import org.everit.json.schema.ValidationException; //导入依赖的package包/类
@Test
public void testLoadInvalidJsonObject() throws IOException, DataPackageException{
    // Create JSON Object for testing
    JSONObject jsonObject = new JSONObject("{\"name\": \"test\"}");
    
    // Build the datapackage, it will throw ValidationException because there are no resources.
    exception.expect(ValidationException.class);
    Package dp = new Package(jsonObject, true);
}
 
开发者ID:frictionlessdata,项目名称:datapackage-java,代码行数:10,代码来源:PackageTest.java


示例12: testValidUrlWithInvalidJson

import org.everit.json.schema.ValidationException; //导入依赖的package包/类
@Test
public void testValidUrlWithInvalidJson() throws DataPackageException, MalformedURLException, IOException{
    // Preferably we would use mockito/powermock to mock URL Connection
    // But could not resolve AbstractMethodError: https://stackoverflow.com/a/32696152/4030804
    URL url = new URL("https://raw.githubusercontent.com/frictionlessdata/datapackage-java/master/src/test/resources/fixtures/simple_invalid_datapackage.json");
    exception.expect(ValidationException.class);
    Package dp = new Package(url, true);
    
}
 
开发者ID:frictionlessdata,项目名称:datapackage-java,代码行数:10,代码来源:PackageTest.java


示例13: testReadFromZipFileWithInvalidDatapackageDescriptorAndStrictValidation

import org.everit.json.schema.ValidationException; //导入依赖的package包/类
@Test
public void testReadFromZipFileWithInvalidDatapackageDescriptorAndStrictValidation() throws Exception{
    String sourceFileAbsPath = PackageTest.class.getResource("/fixtures/zip/invalid_datapackage.zip").getPath();
    
    exception.expect(ValidationException.class);
    Package p = new Package(sourceFileAbsPath, true);
}
 
开发者ID:frictionlessdata,项目名称:datapackage-java,代码行数:8,代码来源:PackageTest.java


示例14: testValidatingInvalidJsonObject

import org.everit.json.schema.ValidationException; //导入依赖的package包/类
@Test
public void testValidatingInvalidJsonObject() throws IOException, DataPackageException {
    JSONObject datapackageJsonObject = new JSONObject("{\"invalid\" : \"json\"}");
    
    exception.expect(ValidationException.class);
    validator.validate(datapackageJsonObject);  
}
 
开发者ID:frictionlessdata,项目名称:datapackage-java,代码行数:8,代码来源:ValidatorTest.java


示例15: testValidatingInvalidJsonString

import org.everit.json.schema.ValidationException; //导入依赖的package包/类
@Test
public void testValidatingInvalidJsonString() throws IOException, DataPackageException{
    String datapackageJsonString = "{\"invalid\" : \"json\"}";
    
    exception.expect(ValidationException.class);
    validator.validate(datapackageJsonString);   
}
 
开发者ID:frictionlessdata,项目名称:datapackage-java,代码行数:8,代码来源:ValidatorTest.java


示例16: deploy

import org.everit.json.schema.ValidationException; //导入依赖的package包/类
/**
 * Deploy a component with given JSON configuration
 *
 * @param deployConfig Json configuration corresponding to a component to be deployed
 * @param future       Future to provide the status of deployment
 * @see <a href="http://vertx.io/docs/apidocs/io/vertx/core/Future.html" target="_blank">Future</a>
 */
public void deploy(JsonObject deployConfig, Future<Boolean> future) {
	if (null == this.vertx) {
		String errMesg = "Not setup yet! Call 'setup' method first.";

		logger.error(errMesg);
		future.fail(new Exception(errMesg));

		return;
	}

	try {
		Schema jsonSchema = BaseUtil.schemaFromResource("/deploy-opts-schema.json");
		String jsonData = deployConfig.toString();

		BaseUtil.validateData(jsonSchema, jsonData);
	} catch (ValidationException vldEx) {
		logger.error("Issue with deployment configuration validation!", vldEx);

		vldEx
				.getCausingExceptions()
				.stream()
				.map(ValidationException::getMessage)
				.forEach((errMsg) -> {
					logger.error(errMsg);
				});

		future.fail(vldEx);

		return;
	} catch (IOException ioEx) {
		logger.error("Issue while loading schema configuration!", ioEx);
		future.fail(ioEx);

		return;
	}

	DeployComponent component = this.setupComponent(deployConfig);
	this.deployRecords.deploy(component.getIdentifier(), component.getDeployOpts(), future);
}
 
开发者ID:mustertech,项目名称:rms-deployer,代码行数:47,代码来源:VtxDeployer.java


示例17: invalidSchemaTest

import org.everit.json.schema.ValidationException; //导入依赖的package包/类
@Test
public void invalidSchemaTest() throws Exception {
	thrown.expect(ValidationException.class);

	Schema jsonSchema = BaseUtil.schemaFromResource("/deployer-schema.json");
	Assert.assertNotNull(jsonSchema);

	File jsonFile = new File("sample/test-component.json");
	Assert.assertNotNull(jsonFile);

	String jsonData = FileUtils.readFileToString(jsonFile, Charset.defaultCharset());
	Assert.assertTrue("JSON string length greater than zero", (0 < jsonData.length()));

	BaseUtil.validateData(jsonSchema, jsonData);
}
 
开发者ID:mustertech,项目名称:rms-deployer,代码行数:16,代码来源:BaseUtilTest.java


示例18: testDeployWrongConfig

import org.everit.json.schema.ValidationException; //导入依赖的package包/类
@Test
public void testDeployWrongConfig(TestContext testContext) throws Exception {
	Future<Void> future = Future.future();

	future.setHandler(testContext.asyncAssertFailure(res -> {
		Assert.assertFalse(vtxDeployer.isVertxSetup());
		Assert.assertTrue("Invalid configuration", ValidationException.class.isInstance(res));
	}));

	vtxDeployer.setup("sample/test-component.json", future);
}
 
开发者ID:mustertech,项目名称:rms-deployer,代码行数:12,代码来源:VtxDeployerTest.java


示例19: collectIncompatibilities

import org.everit.json.schema.ValidationException; //导入依赖的package包/类
public List<SchemaIncompatibility> collectIncompatibilities(final JSONObject schemaJson) {
    final List<SchemaIncompatibility> incompatibilities = new ArrayList<>();

    try {
        metaSchema.validate(schemaJson);
    } catch (final ValidationException e) {
        collectErrorMessages(e, incompatibilities);
    }

    return incompatibilities;
}
 
开发者ID:zalando,项目名称:nakadi,代码行数:12,代码来源:SchemaEvolutionService.java


示例20: collectErrorMessages

import org.everit.json.schema.ValidationException; //导入依赖的package包/类
private void collectErrorMessages(final ValidationException e,
                                  final List<SchemaIncompatibility> incompatibilities) {
    if (e.getCausingExceptions().isEmpty()) {
        incompatibilities.add(
                new ForbiddenAttributeIncompatibility(e.getPointerToViolation(), e.getErrorMessage()));
    } else {
        e.getCausingExceptions()
                .forEach(causingException -> collectErrorMessages(causingException, incompatibilities));
    }
}
 
开发者ID:zalando,项目名称:nakadi,代码行数:11,代码来源:SchemaEvolutionService.java



注:本文中的org.everit.json.schema.ValidationException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EmojiPopup类代码示例发布时间:2022-05-22
下一篇:
Java OkHttpImagePipelineConfigFactory类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap