Hi @tanuj05,
When the same service ranking are registered, and OSGi will invoke the one with the lowest service.id by default, unless a better ranking or filtering mechanism is in place.
Since you're working with multiple generators - some extending ResourceTreeSitemapGenerator and others implementing SitemapGenerator directly - here's how you can correctly control which generator handles which root path.
Solution Overview
You should configure each SitemapGenerator to only apply to specific root paths using the sitemap.resourceTypes or sitemap.paths property. The Apache Sling Sitemap framework relies on this configuration to determine which generator to invoke.
1. Use paths property in your generator service
Each custom generator should explicitly declare the root path(s) it supports:
@Component(
service = SitemapGenerator.class,
property = {
SitemapGeneratorConstants.PROPERTY_PATHS + "=/content/site-a"
}
)
public class SiteASitemapGenerator implements SitemapGenerator {
}
Use /content/site-b for another generator, and so on.
2. Avoid relying solely on service.ranking
Since service.ranking is only used to resolve ties, and service.id is non-deterministic, it's better to delegate control based on path rather than hoping ranking resolves your issue.
3. Alternative - use a delegator generator
If logic is very dynamic, implement a delegating generator that routes requests based on the root path:
@Component(service = SitemapGenerator.class)
public class DelegatingSitemapGenerator implements SitemapGenerator {
@Reference
private List<SitemapGenerator> generators;
@Override
public void generate(Resource resource, SitemapGeneratorContext context) {
for (SitemapGenerator generator : generators) {
if (generator.appliesTo(resource)) {
generator.generate(resource, context);
return;
}
}
}
}
Each generator can implement appliesTo() logic internally based on root path.
4. If you use ResourceTreeSitemapGenerator
That class is built for auto-generating URLs based on resource trees, and it uses resource types to decide what to include. Make sure to configure:
property = {
"sitemap.resourceTypes=mysite/components/page",
SitemapGeneratorConstants.PROPERTY_PATHS + "=/content/mysite"
}