Runmode property for Filter

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Runmode property for Filter

Christopher Rockwell
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
[hidden email]



Reply | Threaded
Open this post in threaded view
|

Re: Runmode property for Filter

Robert Munteanu-2
Hi Cris,

On Thu, 2018-05-10 at 15:48 -0400, Cris Rockwell wrote:
> 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.

(snip)

The way this is usually achieved is by:

- making the component require a configuration ( configurationPolicy =
REQUIRE )
- deploying the configuration only in the publish runmode, for instance
by adding it to a `/apps/myapp/config.publish` folder.

Robert
Reply | Threaded
Open this post in threaded view
|

Re: Runmode property for Filter

Wim Symons
In reply to this post by Christopher Rockwell
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 <[hidden email]> 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
> [hidden email]
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Runmode property for Filter

Christopher Rockwell
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 <[hidden email]> 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 <[hidden email]> 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
>> [hidden email]
>>
>>
>>