in doc-architect/doc-architect-core/src/main/java/com/docarchitect/core/scanner/impl/java/JavaHttpClientScanner.java [305:374]
private FallbackParsingStrategy<Relationship> createFallbackStrategy(Set<String> processedRelationships) {
return (file, content) -> {
List<Relationship> relationships = new ArrayList<>();
// Check if file contains HTTP client patterns
if (!content.contains("FeignClient") && !content.contains("RestTemplate") &&
!content.contains("WebClient") && !content.contains("http://") &&
!content.contains("https://")) {
return relationships;
}
// Extract package using shared utility
String packageName = RegexPatterns.extractPackageName(content);
String sourceComponentId = packageName.isEmpty() ? "default" : packageName.split("\\.")[0];
// Extract FeignClient relationships
Matcher feignMatcher = FEIGN_CLIENT_PATTERN.matcher(content);
while (feignMatcher.find()) {
String serviceName = feignMatcher.group(1);
String targetComponentId = IdGenerator.generate(serviceName);
addRelationship(
sourceComponentId,
targetComponentId,
"Feign client call to " + serviceName,
"HTTP/Feign",
relationships,
processedRelationships
);
}
// Extract RestTemplate relationships
Matcher restTemplateMatcher = REST_TEMPLATE_PATTERN.matcher(content);
while (restTemplateMatcher.find()) {
String url = restTemplateMatcher.group(1);
String targetService = extractServiceNameFromUrl(url);
if (targetService != null && !targetService.isEmpty()) {
String targetComponentId = IdGenerator.generate(targetService);
addRelationship(
sourceComponentId,
targetComponentId,
"RestTemplate call to " + targetService,
"HTTP/RestTemplate",
relationships,
processedRelationships
);
}
}
// Extract WebClient relationships
Matcher webClientMatcher = WEB_CLIENT_PATTERN.matcher(content);
while (webClientMatcher.find()) {
String url = webClientMatcher.group(1);
String targetService = extractServiceNameFromUrl(url);
if (targetService != null && !targetService.isEmpty()) {
String targetComponentId = IdGenerator.generate(targetService);
addRelationship(
sourceComponentId,
targetComponentId,
"WebClient call to " + targetService,
"HTTP/WebClient",
relationships,
processedRelationships
);
}
}
log.debug("Fallback parsing found {} relationships in {}", relationships.size(), file.getFileName());
return relationships;
};
}