Deleting AMS Servlet Response

In AEM, I am trying to write a JSON object that contains a string object via a get servlet, for example:

response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(jsonObject.toString());

      

SlingHttpServletResponse response

When the servlet is accessed in the browser, it gets disconnected with a warning coming out of the aem log:

03.08.2015 16:55:27.359 *WARN* [127.0.0.1 [1438617327343] GET /bin/integration.json HTTP/1.1] com.day.cq.rewriter.linkchecker.impl.LinkCheckerImpl Ignoring malformed URI: java.net.URISyntaxException: Illegal character in path at index 0: \

      

Link checking is bypassed for many templates, including the link above.

For example, a string object inside json:

pageIntro:'this <a href="http://www.domain.com/my-section/page.html">link</a>  doesn't work' 

      

becomes:

pageIntro:'this link</a>  doesn't work' 

      

Any help would be much appreciated.

Cheers, Alex

+3


source to share


1 answer


While running a quick script around AEM 6.0, I cannot reproduce this issue. Here's what I did in the servlet. Snippet attachment below. Is there anything else you are doing to achieve this?

    import java.io.IOException;
    import javax.servlet.ServletException;
    import org.apache.felix.scr.annotations.sling.SlingServlet;
    import org.apache.sling.api.SlingHttpServletRequest;
    import org.apache.sling.api.SlingHttpServletResponse;
    import org.apache.sling.api.servlets.SlingAllMethodsServlet;
    import org.apache.sling.commons.json.JSONException;
    import org.apache.sling.commons.json.JSONObject;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
     @SlingServlet(  label = "Qaru - Sabya Test Servlet", 
                    description = "Used for quick fiddle",
                    paths="/bin/sabya-servlet.json",
                    metatype = true
                )
    public class SabyaTestServlet extends SlingAllMethodsServlet {

        private static final long serialVersionUID = 1335893917596088016L;

        private static final Logger log = LoggerFactory
                .getLogger(SabyaTestServlet.class);


        @Override
        protected void doGet(SlingHttpServletRequest request,
                SlingHttpServletResponse response) throws ServletException,
                IOException {
            log.trace("Sabya Test Servlet : doGet() starts .. ");

            JSONObject jsonObject = new JSONObject();
            try {
                jsonObject.put("pageIntro", "this <a href='http://www.domain.com/my-section/page.html'>link</a>  doesn't work");
                response.setContentType("application/json");
                response.setCharacterEncoding("UTF-8");
                response.getWriter().write(jsonObject.toString());
            } catch (JSONException e) {
                log.error("Something ridiculous has happened !! {}" , e);
            }

            log.trace("Sabya Test Servlet : doGet() ends .. ");
        }
    }

      

Request url: http://localhost:4502/bin/sabya-servlet.json



Answer:

{
pageIntro: "this <a href='http://www.domain.com/my-section/page.html'>link</a> doesn't work"
}

      

Note. I assume you are using org.apache.sling.commons.json.JSONObject

.

+2


source







All Articles