incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
Subject svn commit: r1558706 [1/2] - in /sling/trunk/contrib/extensions/replication: ./ src/main/java/org/apache/sling/replication/agent/ src/main/java/org/apache/sling/replication/agent/impl/ src/main/java/org/apache/sling/replication/event/ src/main/java/org...
Date Thu, 16 Jan 2014 07:29:02 GMT
Author: tommaso
Date: Thu Jan 16 07:29:01 2014
New Revision: 1558706

URL: http://svn.apache.org/r1558706
Log:
SLING-3315 - applied patch by Marius Petria for refactoring replication HTTP API

Added:
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentRootServlet.java   (with props)
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentServlet.java   (with props)
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationConfigurationRootServlet.java   (with props)
    sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/config/
    sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/config/org.apache.sling.replication.serialization.impl.vlt.FileVaultReplicationPackageBuilder.json
    sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/system/
    sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/system/replication/
    sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/system/replication/security.json
Removed:
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/AggregateReplicationServlet.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentCreateServlet.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentPollServlet.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentPostServlet.java
    sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/agents/
Modified:
    sling/trunk/contrib/extensions/replication/pom.xml
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfiguration.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationManager.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentConfigurationManager.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentConfigurationResource.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentQueueResource.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentResource.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentResourceProvider.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/event/ReplicationEventType.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/queue/impl/AbstractReplicationQueueProvider.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackageBuilder.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationConfigurationServlet.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationQueueServlet.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationReceiverServlet.java
    sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/impl/PollingTransportHandler.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationTest.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentConfigurationManagerTest.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentConfigurationResourceTest.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentResourceProviderTest.java
    sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentResourceTest.java

Modified: sling/trunk/contrib/extensions/replication/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/pom.xml?rev=1558706&r1=1558705&r2=1558706&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/pom.xml (original)
+++ sling/trunk/contrib/extensions/replication/pom.xml Thu Jan 16 07:29:01 2014
@@ -67,7 +67,8 @@
               <configuration>
                 <instructions>
                   <Bundle-SymbolicName>org.apache.sling.replication</Bundle-SymbolicName>
-                  <Sling-Initial-Content>SLING-CONTENT/libs/sling/replication;path:=/apps/system;overwrite:=true</Sling-Initial-Content>
+                  <Sling-Initial-Content>SLING-CONTENT/libs/sling/replication;path:=/apps/system;overwrite:=true,
+                      SLING-CONTENT/system/replication;path:=/system/replication;overwrite:=true</Sling-Initial-Content>
                   <Export-Package>
                     org.apache.sling.replication.agent,
                     org.apache.sling.replication.transport.authentication,

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfiguration.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfiguration.java?rev=1558706&r1=1558705&r2=1558706&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfiguration.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfiguration.java Thu Jan 16 07:29:01 2014
@@ -20,6 +20,9 @@ package org.apache.sling.replication.age
 
 import java.util.Arrays;
 import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Map;
+
 import org.apache.sling.commons.osgi.PropertiesUtil;
 
 /**
@@ -47,6 +50,10 @@ public class ReplicationAgentConfigurati
 
     public static final String ENABLED = "enabled";
 
+    public static final String[] COMPONENTS = { TRANSPORT, PACKAGING };
+
+    private final boolean enabled;
+
     private final String name;
 
     private final String endpoint;
@@ -65,8 +72,11 @@ public class ReplicationAgentConfigurati
 
     private final String[] rules;
 
-    public ReplicationAgentConfiguration(Dictionary<?, ?> dictionary) {
+    private final Dictionary<String, Dictionary> componentConfiguration;
+
+    public ReplicationAgentConfiguration(Dictionary<?, ?> dictionary, Dictionary<String, Dictionary> componentConfiguration) {
         this.name = PropertiesUtil.toString(dictionary.get(NAME), "");
+        this.enabled = PropertiesUtil.toBoolean(dictionary.get(ENABLED), true);
         this.endpoint = PropertiesUtil.toString(dictionary.get(ENDPOINT), "");
         this.targetAuthenticationHandlerFactory = PropertiesUtil.toString(
                 dictionary.get(TRANSPORT_AUTHENTICATION_FACTORY), "");
@@ -78,6 +88,8 @@ public class ReplicationAgentConfigurati
         String[] ap = PropertiesUtil.toStringArray(dictionary.get(AUTHENTICATION_PROPERTIES));
         this.authenticationProperties = ap != null ? ap : new String[0];
         this.rules = PropertiesUtil.toStringArray(dictionary.get(RULES), new String[0]);
+
+        this.componentConfiguration = componentConfiguration;
     }
 
     public String[] getAuthenticationProperties() {
@@ -112,15 +124,58 @@ public class ReplicationAgentConfigurati
 
     @Override
     public String toString() {
-        return "{\"" + NAME + "\":\"" + name + "\", \""
+        String result = "{\"";
+
+        result += NAME + "\":\"" + name + "\", \""
                 + ENDPOINT + "\":\"" + endpoint + "\", \""
                 + TRANSPORT + "\":\"" + targetTransportHandler + "\", \""
                 + PACKAGING + "\":\"" + targetReplicationPackageBuilder + "\", \""
                 + QUEUEPROVIDER + "\":\"" + targetReplicationQueueProvider + "\", \""
                 + QUEUE_DISTRIBUTION + "\":\"" + targetReplicationQueueDistributionStrategy+ "\", \""
                 + TRANSPORT_AUTHENTICATION_FACTORY + "\":\"" + targetAuthenticationHandlerFactory + "\", \""
-                + AUTHENTICATION_PROPERTIES + "\":\"" + Arrays.toString(authenticationProperties) + "\", \""
-                + RULES + "\":\"" + Arrays.toString(rules) + "\"}";
+                + AUTHENTICATION_PROPERTIES + "\":\"" + Arrays.toString(authenticationProperties) + "\", \"";
+
+        result += toComponentString();
+
+        result += RULES + "\":\"" + Arrays.toString(rules) + "\"}";
+        return result;
     }
 
+
+    private String toComponentString() {
+
+        String result = "";
+
+        if(componentConfiguration == null)
+            return result;
+
+        for (String component : COMPONENTS){
+            Dictionary properties = componentConfiguration.get(component);
+            if(properties == null) continue;
+
+            Enumeration keys = properties.keys();
+
+            while (keys.hasMoreElements()){
+                String key = (String) keys.nextElement();
+                Object value = properties.get(key);
+
+                if(key.equals("service.pid")) continue;
+
+                result += component + "." + key + "\":\"" +  PropertiesUtil.toString(value, "")  + "\", \"";
+            }
+        }
+
+        return  result;
+    }
+
+    public String toSimpleString() {
+        String result = "{";
+
+        result += "\"" + NAME + "\": \"" + name + "\""
+                + ", \"" + ENABLED + "\": " + enabled;
+
+        result += "}";
+
+        return result;
+    }
 }

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationManager.java?rev=1558706&r1=1558705&r2=1558706&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationManager.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationManager.java Thu Jan 16 07:29:01 2014
@@ -28,29 +28,50 @@ public interface ReplicationAgentConfigu
     /**
      * retrieve a {@link ReplicationAgentConfiguration} for a given {@link ReplicationAgent}
      *
-     * @param replicationAgent a {@link ReplicationAgent}
+     * @param agentName the name of a {@link org.apache.sling.replication.agent.ReplicationAgent}
      * @return a {@link ReplicationAgentConfiguration} for the given agent
      * @throws AgentConfigurationException
      */
