Is there any AEM API which can give me the status of given content fragment when fetched by path whether it is published or not?
CURL https://BASEURI/.../_path
expected response: {"isPublished":true or false}
something like that
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @spidey1405,
There are few options to get above information:
package com.mysite.core.servlets; import com.day.cq.replication.ReplicationStatus; import com.google.gson.JsonObject; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.servlets.HttpConstants; import org.apache.sling.api.servlets.SlingSafeMethodsServlet; import org.osgi.service.component.annotations.Component; import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @Component(service = Servlet.class, property = { "sling.servlet.methods=" + HttpConstants.METHOD_GET, "sling.servlet.resourceTypes=sling/servlet/default", "sling.servlet.selectors=replicationStatus", "sling.servlet.extensions=json" }) public class ReplicationStatusServlet extends SlingSafeMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { Resource resource = request.getResource(); ReplicationStatus replicationStatus = resource.adaptTo(ReplicationStatus.class); JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("isPublished", replicationStatus.isActivated()); response.setContentType("application/json"); response.getWriter().write(jsonObject.toString()); response.setStatus(HttpServletResponse.SC_OK); } }
Hi ,
Content fragment supported api
But there is no specific api for getting replication status.
Thanks
Views
Replies
Total Likes
Hi @spidey1405,
There are few options to get above information:
package com.mysite.core.servlets; import com.day.cq.replication.ReplicationStatus; import com.google.gson.JsonObject; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.servlets.HttpConstants; import org.apache.sling.api.servlets.SlingSafeMethodsServlet; import org.osgi.service.component.annotations.Component; import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @Component(service = Servlet.class, property = { "sling.servlet.methods=" + HttpConstants.METHOD_GET, "sling.servlet.resourceTypes=sling/servlet/default", "sling.servlet.selectors=replicationStatus", "sling.servlet.extensions=json" }) public class ReplicationStatusServlet extends SlingSafeMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { Resource resource = request.getResource(); ReplicationStatus replicationStatus = resource.adaptTo(ReplicationStatus.class); JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("isPublished", replicationStatus.isActivated()); response.setContentType("application/json"); response.getWriter().write(jsonObject.toString()); response.setStatus(HttpServletResponse.SC_OK); } }
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies