mrjayviper
mrjayviper

Reputation: 2388

AEM 6.x: How do I temporarily/programmatically disable the link checker? (trying to return a JSON with links back to browser)

So I have a Sling servlet that reads data from another API (let's call it APIX) and APIX gives me the data in JSON format.

When I debugged my code, it seems the response I get from APIX is intact.

When I pass the JSON I got from APIX to browser, I can see that AEM has "link checked" all the links I have in the JSON. I don't want AEM to do anything with my data.

Base on this Adobe page, I added these lines in my code:

protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
  LinkCheckerSettings linkCheckerSettings = LinkCheckerSettings.fromRequest(request);
  linkCheckerSettings.setIgnoreExternals(true);

  //body of the code here

  response.setCharacterEncoding("UTF-8");
  response.setContentType("application/json;charset=UTF-8");

  printWriter.write(jsonResponse);

  linkCheckerSettings.setIgnoreExternals(false);
}

No effect. I can still see these string

<img src="/libs/cq/linkchecker/resources/linkcheck_o.gif" alt="invalid link: _blank\\" title="invalid link: _blank\\" border="0">

everywhere.

I then tried disabling Linkchecker (via configMgr/Day CQ Link Checker Transformer) and still no effect.

How can I do it?

I called the Slng servlet by typing this URL in my browser: http://localhost:4502/servlets/getpublications?name=john.smith

Thanks!

EDIT:

This is a sample of the JSON data I'm getting from APIX (debugging on IntelliJ):

"LINKS":[
        "<a x-cq-linkchecker=\"skip\" target=\"_blank\" href=\"http:\/\/www.google23.com\">[Web Link]<\/a>"
        ]

This is what I'm getting on the browser (the a tag was somehow replaced by an img tag)

"LINKS":[
         "<img src="/libs/cq/linkchecker/resources/linkcheck_o.gif" alt="invalid link: _blank\\" title="invalid link:_blank\\" border="0">                        [Web Link]<\/a>"
        ]

I have tried using valid and skip for x-cq-linkchecker but nothing happens.

Day CQ Link Checker Transformer config screenshot

enter image description here

Upvotes: 0

Views: 2270

Answers (2)

Saravana Prakash
Saravana Prakash

Reputation: 1323

There are multiple techniques for handling special url patterns, Refer here. And a very good link checker guide here.

Technique 1: Code way(Not recommended since not maintainable). Add class x-cq-linkchecker=”skip”

Technique 2: Disable link checker. Definitely not recommended in author. Author should witness broken links visible. However it is recommended to disable in publish rather than showing ugly broken link icon.

Technique 3: Add special url pattern. Your link checker should looks like this: enter image description here

Upvotes: 1

SubSul
SubSul

Reputation: 2563

I don't think disabling LinkChecker at a global level is recommended. There are a few more ways you can achieve this and place the restriction to only certain use cases -

  1. If the link contains special prefixes like tel:, mailto: etc, - you'll have to add them to Day CQ Link Checker Service in /system/console/configMgr to disable LinkChecker for these links.
  2. Add this parameter x-cq-linkchecker="valid" to the <img> tag to ensure links are marked as valid in AEM - even though AEM considers them invalid.
  3. You can also use x-cq-linkchecker="skip" to skip link checker validation for this element.

You might encounter caching issues after updating the above params(2. and 3.), just try deleting contents in /var/linkchecker before you start testing.

Upvotes: 1

Related Questions