Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Disable Link Filtering in AEM for JSON response from servlet

Avatar

Avatar
Ignite 5
Level 2
sagrawal
Level 2

Likes

3 likes

Total Posts

29 posts

Correct Reply

0 solutions
Top badges earned
Ignite 5
Ignite 3
Ignite 1
Give Back 3
Give Back
View profile

Avatar
Ignite 5
Level 2
sagrawal
Level 2

Likes

3 likes

Total Posts

29 posts

Correct Reply

0 solutions
Top badges earned
Ignite 5
Ignite 3
Ignite 1
Give Back 3
Give Back
View profile
sagrawal
Level 2

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

 

 

View Entire Topic

Avatar

Avatar
Give Back 3
MVP
Manjunath_K
MVP

Likes

138 likes

Total Posts

188 posts

Correct Reply

61 solutions
Top badges earned
Give Back 3
Give Back
Boost 50
Boost 5
Boost 3
View profile

Avatar
Give Back 3
MVP
Manjunath_K
MVP

Likes

138 likes

Total Posts

188 posts

Correct Reply

61 solutions
Top badges earned
Give Back 3
Give Back
Boost 50
Boost 5
Boost 3
View profile
Manjunath_K
MVP

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

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

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

 

 

sagrawal

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

 

Manjunath_K

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

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

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