Friday, May 31, 2013

How to configure custom mappings based on run mode?

 

Scenario: Having a requirement where we need to configure sling mappings based on run mode.

Example: Assume that we’ve three different environments called ‘author’, ‘preprod’ and ‘prod’

When we access http://<hostname>:<port>/projects   It has to redirect to three different urls based on run modes.

In author instance it should be redirected to  /content/test/author.html

In preprod instance it should be redirected to /content/test/preprod.html

In prod instance it should be redirected to /content/test/prod.html

Steps:

1.  Create different config.<runmode> nodes (of type sling:Folder) inside /apps/system/

Eg:    config.author     type    Sling:Folder

config.preprod    type    Sling:Folder

config.prod         type     Sling:Folder

2.   Create a new node of type Sling:OsgiConfig inside configuration folders.

       node name:   org.apache.sling.jcr.resource.internal.JcrResourceResolverFactoryImpl

       type:            Sling:OsgiConfig

      2.a:    Add following properties to the node:

          1.  property name:     resource.resolver.map.location

     type:    String

              value:    /etc/map.<runmode>

2. property name: resource.resolver.manglenamespaces

    type: Boolean

    value: true

3. property name: resource.resolver.default.vanity.redirect.status

    type: Decimal

    value: 302

4. property name:  resource.resolver.mapping

   type: String []

   value: /-/

5. property name:  resource.resolver.searchpath

   type: String []

   value: "/apps","/libs","/apps/foundation/components/primary","/libs/foundation/components/primary"

6. property name: resource.resolver.required.providers

   type: String[]

   value:  org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProviderFactory

7. property name: resource.resolver.allowDirect

   type: Boolean

   value: true

8. property name: resource.resolver.virtual

   type: String[]

   value: /:/

3.    Create different map configurations inside /etc.

       In our example, we can create Sling:Folders with following names:

       a.    map.author

       b.   map.preprod

       c.   map.prod

4.    Create configuration node for sling mapping inside /etc/map.<runmode>

     Eg:      Node name:     test

                 type:     Sling:OsgiConfig

       4.1  Add following properties to the config node

              a.   property name:    sling:match

                    type:    String

                   value:    <Some regular expression/match>

b.    property name: sling:redirect

      type: String

                value: <Some regular expression/match>

5.   Test it..

1 comment:

  1. Is there way to hide /jcr:content/renditions from the url, below is an example

    /content/dam/myimage/someimage/jcr:content/renditions/someimage150x160.png

    Expected result:
    /content/dam/myimage/someimage/someimage150x160.png
    or
    /content/dam/myimage/someimage/$1/$2/someimage150x160.png

    any inputs or help in finding the solution will be higly appreciated

    ReplyDelete