incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1547378 [3/5] - in /sling/trunk/contrib/extensions/replication: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/sling/ src/main/java/org/apache/sling/replication/ src/main/java/org/apa...
Date Tue, 03 Dec 2013 13:19:53 GMT
Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/rule/ReplicationRule.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/rule/ReplicationRule.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/rule/ReplicationRule.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/rule/ReplicationRule.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,48 @@
+/*
+ * 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.rule;
+
+import org.apache.sling.replication.agent.ReplicationAgent;
+
+/**
+ * A replication rule
+ */
+public interface ReplicationRule {
+
+    /**
+     * get the signature of this rule
+     *
+     * @return a <code>String</code> for this rule's signature
+     */
+    String getSignature();
+
+    /**
+     * apply this rule to a replication agent
+     *
+     * @param {@link ReplicationAgent agent} the agent to apply the rule to
+     */
+    void apply(ReplicationAgent agent);
+
+    /**
+     * undo the application of this rule to the given agent
+     *
+     * @param agent the {@link ReplicationAgent agent} on which undoing this rule application
+     */
+    void unapply(ReplicationAgent agent);
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/rule/ReplicationRuleEngine.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/rule/ReplicationRuleEngine.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/rule/ReplicationRuleEngine.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/rule/ReplicationRuleEngine.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,37 @@
+/*
+ * 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.rule;
+
+import org.apache.sling.replication.agent.ReplicationAgent;
+
+/**
+ * A replication rule engine
+ */
+public interface ReplicationRuleEngine {
+
+    /**
+     * reads a <code>String</code>, transforms it into a {@link ReplicationRule} and applies it to the
+     * given {@link ReplicationAgent}
+     *
+     * @param ruleString the <code>String</code> to be read as a {@link ReplicationRule}
+     * @param agent      the {@link ReplicationAgent} to apply the rule to
+     */
+    void applyRule(String ruleString, ReplicationAgent agent);
+
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/rule/impl/TriggerPathReplicationRule.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/rule/impl/TriggerPathReplicationRule.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/rule/impl/TriggerPathReplicationRule.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/rule/impl/TriggerPathReplicationRule.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,47 @@
+/*
+ * 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.rule.impl;
+
+import org.apache.sling.replication.agent.ReplicationAgent;
+import org.apache.sling.replication.rule.ReplicationRule;
+
+/**
+ * a rule for triggering a specific agent upon node / properties being changed under a certain path
+ */
+public class TriggerPathReplicationRule implements ReplicationRule {
+
+    private final String path;
+
+    public TriggerPathReplicationRule(String path) {
+        this.path = path;
+    }
+
+    public String getSignature() {
+        return "trigger on path: ${path}";
+    }
+
+    public void apply(ReplicationAgent agent) {
+        // TODO : register an event handler on path which triggers the agent on node / property changes
+
+    }
+
+    public void unapply(ReplicationAgent agent) {
+        // TODO : unregister the event handler for the given agent on that path
+    }
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/ReplicationPackage.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/ReplicationPackage.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/ReplicationPackage.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/ReplicationPackage.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,42 @@
+/*
+ * 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.serialization;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+
+/**
+ * A replication package
+ */
+public interface ReplicationPackage extends Serializable {
+
+    String getId();
+
+    String[] getPaths();
+
+    String getAction();
+
+    String getType();
+
+    InputStream getInputStream() throws IOException;
+
+    long getLength();
+
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/ReplicationPackageBuilder.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/ReplicationPackageBuilder.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/ReplicationPackageBuilder.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/ReplicationPackageBuilder.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,37 @@
+/*
+ * 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.serialization;
+
+import java.io.InputStream;
+
+import org.apache.sling.replication.communication.ReplicationRequest;
+
+/**
+ * A builder for {@link ReplicationPackage}s
+ */
+// TODO : add context
+public interface ReplicationPackageBuilder {
+    ReplicationPackage createPackage(ReplicationRequest request)
+                    throws ReplicationPackageBuildingException;
+
+    ReplicationPackage readPackage(ReplicationRequest request, InputStream stream, boolean install)
+                    throws ReplicationPackageBuildingException;
+
+    ReplicationPackage getPackage(String id);
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/ReplicationPackageBuilderProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/ReplicationPackageBuilderProvider.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/ReplicationPackageBuilderProvider.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/ReplicationPackageBuilderProvider.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,32 @@
+/*
+ * 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.serialization;
+
+import java.util.Collection;
+
+/**
+ * A provider for {@link ReplicationPackageBuilder}s
+ */
+public interface ReplicationPackageBuilderProvider {
+
+    Collection<ReplicationPackageBuilder> getAvailableReplicationPacakageBuilders();
+
+    ReplicationPackageBuilder getReplicationPacakageBuilder(String name);
+
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/ReplicationPackageBuildingException.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/ReplicationPackageBuildingException.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/ReplicationPackageBuildingException.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/ReplicationPackageBuildingException.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,34 @@
+/*
+ * 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.serialization;
+
+/**
+ * This represents an error happening while building a {@link ReplicationPackage}
+ */
+@SuppressWarnings("serial")
+public class ReplicationPackageBuildingException extends Exception {
+
+    public ReplicationPackageBuildingException(String message) {
+        super(message);
+    }
+
+    public ReplicationPackageBuildingException(Throwable t) {
+        super(t);
+    }
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/AbstractReplicationPackageBuilder.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/AbstractReplicationPackageBuilder.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/AbstractReplicationPackageBuilder.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/AbstractReplicationPackageBuilder.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,71 @@
+/*
+ * 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.serialization.impl;
+
+import java.io.InputStream;
+
+import org.apache.sling.replication.communication.ReplicationActionType;
+import org.apache.sling.replication.communication.ReplicationRequest;
+import org.apache.sling.replication.serialization.ReplicationPackage;
+import org.apache.sling.replication.serialization.ReplicationPackageBuilder;
+import org.apache.sling.replication.serialization.ReplicationPackageBuildingException;
+
+public abstract class AbstractReplicationPackageBuilder implements ReplicationPackageBuilder {
+
+    public ReplicationPackage createPackage(ReplicationRequest request)
+                    throws ReplicationPackageBuildingException {
+        ReplicationPackage replicationPackage = null;
+        if (ReplicationActionType.ACTIVATE.equals(request.getAction())) {
+            replicationPackage = createPackageForActivation(request);
+        } else if (ReplicationActionType.DEACTIVATE.equals(request.getAction())) {
+            replicationPackage = createPackageForDeactivation(request);
+        } else {
+            throw new ReplicationPackageBuildingException("unknown action type "
+                            + request.getAction());
+        }
+        return replicationPackage;
+    }
+
+    protected abstract ReplicationPackage createPackageForDeactivation(
+                    final ReplicationRequest request);
+
+    protected abstract ReplicationPackage createPackageForActivation(ReplicationRequest request)
+                    throws ReplicationPackageBuildingException;
+
+    public ReplicationPackage readPackage(ReplicationRequest request, InputStream stream,
+                    boolean install) throws ReplicationPackageBuildingException {
+        ReplicationPackage replicationPackage = null;
+        if (ReplicationActionType.ACTIVATE.equals(request.getAction())) {
+            replicationPackage = readPackageForActivation(request, stream, install);
+        } else if (ReplicationActionType.DEACTIVATE.equals(request.getAction())) {
+            replicationPackage = readPackageForDeactivation(request, stream, install);
+        } else {
+            throw new ReplicationPackageBuildingException("unknown action type "
+                            + request.getAction());
+        }
+        return replicationPackage;
+    }
+
+    protected abstract ReplicationPackage readPackageForDeactivation(ReplicationRequest request,
+                    InputStream stream, boolean install) throws ReplicationPackageBuildingException;
+
+    protected abstract ReplicationPackage readPackageForActivation(ReplicationRequest request,
+                    InputStream stream, boolean install) throws ReplicationPackageBuildingException;
+
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/ReplicationPackageAdapterFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/ReplicationPackageAdapterFactory.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/ReplicationPackageAdapterFactory.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/ReplicationPackageAdapterFactory.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,103 @@
+/*
+ * 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.serialization.impl;
+
+import java.io.InputStream;
+import java.util.Arrays;
+
+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.jackrabbit.util.Text;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.adapter.AdapterFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.sling.replication.communication.ReplicationActionType;
+import org.apache.sling.replication.communication.ReplicationRequest;
+import org.apache.sling.replication.serialization.ReplicationPackage;
+import org.apache.sling.replication.serialization.ReplicationPackageBuilder;
+import org.apache.sling.replication.serialization.ReplicationPackageBuilderProvider;
+
+/**
+ * {@link AdapterFactory} for
+ * {@link org.apache.sling.replication.serialization.ReplicationPackage}s
+ */
+@Component
+@Service(value = org.apache.sling.api.adapter.AdapterFactory.class)
+@Properties({
+        @Property(name = "adaptables", value = { "org.apache.sling.api.SlingHttpServletRequest" }),
+        @Property(name = "adapters", value = { "org.apache.sling.replication.serialization.ReplicationPackage" }) })
+public class ReplicationPackageAdapterFactory implements AdapterFactory {
+
+    private Logger log = LoggerFactory.getLogger(getClass());
+
+    @Reference
+    private ReplicationPackageBuilderProvider packageBuilderProvider;
+
+    @SuppressWarnings("unchecked")
+    public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
+        if (log.isInfoEnabled()) {
+            log.info("adapting package (from {} to {})", new Object[] { adaptable, type });
+        }
+        ReplicationPackage pkg = null;
+        try {
+            if (adaptable instanceof SlingHttpServletRequest) {
+                SlingHttpServletRequest request = (SlingHttpServletRequest) adaptable;
+                String name = request.getHeader("Type");
+                ReplicationPackageBuilder replicationPacakageBuilder = packageBuilderProvider
+                                .getReplicationPacakageBuilder(name);
+                if (log.isInfoEnabled()) {
+                    log.info("using {} package builder", replicationPacakageBuilder);
+                }
+                if (replicationPacakageBuilder != null) {
+                    InputStream stream = request.getInputStream();
+                    ReplicationActionType action = ReplicationActionType.fromName(request
+                                    .getHeader("Action"));
+                    String[] paths = Text.unescape(request.getHeader("Path")).replace("[", "").replace("]", "").split(", ");
+                    if (log.isInfoEnabled()) {
+                        log.info("action {} on paths {}", action, Arrays.toString(paths));
+                    }
+                    pkg = replicationPacakageBuilder.readPackage(new ReplicationRequest(System.currentTimeMillis(), action, paths), stream, true);
+                    if (pkg != null) {
+                        if (log.isInfoEnabled()) {
+                            log.info("package {} created", Arrays.toString(pkg.getPaths()));
+                        }
+                    } else {
+                        if (log.isWarnEnabled()) {
+                            log.warn("could not read a package");
+                        }
+                    }
+                } else {
+                    if (log.isErrorEnabled()) {
+                        log.error("could not read packages of type {}", type);
+                    }
+                }
+            }
+        } catch (Exception e) {
+            if (log.isErrorEnabled()) {
+                log.error("error while adapting stream to a replication package", e);
+            }
+        }
+        return (AdapterType) pkg;
+    }
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/ReplicationPackageBuilderProviderImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/ReplicationPackageBuilderProviderImpl.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/ReplicationPackageBuilderProviderImpl.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/ReplicationPackageBuilderProviderImpl.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,89 @@
+/*
+ * 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.serialization.impl;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.ReferencePolicy;
+import org.apache.felix.scr.annotations.References;
+import org.apache.felix.scr.annotations.Service;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.sling.replication.serialization.ReplicationPackageBuilder;
+import org.apache.sling.replication.serialization.ReplicationPackageBuilderProvider;
+
+/**
+ * Default implementation of {@link org.apache.sling.replication.agent.ReplicationAgentsManager}
+ */
+@Component
+@References({ 
+    @Reference(name = "replicationPackageBuilder", 
+               referenceInterface = ReplicationPackageBuilder.class, 
+               cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, 
+               policy = ReferencePolicy.DYNAMIC,
+               bind = "bindReplicationPackageBuilder", 
+               unbind = "unbindReplicationPackageBuilder")
+    })
+@Service(value = ReplicationPackageBuilderProvider.class)
+public class ReplicationPackageBuilderProviderImpl implements ReplicationPackageBuilderProvider {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private Map<String, ReplicationPackageBuilder> replicationPackageBuilders = new HashMap<String, ReplicationPackageBuilder>();
+
+    @Deactivate
+    protected void deactivate() {
+        replicationPackageBuilders.clear();
+    }
+
+    protected void bindReplicationPackageBuilder(
+                    final ReplicationPackageBuilder replicationPackageBuilder,
+                    Map<String, Object> properties) {
+        synchronized (replicationPackageBuilders) {
+            replicationPackageBuilders.put(String.valueOf(properties.get("name")),
+                            replicationPackageBuilder);
+        }
+        log.debug("Registering Replication Package Builder {} ", replicationPackageBuilder);
+    }
+
+    protected void unbindReplicationPackageBuilder(
+                    final ReplicationPackageBuilder replicationPackageBuilder,
+                    Map<String, Object> properties) {
+        synchronized (replicationPackageBuilders) {
+            replicationPackageBuilders.remove(String.valueOf("name"));
+        }
+        log.debug("Unregistering Replication PackageBuilder {} ", replicationPackageBuilder);
+    }
+
+    public Collection<ReplicationPackageBuilder> getAvailableReplicationPacakageBuilders() {
+        return replicationPackageBuilders.values();
+    }
+
+    public ReplicationPackageBuilder getReplicationPacakageBuilder(String name) {
+        return replicationPackageBuilders.get(name);
+    }
+
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackage.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackage.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackage.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackage.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,83 @@
+/*
+ * 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.serialization.impl.vlt;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+
+import org.apache.jackrabbit.vault.fs.api.PathFilterSet;
+import org.apache.jackrabbit.vault.packaging.VaultPackage;
+
+import org.apache.sling.replication.communication.ReplicationActionType;
+import org.apache.sling.replication.serialization.ReplicationPackage;
+
+/**
+ * a FileVault {@link ReplicationPackage}
+ */
+public class FileVaultReplicationPackage implements ReplicationPackage {
+
+    private static final long serialVersionUID = 1L;
+
+    private final String id;
+
+    private final String[] paths;
+
+    private VaultPackage pkg;
+
+    private String action;
+
+    public FileVaultReplicationPackage(VaultPackage pkg) {
+        this.pkg = pkg;
+        List<PathFilterSet> filterSets = pkg.getMetaInf().getFilter().getFilterSets();
+        String[] paths = new String[filterSets.size()];
+        for (int i = 0; i < paths.length; i++) {
+            paths[i] = filterSets.get(i).getRoot();
+        }
+        this.paths = paths;
+        this.id = pkg.getFile().getAbsolutePath();
+        this.action = ReplicationActionType.ACTIVATE.toString();
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public String[] getPaths() {
+        return paths;
+    }
+
+    public InputStream getInputStream() throws IOException {
+        return new FileInputStream(pkg.getFile());
+    }
+
+    public long getLength() {
+        return pkg.getFile().length();
+    }
+
+    public String getType() {
+        return FileVaultReplicationPackageBuilder.NAME;
+    }
+
+    public String getAction() {
+        return action;
+    }
+
+}

Added: 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=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackageBuilder.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackageBuilder.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,197 @@
+/*
+ * 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.serialization.impl.vlt;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.Properties;
+
+import javax.jcr.Session;
+
+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.jackrabbit.vault.fs.api.PathFilterSet;
+import org.apache.jackrabbit.vault.fs.config.DefaultMetaInf;
+import org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter;
+import org.apache.jackrabbit.vault.fs.io.ImportOptions;
+import org.apache.jackrabbit.vault.packaging.ExportOptions;
+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.jcr.api.SlingRepository;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.sling.replication.communication.ReplicationRequest;
+import org.apache.sling.replication.serialization.ReplicationPackage;
+import org.apache.sling.replication.serialization.ReplicationPackageBuilder;
+import org.apache.sling.replication.serialization.ReplicationPackageBuildingException;
+import org.apache.sling.replication.serialization.impl.AbstractReplicationPackageBuilder;
+
+/**
+ * a {@link ReplicationPackageBuilder} based on Apache Jackrabbit FileVault.
+ * 
+ * Each {@link ReplicationPackage} created by <code>FileVaultReplicationPackageBuilder</code> is
+ * backed by a {@link VaultPackage}. 
+ */
+@Component(metatype = false)
+@Service(value = ReplicationPackageBuilder.class)
+@Property(name = "name", value = FileVaultReplicationPackageBuilder.NAME)
+public class FileVaultReplicationPackageBuilder extends AbstractReplicationPackageBuilder implements
+                ReplicationPackageBuilder {
+
+    public static final String NAME = "vlt";
+
+    private Logger log = LoggerFactory.getLogger(getClass());
+
+    @Reference
+    private SlingRepository repository;
+
+    @Reference
+    private Packaging packaging;
+
+    protected ReplicationPackage createPackageForActivation(ReplicationRequest request)
+                    throws ReplicationPackageBuildingException {
+        Session session = null;
+        try {
+            // TODO : replace this by using Credentials
+            session = repository.loginAdministrative(null);
+
+            final String[] paths = request.getPaths();
+
+            DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter();
+            DefaultMetaInf inf = new DefaultMetaInf();
+            ExportOptions opts = new ExportOptions();
+            for (String path : paths) {
+                filter.add(new PathFilterSet(path));
+            }
+            inf.setFilter(filter);
+
+            Properties props = new Properties();
+            String packageGroup = new StringBuilder("sling/replication").toString();
+            props.setProperty(VaultPackage.NAME_GROUP, packageGroup);
+            String packageName = String.valueOf(request.getTime());
+            props.setProperty(VaultPackage.NAME_NAME, packageName);
+            if (log.isInfoEnabled()) {
+                log.info("assembling package {}", new StringBuilder(packageGroup).append('/')
+                                .append(packageName).toString());
+            }
+            inf.setProperties(props);
+
+            opts.setMetaInf(inf);
+            opts.setRootPath("/");
+            File tmpFile = File.createTempFile("vlt-rp-" + System.nanoTime(), ".zip");
+            tmpFile.createNewFile();
+            VaultPackage pkg = packaging.getPackageManager().assemble(session, opts, tmpFile);
+
+            return new FileVaultReplicationPackage(pkg);
+        } catch (Exception e) {
+            throw new ReplicationPackageBuildingException(e);
+        } finally {
+            if (session != null) {
+                session.logout();
+            }
+        }
+    }
+
+    @Override
+    protected ReplicationPackage readPackageForActivation(ReplicationRequest request,
+                    final InputStream stream, boolean install)
+                    throws ReplicationPackageBuildingException {
+        if (log.isInfoEnabled()) {
+            log.info("reading a stream {}", stream);
+        }
+        Session session = null;
+        ReplicationPackage pkg = null;
+        try {
+            session = repository.loginAdministrative(null);
+            final JcrPackage jcrPackage = packaging.getPackageManager(session).upload(stream, true,
+                            false);
+            if (install) {
+                jcrPackage.install(new ImportOptions());
+            }
+            pkg = new FileVaultReplicationPackage(jcrPackage.getPackage());
+        } catch (Exception e) {
+            if (log.isErrorEnabled()) {
+                log.error("could not read / install the package", e);
+            }
+            throw new ReplicationPackageBuildingException(e);
+        } finally {
+            if (session != null) {
+                session.logout();
+            }
+        }
+        return pkg;
+    }
+
+    public ReplicationPackage getPackage(String id) {
+        ReplicationPackage replicationPackage = null;
+        try {
+            VaultPackage pkg = packaging.getPackageManager().open(new File(id));
+            replicationPackage = new FileVaultReplicationPackage(pkg);
+        } catch (Exception e) {
+            if (log.isWarnEnabled()) {
+                log.info("could not find a package with id : {}", id);
+            }
+        }
+        return replicationPackage;
+    }
+
+    @Override
+    protected ReplicationPackage readPackageForDeactivation(ReplicationRequest request,
+                    InputStream stream, boolean install) throws ReplicationPackageBuildingException {
+        Session session = null;
+        ReplicationPackage pkg = new VoidReplicationPackage(request, NAME);
+        try {
+            session = repository.loginAdministrative(null);
+            for (String path : request.getPaths()) {
+                try {
+                    if (session.itemExists(path)) {
+                        session.removeItem(path);
+                    }
+                    else if (log.isInfoEnabled()) {
+                        log.info("nothing to remove: path {} doesn't exist", path);
+                    }
+                } catch (Exception e) {
+                    if (log.isInfoEnabled()) {
+                        log.info("could not remove path {}", path, e);
+                    }
+                }
+            }
+            session.save();
+        } catch (Exception e) {
+            if (log.isErrorEnabled()) {
+                log.error("could not read / install the package", e);
+            }
+        } finally {
+            if (session != null) {
+                session.logout();
+            }
+        }
+        return pkg;
+    }
+
+    @Override
+    protected ReplicationPackage createPackageForDeactivation(ReplicationRequest request) {
+        return new VoidReplicationPackage(request, NAME);
+    }
+
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/vlt/VoidReplicationPackage.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/vlt/VoidReplicationPackage.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/vlt/VoidReplicationPackage.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/serialization/impl/vlt/VoidReplicationPackage.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,72 @@
+/*
+ * 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.serialization.impl.vlt;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.sling.replication.communication.ReplicationActionType;
+import org.apache.sling.replication.communication.ReplicationRequest;
+import org.apache.sling.replication.serialization.ReplicationPackage;
+
+/**
+ * A void {@link ReplicationPackage} used mainly for deactivation
+ */
+public class VoidReplicationPackage implements ReplicationPackage {
+
+    private String type;
+
+    private String[] paths;
+
+    private String id;
+
+    public VoidReplicationPackage(ReplicationRequest request, String type) {
+        this.type = type;
+        this.paths = request.getPaths();
+        this.id = String.valueOf(request.getTime());
+    }
+
+    private static final long serialVersionUID = 1L;
+
+    public String getType() {
+        return type;
+    }
+
+    public String[] getPaths() {
+        return paths;
+    }
+
+    public long getLength() {
+        return 0;
+    }
+
+    public InputStream getInputStream() throws IOException {
+        return new ByteArrayInputStream("".getBytes());
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public String getAction() {
+        return ReplicationActionType.DEACTIVATE.toString();
+    }
+
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/AggregateReplicationServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/AggregateReplicationServlet.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/AggregateReplicationServlet.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/AggregateReplicationServlet.java Tue Dec  3 13:19:50 2013
@@ -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.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.paths", value = "/system/replication/agents"),
+    @Property(name = "sling.servlet.methods", value = "POST")
+})
+public class AggregateReplicationServlet 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) {
+                if (log.isWarnEnabled()) {
+                    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);
+        }
+    }
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentPollServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentPollServlet.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentPollServlet.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentPollServlet.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,98 @@
+/*
+ * 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.Arrays;
+
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.sling.replication.agent.ReplicationAgent;
+import org.apache.sling.replication.agent.impl.ReplicationAgentResource;
+import org.apache.sling.replication.queue.ReplicationQueue;
+import org.apache.sling.replication.serialization.ReplicationPackage;
+
+@Component(metatype = false)
+@Service(value = Servlet.class)
+@Properties({
+        @Property(name = "sling.servlet.resourceTypes", value = ReplicationAgentResource.RESOURCE_TYPE),
+        @Property(name = "sling.servlet.methods", value = "GET") })
+public class ReplicationAgentPollServlet extends SlingAllMethodsServlet {
+
+    private static final long serialVersionUID = 1L;
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Override
+    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
+                    throws ServletException, IOException {
+
+        response.setContentType(ContentType.APPLICATION_OCTET_STREAM.toString());
+
+        String queueName = request.getParameter("queue");
+
+        ReplicationAgent agent = request.getResource().adaptTo(ReplicationAgent.class);
+
+        if (agent != null) {
+            try {
+                // TODO : consider using queue distribution strategy some way and validating who's making this request
+                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("type", head.getType());
+                    response.setHeader("action", head.getAction().toString());
+                    response.setHeader("path", Arrays.toString(head.getPaths()));
+                    if (log.isInfoEnabled()) {
+                        log.info("{} bytes written into the response", bytesCopied);
+                    }
+                } 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);
+        }
+    }
+
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentPostServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentPostServlet.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentPostServlet.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentPostServlet.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,92 @@
+/*
+ * 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 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.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.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.ReplicationRequest;
+import org.apache.sling.replication.communication.ReplicationResponse;
+import org.apache.sling.replication.queue.ReplicationQueueItemState.ItemState;
+
+/**
+ * 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 ReplicationAgentPostServlet extends SlingAllMethodsServlet {
+
+    @Override
+    protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response)
+                    throws ServletException, IOException {
+
+        response.setContentType("application/json");
+
+        String action = request.getParameter("action");
+        String[] path = request.getParameterValues("path");
+
+        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.isSuccessfull()
+                                || 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\"}");
+        }
+    }
+}

Added: 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=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationConfigurationServlet.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationConfigurationServlet.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,85 @@
+/*
+ * 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.Map;
+
+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.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;
+import org.apache.sling.replication.agent.impl.ReplicationAgentConfigurationResource;
+
+@SuppressWarnings("serial")
+@Component(metatype = false)
+@Service(value = Servlet.class)
+@Properties({
+        @Property(name = "sling.servlet.resourceTypes", value = ReplicationAgentConfigurationResource.RESOURCE_TYPE),
+        @Property(name = "sling.servlet.methods", value = { "POST", "GET" }) })
+public class ReplicationConfigurationServlet extends SlingAllMethodsServlet {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Reference
+    private ReplicationAgentConfigurationManager agentConfigurationManager;
+
+    @Override
+    protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response)
+                    throws ServletException, IOException {
+        @SuppressWarnings("unchecked")
+        Map<String, Object> parameterMap = request.getParameterMap();
+        Resource agentResource = request.getResource().getParent();
+        ReplicationAgent agent = agentResource.adaptTo(ReplicationAgent.class);
+        ReplicationAgentConfiguration configuration;
+        try {
+            configuration = agentConfigurationManager.updateConfiguration(agent, parameterMap);
+            response.getWriter().write(configuration.toString());
+        } catch (AgentConfigurationException e) {
+            if (log.isErrorEnabled()) {
+                log.error("cannot update configuration for agent {}", agent, e);
+            }
+        }
+    }
+
+    @Override
+    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
+                    throws ServletException, IOException {
+        Resource resource = request.getResource();
+        ReplicationAgentConfiguration configuration = resource
+                        .adaptTo(ReplicationAgentConfiguration.class);
+        response.getWriter().write(configuration.toString());
+    }
+
+}

Added: 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=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationReceiverServlet.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/servlet/ReplicationReceiverServlet.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,95 @@
+/*
+ * 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.Arrays;
+
+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.Service;
+import org.apache.jackrabbit.util.Text;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.servlets.SlingAllMethodsServlet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.sling.replication.communication.ReplicationActionType;
+import org.apache.sling.replication.serialization.ReplicationPackage;
+
+/**
+ * Servlet to handle reception of replication content.
+ */
+@SuppressWarnings("serial")
+@Component(metatype = false)
+@Service(value = Servlet.class)
+@Properties({ @Property(name = "sling.servlet.paths", value = "/system/replication/receive"),
+        @Property(name = "sling.servlet.methods", value = "POST") })
+public class ReplicationReceiverServlet extends SlingAllMethodsServlet {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Override
+    protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response)
+                    throws ServletException, IOException {
+        boolean success = false;
+        final long start = System.currentTimeMillis();
+        response.setContentType("text/plain");
+        response.setCharacterEncoding("utf-8");
+        ReplicationActionType actionType = ReplicationActionType.fromName(request
+                        .getHeader("Action"));
+
+        String path = Text.unescape(request.getHeader("Path"));
+        try {
+
+            ReplicationPackage replicationPackage = request.adaptTo(ReplicationPackage.class);
+            if (replicationPackage != null) {
+                if (log.isInfoEnabled()) {
+                    log.info("replication package read and installed for path(s) {}",
+                                    Arrays.toString(replicationPackage.getPaths()));
+                }
+                success = true;
+            } else {
+                if (log.isInfoEnabled()) {
+                    log.info("could not read a replication package for path(s) {}", path);
+                }
+            }
+        } catch (final Exception e) {
+            response.setStatus(400);
+            if (log.isErrorEnabled()) {
+                log.error("Error during replication: {}", e.getMessage(), e);
+            }
+            response.getWriter().print("error: " + e.toString());
+        }
+        finally {
+            final long end = System.currentTimeMillis();
+            if (log.isInfoEnabled()) {
+                log.info("Processed replication request in {}ms: {} of {} : {}", new Object[] {
+                        end - start, actionType, path, success });
+            }
+        }
+
+    }
+
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/ReplicationTransportException.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/ReplicationTransportException.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/ReplicationTransportException.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/ReplicationTransportException.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,35 @@
+/*
+ * 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.transport;
+
+/**
+ * Represents an error happened while a {@link TransportHandler} is delivering a replication item to
+ * and endpoint.
+ */
+@SuppressWarnings("serial")
+public class ReplicationTransportException extends Exception {
+
+    public ReplicationTransportException(Exception e) {
+        super(e);
+    }
+
+    public ReplicationTransportException(String string) {
+        super(string);
+    }
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/TransportHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/TransportHandler.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/TransportHandler.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/TransportHandler.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,37 @@
+/*
+ * 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.transport;
+
+import org.apache.sling.replication.transport.authentication.AuthenticationHandler;
+import org.apache.sling.replication.communication.ReplicationEndpoint;
+import org.apache.sling.replication.serialization.ReplicationPackage;
+
+/**
+ * A <code>TransportHandler</code> is responsible for implementing the transport of a
+ * {@link ReplicationPackage}s to / from another instance described by a {@link ReplicationEndpoint}
+ */
+public interface TransportHandler {
+
+    void transport(ReplicationPackage replicationPackage, ReplicationEndpoint replicationEndpoint,
+                    AuthenticationHandler<?, ?> authenticationHandler)
+                    throws ReplicationTransportException;
+
+    boolean supportsAuthenticationHandler(AuthenticationHandler<?, ?> authenticationHandler);
+
+}
\ No newline at end of file

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/AuthenticationContext.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/AuthenticationContext.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/AuthenticationContext.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/AuthenticationContext.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,40 @@
+/*
+ * 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.transport.authentication;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class AuthenticationContext {
+    private Map<String, Object> attributes = new HashMap<String, Object>();
+
+    @SuppressWarnings("unchecked")
+    public <T extends Object> T getAttribute(String name, Class<? extends T> klass) {
+        T result = null;
+        Object object = attributes.get(name);
+        if (klass.isInstance(object)) {
+            result = (T) object;
+        }
+        return result;
+    }
+
+    public <T extends Object> void addAttribute(String name, T object) {
+        attributes.put(name, object);
+    }
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/AuthenticationException.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/AuthenticationException.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/AuthenticationException.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/AuthenticationException.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,33 @@
+/*
+ * 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.transport.authentication;
+
+
+@SuppressWarnings("serial")
+public class AuthenticationException extends Exception {
+
+    public AuthenticationException(String string) {
+        super(string);
+    }
+
+    public AuthenticationException(Exception e) {
+        super(e);
+    }
+
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/AuthenticationHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/AuthenticationHandler.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/AuthenticationHandler.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/AuthenticationHandler.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,33 @@
+/*
+ * 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.transport.authentication;
+
+
+/**
+ * An <code>AuthenticationHandler</code> is responsible for authentication of instances sending and
+ * receiving replication items.
+ */
+public interface AuthenticationHandler<A, T> {
+
+    boolean canAuthenticate(Class<?> authenticable);
+
+    T authenticate(A authenticable, AuthenticationContext context)
+                    throws AuthenticationException;
+
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/AuthenticationHandlerFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/AuthenticationHandlerFactory.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/AuthenticationHandlerFactory.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/AuthenticationHandlerFactory.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,31 @@
+/*
+ * 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.transport.authentication;
+
+import java.util.Map;
+
+/**
+ * Factory for {@link AuthenticationHandler}s
+ */
+public interface AuthenticationHandlerFactory {
+
+    AuthenticationHandler<?, ?> createAuthenticationHandler(Map<String, String> properties);
+
+    String getType();
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/AuthenticationHandlerProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/AuthenticationHandlerProvider.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/AuthenticationHandlerProvider.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/AuthenticationHandlerProvider.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,30 @@
+/*
+ * 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.transport.authentication;
+
+import java.util.Map;
+
+/**
+ * Provides {@link AuthenticationHandler}s instances of specific types with specific properties
+ */
+public interface AuthenticationHandlerProvider {
+
+    AuthenticationHandler<?, ?> getAuthenticationHandler(String type, Map<String, String> properties);
+
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/DefaultAuthenticationHandlerManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/DefaultAuthenticationHandlerManager.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/DefaultAuthenticationHandlerManager.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/DefaultAuthenticationHandlerManager.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,89 @@
+/*
+ * 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.transport.authentication.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.ReferencePolicy;
+import org.apache.felix.scr.annotations.References;
+import org.apache.sling.replication.transport.authentication.AuthenticationHandler;
+import org.apache.sling.replication.transport.authentication.AuthenticationHandlerFactory;
+import org.apache.sling.replication.transport.authentication.AuthenticationHandlerProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component
+@References({ 
+    @Reference(name = "authenticationHandlerFactory", 
+                    referenceInterface = AuthenticationHandlerFactory.class,
+                    cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, 
+                    policy = ReferencePolicy.DYNAMIC, 
+                    bind = "bindAuthenticationHandlerFactory", 
+                    unbind = "unbindAuthenticationHandlerFactory")
+    })
+public class DefaultAuthenticationHandlerManager implements AuthenticationHandlerProvider {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private Map<String, AuthenticationHandlerFactory> authenticationHandlerFactories = new HashMap<String, AuthenticationHandlerFactory>();
+
+    @Deactivate
+    protected void deactivate() {
+        authenticationHandlerFactories.clear();
+    }
+
+    public AuthenticationHandler<?, ?> getAuthenticationHandler(String type,
+                    Map<String, String> properties) {
+        AuthenticationHandler<?, ?> authenticationHandler = null;
+        AuthenticationHandlerFactory authenticationHandlerFactory = authenticationHandlerFactories
+                        .get(type);
+        if (authenticationHandlerFactory != null) {
+            authenticationHandler = authenticationHandlerFactory
+                            .createAuthenticationHandler(properties);
+        }
+        return authenticationHandler;
+    }
+
+    public void bindAuthenticationHandlerFactory(
+                    AuthenticationHandlerFactory authenticationHandlerFactory) {
+        synchronized (authenticationHandlerFactories) {
+            authenticationHandlerFactories.put(authenticationHandlerFactory.getType(),
+                            authenticationHandlerFactory);
+        }
+        if (log.isInfoEnabled()) {
+            log.info("Registered AuthenticationHandlerFactory {}", authenticationHandlerFactory);
+        }
+    }
+
+    public void unbindAuthenticationHandlerFactory(
+                    AuthenticationHandlerFactory authenticationHandlerFactory) {
+        synchronized (authenticationHandlerFactories) {
+            authenticationHandlerFactories.remove(authenticationHandlerFactory.getType());
+        }
+        if (log.isInfoEnabled()) {
+            log.info("Unregistered AuthenticationHandlerFactory {}", authenticationHandlerFactory);
+        }
+    }
+
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/NopAuthenticationHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/NopAuthenticationHandler.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/NopAuthenticationHandler.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/NopAuthenticationHandler.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,44 @@
+/*
+ * 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.transport.authentication.impl;
+
+import org.apache.sling.replication.transport.TransportHandler;
+import org.apache.sling.replication.transport.authentication.AuthenticationContext;
+import org.apache.sling.replication.transport.authentication.AuthenticationException;
+import org.apache.sling.replication.transport.authentication.AuthenticationHandler;
+
+/**
+ * {@link AuthenticationHandler} used when no authentication is required
+ */
+public class NopAuthenticationHandler implements AuthenticationHandler<Object, Object> {
+
+    public boolean supportsTransportHandler(TransportHandler transportHandler) {
+        return true;
+    }
+
+    public Object authenticate(Object authenticable, AuthenticationContext context)
+                    throws AuthenticationException {
+        return authenticable;
+    }
+
+    public boolean canAuthenticate(Class<?> authenticable) {
+        return true;
+    }
+
+}



Mime
View raw message