use of io.atlasmap.kafkaconnect.inspect.KafkaConnectInspectionService in project atlasmap by atlasmap.
the class KafkaConnectService method inspect.
/**
* Inspects a Kafka Connect schema and return a Document object.
* @param request request
* @return {@link KafkaConnectInspectionResponse}
*/
public Response inspect(KafkaConnectInspectionRequest request) {
long startTime = System.currentTimeMillis();
KafkaConnectInspectionResponse response = new KafkaConnectInspectionResponse();
KafkaConnectDocument d = null;
try {
ClassLoader loader = resourceContext != null ? resourceContext.getResource(AtlasService.class).getLibraryLoader() : KafkaConnectService.class.getClassLoader();
KafkaConnectInspectionService s = new KafkaConnectInspectionService(loader);
String schemaTypeStr = request.getOptions().get(KafkaConnectConstants.OPTIONS_SCHEMA_TYPE);
KafkaConnectSchemaType schemaType = KafkaConnectSchemaType.valueOf(schemaTypeStr);
HashMap<String, Object> options = KafkaConnectUtil.repackParserOptions(request.getOptions());
switch(schemaType) {
case JSON:
d = s.inspectJson(request.getSchemaData(), options);
break;
case AVRO:
d = s.inspectAvro(request.getSchemaData(), options);
break;
default:
response.setErrorMessage("Unsupported inspection type: " + schemaType);
break;
}
} catch (Exception e) {
LOG.error("Error inspecting Kafka Connect schema: " + e.getMessage(), e);
response.setErrorMessage(e.getMessage());
} finally {
response.setExecutionTime(System.currentTimeMillis() - startTime);
}
response.setKafkaConnectDocument(d);
return Response.ok().entity(toJson(response)).build();
}
Aggregations