in library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/json/JsonSchemaResolver.java [98:144]
private JsonNode computeIfAbsent(Exchange exchange) {
if (this.schema != null) {
return this.schema;
}
JsonNode answer = exchange.getProperty(SchemaHelper.CONTENT_SCHEMA, JsonNode.class);
if (answer == null && exchange.getProperties().containsKey(SchemaHelper.SCHEMA)) {
String schemaJson = exchange.getProperty(SchemaHelper.SCHEMA, String.class);
try {
answer = Json.MAPPER.readTree(schemaJson);
} catch (JsonProcessingException e) {
throw new RuntimeException("Unable to load Json schema", e);
}
}
if (answer == null) {
String contentClass = SchemaHelper.resolveContentClass(exchange, this.contentClass);
if (contentClass != null) {
answer = this.schemes.computeIfAbsent(contentClass, t -> {
Resource res = PluginHelper.getResourceLoader(exchange.getContext())
.resolveResource("classpath:schemas/" + SchemaType.JSON.type() + "/" + t + "." + SchemaType.JSON.type());
try {
if (res.exists()) {
try (InputStream is = res.getInputStream()) {
if (is != null) {
return Json.MAPPER.readTree(is);
}
}
}
} catch (Exception e) {
throw new RuntimeException(
"Unable to load Json schema for type: " + t + ", resource: " + res.getLocation(), e);
}
return null;
});
}
}
if (answer != null) {
this.schema = answer;
}
return answer;
}