-    ReplicationAgentConfiguration getConfiguration(ReplicationAgent replicationAgent)
+    ReplicationAgentConfiguration getConfiguration(String agentName)
             throws AgentConfigurationException;
 
     /**
      * updates the {@link ReplicationAgentConfiguration} of a certain {@link ReplicationAgent}
      *
-     * @param agent      a {@link ReplicationAgent}
-     * @param properties a {@link Map} of properties used to update the configuration
+     * @param agentName  the name of a {@link org.apache.sling.replication.agent.ReplicationAgent}
+     * @param properties a {@link java.util.Map} of properties used to update the configuration
      * @return the updated {@link ReplicationAgentConfiguration} for the given agent
      * @throws AgentConfigurationException
      */
-    ReplicationAgentConfiguration updateConfiguration(ReplicationAgent agent,
-                                                      Map<String, Object> properties) throws AgentConfigurationException;
+    ReplicationAgentConfiguration updateConfiguration(String agentName, Map<String, Object> properties)
+            throws AgentConfigurationException;
 
     /**
      * creates a configuration for a {@link ReplicationAgent}
      *
+     *
+     * @param agentName
      * @param properties the configuration of the agent to create
      * @throws AgentConfigurationException
      */
-    void createAgentConfiguration(Map<String, Object> properties) throws AgentConfigurationException;
+    void createAgentConfiguration(String agentName, Map<String, Object> properties)
+            throws AgentConfigurationException;
+
+    /**
+     * creates a configuration for a {@link ReplicationAgent}       *
+     *
+     * @param agentName
+     * @throws AgentConfigurationException
+     */
+    void deleteAgentConfiguration(String agentName)
+            throws AgentConfigurationException;
+
+    /**
+     * lists all configurations for {@link ReplicationAgent}
+     *
+     */
+    ReplicationAgentConfiguration[] listAllAgentConfigurations()
+            throws AgentConfigurationException;
+
+
 }

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentConfigurationManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentConfigurationManager.java?rev=1558706&r1=1558705&r2=1558706&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentConfigurationManager.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentConfigurationManager.java Thu Jan 16 07:29:01 2014
@@ -25,8 +25,8 @@ import java.util.Map;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.apache.sling.replication.agent.AgentConfigurationException;
-import org.apache.sling.replication.agent.ReplicationAgent;
 import org.apache.sling.replication.agent.ReplicationAgentConfiguration;
 import org.apache.sling.replication.agent.ReplicationAgentConfigurationManager;
 import org.osgi.service.cm.Configuration;
@@ -47,77 +47,165 @@ public class DefaultReplicationAgentConf
     @Reference
     private ConfigurationAdmin configAdmin;
 
-    public ReplicationAgentConfiguration getConfiguration(ReplicationAgent replicationAgent)
+    public ReplicationAgentConfiguration getConfiguration(String agentName)
             throws AgentConfigurationException {
-        if (log.isInfoEnabled()) {
-            log.info("retrieving configuration for agent {}", replicationAgent);
-        }
+
+        log.info("retrieving configuration for agent {}", agentName);
+
         try {
-            Configuration configuration = getOsgiConfiguration(replicationAgent);
-            if (log.isInfoEnabled()) {
-                log.info("configuration for agent {} found {}", replicationAgent, configuration);
-            }
-            return new ReplicationAgentConfiguration(configuration.getProperties());
+            Dictionary agentProperties = getOrSetProperties(agentName, null);
+            Dictionary<String, Dictionary> componentProperties = getOrSetComponentProperties(agentName, null);
+
+            log.info("configuration for agent {} found {}", agentName, agentProperties);
+
+            return new ReplicationAgentConfiguration(agentProperties, componentProperties);
 
         } catch (Exception e) {
-            if (log.isErrorEnabled()) {
-                log.error("configuration for agent {} cannot be found", replicationAgent.getName());
-            }
+
+            log.error("configuration for agent {} cannot be found", agentName);
             throw new AgentConfigurationException(e);
         }
     }
 
