Expand my Community achievements bar.

SOLVED

Disable Link Filtering in AEM for JSON response from servlet

Avatar

Level 2

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

 

 

1 Accepted Solution

Avatar

Correct answer by
Level 8

@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

View solution in original post

11 Replies

Avatar

Community Advisor

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.

Avatar

Level 2

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. 

Avatar

Correct answer by
Level 8

@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

Avatar

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

Avatar

Level 8

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

 

 

Avatar

Level 2

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

 

Avatar

Level 8

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

Avatar

Level 2
Thanks @Manjunath_K. Issus is resolved and your inputs was really helpful.

Avatar

Level 2
Hi I have raised as query on style system "Custom Component: Style tab is not showing". If possible can you please guide me,

Avatar

Level 8

@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.