Hi @hemalatha,
Create a custom implementation for TransformerFactory and reference the desired OSGI service there.
In the createTransformer() method of TransformerFactory, invoke your custom Transformer class (Passing the referenced OSGI service via Parameterized constructor)
Below sample skeleton for reference. (Haven't tried for actual implementation, below is just the sample structure)
CustomTransformerFactory.class
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.rewriter.Transformer;
import org.apache.sling.rewriter.TransformerFactory;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
@Component(service = TransformerFactory.class, property = { "pipeline.mode=global",
"pipeline.paths=/content/learnings", "pipeline-type=linkrewriter" }, immediate = true)
public class CustomTransformerFactory implements TransformerFactory {
@Reference //if this is not working try bind/unbind reference
private ResourceResolverFactory rescFactory;
@Override
public Transformer createTransformer() {
return new CustomTransformer(rescFactory);
}
}CustomTransformer.class
public class CustomTransformer implements Transformer {
private ResourceResolverFactory rescFactory; // This instance variable is initialized in the below constructor(as invoked from Factory) can then be used in the overridden methods of Transformer.
public CustomTransformer(ResourceResolverFactory rescFactory) {
this.rescFactory = rescFactory;
}
}