Apache Sling Resource Resolver

Clone this repo:
  1. 272ea9a SLING-9040 only update intersecting ResourceProviderHandler by Dirk Rudolph · 4 months ago master
  2. dc56b45 Merge pull request #15 from apache/feature/SLING-7768 by Andreas Schaefer · 4 months ago
  3. 3301e49 Fixed two code smells. Ignored the ones of the Interpolator as this is not my code by Andreas Schaefer · 4 months ago
  4. 81e2bc9 Added Interpolator tests for additional jacoco test coverage requested by Betrand by Andreas Schaefer · 4 months ago
  5. 4e7c2ef Changes requested by Carsten’s Code Review or PR 15 by Andreas Schaefer · 4 months ago

Build Status Test Status Maven Central JavaDocs License

Apache Sling Resource Resolver

This module is part of the Apache Sling project.

This bundle provides the Resource Resolver and Resource Resolver Factory

ETC Map String Interpolation

Setting up ETC Mappings (/etc/map) for different instances like dev, stage, qa and production was time consuming and error prone due to copy-n-paste errors. As a new feature Sling now supports String Interpolation in the /etc/map. With this it is possible to add placeholders to sling:match entries to make it possible to have them work for different environments. The values are either provides by System, Bundle Context or String Interpolation Configuration values. The placeholders have this format: $[‘type’:‘name’;default=‘default value’]. The type is can be:

  • env: take from the System Properties
  • prop: taken from the Bundle Context Properties
  • otherwise: taken from the String Interpolation Configuration

With it it is possible to create a single set of etc-mapping and then adjust the actual values of an instance by an OSGi configuration. Note: the placeholder must be placed into a sling:match entry and cannot be the JCR Node Name as some of the characters are not allowed.

Setup

The Substitution Configuration can be found in the OSGi Configuration as Apache Sling String Interpolation Provider. The property Placeholder Values takes a list of key=value entries where each of them map a variable with its actual value. In our little introduction we add an entry of phv.default.host.name=localhost. Save the configuration for now. Before going on make sure that you know Mapping Location configuration in the OSGi configuration of Apache Sling Resource Resolver Factory. Now to to composum and go to that node. If it does not exist then create one. The mapping should look like this:

  • etc
    • map
      • http
        • my-mapping
          • sling:match=$[phv.fq.host.name].8080

Opening the page http://localhost:8080/starter/index.html should work just fine. This is a mapping from System Properties with a default:

  • etc
    • map
      • http
        • my-mapping
          • sling:match=$[env:phv.fq.host.name;default=localhost].8080

Testing

Now got back to the String Interpolation configuration and change the value to qa.author.acme.com and save it.

For local testing open your hosts file (/etc/hosts on Unix) and add a line like this:

127.0.0.1 qa.author.acme.com

save it and test with ping qa.author.acme.com to make sure the name resolves. Now you should be able to open the same page with: http://qa.author.acme.com/starter/index.html.

Now do the same with phv.fq.host.name=staging.author.acme.com.

The String Interpolation works with any part of the etc-map tree.