Thank you Wim and Robert for the very useful advice! 

I have two follow up questions:

1) Is it possible to set the value of EngineConstants.SLING_FILTER_PATTERN as a 
configuration? I have the code below. Ideally, I would be able to set something 
useful in the config and not just an enable boolean. Is this possible to set an 
@Component( property = {}) with configuration? 

2) The filter component service type is singleton. For the configuration 
properties, should I set these to static?


Thanks!
Cris 



/*
 * example code
 */

@Component(service = Filter.class,
        immediate = true,
        configurationPolicy = REQUIRE,
        property = {
                Constants.SERVICE_DESCRIPTION + "=Demo to filter incoming 
requests",
                EngineConstants.SLING_FILTER_SCOPE + "=" + 
EngineConstants.FILTER_SCOPE_REQUEST,
                Constants.SERVICE_RANKING + "=-700",
                EngineConstants.SLING_FILTER_PATTERN + 
“=/can/this/be/configuration.?"
        },
        configurationPid = "edu.yada.filters.MyFilter”)

@Designate(ocd=MyFilter.Configuration.class)
public final class MyFilter implements Filter {

          private static String CONFIG_1; // static ok?
          private static String CONFIG_2;
          private static String PATH_PATTERN;


// inside MyFilter class there is this subclass
@ObjectClassDefinition(name = "LSA Filter Configurations")
public @interface Configuration {
    @AttributeDefinition(
            name = “Filter Pattern"
    )
    String filter_pattern() default "";
}


         // using the configurations
        protected void Activate(Configuration config) {
              pattern = config.filter_pattern();
              // How to set EngineConstants.SLING_FILTER_PATTERN from Activate?
         }
}



> On May 10, 2018, at 3:54 PM, Wim Symons <[email protected]> wrote:
> 
> Cris,
> 
> See the explanation at 
> http://www.computepatterns.com/43/osgi-component-in-aem-that-is-active-only-in-specific-run-mode-say-publish/.
> 
> Kind regards
> 
> Wim
> 
>> Op 10 mei 2018 om 21:48 heeft Cris Rockwell <[email protected]> het 
>> volgende geschreven:
>> 
>> Hi folks
>> 
>> If I have a filter like the one shown below and in the link, is it possible 
>> to set a property so it only takes effect on a certain Runmode? I would like 
>> my filter to only run on instances having the publish run mode. 
>> 
>> https://sling.apache.org/documentation/the-sling-engine/filters.html 
>> <https://sling.apache.org/documentation/the-sling-engine/filters.html>
>> 
>> 
>> @Component(service = Filter.class,
>>       property = {
>>               Constants.SERVICE_DESCRIPTION + "=Demo to filter incoming 
>> requests",
>>               EngineConstants.SLING_FILTER_SCOPE + "=" + 
>> EngineConstants.FILTER_SCOPE_REQUEST,
>>               Constants.SERVICE_RANKING + "=-700",
>>               EngineConstants.SLING_FILTER_PATTERN + 
>> "=/content/my-project/.*"
>>       })
>> 
>> public final class OpenIDConnectFilter implements Filter {
>> 
>> }
>> 
>> Thanks!
>> Cris Rockwell
>> App Sys Analyst/Programmer Sr | U-M LSA Web Services 
>> [email protected]
>> 
>> 
>> 

Reply via email to