Disable Link Filtering in AEM for JSON response from servlet

Avatar

Avatar

sagrawal

Avatar

sagrawal

sagrawal

30-08-2020

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.

image.png

 

 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Manjunath_K

Avatar

Manjunath_K

Manjunath_K

03-10-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.

transformer.png

 

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.

rewriter.png

 

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:

rewrite-before.png

 

Servlet JSON response after fix:

rewrite-after.PNG

 

 

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

Actually i don't see this node in project then do I need to add this node under config folder.

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

 

 

Thanks for your response. If I remove the a:link then href is repaced with "\" in JSON response. 

 

I am sending JSON response using - public class ArticleServlet extends SlingSafeMethodsServlet {}

response.getWriter().write(articledata json);

 

Below response i am receiving 

content":"<p>test <a href="\">wiki</a></p>"

 

Hi @sagrawal 

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");

 

 

response.png

 

network.png

 

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.

href.png

 

no-content.png

Sure.. I will check this and will update you.
Thanks @Manjunath_K. Issus is resolved and your inputs was really helpful.
Hi I have raised as query on style system "Custom Component: Style tab is not showing". If possible can you please guide me,

@sagrawal 

You’re welcome 🙂

Sure, i will check your query related  "Custom Component: Style tab is not showing" & provide if any inputs that i can share.

Answers (1)

Answers (1)

Avatar

Avatar

Singaiah_Chintalapudi

MVP

Avatar

Singaiah_Chintalapudi

MVP

Singaiah_Chintalapudi
MVP

30-08-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.