-    private Configuration getOsgiConfiguration(ReplicationAgent replicationAgent) throws Exception {
+    private Dictionary getOrSetProperties(String agentName, Dictionary properties) throws Exception {
+        Configuration agentConfiguration = getAgentConfiguration(agentName);
 
-        String filter = "(name=" + replicationAgent.getName() + ")";
-        Configuration[] configurations = configAdmin.listConfigurations(filter);
-        if (configurations == null) {
+        if(agentConfiguration == null)
             throw new Exception("no configuration found");
-        } else if (configurations.length == 1) {
-            if (log.isInfoEnabled()) {
-                log.info("found configuration {} for agent {}", configurations[0],
-                        replicationAgent.getName());
+
+        if(properties != null)
+            agentConfiguration.update(properties);
+        return agentConfiguration.getProperties();
+    }
+
+
+    private Dictionary<String, Dictionary> getOrSetComponentProperties(String agentName, Dictionary<String, Dictionary> properties) throws Exception {
+        Dictionary<String, Dictionary> result = new Hashtable<String, Dictionary>();
+
+        Configuration agentConfiguration = getAgentConfiguration(agentName);
+
+        for(String component : ReplicationAgentConfiguration.COMPONENTS){
+            Configuration componentConfiguration = getComponentConfiguration(agentConfiguration, component);
+
+            if(componentConfiguration == null)
+                continue;
+
+            if(properties != null){
+                Dictionary componentProperties = properties.get(component);
+                if(componentProperties != null)
+                    componentConfiguration.update(componentProperties);
             }
+
+            result.put(component, componentConfiguration.getProperties());
+        }
+
+        return result;
+    }
+
+    private Configuration getAgentConfiguration(String agentName) throws Exception {
+        String filter = "(name=" + agentName + ")";
+        return getOsgiConfiguration(filter);
+    }
+
+    private Configuration getComponentConfiguration(Configuration agentConfiguration, String component) throws Exception {
+        try{
+            String filter = PropertiesUtil.toString(agentConfiguration.getProperties().get(component), "");
+            return getOsgiConfiguration(filter);
+        }
+        catch (Exception ex){
+            return null;
+        }
+    }
+
+    private Configuration getOsgiConfiguration(String filter) throws Exception {
+        Configuration[] configurations = getAllOsgiConfigurations(filter);
+        if(configurations == null || configurations.length == 0){
+            log.info("no configurations for filter {}", filter);
+            return null;
+        } else if (configurations.length == 1) {
+            log.info("found configuration {} for filter {}", configurations[0], filter);
             return configurations[0];
         } else {
-            if (log.isErrorEnabled()) {
-                log.error("{} configurations for agent {} found", configurations.length,
-                        replicationAgent.getName());
-            }
+            log.error("{} configurations for filter {} found", configurations.length, filter);
             throw new Exception("too many configurations found");
         }
     }
 
-    public ReplicationAgentConfiguration updateConfiguration(ReplicationAgent replicationAgent,
+    private Configuration[] getAllOsgiConfigurations(String filter) throws Exception {
+        Configuration[] configurations = configAdmin.listConfigurations(filter);
+        return configurations;
+    }
+
+    public ReplicationAgentConfiguration updateConfiguration(String agentName,
                                                              Map<String, Object> updateProperties) throws AgentConfigurationException {
         try {
-            Configuration configuration = getOsgiConfiguration(replicationAgent);
-            @SuppressWarnings("unchecked")
-            Dictionary<String, Object> configurationProperties = configuration.getProperties();
+
+            String configName = PropertiesUtil.toString(updateProperties.get("name"),"");
+
+            if(agentName == null || agentName.length() ==0)
+                throw new Exception("agent name cannot be empty");
+
+            if(!agentName.equals(configName))
+                throw new Exception("cannot change name of a configuration");
+
+            Dictionary agentProperties = getOrSetProperties(agentName, null);
+            Dictionary<String, Dictionary> componentProperties = getOrSetComponentProperties(agentName, null);
+
             for (Map.Entry<String, Object> entry : updateProperties.entrySet()) {
                 String key = entry.getKey();
                 if (key.startsWith("X-replication-")) {
                     key = key.substring(0, 14);
                 }
-                configurationProperties.put(key, entry.getValue());
+
+
+                String component = extractComponent(key);
+                if(component != null){
+                    key = key.substring(component.length()+1);
+                    Dictionary dictionary = componentProperties.get(component);
+                    if(dictionary!= null)
+                        dictionary.put(key, entry.getValue());
+                }
+                else {
+                    agentProperties.put(key, entry.getValue());
+                }
             }
-            configuration.update(configurationProperties);
-            return new ReplicationAgentConfiguration(configuration.getProperties());
+
+            agentProperties = getOrSetProperties(agentName, agentProperties);
+            componentProperties = getOrSetComponentProperties(agentName, componentProperties);
+
+            return new ReplicationAgentConfiguration(agentProperties, componentProperties);
+
         } catch (Exception e) {
-            if (log.isErrorEnabled()) {
-                log.error("configuration for agent {} was not found", replicationAgent.getName());
-            }
+            log.error("configuration for agent {} was not found", agentName);
+
             throw new AgentConfigurationException(e);
         }
+    }
+
 
+    String extractComponent(String string){
+        for(String component : ReplicationAgentConfiguration.COMPONENTS){
+            if(string.startsWith(component+ "."))
+                return component;
+        }
+        return null;
     }
 
-    public void createAgentConfiguration(Map<String, Object> properties) throws AgentConfigurationException {
+    public void createAgentConfiguration(String agentName, Map<String, Object> properties) throws AgentConfigurationException {
 
-        Object name = properties.get("name");
-        if (name != null) {
+        if (agentName != null) {
             try {
-                Configuration configuration = configAdmin.createFactoryConfiguration(ReplicationAgentServiceFactory.SERVICE_PID + "-" + parseString(name));
+
+                Configuration configuration = getAgentConfiguration(agentName);
+
+                if(configuration != null)
+                    throw new Exception("the agent name is already in use");
+
+                configuration = configAdmin.createFactoryConfiguration(ReplicationAgentServiceFactory.SERVICE_PID);
+
+                if(configuration == null)
+                    throw new Exception("configuration cannot be created");
+
                 @SuppressWarnings("unchecked")
                 Dictionary<String, Object> configurationProperties = new Hashtable<String, Object>();
 
@@ -130,10 +218,10 @@ public class DefaultReplicationAgentConf
                     configurationProperties.put(key, value);
                 }
                 configuration.update(configurationProperties);
+
             } catch (Exception e) {
-                if (log.isErrorEnabled()) {
-                    log.error("cannot create agent {} ", name);
-                }
+                log.error("cannot create agent {} ", agentName);
+
                 throw new AgentConfigurationException(e);
             }
         } else {
@@ -141,6 +229,43 @@ public class DefaultReplicationAgentConf
         }
     }
 
+
+    public void deleteAgentConfiguration(String agentName) throws AgentConfigurationException {
+
+        if (agentName != null) {
+            try {
+                Configuration configuration =  getAgentConfiguration(agentName);
+
+                configuration.delete();
+            } catch (Exception e) {
+                log.error("cannot delete agent {} ", agentName);
+
+                throw new AgentConfigurationException(e);
+            }
+        } else {
+            throw new AgentConfigurationException("a (unique) name is needed in order to create an agent");
+        }
+    }
+
+    public ReplicationAgentConfiguration[] listAllAgentConfigurations() throws AgentConfigurationException {
+        try {
+            String filter = "("+ ConfigurationAdmin.SERVICE_FACTORYPID + "=" + ReplicationAgentServiceFactory.SERVICE_PID + ")";
+            Configuration[] configurations = getAllOsgiConfigurations(filter);
+
+            ReplicationAgentConfiguration[] result = new ReplicationAgentConfiguration[configurations.length];
+            for(int i=0; i< configurations.length; i++){
+                String agentName = (String) configurations[i].getProperties().get("name");
+                result[i] = getConfiguration(agentName);
+            }
+
+            return result;
+
+        } catch (Exception e) {
+            log.error("configurations for agents cannot be retrieved");
+            throw new AgentConfigurationException(e);
+        }
+    }
+
     private String parseString(Object object) {
         String value;
         if (object instanceof String[]) {

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentConfigurationResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentConfigurationResource.java?rev=1558706&r1=1558705&r2=1558706&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentConfigurationResource.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentConfigurationResource.java Thu Jan 16 07:29:01 2014
@@ -29,8 +29,12 @@ import org.apache.sling.replication.agen
  */
 public class ReplicationAgentConfigurationResource extends AbstractResource {
 
-    public static final String RESOURCE_TYPE = "sling/replication/agent/configuration";
+    public static final String RESOURCE_TYPE = "sling/replication/config/agent";
 
+    public static final String RESOURCE_ROOT_TYPE = "sling/replication/config/agent/root";
+
+
+    public static final String BASE_PATH = "/system/replication/config/agent";
 
     private final ReplicationAgentConfiguration replicationAgentConfiguration;
 
@@ -47,7 +51,7 @@ public class ReplicationAgentConfigurati
     }
 
     public String getPath() {
-        return ReplicationAgentResource.BASE_PATH + '/' + replicationAgentConfiguration.getName() + "/configuration";
+        return BASE_PATH + '/' + replicationAgentConfiguration.getName();
     }
 
     public String getResourceType() {
@@ -60,7 +64,7 @@ public class ReplicationAgentConfigurati
 
     public ResourceMetadata getResourceMetadata() {
         ResourceMetadata metadata = new ResourceMetadata();
-        metadata.setResolutionPath(ReplicationAgentResource.BASE_PATH + '/' + replicationAgentConfiguration.getName());
+        metadata.setResolutionPath(getPath());
         return metadata;
     }
 

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentQueueResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentQueueResource.java?rev=1558706&r1=1558705&r2=1558706&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentQueueResource.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentQueueResource.java Thu Jan 16 07:29:01 2014
@@ -30,6 +30,8 @@ public class ReplicationAgentQueueResour
 
     public static final String RESOURCE_TYPE = "sling/replication/agent/queue";
 
+    public static final String SUFFIX_PATH = "/queue";
+
     private final ReplicationQueue queue;
 
     private final ResourceResolver resourceResolver;

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentResource.java?rev=1558706&r1=1558705&r2=1558706&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentResource.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentResource.java Thu Jan 16 07:29:01 2014
@@ -33,6 +33,13 @@ public class ReplicationAgentResource ex
 
     public static final String RESOURCE_TYPE = "sling/replication/agent";
 
+    public static final String RESOURCE_ROOT_TYPE = "sling/replication/agent/root";
+
+    public static final String IMPORTER_RESOURCE_TYPE = "sling/replication/agent/importer";
+
+    public static final String IMPORTER_BASE_PATH =  "/system/replication/receive";
+
+
     private ReplicationAgent replicationAgent;
 
     private ResourceResolver resourceResolver;
@@ -60,7 +67,7 @@ public class ReplicationAgentResource ex
 
     public ResourceMetadata getResourceMetadata() {
         ResourceMetadata metadata = new ResourceMetadata();
-        metadata.setResolutionPath(BASE_PATH);
+        metadata.setResolutionPath(getPath());
         return metadata;
     }
 

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentResourceProvider.java?rev=1558706&r1=1558705&r2=1558706&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentResourceProvider.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentResourceProvider.java Thu Jan 16 07:29:01 2014
@@ -19,42 +19,46 @@
 package org.apache.sling.replication.agent.impl;
 
 import java.util.Iterator;
+import javax.jcr.Session;
 import javax.servlet.http.HttpServletRequest;
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Deactivate;
+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.resource.Resource;
 import org.apache.sling.api.resource.ResourceProvider;
 import org.apache.sling.api.resource.ResourceResolver;
-
+import org.apache.sling.api.resource.SyntheticResource;
 import org.apache.sling.replication.agent.AgentConfigurationException;
 import org.apache.sling.replication.agent.ReplicationAgent;
 import org.apache.sling.replication.agent.ReplicationAgentConfiguration;
 import org.apache.sling.replication.agent.ReplicationAgentConfigurationManager;
+import org.apache.sling.replication.queue.ReplicationQueueException;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import org.apache.sling.replication.agent.AgentConfigurationException;
-import org.apache.sling.replication.agent.ReplicationAgent;
-import org.apache.sling.replication.agent.ReplicationAgentConfiguration;
-import org.apache.sling.replication.agent.ReplicationAgentConfigurationManager;
-
 /**
  * {@link ResourceProvider} for {@link ReplicationAgent}s
  */
 @Component(metatype = false)
 @Service(value = ResourceProvider.class)
-@Property(name = ResourceProvider.ROOTS, value = ReplicationAgentResource.BASE_PATH)
-public class ReplicationAgentResourceProvider implements ResourceProvider {
+@Properties({
+        @Property(name = ResourceProvider.ROOTS,
+            value = {
+                    ReplicationAgentResource.BASE_PATH,
+                    ReplicationAgentConfigurationResource.BASE_PATH,
+                    ReplicationAgentResource.IMPORTER_BASE_PATH
+            })
 
-    private static final String CONFIGURATION_PATH = "/configuration";
+})
+public class ReplicationAgentResourceProvider implements ResourceProvider {
 
-    private static final String QUEUE_PATH = "/queue";
+    static final String SECURITY_OBJECT = "/system/replication/security";
 
     private final Logger log = LoggerFactory.getLogger(getClass());
 
@@ -78,90 +82,119 @@ public class ReplicationAgentResourcePro
 
     public Resource getResource(ResourceResolver resourceResolver, String path) {
 
+        if(!isAuthorized(resourceResolver)) return null;
+
         Resource resource = null;
-        if (path.endsWith(CONFIGURATION_PATH)) {
-            String agentPath = path.substring(0, path.lastIndexOf(CONFIGURATION_PATH));
-            if (log.isInfoEnabled()) {
-                log.info("resolving configuration for agent {}", agentPath);
-            }
-            ReplicationAgent replicationAgent = getAgentAtPath(agentPath);
-            if (replicationAgent != null) {
-                ServiceReference configurationManagerServiceReference = context
-                        .getServiceReference(ReplicationAgentConfigurationManager.class
-                                .getName());
-                if (configurationManagerServiceReference != null) {
-                    ReplicationAgentConfigurationManager agentConfigurationManager = (ReplicationAgentConfigurationManager) context
-                            .getService(configurationManagerServiceReference);
-                    ReplicationAgentConfiguration configuration;
-                    try {
-                        configuration = agentConfigurationManager
-                                .getConfiguration(replicationAgent);
-                        resource = new ReplicationAgentConfigurationResource(configuration,
-                                resourceResolver);
-                    } catch (AgentConfigurationException e) {
-                        if (log.isWarnEnabled()) {
-                            log.warn("could not find a configuration", e);
-                        }
-                    }
-                } else {
-                    if (log.isWarnEnabled()) {
-                        log.warn("could not find a configuration manager service");
-                    }
+
+        if (path.equals(ReplicationAgentConfigurationResource.BASE_PATH)) {
+
+            return new SyntheticResource(resourceResolver, path, ReplicationAgentConfigurationResource.RESOURCE_ROOT_TYPE);
+
+        } else if (path.equals(ReplicationAgentResource.BASE_PATH)) {
+
+            return new SyntheticResource(resourceResolver, path, ReplicationAgentResource.RESOURCE_ROOT_TYPE);
+
+        } else if (path.equals(ReplicationAgentResource.IMPORTER_BASE_PATH)) {
+
+            return new SyntheticResource(resourceResolver, path, ReplicationAgentResource.IMPORTER_RESOURCE_TYPE);
+
+        } else if (path.startsWith(ReplicationAgentConfigurationResource.BASE_PATH + "/")) {
+
+            String agentName = getAgentNameAtPath(path);
+
+            ServiceReference configurationManagerServiceReference = context
+                    .getServiceReference(ReplicationAgentConfigurationManager.class
+                            .getName());
+            if (configurationManagerServiceReference != null) {
+                ReplicationAgentConfigurationManager agentConfigurationManager = (ReplicationAgentConfigurationManager) context
+                        .getService(configurationManagerServiceReference);
+                ReplicationAgentConfiguration configuration;
+                try {
+                    configuration = agentConfigurationManager.getConfiguration(agentName);
+                    resource = new ReplicationAgentConfigurationResource(configuration, resourceResolver);
+                } catch (AgentConfigurationException e) {
+                    log.warn("could not find a configuration", e);
                 }
+            } else {
+                log.warn("could not find a configuration manager service");
             }
-        } else if (path.endsWith(QUEUE_PATH)) {
-            String agentPath = path.substring(0, path.lastIndexOf(QUEUE_PATH));
-            if (log.isInfoEnabled()) {
-                log.info("resolving queue for agent {}", agentPath);
-            }
-            ReplicationAgent replicationAgent = getAgentAtPath(agentPath);
-            if (replicationAgent != null) {
+        } else if(path.startsWith(ReplicationAgentResource.BASE_PATH+"/")) {
+
+            if (path.endsWith(ReplicationAgentQueueResource.SUFFIX_PATH)) {
+                String agentPath = path.substring(0, path.lastIndexOf('/'));
+                log.info("resolving queue with path {}", agentPath);
+
+                ReplicationAgent replicationAgent = getAgentAtPath(agentPath);
                 try {
-                    resource = new ReplicationAgentQueueResource(replicationAgent.getQueue(null), resourceResolver);
-                } catch (Exception e) {
-                    if (log.isWarnEnabled()) {
-                        log.warn("could not find a queue for agent {}", replicationAgent.getName());
-                    }
+                    resource = replicationAgent != null ? new ReplicationAgentQueueResource(replicationAgent.getQueue(null),
+                            resourceResolver) : null;
+                } catch (ReplicationQueueException e) {
+                    log.warn("could not find a queue for agent {}", agentPath);
                 }
+            } else {
+                String agentPath = path;
+                ReplicationAgent replicationAgent = getAgentAtPath(path);
+                log.info("resolving agent with path {}", agentPath);
+
+                resource = replicationAgent != null ? new ReplicationAgentResource(replicationAgent,
+                        resourceResolver) : null;
             }
-        } else {
-            if (log.isInfoEnabled()) {
-                log.info("resolving agent with path {}", path);
+        }
+
+        log.info("resource found: {}", resource != null ? resource.getPath() : "none");
+        return resource;
+    }
+
+
+    private boolean isAuthorized(ResourceResolver resourceResolver){
+        boolean isAuthorized = false;
+        Session session = resourceResolver.adaptTo(Session.class);
+        if(session != null) {
+            try{
+                isAuthorized = session.nodeExists(SECURITY_OBJECT);
             }
-            ReplicationAgent replicationAgent = getAgentAtPath(path);
-            resource = replicationAgent != null ? new ReplicationAgentResource(replicationAgent,
-                    resourceResolver) : null;
+            catch (Exception ex){
+            }
+        }
+
+
+        if(isAuthorized){
+            log.debug("granting access to agent resources as user can read /system/replication/security");
         }
-        if (log.isInfoEnabled()) {
-            log.info("resource found: {}", resource != null ? resource.getPath() : "none");
+        else {
+            log.debug("denying access to agent resources as user can't read /system/replication/security");
         }
-        return resource;
+
+        return isAuthorized;
+    }
+
+    private String getAgentNameAtPath(String path) {
+        String agentName = path.substring(path.lastIndexOf('/') + 1);
+
+        return agentName;
     }
 
     private ReplicationAgent getAgentAtPath(String path) {
         ReplicationAgent replicationAgent = null;
-        String agentName = path.substring(path.lastIndexOf('/') + 1);
-        if (log.isDebugEnabled()) {
-            log.debug("resolving agent {} at {}", agentName, path);
-        }
+        String agentName = getAgentNameAtPath(path);
+
+        log.debug("resolving agent {} at {}", agentName, path);
+
         ServiceReference[] replicationAgentReferences;
         try {
             replicationAgentReferences = context.getServiceReferences(
-                    ReplicationAgent.class.getName(),
-                    "(name=" + agentName + ")");
+                    ReplicationAgent.class.getName(), "(name=" + agentName + ")");
+
             if (replicationAgentReferences != null && replicationAgentReferences.length == 1) {
                 replicationAgent = (ReplicationAgent) context
                         .getService(replicationAgentReferences[0]);
-                if (log.isDebugEnabled()) {
-                    log.debug("replication agent found: {}", replicationAgent);
-                }
+
+                log.debug("replication agent found: {}", replicationAgent);
             } else {
                 log.warn("could not find a replication agent with name {}", agentName);
             }
         } catch (InvalidSyntaxException e) {
-            if (log.isWarnEnabled()) {
-                log.warn("there was a syntax problem while getting agent service {}", e);
-            }
+            log.warn("there was a syntax problem while getting agent service {}", e);
         }
         return replicationAgent;
     }

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/event/ReplicationEventType.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/event/ReplicationEventType.java?rev=1558706&r1=1558705&r2=1558706&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/event/ReplicationEventType.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/event/ReplicationEventType.java Thu Jan 16 07:29:01 2014
@@ -24,6 +24,7 @@ package org.apache.sling.replication.eve
 public enum ReplicationEventType {
 
     PACKAGE_CREATED,
+    PACKAGE_QUEUED,
     PACKAGE_DELETED,
     PACKAGE_REPLICATED,
     PACKAGE_INSTALLED,

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/queue/impl/AbstractReplicationQueueProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/queue/impl/AbstractReplicationQueueProvider.java?rev=1558706&r1=1558705&r2=1558706&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/queue/impl/AbstractReplicationQueueProvider.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/queue/impl/AbstractReplicationQueueProvider.java Thu Jan 16 07:29:01 2014
@@ -49,11 +49,11 @@ public abstract class AbstractReplicatio
                     throws ReplicationQueueException {
         String key = agent.getName() + queueName;
 
-        if (log.isInfoEnabled()) {
-            log.info("creating a queue with key {}", key);
-        }
         ReplicationQueue queue = queueMap.get(key);
         if (queue == null) {
+            if (log.isInfoEnabled()) {
+                log.info("creating a queue with key {}", key);
+            }
             queue = getOrCreateQueue(agent, queueName);
             queueMap.put(key, queue);
             if (log.isInfoEnabled()) {

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackageBuilder.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackageBuilder.java?rev=1558706&r1=1558705&r2=1558706&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackageBuilder.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackageBuilder.java Thu Jan 16 07:29:01 2014
@@ -24,11 +24,9 @@ import java.util.Properties;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
 
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.Service;
+import org.apache.felix.scr.annotations.*;
 import org.apache.jackrabbit.vault.fs.api.PathFilterSet;
 import org.apache.jackrabbit.vault.fs.config.DefaultMetaInf;
 import org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter;
@@ -37,8 +35,10 @@ import org.apache.jackrabbit.vault.packa
 import org.apache.jackrabbit.vault.packaging.JcrPackage;
 import org.apache.jackrabbit.vault.packaging.Packaging;
 import org.apache.jackrabbit.vault.packaging.VaultPackage;
+import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.apache.sling.jcr.api.SlingRepository;
 
+import org.apache.sling.replication.communication.ReplicationHeader;
 import org.apache.sling.replication.communication.ReplicationRequest;
 import org.apache.sling.replication.serialization.ReplicationPackage;
 import org.apache.sling.replication.serialization.ReplicationPackageBuilder;
@@ -46,6 +46,7 @@ import org.apache.sling.replication.seri
 
 import org.apache.sling.replication.serialization.ReplicationPackageReadingException;
 import org.apache.sling.replication.serialization.impl.AbstractReplicationPackageBuilder;
+import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -55,27 +56,41 @@ import org.slf4j.LoggerFactory;
  * Each {@link ReplicationPackage} created by <code>FileVaultReplicationPackageBuilder</code> is
  * backed by a {@link VaultPackage}. 
  */
-@Component(metatype = false)
+@Component(metatype = true,
+        label = "Replication Package Builder - FileVault",
+        description = "OSGi configuration based PackageBuilder service factory",
+        name = FileVaultReplicationPackageBuilder.SERVICE_PID)
 @Service(value = ReplicationPackageBuilder.class)
 @Property(name = "name", value = FileVaultReplicationPackageBuilder.NAME)
 public class FileVaultReplicationPackageBuilder extends AbstractReplicationPackageBuilder implements
         ReplicationPackageBuilder {
 
+    static final String SERVICE_PID = "org.apache.sling.replication.serialization.impl.vlt.FileVaultReplicationPackageBuilder";
+
     public static final String NAME = "vlt";
 
     private final Logger log = LoggerFactory.getLogger(getClass());
 
+    @Property
+    private static final String USERNAME = "username";
+
+    @Property
+    private static final String PASSWORD = "password";
+
     @Reference
     private SlingRepository repository;
 
     @Reference
     private Packaging packaging;
 
+
+    private String username;
+    private String password;
+
     protected ReplicationPackage createPackageForAdd(ReplicationRequest request)
             throws ReplicationPackageBuildingException {
         Session session = null;
         try {
-            // TODO : replace this by using Credentials
             session = getSession();
 
             final String[] paths = request.getPaths();
@@ -119,7 +134,7 @@ public class FileVaultReplicationPackage
 
     @Override
     protected Session getSession() throws RepositoryException {
-        return repository.loginAdministrative(null);
+        return repository.login(new SimpleCredentials(username, password.toCharArray()));
     }
 
     @Override
@@ -134,7 +149,7 @@ public class FileVaultReplicationPackage
             if (log.isInfoEnabled()) {
                 log.info("reading package for addition");
             }
-            // TODO : use proper Credentials here
+
             session = getSession();
             if (session != null) {
                 final JcrPackage jcrPackage = packaging.getPackageManager(session).upload(stream, true,
@@ -173,4 +188,14 @@ public class FileVaultReplicationPackage
         return replicationPackage;
     }
 
+
+
+    @Activate
+    @Modified
+    protected void activate(ComponentContext ctx) {
+        username = PropertiesUtil.toString(ctx.getProperties().get(USERNAME), "").trim();
+        password = PropertiesUtil.toString(ctx.getProperties().get(PASSWORD), "").trim();
+    }
+
+
 }

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentRootServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentRootServlet.java?rev=1558706&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentRootServlet.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentRootServlet.java Thu Jan 16 07:29:01 2014
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.replication.servlet;
+
+import java.io.IOException;
+import java.util.SortedSet;
+
+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.servlets.SlingAllMethodsServlet;
+import org.apache.sling.replication.agent.impl.ReplicationAgentResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.sling.replication.agent.AgentReplicationException;
+import org.apache.sling.replication.agent.ReplicationAgent;
+import org.apache.sling.replication.agent.ReplicationAgentsManager;
+import org.apache.sling.replication.communication.ReplicationActionType;
+import org.apache.sling.replication.communication.ReplicationRequest;
+
+/**
+ * Servlet for aggregate replication on all agents
+ */
+@SuppressWarnings("serial")
+@Component(metatype = false)
+@Service(value = Servlet.class)
+@Properties({
+    @Property(name = "sling.servlet.resourceTypes", value = ReplicationAgentResource.RESOURCE_ROOT_TYPE),
+    @Property(name = "sling.servlet.methods", value = "POST")
+})
+public class ReplicationAgentRootServlet extends SlingAllMethodsServlet {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private static final String PATH_PARAMETER = "path";
+
+    private static final String ACTION_PARAMETER = "action";
+
+    @Reference
+    private ReplicationAgentsManager replicationAgentsManager;
+
+    @Override
+    protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response)
+                    throws ServletException, IOException {
+
+        String a = request.getParameter(ACTION_PARAMETER);
+        String[] paths = request.getParameterValues(PATH_PARAMETER);
+
+        ReplicationActionType action = ReplicationActionType.fromName(a);
+        SortedSet<ReplicationAgent> agents = replicationAgentsManager.getAgentsFor(action, paths);
+
+        ReplicationRequest replicationRequest = new ReplicationRequest(System.currentTimeMillis(),
+                        action, paths);
+
+        boolean failed = false;
+        for (ReplicationAgent agent : agents) {
+            try {
+                agent.send(replicationRequest);
+            } catch (AgentReplicationException e) {
+                log.warn("agent {} failed", agent.getName(), e);
+
+                response.getWriter().append("error :'").append(e.toString()).append("'");
+                if (!failed) {
+                    failed = true;
+                }
+            }
+        }
+        if (failed) {
+            response.setStatus(503);
+            response.getWriter().append("status : ").append("503");
+        }
+        else {
+            response.setStatus(200);
+        }
+    }
+}

Propchange: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentRootServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentServlet.java?rev=1558706&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentServlet.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentServlet.java Thu Jan 16 07:29:01 2014
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.replication.servlet;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+
+import org.apache.commons.io.IOUtils;
+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.http.entity.ContentType;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.servlets.SlingAllMethodsServlet;
+
+import org.apache.sling.replication.agent.AgentReplicationException;
+import org.apache.sling.replication.agent.ReplicationAgent;
+import org.apache.sling.replication.agent.impl.ReplicationAgentResource;
+import org.apache.sling.replication.communication.ReplicationActionType;
+import org.apache.sling.replication.communication.ReplicationHeader;
+import org.apache.sling.replication.communication.ReplicationRequest;
+import org.apache.sling.replication.communication.ReplicationResponse;
+import org.apache.sling.replication.queue.ReplicationQueue;
+import org.apache.sling.replication.queue.ReplicationQueueItemState.ItemState;
+import org.apache.sling.replication.serialization.ReplicationPackage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Servlet to ask {@link ReplicationAgent}s to replicate (via HTTP POST).
+ */
+@SuppressWarnings("serial")
+@Component(metatype = false)
+@Service(value = Servlet.class)
+@Properties({
+        @Property(name = "sling.servlet.resourceTypes", value = ReplicationAgentResource.RESOURCE_TYPE),
+        @Property(name = "sling.servlet.methods", value = "POST") })
+public class ReplicationAgentServlet extends SlingAllMethodsServlet {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Override
+    protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response)
+            throws ServletException, IOException {
+        String action = request.getHeader(ReplicationHeader.ACTION.toString());
+
+        if(ReplicationActionType.POLL.getName().equalsIgnoreCase(action)){
+            doRemove(request, response);
+            return;
+        }
+        else {
+            doCreate(request, response);
+            return;
+        }
+    }
+
+    private void doCreate(SlingHttpServletRequest request, SlingHttpServletResponse response)
+            throws ServletException, IOException {
+
+        response.setContentType("application/json");
+
+        String action = request.getHeader(ReplicationHeader.ACTION.toString());
+        String[] path = toStringArray(request.getHeaders(ReplicationHeader.PATH.toString()));
+
+        ReplicationRequest replicationRequest = new ReplicationRequest(System.currentTimeMillis(),
+                ReplicationActionType.valueOf(action), path);
+
+        ReplicationAgent agent = request.getResource().adaptTo(ReplicationAgent.class);
+
+        if (agent != null) {
+            try {
+                ReplicationResponse replicationResponse = agent.execute(replicationRequest);
+                if (replicationResponse.isSuccessful()
+                        || ItemState.DROPPED.toString().equals(
+                        replicationResponse.getStatus())) {
+                    response.setStatus(200);
+                } else if (ItemState.QUEUED.toString().equals(replicationResponse.getStatus())
+                        || ItemState.ACTIVE.toString().equals(
+                        replicationResponse.getStatus())) {
+                    response.setStatus(202);
+                } else {
+                    response.setStatus(400);
+                }
+                response.getWriter().append(replicationResponse.toString());
+            } catch (AgentReplicationException e) {
+                response.setStatus(503);
+                response.getWriter().append("{\"error\" : \"").append(e.toString()).append("\"}");
+            }
+        } else {
+            response.setStatus(404);
+            response.getWriter().append("{\"error\" : \"agent ").append(request.getServletPath())
+                    .append(" not found\"}");
+        }
+    }
+
+    private void doRemove(SlingHttpServletRequest request, SlingHttpServletResponse response)
+            throws ServletException, IOException {
+
+        response.setContentType(ContentType.APPLICATION_OCTET_STREAM.toString());
+
+        String queueName = request.getParameter(ReplicationHeader.QUEUE.toString());
+
+        ReplicationAgent agent = request.getResource().adaptTo(ReplicationAgent.class);
+
+        /* directly polling an agent queue is only possible if such an agent doesn't have its own endpoint
+        (that is it just adds items to its queue to be polled remotely)*/
+        if (agent != null && (agent.getEndpoint() == null || agent.getEndpoint().toString().length() == 0 )) {
+            try {
+                // TODO : consider using queue distribution strategy and validating who's making this request
+                if (log.isInfoEnabled()) {
+                    log.info("getting item from queue {}", queueName);
+                }
+                ReplicationQueue queue = agent.getQueue(queueName);
+                // get first item
+                ReplicationPackage head = queue.getHead();
+                if (head != null) {
+                    int bytesCopied = IOUtils.copy(head.getInputStream(),
+                            response.getOutputStream());
+                    response.setHeader(ReplicationHeader.TYPE.toString(), head.getType());
+                    if (log.isInfoEnabled()) {
+                        log.info("{} bytes written into the response", bytesCopied);
+                    }
+                    // remove the item from the queue
+                    queue.removeHead();
+                } else {
+                    if (log.isInfoEnabled()) {
+                        log.info("nothing to fetch");
+                    }
+                }
+            } catch (Exception e) {
+                response.setStatus(503);
+                if (log.isErrorEnabled()) {
+                    log.error("error while reverse replicating from agent", e);
+                }
+            }
+            // everything ok
+            response.setStatus(200);
+        } else {
+            response.setStatus(404);
+        }
+    }
+
+    String[] toStringArray(Enumeration<String> e){
+        List<String> l = new ArrayList<String>();
+        while (e.hasMoreElements()){
+            l.add(e.nextElement());
+        }
+
+        return l.toArray(new String[0]);
+
+    }
+}

Propchange: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationConfigurationRootServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationConfigurationRootServlet.java?rev=1558706&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationConfigurationRootServlet.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationConfigurationRootServlet.java Thu Jan 16 07:29:01 2014
@@ -0,0 +1,99 @@
+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.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.apache.sling.replication.agent.impl.ReplicationAgentConfigurationResource;
+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.resourceTypes",
+                value = ReplicationAgentConfigurationResource.RESOURCE_ROOT_TYPE),
+        @Property(name = "sling.servlet.methods", value = { "POST", "GET" } )})
+public class ReplicationConfigurationRootServlet 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 agentName = request.getParameter("name");
+
+        try {
+            agentConfigurationManager.createAgentConfiguration(agentName, request.getParameterMap());
+            log.info("agent configuration for {} created", agentName);
+
+            ReplicationAgentConfiguration configuration = agentConfigurationManager.getConfiguration(agentName);
+
+            response.getWriter().write(configuration.toString());
+            response.setStatus(201);
+
+        } catch (AgentConfigurationException e) {
+            log.error("cannot create agent {}", agentName, e);
+
+            response.setStatus(404);
+        }
+    }
+
+    @Override
+    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
+            throws ServletException, IOException {
+        response.setContentType("application/json");
+
+        try {
+            ReplicationAgentConfiguration[] agentConfigurations = agentConfigurationManager.listAllAgentConfigurations();
+
+            response.getWriter().write(toJson(agentConfigurations));
+            response.setStatus(200);
+
+        } catch (AgentConfigurationException e) {
+            log.error("cannot retrieve agent configurations", e);
+
+            response.setStatus(404);
+        }
+    }
+
+
+    String toJson(ReplicationAgentConfiguration[] agentConfigurations){
+        StringBuilder sb = new StringBuilder();
+        sb.append("{");
+        sb.append("\"agents\": [");
+
+        for(int i=0; i < agentConfigurations.length; i++){
+            ReplicationAgentConfiguration configuration = agentConfigurations[i];
+            sb.append(configuration.toSimpleString());
+            if(i < agentConfigurations.length -1)
+                sb.append(",");
+
+        }
+
+        sb.append("]");
+
+        sb.append("}");
+
+        return sb.toString();
+    }
+}

Propchange: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationConfigurationRootServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationConfigurationServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationConfigurationServlet.java?rev=1558706&r1=1558705&r2=1558706&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationConfigurationServlet.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationConfigurationServlet.java Thu Jan 16 07:29:01 2014
@@ -47,7 +47,7 @@ import org.apache.sling.replication.agen
 @Service(value = Servlet.class)
 @Properties({
         @Property(name = "sling.servlet.resourceTypes", value = ReplicationAgentConfigurationResource.RESOURCE_TYPE),
-        @Property(name = "sling.servlet.methods", value = { "POST", "GET" }) })
+        @Property(name = "sling.servlet.methods", value = { "POST", "PUT", "GET", "DELETE" }) })
 public class ReplicationConfigurationServlet extends SlingAllMethodsServlet {
 
     private final Logger log = LoggerFactory.getLogger(getClass());
@@ -58,19 +58,29 @@ public class ReplicationConfigurationSer
     @Override
     protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response)
                     throws ServletException, IOException {
-        response.setContentType("application/json");
+
+
+
         @SuppressWarnings("unchecked")
-        Map<String, Object> parameterMap = request.getParameterMap();
-        Resource agentResource = request.getResource().getParent();
-        ReplicationAgent agent = agentResource.adaptTo(ReplicationAgent.class);
-        ReplicationAgentConfiguration configuration;
+        String operation = request.getParameter(":operation");
+
+        if("delete".equals(operation)) {
+            doDelete(request, response);
+            return;
+        };
+
+        response.setContentType("application/json");
+
+        Resource configurationResource = request.getResource();
+        ReplicationAgentConfiguration configuration = configurationResource.adaptTo(ReplicationAgentConfiguration.class);
+        String agentName = configuration.getName();
+
+        Map parameterMap = request.getParameterMap();
         try {
-            configuration = agentConfigurationManager.updateConfiguration(agent, parameterMap);
+            configuration = agentConfigurationManager.updateConfiguration(agentName, parameterMap);
             response.getWriter().write(configuration.toString());
         } catch (AgentConfigurationException e) {
-            if (log.isErrorEnabled()) {
-                log.error("cannot update configuration for agent {}", agent, e);
-            }
+            log.error("cannot update configuration for agent {}", agentName, e);
         }
     }
 
@@ -79,9 +89,27 @@ public class ReplicationConfigurationSer
                     throws ServletException, IOException {
         response.setContentType("application/json");
         Resource resource = request.getResource();
-        ReplicationAgentConfiguration configuration = resource
-                        .adaptTo(ReplicationAgentConfiguration.class);
+        ReplicationAgentConfiguration configuration = resource.adaptTo(ReplicationAgentConfiguration.class);
         response.getWriter().write(configuration.toString());
     }
 
+
+    @Override
+    protected void doDelete(SlingHttpServletRequest request, SlingHttpServletResponse response)
+            throws ServletException, IOException {
+
+        @SuppressWarnings("unchecked")
+
+        Resource configurationResource = request.getResource();
+        ReplicationAgentConfiguration configuration = configurationResource.adaptTo(ReplicationAgentConfiguration.class);
+        String agentName = configuration.getName();
+        try {
+            agentConfigurationManager.deleteAgentConfiguration(agentName);
+            response.setStatus(204);
+        } catch (AgentConfigurationException e) {
+            log.error("cannot update configuration for agent {}", agentName, e);
+            response.setStatus(400);
+        }
+    }
+
 }

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationQueueServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationQueueServlet.java?rev=1558706&r1=1558705&r2=1558706&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationQueueServlet.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationQueueServlet.java Thu Jan 16 07:29:01 2014
@@ -19,36 +19,57 @@
 package org.apache.sling.replication.servlet;
 
 import java.io.IOException;
+
 import javax.servlet.Servlet;
 import javax.servlet.ServletException;
+
+import org.apache.commons.io.IOUtils;
 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.http.entity.ContentType;
+import org.apache.jackrabbit.util.Text;
 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.AgentReplicationException;
+import org.apache.sling.replication.agent.ReplicationAgent;
 import org.apache.sling.replication.agent.impl.ReplicationAgentQueueResource;
+import org.apache.sling.replication.agent.impl.ReplicationAgentResource;
+import org.apache.sling.replication.communication.ReplicationActionType;
+import org.apache.sling.replication.communication.ReplicationHeader;
+import org.apache.sling.replication.communication.ReplicationRequest;
+import org.apache.sling.replication.communication.ReplicationResponse;
 import org.apache.sling.replication.queue.ReplicationQueue;
 import org.apache.sling.replication.queue.ReplicationQueueItemState;
+import org.apache.sling.replication.queue.ReplicationQueueItemState.ItemState;
 import org.apache.sling.replication.serialization.ReplicationPackage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
+/**
+ * Servlet to ask {@link ReplicationAgent}s to replicate (via HTTP POST).
+ */
 @SuppressWarnings("serial")
 @Component(metatype = false)
 @Service(value = Servlet.class)
 @Properties({
         @Property(name = "sling.servlet.resourceTypes", value = ReplicationAgentQueueResource.RESOURCE_TYPE),
-        @Property(name = "sling.servlet.methods", value = {"GET"})})
+        @Property(name = "sling.servlet.methods", value = { "GET" } ) })
 public class ReplicationQueueServlet extends SlingAllMethodsServlet {
 
     @Override
     protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
             throws ServletException, IOException {
         response.setContentType("application/json");
-        Resource resource = request.getResource();
-        ReplicationQueue queue = resource
-                .adaptTo(ReplicationQueue.class);
+
+        String queueName = request.getParameter(ReplicationHeader.QUEUE.toString());
+
+        ReplicationQueue queue = request.getResource().adaptTo(ReplicationQueue.class);
+
         if (queue != null) {
             try {
                 response.getWriter().write(toJSoN(queue));
@@ -86,7 +107,7 @@ public class ReplicationQueueServlet ext
 
     private String toJSoN(ReplicationPackage item) {
         StringBuilder builder = new StringBuilder();
-        builder.append("\"id\":\"").append(item.getId());
+        builder.append("\"id\":\"").append(item.getId().replace("\\","\\\\"));
         builder.append("\",\"paths\":[");
         for (int i = 0; i < item.getPaths().length; i++) {
             builder.append("\"");
@@ -101,5 +122,4 @@ public class ReplicationQueueServlet ext
 
         return builder.toString();
     }
-
 }

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationReceiverServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationReceiverServlet.java?rev=1558706&r1=1558705&r2=1558706&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationReceiverServlet.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationReceiverServlet.java Thu Jan 16 07:29:01 2014
@@ -30,6 +30,8 @@ import org.apache.felix.scr.annotations.
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.SlingHttpServletResponse;
 import org.apache.sling.api.servlets.SlingAllMethodsServlet;
+import org.apache.sling.replication.agent.impl.ReplicationAgentResource;
+import org.apache.sling.replication.agent.impl.ReplicationAgentResourceProvider;
 import org.apache.sling.replication.communication.ReplicationHeader;
 import org.apache.sling.replication.serialization.ReplicationPackageImporter;
 import org.slf4j.Logger;
@@ -41,7 +43,8 @@ import org.slf4j.LoggerFactory;
 @SuppressWarnings("serial")
 @Component(metatype = false)
 @Service(value = Servlet.class)
-@Properties({@Property(name = "sling.servlet.paths", value = "/system/replication/receive"),
+@Properties({
+        @Property(name = "sling.servlet.resourceTypes", value = ReplicationAgentResource.IMPORTER_RESOURCE_TYPE),
         @Property(name = "sling.servlet.methods", value = "POST")})
 public class ReplicationReceiverServlet extends SlingAllMethodsServlet {
 

Modified: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/impl/PollingTransportHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/impl/PollingTransportHandler.java?rev=1558706&r1=1558705&r2=1558706&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/impl/PollingTransportHandler.java (original)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/impl/PollingTransportHandler.java Thu Jan 16 07:29:01 2014
@@ -29,6 +29,7 @@ import org.apache.http.HttpResponse;
 import org.apache.http.client.fluent.Executor;
 import org.apache.http.client.fluent.Request;
 import org.apache.sling.commons.osgi.PropertiesUtil;
+import org.apache.sling.replication.communication.ReplicationActionType;
 import org.apache.sling.replication.communication.ReplicationEndpoint;
 import org.apache.sling.replication.communication.ReplicationHeader;
 import org.apache.sling.replication.serialization.ReplicationPackage;
@@ -82,7 +83,9 @@ public class PollingTransportHandler imp
             executor = ((TransportAuthenticationProvider<Executor, Executor>) transportAuthenticationProvider)
                     .authenticate(executor, context);
 
-            Request req = Request.Get(replicationEndpoint.getUri()).useExpectContinue();
+            Request req = Request.Post(replicationEndpoint.getUri())
+                    .addHeader(ReplicationHeader.ACTION.toString(), ReplicationActionType.POLL.getName())
+                    .useExpectContinue();
             // TODO : add queue header
 
             int polls = pollItems;

Added: sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/config/org.apache.sling.replication.serialization.impl.vlt.FileVaultReplicationPackageBuilder.json
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/config/org.apache.sling.replication.serialization.impl.vlt.FileVaultReplicationPackageBuilder.json?rev=1558706&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/config/org.apache.sling.replication.serialization.impl.vlt.FileVaultReplicationPackageBuilder.json (added)
+++ sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/config/org.apache.sling.replication.serialization.impl.vlt.FileVaultReplicationPackageBuilder.json Thu Jan 16 07:29:01 2014
@@ -0,0 +1,6 @@
+{
+    "jcr:primaryType" : "sling:OsgiConfig",
+    "name" : "vlt",
+    "username" : "admin",
+    "password" : "admin"
+}
\ No newline at end of file

Added: sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/system/replication/security.json
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/system/replication/security.json?rev=1558706&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/system/replication/security.json (added)
+++ sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/system/replication/security.json Thu Jan 16 07:29:01 2014
@@ -0,0 +1,5 @@
+{
+    "jcr:primaryType" : "nt:unstructured",
+    "name" : "Replication Security",
+    "description" : "This node controls security access to replication. Whoever can access it can also access replication HTTP API. Set the appropriate ACLs to enforce access restrictions."
+}
\ No newline at end of file

Modified: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationTest.java?rev=1558706&r1=1558705&r2=1558706&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationTest.java (original)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationTest.java Thu Jan 16 07:29:01 2014
@@ -29,7 +29,7 @@ import static org.junit.Assert.assertNot
 public class ReplicationAgentConfigurationTest {
     @Test
     public void testNullsWithDefaultConfiguration() throws Exception {
-        ReplicationAgentConfiguration replicationAgentConfiguration = new ReplicationAgentConfiguration(new Properties());
+        ReplicationAgentConfiguration replicationAgentConfiguration = new ReplicationAgentConfiguration(new Properties(), null);
         assertNotNull(replicationAgentConfiguration.getAuthenticationProperties());
         assertNotNull(replicationAgentConfiguration.getEndpoint());
         assertNotNull(replicationAgentConfiguration.getName());

Modified: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentConfigurationManagerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentConfigurationManagerTest.java?rev=1558706&r1=1558705&r2=1558706&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentConfigurationManagerTest.java (original)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentConfigurationManagerTest.java Thu Jan 16 07:29:01 2014
@@ -37,14 +37,14 @@ public class DefaultReplicationAgentConf
     @Test
     public void testRetrievalWithNoConfigurationAvailable() throws Exception {
         ConfigurationAdmin configAdmin = mock(ConfigurationAdmin.class);
-        ReplicationAgent agent = mock(ReplicationAgent.class);
+
         DefaultReplicationAgentConfigurationManager defaultReplicationAgentConfigurationManager = new DefaultReplicationAgentConfigurationManager();
         Field configAdminField = defaultReplicationAgentConfigurationManager.getClass().getDeclaredField("configAdmin");
         configAdminField.setAccessible(true);
         configAdminField.set(defaultReplicationAgentConfigurationManager, configAdmin);
         
         try {
-            defaultReplicationAgentConfigurationManager.getConfiguration(agent);
+            defaultReplicationAgentConfigurationManager.getConfiguration("fake");
             fail("an exception should be thrown when no configuration is available");
         } catch (Exception e) {
             // failure is expected
@@ -54,8 +54,7 @@ public class DefaultReplicationAgentConf
     @Test
     public void testRetrievalWithMultipleConfigurationsAvailable() throws Exception {
         ConfigurationAdmin configAdmin = mock(ConfigurationAdmin.class);
-        ReplicationAgent agent = mock(ReplicationAgent.class);
-        when(agent.getName()).thenReturn("publish");
+
         when(configAdmin.listConfigurations("(name=publish)")).thenReturn(new Configuration[]{null, null});
         DefaultReplicationAgentConfigurationManager defaultReplicationAgentConfigurationManager = new DefaultReplicationAgentConfigurationManager();
         Field configAdminField = defaultReplicationAgentConfigurationManager.getClass().getDeclaredField("configAdmin");
@@ -63,7 +62,7 @@ public class DefaultReplicationAgentConf
         configAdminField.set(defaultReplicationAgentConfigurationManager, configAdmin);
         
         try {
-            defaultReplicationAgentConfigurationManager.getConfiguration(agent);
+            defaultReplicationAgentConfigurationManager.getConfiguration("publish");
             fail("an exception should be thrown when multiple configurations are available");
         } catch (Exception e) {
             // failure is expected
@@ -75,13 +74,12 @@ public class DefaultReplicationAgentConf
         Configuration configuration = mock(Configuration.class);
         when(configuration.getProperties()).thenReturn(new Properties());
         ConfigurationAdmin configAdmin = mock(ConfigurationAdmin.class);
-        ReplicationAgent agent = mock(ReplicationAgent.class);
-        when(agent.getName()).thenReturn("publish");
+
         when(configAdmin.listConfigurations("(name=publish)")).thenReturn(new Configuration[]{configuration});
         DefaultReplicationAgentConfigurationManager defaultReplicationAgentConfigurationManager = new DefaultReplicationAgentConfigurationManager();
         Field configAdminField = defaultReplicationAgentConfigurationManager.getClass().getDeclaredField("configAdmin");
         configAdminField.setAccessible(true);
         configAdminField.set(defaultReplicationAgentConfigurationManager, configAdmin);
-        defaultReplicationAgentConfigurationManager.getConfiguration(agent);
+        defaultReplicationAgentConfigurationManager.getConfiguration("publish");
     }
 }



Mime
View raw message