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

Sling servlet response: How do I tell AEM to keep its hands off (link checker) my JSON data?

Avatar

Avatar
Validate 25
Level 4
jayv25585659
Level 4

Likes

46 likes

Total Posts

118 posts

Correct Reply

0 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Contributor 2
Ignite 5
View profile

Avatar
Validate 25
Level 4
jayv25585659
Level 4

Likes

46 likes

Total Posts

118 posts

Correct Reply

0 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Contributor 2
Ignite 5
View profile
jayv25585659
Level 4

30-05-2018

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 liks I have in the JSON. I don't want AEM to do anything with my data.

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

This is the code I used to pass back the JSON response.

response.setCharacterEncoding("UTF-8");

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

printWriter.write(jsonResponse);

Thanks!

Replies

Avatar

Avatar
Validate 10
MVP
kunal23
MVP

Likes

166 likes

Total Posts

565 posts

Correct Reply

172 solutions
Top badges earned
Validate 10
Validate 1
Ignite 3
Ignite 1
Give Back 50
View profile

Avatar
Validate 10
MVP
kunal23
MVP

Likes

166 likes

Total Posts

565 posts

Correct Reply

172 solutions
Top badges earned
Validate 10
Validate 1
Ignite 3
Ignite 1
Give Back 50
View profile
kunal23
MVP

30-05-2018

Try after enabling the strict extension check in the Link Checker Transformer configuration.

http://localhost:4502/system/console/configMgr/com.day.cq.rewriter.linkchecker.impl.LinkCheckerTrans...

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

30-05-2018

Avatar

Avatar
Validate 25
Level 4
jayv25585659
Level 4

Likes

46 likes

Total Posts

118 posts

Correct Reply

0 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Contributor 2
Ignite 5
View profile

Avatar
Validate 25
Level 4
jayv25585659
Level 4

Likes

46 likes

Total Posts

118 posts

Correct Reply

0 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Contributor 2
Ignite 5
View profile
jayv25585659
Level 4

30-05-2018

kunal23

no effect when I enabled it. Thanks though!

----------------

smacdonald2008

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

  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) and still no effect. Anymore suggestions? Thanks!

Avatar

Avatar
Level 1
srikanthb724960
Level 1

Likes

0 likes

Total Posts

3 posts

Correct Reply

0 solutions
View profile

Avatar
Level 1
srikanthb724960
Level 1

Likes

0 likes

Total Posts

3 posts

Correct Reply

0 solutions
View profile
srikanthb724960
Level 1

24-08-2019

Hi Jay,

Did you find any solution for this? if yes, please share. I'm facing same issues with my servlet response(AEM 6.4) too.

Thanks!

Avatar

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,089 likes

Total Posts

3,123 posts

Correct Reply

1,063 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,089 likes

Total Posts

3,123 posts

Correct Reply

1,063 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile
Jörg_Hoh
Employee

25-08-2019

The linkchecker only checks links in HTML documents. Have you checked that both the MIME type and the extension of the file are set accordingly? How do you pass this JSON to the browser? Embedded into an HTML document? Or as response to a request specifically for this?

Avatar

Avatar
Level 1
srikanthb724960
Level 1

Likes

0 likes

Total Posts

3 posts

Correct Reply

0 solutions
View profile

Avatar
Level 1
srikanthb724960
Level 1

Likes

0 likes

Total Posts

3 posts

Correct Reply

0 solutions
View profile
srikanthb724960
Level 1

25-08-2019

Thanks for your reply, Jorg.

Yes, It's a response(with a little html content in it) to a request(http://myDomain.com:port/servletURL?path=/test/test./././) specifically for this. I'd like to tell AEM to keeps it hands-off my servlet response.

Note: Same request is just working fine in AEM 6.1 but not in AEM 6.4.

JSON Response when I printed in the logs:

