Skip to content

Instantly share code, notes, and snippets.

@joemaffia
Created October 16, 2013 09:12
Show Gist options
  • Save joemaffia/7004921 to your computer and use it in GitHub Desktop.
Save joemaffia/7004921 to your computer and use it in GitHub Desktop.
Adobe CQ Servlet that will expose the GoodbyeWorldService
package com.company.cq.servlets;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import java.io.IOException;
/**
* Created with IntelliJ IDEA.
* User: joemaffia
* Date: 15/10/2013
* Time: 16:46
*
* Servlet that will expose the GoodbyeWorldService
*
* http://sling.apache.org/site/servlet-resolution.html
*/
@Component(metatype = false)
@Service(Servlet.class)
@Properties({
@Property(name = "service.pid", value = "...", propertyPrivate = false),
@Property(name = "service.description", value = "...", propertyPrivate = false),
@Property(name = "sling.servlet.extensions", value = "json"),
@Property(name = "sling.servlet.methods", value = "GET"),
@Property(name = "sling.servlet.selectors", value = "selector"),
@Property(name = "sling.servlet.resourceTypes", value = "apps/xxx/content/xxx")
})
public class GoodbyeWorldServlet extends SlingAllMethodsServlet {
private static final Logger LOG = LoggerFactory.getLogger(GoodbyeWorldServlet.class);
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException
{
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
com.company.cq.services.GoodbyeWorldService service = new com.company.cq.services.GoodbyeWorldService();
response.getWriter().println(service.getMessage());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment