I have this html data -
<img width="138px" height="74px" rev="om" src="//www.xyz.net/abc/2/3/4/data/image/data_6812?wid=138&hei=74&qlt=90,0&resMode=sharp&op_usm=1.1,0.5,1,0" alt="category"/><p>Category</p>
but when I call and get the json it not able to traslate the html properly and spits the output as -
{"name":"<img width="\" height="138px\\" rev="74px\\" src="om\\" alt="//www.xyz.net/abc/2/3/4/data/image/data_6812"/><p>Category<\/p>"}
instead it should have been like if it was correctly escaped-
<img width=\"138px\" height=\"74px\" rev=\"om\" src=\"//www.xyz.net/abc/2/3/4/data/image/data_6812\" alt=\"Category\"/><p>Category</p>;
in my servlet I have set the content type as - application/json and the when I print the out put in my log file it is correctly escaping and showing the right value but in the browser it does not.
I have disabled the link checker, but still it does not load correctly. Does anyone know what else I need to do in order to have html data correctly being displayed on the browser? I could use the StringEscapeUtils.escapeHtml method but it escapes the whole html which is not desired.
Thanks.
Solved! Go to Solution.
Views
Replies
Total Likes
MC Stuff wrote...
Hi Vsharm,
Can you try with disabling xss filter?
Thanks,
I tried disabling the xss filters but that did not help.
The problem got isolated in "Day CQ Path Rewriting Transformer Factory" from /system/console/configMgr where I have to keep the image mapping as black instead of "img:src". check the screen shot. after that we had to restart the Apache Sling Rewriterorg.apache.sling.rewriter from /system/console/bundles. It was a big relief for my project.
My problem has been solved. Hope this solution will help someone in this forum who gets into this issue.
Thank you everyone for your valuable input in figuring out and solving the issue.
Views
Replies
Total Likes
Hi, Vivek.
Sorry, but I couldn't follow you. What is this HTML data? Is it a property of a JCR node? Is it a cq page?
How has it been filled in? How is it being rendering? Are you using a JSP or a HTL as render script?
Can you please provide more details?
Regards,
Daniel.
Views
Replies
Total Likes
Are you using custom Java logic to convert the HTML to JSON?
Views
Replies
Total Likes
Hello Daniel, Scott - Thanks. Yes, it is a node property under jcr:content where I am storing this html image data from a UI and from an API call from another system. I have a servlet which is reading the data from the jcr node and exposing the contents in JSONObject using response.getWriter().print(jsonObj);. All other node property where there is no html are getting served properly in the json feed except this html.
To troubleshoot, I tried to expose this data using this servlet like below and same issue.
response.setHeader("Content-Type", "application/json");
JSONObject jsonObj = new JSONObject();
try {
jsonObj.put("name", "<img width=\"138px\" height=\"74px\" rev=\"om\" src=\"//www.xyz.net/abc/2/3/4/data/image/data_6812\" alt=\"Category\"/><p>Category</p>");
response.getWriter().print(jsonObj);
} catch (IOException e) {
log.error("IO Exception ", e);
Views
Replies
Total Likes
daniel_henrique wrote...
Hi, Vivek.
Sorry, but I couldn't follow you. What is this HTML data? Is it a property of a JCR node? Is it a cq page?
How has it been filled in? How is it being rendering? Are you using a JSP or a HTL as render script?
Can you please provide more details?
Regards,
Daniel.
It is a node under jcr:content. attached screen shot.
Views
Replies
Total Likes
Hi Vsharm,
if you are using jdk JSONObject then need to manually escape double quote OR use single quote instead of double. The other alternative is to use gson library which provides option to disable Html Escaping.
Thanks,
Views
Replies
Total Likes
Hello all, thanks you for all of your responses. I have tried the GSON library as well as well as replacing the double quote and single quotes and same issue :(. Found the issue with the "<img" tag which is/was causing all this issue with making the json invalid.
I am not sure why would it do that. If I replace the "<img" with "<img" then everything works just fine. I am not sure what's going on. Initially we thought it could be sling rewrite issue but at /libs/cq/config/rewriter/default, it has the content type as "html/text" and even my servlet has content type as "application/json". We tried disabling the sling rewrite but that too did not help. We had also tried disabling the link checker and that also did not work.
As a work around I am replacing "<img" with <img. Please let me know if someone know why would it do that and if there is a work around.
Views
Replies
Total Likes
Hi Vsharm,
Can you try with disabling xss filter?
Thanks,
Views
Replies
Total Likes
MC Stuff wrote...
Hi Vsharm,
Can you try with disabling xss filter?
Thanks,
I tried disabling the xss filters but that did not help.
The problem got isolated in "Day CQ Path Rewriting Transformer Factory" from /system/console/configMgr where I have to keep the image mapping as black instead of "img:src". check the screen shot. after that we had to restart the Apache Sling Rewriterorg.apache.sling.rewriter from /system/console/bundles. It was a big relief for my project.
My problem has been solved. Hope this solution will help someone in this forum who gets into this issue.
Thank you everyone for your valuable input in figuring out and solving the issue.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies