当前位置: 首页>>代码示例>>Java>>正文


Java ValidationException类代码示例

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


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


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