Skip navigation
jan olszewski
Currently Being Moderated

Link Externalizer - automatic author/publish absolute links setting?

Apr 6, 2012 1:25 AM

Tags: #absolute_links #cq5

Hi guys,

 

I was wondering whether it is feasible to get the code figure out by itself on which instance it is running, in order to set external (absolute) links accordingly via Externalizer.

 

According to the latest API version, the Day CQ5 Link Externalizer config object exposes separate environment properties (publish/author/local) one should use to set base URLs for them.

Which is more than fine. Question is though: how do I refer to one or another definition, given the instance it is running on?

To be more specific: same bundle, same java code, running on author and publish, producing external links according to the environment.

 

Thanks in advance.

Jan

 
Replies
  • Currently Being Moderated
    Apr 6, 2012 7:25 AM   in reply to jan olszewski

    Not sure if I understood correctly your question, but you can use sling run.mode to determine which instance the code is running on, see

    http://sling.apache.org/site/run-modes-orgapacheslingrunmode.html

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 9, 2012 6:40 AM   in reply to jan olszewski

    Jan, the way it works is for each CQ instance you can configure the Exteranlizer. When you get the Exeternalizer Service within CQ, it will only return the single configured service. If you want different configs between environments (prod, stage, test, etc) - you would need to configure the Externalizer differently on each environment. You can do this manually as illustrated in the attached image via the Felix Console, or you can use use osgi config nodes and leverage sling run modes as pacoolsky suggested (using sling run modes is the proper way).

     

    Hope this helps

     

    https://img.skitch.com/20120409-kqnp9u87352beduyxappgd811s.png

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 18, 2012 3:37 PM   in reply to jan olszewski

    No, coding in runmode in your app code is the wrong solution - what you want is to have different externalizer configs depending on the runmode (as ootb), and use "local" in your case.

     

    This purely depends on what link you want to generate:

    • should later point to publish (even if created on author instance) -> use "publish"
    • should point to author (even if created on publish instance, rare case, but for intranet situations maybe) -> use "author"
    • should point to the current instance -> use "local" (this is not "localhost", but you have to configure that differently on instances, e.g. for author runmode this config would be the same as the "author" domain, in publish runmode "local" = "publish" domain)
     
    |
    Mark as:
  • Currently Being Moderated
    Apr 20, 2012 12:33 PM   in reply to jan olszewski

    "Retrieving the run mode of the instance" <- that's what I mean with "coding in runmode". Code should usually never ask for the runmode (via sling settings service), but you should have a service that has your specific semantics as configuration options, and these are differently configured in different runmodes, i.e. by having different sling:OsgiConfig nodes in config.author, config.publish etc.

     

    In your case of multiple sites I would replicate the ootb constants per site: local-<site>, author-<site>, publish-<site> (if you really need all 3 to differentiate between author and publish, maybe just <site> is enough). Then all you need is to call externalizer.externalLink(resolver, "<site>", "/path") in your code, and have different runmode configs for the externalizer service.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points