Skip to content

Commit

Permalink
Fix loading of Validation Rule Schema from classpath (#97)
Browse files Browse the repository at this point in the history
Out of the box, the gateway is configured to load the
validation rule schema from within the classpath,
rather than from a file on disk. This was resulting
in a failure[1] as `ResourceUtils.getFile()` does not
support loading from a classpath.

By switching to use `getURL().openStream()`, both
classpath and filesystem loads will work correctly.

[1]: `Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'validationRuleSchemaProvider': Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [validation-rule.schema.json] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/dgcg.jar!/BOOT-INF/classes!/validation-rule.schema.json`

Co-authored-by: Felix Dittrich <[email protected]>
  • Loading branch information
kiall and f11h authored Jun 30, 2021
1 parent 5c570c7 commit 286e99e
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
package eu.europa.ec.dgc.gateway.config;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import javax.annotation.PostConstruct;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand All @@ -45,13 +46,17 @@ public class ValidationRuleSchemaProvider {
private Schema validationRuleSchema;

@PostConstruct
void setup() throws FileNotFoundException {
File schemaFile = ResourceUtils.getFile(configProperties.getValidationRuleSchema());

validationRuleSchema = SchemaLoader.builder()
.schemaJson(new JSONObject(new JSONTokener(new FileInputStream(schemaFile))))
.draftV7Support()
.build().load().build();
void setup() throws FileNotFoundException, IOException {
InputStream schemaInputStream = ResourceUtils.getURL(configProperties.getValidationRuleSchema()).openStream();

try {
validationRuleSchema = SchemaLoader.builder()
.schemaJson(new JSONObject(new JSONTokener(schemaInputStream)))
.draftV7Support()
.build().load().build();
} finally {
schemaInputStream.close();
}
}

}

0 comments on commit 286e99e

Please sign in to comment.