in lib/HTTPLookupService.cc [367:427]
void HTTPLookupService::handleGetSchemaHTTPRequest(GetSchemaPromise promise, const std::string completeUrl) {
std::string responseData;
long responseCode = -1;
Result result = sendHTTPRequest(completeUrl, responseData, responseCode);
if (responseCode == 404) {
promise.setFailed(ResultTopicNotFound);
} else if (result != ResultOk) {
promise.setFailed(result);
} else {
ptree::ptree root;
std::stringstream stream(responseData);
try {
ptree::read_json(stream, root);
} catch (ptree::json_parser_error &e) {
LOG_ERROR("Failed to parse json of Partition Metadata: " << e.what()
<< "\nInput Json = " << responseData);
promise.setFailed(ResultInvalidMessage);
return;
}
const std::string defaultNotFoundString = "Not found";
auto schemaTypeStr = root.get<std::string>("type", defaultNotFoundString);
if (schemaTypeStr == defaultNotFoundString) {
LOG_ERROR("malformed json! - type not present" << responseData);
promise.setFailed(ResultInvalidMessage);
return;
}
auto schemaData = root.get<std::string>("data", defaultNotFoundString);
if (schemaData == defaultNotFoundString) {
LOG_ERROR("malformed json! - data not present" << responseData);
promise.setFailed(ResultInvalidMessage);
return;
}
auto schemaType = enumSchemaType(schemaTypeStr);
if (schemaType == KEY_VALUE) {
ptree::ptree kvRoot;
std::stringstream kvStream(schemaData);
try {
ptree::read_json(kvStream, kvRoot);
} catch (ptree::json_parser_error &e) {
LOG_ERROR("Failed to parse json of Partition Metadata: " << e.what()
<< "\nInput Json = " << schemaData);
promise.setFailed(ResultInvalidMessage);
return;
}
const auto keyData = toJson(kvRoot.get_child("key"));
const auto valueData = toJson(kvRoot.get_child("value"));
schemaData = mergeKeyValueSchema(keyData, valueData);
}
StringMap properties;
auto propertiesTree = root.get_child("properties");
for (const auto &item : propertiesTree) {
properties[item.first] = item.second.get_value<std::string>();
}
SchemaInfo schemaInfo = SchemaInfo(schemaType, "", schemaData, properties);
promise.setValue(schemaInfo);
}
}