incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1556512 - /sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentCreateServlet.java
Date Wed, 08 Jan 2014 12:13:33 GMT
Author: bdelacretaz
Date: Wed Jan  8 12:13:33 2014
New Revision: 1556512

URL: http://svn.apache.org/r1556512
Log:
SLING-3300 -  API to create replication agent (configuration) - adding missing servlet, contributed
by Tommaso Teofili, thanks!

Added:
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentCreateServlet.java

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentCreateServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentCreateServlet.java?rev=1556512&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentCreateServlet.java
(added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentCreateServlet.java
Wed Jan  8 12:13:33 2014
@@ -0,0 +1,66 @@
+package org.apache.sling.replication.servlet;
+
+import java.io.IOException;
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+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.Reference;
+import org.apache.felix.scr.annotations.Service;
+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.SlingAllMethodsServlet;
+import org.apache.sling.replication.agent.AgentConfigurationException;
+import org.apache.sling.replication.agent.ReplicationAgentConfiguration;
+import org.apache.sling.replication.agent.ReplicationAgentConfigurationManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Servlet to create {@link org.apache.sling.replication.agent.ReplicationAgent}s (via HTTP
PUT).
+ */
+@SuppressWarnings("serial")
+@Component(metatype = false)
+@Service(value = Servlet.class)
+@Properties({
+        @Property(name = "sling.servlet.paths", value = "/system/replication/agent"),
+        @Property(name = "sling.servlet.methods", value = "POST")})
+public class ReplicationAgentCreateServlet extends SlingAllMethodsServlet {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Reference
+    private ReplicationAgentConfigurationManager agentConfigurationManager;
+
+    @Override
+    protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response)
+            throws ServletException, IOException {
+        response.setContentType("application/json");
+
+        String name = request.getParameter("name");
+
+        try {
+            agentConfigurationManager.createAgentConfiguration(request.getParameterMap());
+            if (log.isInfoEnabled()) {
+                log.info("agent configuration for {} created", name);
+            }
+
+        } catch (AgentConfigurationException e) {
+            if (log.isErrorEnabled()) {
+                log.error("cannot create agent {}", name, e);
+            }
+        }
+        Resource agentResource = request.getResource().getChild(name);
+        if (agentResource != null) {
+            Resource resource = agentResource.getChild("configuration");
+            ReplicationAgentConfiguration configuration = resource
+                    .adaptTo(ReplicationAgentConfiguration.class);
+            response.getWriter().write(configuration.toString());
+        } else {
+            response.setStatus(404);
+            response.getWriter().write("the configuration was correctly created but the related
agent cannot be found");
+        }
+    }
+}



Mime
View raw message