ofuangka
ofuangka

Reputation: 3

Adding a SlingFilter to Apache Felix configMgr

I'm writing a simple Sling filter to run on AEM 5.6.1. I've made the filter use configuration properties, and I would have expected it to show up in /system/console/configMgr but it does not.

@SlingFilter(generateComponent = true, generateService = true, order = -700, scope = SlingFilterScope.REQUEST)
public class SimpleFilter implements Filter {

    @Property(value = "property.defaultvalue")
    private static final String PROPERTY_KEY = "property.key";

    private String configuredValue;

    @Activate
    protected void activate(final ComponentContext componentContext) throws Exception {
        Map<String, String> config = (Map<String, String>) componentContext.getProperties();
        this.configuredValue = config.get(PROPERTY_KEY);
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println(this.configuredValue);
    }
}

I'm able to install the bundle, see that the filter is working and can find it in /system/console/bundles, but it doesn't get added to /system/console/configMgr like I thought it would from the presense of the @Property annotation. Did I miss a step?

Upvotes: 0

Views: 200

Answers (1)

rakhi4110
rakhi4110

Reputation: 9281

You need to specify metatype = true along with the generateComponent if you need to configurations to appear in the configuration manager. By default metatype is false.

@SlingFilter(generateComponent = true, 
    generateService = true, 
    metatype = true,
    order = -700, 
    scope = SlingFilterScope.REQUEST)

Refer Apache Felix - SCR Annotations and Apache Felix Metatype Service to understand it better.

Upvotes: 1

Related Questions