{

"jcr:primaryType": "nt:unstructured",

"jcr:mixinTypes": ["cq:ReplicationStatus"],

"dateRemoved": "",

"cq:lastReplicationAction": "Activate",

...

"isEditable": {

"jcr:primaryType": "nt:unstructured",

.....

"productDetXXXXX": "<span style=\"font-family: Georgia, \"Times New Roman\", Times, serif;\">lkjakljdlkajlkdjl a ajdlkajladjlkdajlkajl  <\/span><a href=\"https://www.myDomain.com/tests/test.jsp?bid=101\" x-cq-linkchecker=\"skip\" style=\"outline: 0px; color: rgb(0, 98, 193); text-decoration-line: none; font-family: Georgia, \"Times New Roman\", Times, serif; background-color: rgb(255, 255, 255);\">Link-Label<\/a><span style=\"font-family: Georgia, \"Times New Roman\", Times, serif;\"> XXXX <\/span><a href=\"https://www.myDomain.com/tests/test.jsp?bid=101\" x-cq-linkchecker=\"skip\" style=\"outline: 0px; color: rgb(0, 98, 193); text-decoration-line: none; font-family: Georgia, \"Times New Roman\", Times, serif; background-color: rgb(255, 255, 255);\">Financial Center<\/a><span style=\"font-family: Georgia, \"Times New Roman\", Times, serif;\">.<\/span>",

.....

"recommendedXXX": {

"jcr:primaryType": "nt:unstructured"

}

},

"xxxxx": {

.......

},

}

}

JSON Response when I request in the browser (http://myDomain.com:port/bin/test/testServlet?path=/test/test./././):

AEM removing the links by injecting cq invalid tags to it.

{

"jcr:primaryType":"nt:unstructured",

.........

"productDetXXXXX":"<span style=\"font-family: Georgia, \"Times New Roman\", Times, serif;\">lkjakljdlkajlkdjl a ajdlkajladjlkdajlkajl  </span><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"><a href="\" style="skip\\" times new roman\>Link-Label</a><img class="cq-LinkChecker cq-LinkChecker--suffix cq-LinkChecker--invalid" src="/libs/cq/linkchecker/resources/linkcheck_c.gif" border="0"><span style=\"font-family: Georgia, \"Times New Roman\", Times, serif;\"> XXXX </span><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"><a href="\" style="skip\\" times new roman\>Financial Center</a><img class="cq-LinkChecker cq-LinkChecker--suffix cq-LinkChecker--invalid" src="/libs/cq/linkchecker/resources/linkcheck_c.gif" border="0"><span style=\"font-family: Georgia, \"Times New Roman\", Times, serif;\">.</span>"

......

    .......

Thanks!

Avatar

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,089 likes

Total Posts

3,123 posts

Correct Reply

1,063 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,089 likes

Total Posts

3,123 posts

Correct Reply

1,063 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile
Jörg_Hoh
Employee

26-08-2019

just for my understanding: This servlet does not use any extension? What mime-type do you send?

Can you try and add the extension ".json" to the servlet and use the appropriate mimetype for JSON?

Additional recommendation: Please bind your servlet to a resource instead to a harcoded path, and use a selector for selection. Because then you don't need to pass any path as query string to it, but whenever the servlet is invoked only if the resource is available.

Jörg

Avatar

Avatar
Level 1
srikanthb724960
Level 1

Likes

0 likes

Total Posts

3 posts

Correct Reply

0 solutions
View profile

Avatar
Level 1
srikanthb724960
Level 1

Likes

0 likes

Total Posts

3 posts

Correct Reply

0 solutions
View profile
srikanthb724960
Level 1

26-08-2019

mimetype is: "application/json"

yes, I can use json extension, but the output is same even I use it.

Avatar

Avatar
Validate 1
Level 2
Dana__Anthony
Level 2

Likes

2 likes

Total Posts

10 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Ignite 1
Give Back 3
Give Back
Boost 1
View profile

Avatar
Validate 1
Level 2
Dana__Anthony
Level 2

Likes

2 likes

Total Posts

10 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Ignite 1
Give Back 3
Give Back
Boost 1
View profile
Dana__Anthony
Level 2

28-08-2019

I have the same problem.

In addition to trying the linkCheckerSettings approach, I tried adding x-cq-linkchecker="valid" or x-cq-linkchecker="skip" (I tried each of these options) and those were also unsuccessful at getting the link checker to stop making my json invalid by removing the links and replacing with img tags that did not have escaped double-quotes.