Disable Link Filtering in AEM for JSON response from servlet | Community
Skip to main content
Level 2
August 30, 2020
Solved

Disable Link Filtering in AEM for JSON response from servlet

  • August 30, 2020
  • 2 replies
  • 4064 views

I need help on hyperlink filtering in response and flow if like below.

1. I have article data response in article data JSON response (we recived pasre JSON)

 [Actual Response from Service provider]

{
"article": [
{
"name": "Test links",
"content": "<p>test <a href=\"https://en.wikipedia.org/wiki/Season\">Teslink</a></p>"
}
]
}

 [Getting response from singlet servlet] [public class ArticleServlet extends SlingSafeMethodsServlet]

 

{"article":[{"name":"Test links","approverOrderNumber":0,"content":"<p>test <img class="cq-LinkChecker cq-LinkChecker--prefix cq-LinkChecker--invalid" src="/libs/cq/linkchecker/resources/linkcheck_o.gif" alt="invalid link: \" title="invalid link: \" border="0">eGain1<img class="cq-LinkChecker cq-LinkChecker--suffix cq-LinkChecker--invalid" src="/libs/cq/linkchecker/resources/linkcheck_c.gif" border="0"></p>"
}
]
}

 

 

So its unnecessary adds "LinkChecker cq-LinkChecker--prefix cq-LinkChecker--invalid" these link in contents and its break everything in response.  

 

How can we stop link checker service in aem itself.

 

one method i seen is adding "x-cq-linkchecker="skip" but is there any other solution ?

 

Is it mandatory to add "x-cq-linkchecker="skip" in link ?

 

 
 

I tried below also then it removed "href" completely and send value as "href=/" in response.

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Manjunath_K

@sagrawal 

Link checker checks anchor links in servlet response & rewrites only in following scenarios.

 

If "a:href" present in the Day CQ Link Checker Transformer configuration. if your requirement is to 

  • disable link checker across the site irrespective of content type(application/json, text/html etc.) then removing "a:href" from this configuration will resolve your issue.
  • disable link checker only for json response then do not remove "a:href" from here & let it be as it is so that link checker applies to sightly html & other configured content type. check below solution to disable link checker only for json response.

 

Disable link checker only for JSON response content type

1. If you have added "application/json" content type in rewrite config under /apps/project/config/rewriter/project then remove this content type from configuration.

 

2. Set content type to servlet json response in servlet so that link checker rewrite will not be applied this content type since this content type is removed in step 1.

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

 

Above 2 steps will resolve link checker issue on json content type response.

 

Servlet JSON response before fix:

 

Servlet JSON response after fix:

 

 

As i mentioned in above comment no need to removing a:href or disabling link checker from "Day CQ Link Checker Transformer" for the issue which your facing because this will completely remove link checker for other content type as well.

 

so, just add content type in servlet response as mentioned below. if you have already added this then please share the header & response tab screenshot from browser network tab when we can see whether content type is set or not in response headers.

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

 

 

 

 

 

 

You will get href="\" i.e. link getting removed when there is no proper content type is set refer below screenshot where content type is not set.

 

 

 

 

 

-Manjunath

2 replies

Singaiah_Chintalapudi
Level 7
August 30, 2020

If you're referring this on publisher then, you should disable all Link Checker service configs.

 

On author, try modifying the Day CQ Link Checker Transformer: remove a:href from the Rewrite Elements config.

sagrawalAuthor
Level 2
October 3, 2020

I tried all option of disabling the service still this doesn't work.  In my servlet i am getting article content from 3rd part system so I can't add skip tag in content. 

Is there is any way programmatically we can disable link checker service while sending out JSON response. 

Manjunath_K
Manjunath_KAccepted solution
Level 7
October 3, 2020

@sagrawal 

Link checker checks anchor links in servlet response & rewrites only in following scenarios.

 

If "a:href" present in the Day CQ Link Checker Transformer configuration. if your requirement is to 

  • disable link checker across the site irrespective of content type(application/json, text/html etc.) then removing "a:href" from this configuration will resolve your issue.
  • disable link checker only for json response then do not remove "a:href" from here & let it be as it is so that link checker applies to sightly html & other configured content type. check below solution to disable link checker only for json response.

 

Disable link checker only for JSON response content type

1. If you have added "application/json" content type in rewrite config under /apps/project/config/rewriter/project then remove this content type from configuration.

 

2. Set content type to servlet json response in servlet so that link checker rewrite will not be applied this content type since this content type is removed in step 1.

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

 

Above 2 steps will resolve link checker issue on json content type response.

 

Servlet JSON response before fix:

 

Servlet JSON response after fix:

 

 

As i mentioned in above comment no need to removing a:href or disabling link checker from "Day CQ Link Checker Transformer" for the issue which your facing because this will completely remove link checker for other content type as well.

 

so, just add content type in servlet response as mentioned below. if you have already added this then please share the header & response tab screenshot from browser network tab when we can see whether content type is set or not in response headers.

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

 

 

 

 

 

 

You will get href="\" i.e. link getting removed when there is no proper content type is set refer below screenshot where content type is not set.

 

 

 

 

 

-Manjunath

Manjunath_K
Level 7
October 5, 2020

Hi @sagrawal 

If your project doesn't have custom link rewrite service config then you can ignore step2 mentioned above & it will be referred to OOTB rewrite config present under /libs/cq/config/rewriter/default which does not have application/json in contentType list.

 

so, setting content type to servlet response as per step1 will resolve your issue.

 

-Manjunath