0

I have created an OSGi Bundle and uploaded to a CQ5 server. This bundle contains a SlingServlet like this:

@SlingServlet(paths = { "/rest/matches" }, methods = { "POST", "GET" })
public class MatchDayRestServlet extends SlingAllMethodsServlet {
    private static final long serialVersionUID = 5088643736228890684L;

    @Override
    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
        String responseString = "Hello World!";
        response.setStatus(HttpServletResponse.SC_OK);
        response.getWriter().write(responseString);
        response.getWriter().flush();
        response.getWriter().close();
    }
}

Now I am stucked because I have no idea what URL I should use to make GET calls to this servlet.

My CRXDE is located at http://HOST:IP/crx/de/index.jsp

Alexandru Pupsa
  • 1,798
  • 4
  • 21
  • 40
  • 4
    Add `/rest/` in the `Execution Paths` of `Apache Sling Servlet/Script Resolver and Error Handler` configuration available at `http://host:ip/system/console/configMgr`, and then access your servlet using the URL `http://host:ip/rest/matches` – rakhi4110 May 26 '15 at 12:42
  • In the meantime I tried it using the "/bin/matches" path and it worked. That's probably because the "/bin/" path is already added to the Execution Paths. I'm guessing it's better to use the "/rest/" path, though. Thanks for your comment! – Alexandru Pupsa May 26 '15 at 13:24
  • 1
    Note that in Sling creating a resource at the desired path, and configuring a servlet to handle it via the sling:resourceType property, is much preferred over mounting servlets on paths. https://sling.apache.org/documentation/the-sling-engine/servlets.html has more info about that. Apart from that you are right that only specific paths prefixes are allowed for servlet execution, as configured on your system. – Bertrand Delacretaz May 27 '15 at 05:51

0 Answers0