Highlighted

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

jayv25585659

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

Highlighted

jayv25585659

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!

Highlighted

srikanthb724960

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!

Highlighted

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?

Highlighted

srikanthb724960

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!

Highlighted

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

Highlighted

Dana__Anthony

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.