Get rewritten URL in Java/Rhino

Avatar

Avatar

jamiec4451712

Avatar

jamiec4451712

jamiec4451712

14-11-2018

Hey everyone,

I'm looking for a way to get a fully rewritten URL before the URL is written to the HTML response. For example, I have a page located at the path: /content/mysite/en/page. This means that when working locally, I will access it at something like http://localhost:4502/content/mysite/page.html. However, in higher environments, there are outbound mappings that will rewrite this URL if it appears on a page. For example, a link on my homepage may be rewritten to something like:

  /content/mysite/page (no HTML extension)

Or:

  /page.html (no content prefix)

Or simply:

  /page (no content prefix or HTML extension)

I understand that this is the role of a few services, including the Day CQ Link Checker Transformer and the Apache Sling Resource Resolver Factory. Let's say I have the Link Checker Transformer configured to rewrite the HTML extension by configuring it in the OSGI Config Manager and I have the Resource Resolver Factory configured with the mapping:

  /content/mysite/</

Now, in a Java service, given a string to a page, such as:

  /content/mysite/page

I'd like to essentially determine (without writing to the HTML response) exactly what the final, rewritten URL will be for the current environment based on the previous configurations. In the case above, it should be:

  /page

I've tried something like:

LinkCheckerSettings linkCheckerSettings = LinkCheckerSettings.fromRequest(request);

String result = this.linkChecker.getLink("/content/mysite/page", linkCheckerSettings).getHref();

But it just returns the input string ("/content/mysite/page"). The expected "result" of this would be "/page". If the Link Checker was configured to not rewrite the HTML extension, the expected output would be "/page.html".

Thank you!

Accepted Solutions (0)

Answers (1)

Answers (1)

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

1.0K

Correct Reply

838

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

1.0K

Correct Reply

838
Arun_Patidar
MVP

14-11-2018

Can you try with below if helps

ResourceResolver (Apache Sling 7 API)