Author: tommaso
Date: Mon Aug 25 13:19:09 2014
New Revision: 1620322

URL: http://svn.apache.org/r1620322
Log:
SLING-3871 - applied Marius Petria's patch fixing event rule

Added:
    
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/ReplicationRequestHandler.java
   (with props)
Modified:
    
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/ReplicationRule.java
    
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ChainReplicateReplicationRule.java
    
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/DefaultReplicationRuleEngine.java
    
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ReplicateOnQueueEventRule.java
    
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ScheduleReplicateReplicationRule.java
    
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/TriggerPathReplicationRule.java
    
sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/rule/impl/ChainReplicateReplicationRuleTest.java
    
sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/rule/impl/ScheduleReplicateReplicationRuleTest.java
    
sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/rule/impl/TriggerPathReplicationRuleTest.java
    
sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationUtils.java

Added: 
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/ReplicationRequestHandler.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/ReplicationRequestHandler.java?rev=1620322&view=auto
==============================================================================
--- 
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/ReplicationRequestHandler.java
 (added)
+++ 
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/ReplicationRequestHandler.java
 Mon Aug 25 13:19:09 2014
@@ -0,0 +1,25 @@
+/*
+ * 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.communication.ReplicationRequest;
+
+public interface ReplicationRequestHandler {
+    void execute(ReplicationRequest request);
+}

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

Modified: 
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/ReplicationRule.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/ReplicationRule.java?rev=1620322&r1=1620321&r2=1620322&view=diff
==============================================================================
--- 
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/ReplicationRule.java
 (original)
+++ 
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/ReplicationRule.java
 Mon Aug 25 13:19:09 2014
@@ -44,14 +44,14 @@ public interface ReplicationRule {
      * apply this rule to a replication agent
      *
      * @param ruleString the rule to apply to the agent
-     * @param agent      {@link ReplicationAgent agent} the agent to apply the 
rule to
+     * @param requestHandler      {@link ReplicationRequestHandler agent} the 
agent to apply the rule to
      */
-    void apply(String ruleString, ReplicationAgent agent);
+    void apply(String handlerId, ReplicationRequestHandler requestHandler, 
String ruleString);
 
     /**
      * undo the application of this rule to the given agent
      *
-     * @param agent the {@link ReplicationAgent agent} on which undoing this 
rule application
+     * @param handlerId the {@link ReplicationAgent agent} on which undoing 
this rule application
      */
-    void undo(String ruleString, ReplicationAgent agent);
+    void undo(String handlerId);
 }

Modified: 
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ChainReplicateReplicationRule.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ChainReplicateReplicationRule.java?rev=1620322&r1=1620321&r2=1620322&view=diff
==============================================================================
--- 
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ChainReplicateReplicationRule.java
 (original)
+++ 
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ChainReplicateReplicationRule.java
 Mon Aug 25 13:19:09 2014
@@ -32,6 +32,7 @@ import org.apache.sling.replication.comm
 import org.apache.sling.replication.communication.ReplicationRequest;
 import org.apache.sling.replication.event.ReplicationEvent;
 import org.apache.sling.replication.event.ReplicationEventType;
+import org.apache.sling.replication.rule.ReplicationRequestHandler;
 import org.apache.sling.replication.rule.ReplicationRule;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
@@ -75,18 +76,18 @@ public class ChainReplicateReplicationRu
         return SIGNATURE;
     }
 
-    public void apply(String ruleString, ReplicationAgent agent) {
+    public void apply(String handlerId, ReplicationRequestHandler agent, 
String ruleString) {
         if (signatureMatches(ruleString)) {
             // register an event handler on replication package install (on a 
certain path) which triggers the chain replication of that same package
             Dictionary<String, Object> properties = new Hashtable<String, 
Object>();
             properties.put(EventConstants.EVENT_TOPIC, 
ReplicationEvent.getTopic(ReplicationEventType.PACKAGE_INSTALLED));
             String path = ruleString.substring(ruleString.indexOf(':') + 
1).trim();
-            log.info("agent {} will chain replication on path '{}'", 
agent.getName(), path);
+            log.info("handler {} will chain replication on path '{}'", 
handlerId, path);
 
 //            properties.put(EventConstants.EVENT_FILTER, "(path=" + path + 
"/*)");
             if (bundleContext != null) {
                 ServiceRegistration triggerPathEventRegistration = 
bundleContext.registerService(EventHandler.class.getName(), new 
TriggerAgentEventListener(agent, path), properties);
-                registrations.put(agent.getName() + ruleString, 
triggerPathEventRegistration);
+                registrations.put(handlerId, triggerPathEventRegistration);
             } else {
                 log.error("cannot register trigger since bundle context is 
null");
 
@@ -102,24 +103,20 @@ public class ChainReplicateReplicationRu
         return ruleString.startsWith(PREFIX) && 
ruleString.substring(PREFIX.length() + 1).matches("\\s*(\\/\\w+)+");
     }
 
-    public void undo(String ruleString, ReplicationAgent agent) {
-        if (signatureMatches(ruleString)) {
-            ServiceRegistration serviceRegistration = 
registrations.get(agent.getName() + ruleString);
-            if (serviceRegistration != null) {
-                serviceRegistration.unregister();
-            }
-        } else {
-            log.warn("rule {} doesn't match signature: {}", ruleString, 
SIGNATURE);
+    public void undo(String handleId) {
+        ServiceRegistration serviceRegistration = registrations.get(handleId);
+        if (serviceRegistration != null) {
+            serviceRegistration.unregister();
         }
     }
 
 
     private class TriggerAgentEventListener implements EventHandler {
 
-        private final ReplicationAgent agent;
+        private final ReplicationRequestHandler agent;
         private final String path;
 
-        public TriggerAgentEventListener(ReplicationAgent agent, String path) {
+        public TriggerAgentEventListener(ReplicationRequestHandler agent, 
String path) {
             this.agent = agent;
             this.path = path;
         }
@@ -134,11 +131,7 @@ public class ChainReplicateReplicationRu
                         log.info("triggering chain replication from event {}", 
event);
 
                         ReplicationActionType action = 
ReplicationActionType.valueOf(String.valueOf(actionProperty));
-                        try {
-                            agent.execute(new 
ReplicationRequest(System.currentTimeMillis(), action, paths));
-                        } catch (AgentReplicationException e) {
-                            log.error("triggered replication resulted in an 
error {}", e);
-                        }
+                        agent.execute(new 
ReplicationRequest(System.currentTimeMillis(), action, paths));
                         break;
                     }
                 }

Modified: 
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/DefaultReplicationRuleEngine.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/DefaultReplicationRuleEngine.java?rev=1620322&r1=1620321&r2=1620322&view=diff
==============================================================================
--- 
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/DefaultReplicationRuleEngine.java
 (original)
+++ 
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/DefaultReplicationRuleEngine.java
 Mon Aug 25 13:19:09 2014
@@ -28,7 +28,11 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.ReferencePolicy;
 import org.apache.felix.scr.annotations.References;
 import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.replication.agent.AgentReplicationException;
 import org.apache.sling.replication.agent.ReplicationAgent;
+import org.apache.sling.replication.communication.ReplicationRequest;
+import org.apache.sling.replication.communication.ReplicationResponse;
+import org.apache.sling.replication.rule.ReplicationRequestHandler;
 import org.apache.sling.replication.rule.ReplicationRule;
 import org.apache.sling.replication.rule.ReplicationRuleEngine;
 import org.slf4j.Logger;
@@ -79,10 +83,9 @@ public class DefaultReplicationRuleEngin
 
             for (ReplicationRule rule : replicationRules) {
                 if (rule.signatureMatches(ruleString)) {
-                    if (log.isInfoEnabled()) {
-                        log.info("applying rule {} with string {} to agent 
{}", new Object[]{rule, ruleString, agent});
-                    }
-                    rule.apply(ruleString, agent);
+                    log.info("applying rule {} with string {} to agent {}", 
new Object[]{rule, ruleString, agent});
+
+                    rule.apply(agent.getName()+ruleString, 
handlerForAgent(agent), ruleString);
                     break;
                 }
             }
@@ -95,10 +98,9 @@ public class DefaultReplicationRuleEngin
 
             for (ReplicationRule rule : replicationRules) {
                 if (rule.signatureMatches(ruleString)) {
-                    if (log.isInfoEnabled()) {
-                        log.info("un-applying rule {} with string {} to agent 
{}", new Object[]{rule, ruleString, agent});
-                    }
-                    rule.undo(ruleString, agent);
+                    log.info("un-applying rule {} with string {} to agent {}", 
new Object[]{rule, ruleString, agent});
+
+                    rule.undo(agent.getName() + ruleString);
                     break;
                 }
             }
@@ -106,4 +108,28 @@ public class DefaultReplicationRuleEngin
         }
     }
 
+
+    public class AgentBasedRequestHandler implements ReplicationRequestHandler 
{
+        private final ReplicationAgent agent;
+
+        public AgentBasedRequestHandler(ReplicationAgent agent) {
+
+            this.agent = agent;
+        }
+
+        public void execute(ReplicationRequest request) {
+            try {
+                agent.execute(request);
+            }
+            catch (AgentReplicationException e) {
+                log.error("Error executing handler", e);
+            }
+        }
+    }
+
+
+    ReplicationRequestHandler handlerForAgent(ReplicationAgent agent) {
+        return new AgentBasedRequestHandler(agent);
+    }
+
 }

Modified: 
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ReplicateOnQueueEventRule.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ReplicateOnQueueEventRule.java?rev=1620322&r1=1620321&r2=1620322&view=diff
==============================================================================
--- 
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ReplicateOnQueueEventRule.java
 (original)
+++ 
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ReplicateOnQueueEventRule.java
 Mon Aug 25 13:19:09 2014
@@ -20,16 +20,15 @@ package org.apache.sling.replication.rul
 
 import java.io.IOException;
 import java.net.URI;
+import java.nio.ByteBuffer;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.Future;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.Service;
+import org.apache.felix.scr.annotations.*;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpResponse;
 import org.apache.http.auth.AuthScope;
@@ -44,6 +43,7 @@ import org.apache.http.nio.ContentDecode
 import org.apache.http.nio.IOControl;
 import org.apache.http.nio.protocol.BasicAsyncRequestProducer;
 import org.apache.http.nio.protocol.BasicAsyncResponseConsumer;
+import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.apache.sling.commons.scheduler.ScheduleOptions;
 import org.apache.sling.commons.scheduler.Scheduler;
 import org.apache.sling.replication.agent.AgentReplicationException;
@@ -51,8 +51,10 @@ import org.apache.sling.replication.agen
 import org.apache.sling.replication.communication.ReplicationActionType;
 import org.apache.sling.replication.communication.ReplicationRequest;
 import org.apache.sling.replication.resources.ReplicationConstants;
+import org.apache.sling.replication.rule.ReplicationRequestHandler;
 import org.apache.sling.replication.rule.ReplicationRule;
 import org.apache.sling.replication.transport.ReplicationTransportHandler;
+import 
org.apache.sling.replication.transport.impl.ReplicationTransportConstants;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.slf4j.Logger;
@@ -66,11 +68,14 @@ import org.slf4j.LoggerFactory;
 @Service(value = ReplicationRule.class)
 public class ReplicateOnQueueEventRule implements ReplicationRule {
 
+    @Property(label = "Name", value = "remote", propertyPrivate = true)
+    private static final String NAME = "name";
+
     private final Logger log = LoggerFactory.getLogger(getClass());
 
-    private static final String SIGNATURE = "queue event based {action} [on 
${path}]";
+    private static final String SIGNATURE = "remote trigger on {path} with 
user {user} and password {password}";
 
-    private static final String SIGNATURE_REGEX = 
"(queue\\sevent\\sbased)\\s(add|delete|poll)(\\s(on)\\s(\\/\\w+)+)?";
+    private static final String SIGNATURE_REGEX = 
"remote\\strigger\\son\\s([^\\s]+)\\swith\\suser\\s([^\\s]+)\\sand\\spassword\\s([^\\s]+)";
 
     private static final Pattern signaturePattern = 
Pattern.compile(SIGNATURE_REGEX);
 
@@ -82,7 +87,7 @@ public class ReplicateOnQueueEventRule i
     private Map<String, Future<HttpResponse>> requests;
 
     @Activate
-    protected void activate(BundleContext context) {
+    protected void activate(BundleContext context, Map<String, ?> config) {
         this.context = context;
         this.requests = new ConcurrentHashMap<String, Future<HttpResponse>>();
     }
@@ -95,18 +100,21 @@ public class ReplicateOnQueueEventRule i
         return ruleString.matches(SIGNATURE_REGEX);
     }
 
-    public void apply(String ruleString, ReplicationAgent agent) {
+    public void apply(String handleId, ReplicationRequestHandler agent, String 
ruleString) {
         Matcher matcher = signaturePattern.matcher(ruleString);
         if (matcher.find()) {
-            String action = matcher.group(2);
-            ReplicationActionType actionType = 
ReplicationActionType.fromName(action.toUpperCase());
-            String path = matcher.group(5); // can be null
+            String remotePath = matcher.group(1);
+            String user = matcher.group(2);
+            String password = matcher.group(3);
+
+
+
             try {
                 log.info("applying queue event replication rule");
 
                 ScheduleOptions options = scheduler.NOW();
-                options.name(agent.getName() + " " + ruleString);
-                scheduler.schedule(new EventBasedReplication(agent, 
actionType, path, null), options);
+                options.name(handleId);
+                scheduler.schedule(new EventBasedReplication(handleId, agent, 
remotePath, user, password), options);
 
             } catch (Exception e) {
                 log.error("{}", e);
@@ -116,8 +124,8 @@ public class ReplicateOnQueueEventRule i
         }
     }
 
-    public void undo(String ruleString, ReplicationAgent agent) {
-        Future<HttpResponse> httpResponseFuture = 
requests.remove(agent.getName());
+    public void undo(String handleId) {
+        Future<HttpResponse> httpResponseFuture = requests.remove(handleId);
         if (httpResponseFuture != null) {
             httpResponseFuture.cancel(true);
         }
@@ -125,30 +133,30 @@ public class ReplicateOnQueueEventRule i
 
     private class SSEResponseConsumer extends BasicAsyncResponseConsumer {
 
-        private final ReplicationAgent agent;
-        private final ReplicationActionType action;
-        private final String path;
+        private final String handleId;
+        private final ReplicationRequestHandler agent;
+
 
-        private SSEResponseConsumer(ReplicationAgent agent, 
ReplicationActionType action, String path) {
+        private SSEResponseConsumer(String handleId, ReplicationRequestHandler 
agent) {
+            this.handleId = handleId;
             this.agent = agent;
-            this.action = action;
-            this.path = path == null ? "/" : path;
+
         }
 
         @Override
         protected void onContentReceived(ContentDecoder decoder, IOControl 
ioctrl) throws IOException {
-//            log.info("complete ? ", decoder.isCompleted());
-//            ByteBuffer buffer = ByteBuffer.allocate(1024);
-//            decoder.read(buffer);
-//            log.info("content {} received {},{}", new Object[]{buffer, 
decoder, ioctrl});
+            log.info("complete ? ", decoder.isCompleted());
+            ByteBuffer buffer = ByteBuffer.allocate(1024);
+            decoder.read(buffer);
+            log.info("content {} received {},{}", new Object[]{buffer, 
decoder, ioctrl});
             log.info("event received");
 
-            try {
-                asyncReplicate(agent, action, path);
-                log.info("replication request to agent {} sent ({} on {})", 
new Object[]{agent.getName(), action, path});
-            } catch (AgentReplicationException e) {
-                log.error("cannot replicate to agent {}, {}", agent.getName(), 
e);
-            }
+            ReplicationRequest replicationRequest = new 
ReplicationRequest(System.currentTimeMillis(), ReplicationActionType.POLL, 
null);
+            agent.execute(replicationRequest);
+            log.info("replication request to agent {} sent ({} on {})", new 
Object[]{
+                    handleId,
+                    replicationRequest.getAction(),
+                    replicationRequest.getPaths()});
 
             super.onContentReceived(decoder, ioctrl);
         }
@@ -160,74 +168,55 @@ public class ReplicateOnQueueEventRule i
         }
     }
 
-    private void asyncReplicate(ReplicationAgent agent, ReplicationActionType 
action, String path) throws AgentReplicationException {
-        agent.execute(new ReplicationRequest(System.currentTimeMillis(), 
action, path));
-    }
+
 
     private class EventBasedReplication implements Runnable {
-        private final ReplicationAgent agent;
-        private final ReplicationActionType actionType;
+        private final String handleId;
+        private final ReplicationRequestHandler agent;
         private final String targetTransport;
-        private final String path;
+        private final String userName;
+        private final String password;
 
-        public EventBasedReplication(ReplicationAgent agent, 
ReplicationActionType actionType, String path, String targetTransport) {
+        public EventBasedReplication(String handleId, 
ReplicationRequestHandler agent, String targetTransport, String userName, 
String password) {
+            this.handleId = handleId;
             this.agent = agent;
-            this.actionType = actionType;
             this.targetTransport = targetTransport;
-            this.path = path;
+            this.userName = userName;
+            this.password = password;
         }
 
         public void run() {
             try {
-                ServiceReference[] serviceReferences = 
context.getServiceReferences(ReplicationTransportHandler.class.getName(), 
targetTransport);
 
-                log.info("reference transport for {} found {}", 
targetTransport, serviceReferences != null);
 
-                if (serviceReferences != null && serviceReferences.length == 
1) {
+                log.info("getting event from {}", targetTransport + 
"?sec=600");
+
+                URI eventEndpoint = URI.create(targetTransport);
 
-                    Object endpointsProperty = 
serviceReferences[0].getProperty("endpoints");
-                    Object authenticationPropertiesProperty = 
serviceReferences[0].getProperty("authentication.properties");
 
-                    log.info("endpoint prop: {} authentication properties 
prop: {}", endpointsProperty, authenticationPropertiesProperty);
-
-                    String[] endpoints = (String[]) endpointsProperty;
-                    Map<String, String> authenticationProperties = 
(Map<String, String>) authenticationPropertiesProperty;
-
-                    log.info("endpoint {} props {}", endpoints, 
authenticationProperties);
-                    // only works with HTTP
-                    if (endpoints.length == 1 && 
endpoints[0].startsWith("http") && authenticationProperties != null) {
-                        log.info("getting event queue URI");
-                        URI eventEndpoint = URI.create(endpoints[0] + 
ReplicationConstants.SUFFIX_AGENT_QUEUE_EVENT);
-                        String userName = authenticationProperties.get("user");
-                        String password = 
authenticationProperties.get("password");
-
-                        log.info("preparing request");
-                        CredentialsProvider credentialsProvider = new 
BasicCredentialsProvider();
-                        credentialsProvider.setCredentials(
-                                new AuthScope(eventEndpoint.getHost(), 
eventEndpoint.getPort()),
-                                new UsernamePasswordCredentials(userName, 
password));
-                        CloseableHttpAsyncClient httpClient = 
HttpAsyncClients.custom()
-                                
.setDefaultCredentialsProvider(credentialsProvider)
-                                .build();
-                        try {
-                            HttpGet get = new HttpGet(eventEndpoint);
-                            HttpHost target = 
URIUtils.extractHost(get.getURI());
-                            BasicAsyncRequestProducer 
basicAsyncRequestProducer = new BasicAsyncRequestProducer(target, get);
-                            httpClient.start();
-                            log.info("sending request");
-                            Future<HttpResponse> futureResponse = 
httpClient.execute(
-                                    basicAsyncRequestProducer,
-                                    new SSEResponseConsumer(agent, actionType, 
path), null);
-                            requests.put(agent.getName(), futureResponse);
-                            futureResponse.get();
-                        } finally {
-                            httpClient.close();
-                        }
-                        log.info("request finished");
-                    }
+                log.info("preparing request");
+                CredentialsProvider credentialsProvider = new 
BasicCredentialsProvider();
+                credentialsProvider.setCredentials(
+                        new AuthScope(eventEndpoint.getHost(), 
eventEndpoint.getPort()),
+                        new UsernamePasswordCredentials(userName, password));
+                CloseableHttpAsyncClient httpClient = HttpAsyncClients.custom()
+                        .setDefaultCredentialsProvider(credentialsProvider)
+                        .build();
+                try {
+                    HttpGet get = new HttpGet(eventEndpoint);
+                    HttpHost target = URIUtils.extractHost(get.getURI());
+                    BasicAsyncRequestProducer basicAsyncRequestProducer = new 
BasicAsyncRequestProducer(target, get);
+                    httpClient.start();
+                    log.info("sending request");
+                    Future<HttpResponse> futureResponse = httpClient.execute(
+                            basicAsyncRequestProducer,
+                            new SSEResponseConsumer(handleId, agent), null);
+                    requests.put(handleId, futureResponse);
+                    futureResponse.get();
+                } finally {
+                    httpClient.close();
                 }
-            } catch (RuntimeException e) {
-                throw e;
+                log.info("request finished");
             } catch (Exception e) {
                 log.error("cannot execute event based replication");
             }

Modified: 
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ScheduleReplicateReplicationRule.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ScheduleReplicateReplicationRule.java?rev=1620322&r1=1620321&r2=1620322&view=diff
==============================================================================
--- 
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ScheduleReplicateReplicationRule.java
 (original)
+++ 
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/ScheduleReplicateReplicationRule.java
 Mon Aug 25 13:19:09 2014
@@ -21,6 +21,7 @@ package org.apache.sling.replication.rul
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 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.sling.commons.scheduler.ScheduleOptions;
@@ -29,6 +30,7 @@ import org.apache.sling.replication.agen
 import org.apache.sling.replication.agent.ReplicationAgent;
 import org.apache.sling.replication.communication.ReplicationActionType;
 import org.apache.sling.replication.communication.ReplicationRequest;
+import org.apache.sling.replication.rule.ReplicationRequestHandler;
 import org.apache.sling.replication.rule.ReplicationRule;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -47,6 +49,9 @@ public class ScheduleReplicateReplicatio
 
     private final Logger log = LoggerFactory.getLogger(getClass());
 
+    @Property(label = "Name", value = "schedule", propertyPrivate = true)
+    private static final String NAME = "name";
+
     @Reference
     private Scheduler scheduler;
 
@@ -58,7 +63,7 @@ public class ScheduleReplicateReplicatio
         return ruleString.matches(SIGNATURE_REGEX);
     }
 
-    public void apply(String ruleString, ReplicationAgent agent) {
+    public void apply(String handleId, ReplicationRequestHandler agent, String 
ruleString) {
         if (signatureMatches(ruleString)) {
             Matcher matcher = signaturePattern.matcher(ruleString);
             if (matcher.find()) {
@@ -67,38 +72,31 @@ public class ScheduleReplicateReplicatio
                 String path = matcher.group(5); // can be null
                 int seconds = Integer.parseInt(matcher.group(7));
                 ScheduleOptions options = scheduler.NOW(-1, seconds);
-                options.name(agent.getName() + " " + ruleString);
+                options.name(handleId);
                 scheduler.schedule(new ScheduledReplication(agent, actionType, 
path), options);
             }
         }
     }
 
-    public void undo(String ruleString, ReplicationAgent agent) {
-        if (signatureMatches(ruleString)) {
-            scheduler.unschedule(agent.getName() + " " + ruleString);
-        }
+    public void undo(String handleId) {
+        scheduler.unschedule(handleId);
     }
 
     private class ScheduledReplication implements Runnable {
-        private final ReplicationAgent agent;
+        private final ReplicationRequestHandler agent;
         private final ReplicationActionType action;
         private final String path;
 
-        public ScheduledReplication(ReplicationAgent agent, 
ReplicationActionType action, String path) {
+        public ScheduledReplication(ReplicationRequestHandler agent, 
ReplicationActionType action, String path) {
             this.agent = agent;
             this.action = action;
             this.path = path != null ? path : "/";
         }
 
         public void run() {
-            try {
-                log.debug("agent {}: scheduling {} replication of {}", new 
Object[]{agent, action, path});
+            log.debug("agent {}: scheduling {} replication of {}", new 
Object[]{agent, action, path});
 
-                agent.execute(new 
ReplicationRequest(System.currentTimeMillis(), action, path));
-            } catch (AgentReplicationException e) {
-                log.error("failed scheduled replication {} on agent {} for 
path {}", new Object[]{
-                        action.name(), agent.getName(), path}, e);
-            }
+            agent.execute(new ReplicationRequest(System.currentTimeMillis(), 
action, path));
         }
     }
 }

Modified: 
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/TriggerPathReplicationRule.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/TriggerPathReplicationRule.java?rev=1620322&r1=1620321&r2=1620322&view=diff
==============================================================================
--- 
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/TriggerPathReplicationRule.java
 (original)
+++ 
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/rule/impl/TriggerPathReplicationRule.java
 Mon Aug 25 13:19:09 2014
@@ -31,6 +31,7 @@ import org.apache.sling.replication.agen
 import org.apache.sling.replication.agent.ReplicationAgent;
 import org.apache.sling.replication.communication.ReplicationActionType;
 import org.apache.sling.replication.communication.ReplicationRequest;
+import org.apache.sling.replication.rule.ReplicationRequestHandler;
 import org.apache.sling.replication.rule.ReplicationRule;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
@@ -47,7 +48,6 @@ import org.slf4j.LoggerFactory;
 @Service(value = ReplicationRule.class)
 public class TriggerPathReplicationRule implements ReplicationRule {
 
-    //    private static final Pattern p = Pattern.compile("(\\/\\w+)+\\/?");
     private static final String PREFIX = "trigger on path:";
     private static final String SIGNATURE = "trigger on path: ${path}";
 
@@ -75,19 +75,19 @@ public class TriggerPathReplicationRule 
         return SIGNATURE;
     }
 
-    public void apply(String ruleString, ReplicationAgent agent) {
+    public void apply(String handleId, ReplicationRequestHandler agent, String 
ruleString) {
         if (signatureMatches(ruleString)) {
             // register an event handler on path which triggers the agent on 
node / property changes / addition / removals
             Dictionary<String, Object> properties = new Hashtable<String, 
Object>();
             properties.put(EventConstants.EVENT_TOPIC, new 
String[]{SlingConstants.TOPIC_RESOURCE_ADDED,
                     SlingConstants.TOPIC_RESOURCE_CHANGED, 
SlingConstants.TOPIC_RESOURCE_REMOVED});
             String path = ruleString.substring(ruleString.indexOf(':') + 
1).trim();
-            log.info("trigger agent {} on path '{}'", agent.getName(), path);
+            log.info("trigger agent {} on path '{}'", handleId, path);
 
             properties.put(EventConstants.EVENT_FILTER, "(path=" + path + 
"/*)");
             if (bundleContext != null) {
                 ServiceRegistration triggerPathEventRegistration = 
bundleContext.registerService(EventHandler.class.getName(), new 
TriggerAgentEventListener(agent), properties);
-                registrations.put(agent.getName() + ruleString, 
triggerPathEventRegistration);
+                registrations.put(handleId, triggerPathEventRegistration);
             } else {
                 log.error("cannot register trigger since bundle context is 
null");
 
@@ -103,24 +103,19 @@ public class TriggerPathReplicationRule 
         return ruleString.startsWith(PREFIX) && 
ruleString.substring(PREFIX.length() + 1).matches("\\s*(\\/\\w+)+");
     }
 
-    public void undo(String ruleString, ReplicationAgent agent) {
-        if (signatureMatches(ruleString)) {
-            ServiceRegistration serviceRegistration = 
registrations.get(agent.getName() + ruleString);
-            if (serviceRegistration != null) {
-                serviceRegistration.unregister();
-            }
-        } else {
-            log.warn("rule {} doesn't match signature: {}", ruleString, 
SIGNATURE);
-
+    public void undo(String handleId) {
+        ServiceRegistration serviceRegistration = registrations.get(handleId);
+        if (serviceRegistration != null) {
+            serviceRegistration.unregister();
         }
     }
 
 
     private class TriggerAgentEventListener implements EventHandler {
 
-        private final ReplicationAgent agent;
+        private final ReplicationRequestHandler agent;
 
-        public TriggerAgentEventListener(ReplicationAgent agent) {
+        public TriggerAgentEventListener(ReplicationRequestHandler agent) {
             this.agent = agent;
         }
 
@@ -131,11 +126,7 @@ public class TriggerPathReplicationRule 
             Object eventProperty = event.getProperty("path");
             if (eventProperty != null) {
                 String replicatingPath = String.valueOf(eventProperty);
-                try {
-                    agent.execute(new 
ReplicationRequest(System.currentTimeMillis(), action, replicatingPath));
-                } catch (AgentReplicationException e) {
-                    log.error("triggered replication resulted in an error", e);
-                }
+                agent.execute(new 
ReplicationRequest(System.currentTimeMillis(), action, replicatingPath));
             }
         }
     }

Modified: 
sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/rule/impl/ChainReplicateReplicationRuleTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/rule/impl/ChainReplicateReplicationRuleTest.java?rev=1620322&r1=1620321&r2=1620322&view=diff
==============================================================================
--- 
sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/rule/impl/ChainReplicateReplicationRuleTest.java
 (original)
+++ 
sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/rule/impl/ChainReplicateReplicationRuleTest.java
 Mon Aug 25 13:19:09 2014
@@ -19,6 +19,7 @@
 package org.apache.sling.replication.rule.impl;
 
 import org.apache.sling.replication.agent.ReplicationAgent;
+import org.apache.sling.replication.rule.ReplicationRequestHandler;
 import org.junit.Test;
 import org.osgi.framework.BundleContext;
 
@@ -52,71 +53,58 @@ public class ChainReplicateReplicationRu
     public void testApplyWithNonMatchingString() throws Exception {
         ChainReplicateReplicationRule chainPathReplicationRule = new 
ChainReplicateReplicationRule();
         String ruleString = "";
-        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
-        chainPathReplicationRule.apply(ruleString, replicationAgent);
+        ReplicationRequestHandler requestHandler = 
mock(ReplicationRequestHandler.class);
+        chainPathReplicationRule.apply("", requestHandler, ruleString);
     }
 
     @Test
     public void testApplyWithMatchingString() throws Exception {
         ChainReplicateReplicationRule chainPathReplicationRule = new 
ChainReplicateReplicationRule();
         String ruleString = "chain on path: /foo/bar";
-        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
-        chainPathReplicationRule.apply(ruleString, replicationAgent);
+        ReplicationRequestHandler requestHandler = 
mock(ReplicationRequestHandler.class);
+        chainPathReplicationRule.apply("", requestHandler, ruleString);
     }
 
     @Test
     public void testApplyWithMatchingStringAndRegisteredContext() throws 
Exception {
         ChainReplicateReplicationRule chainPathReplicationRule = new 
ChainReplicateReplicationRule();
         String ruleString = "chain on path: /foo/bar";
-        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
+        ReplicationRequestHandler requestHandler = 
mock(ReplicationRequestHandler.class);
         BundleContext context = mock(BundleContext.class);
         chainPathReplicationRule.activate(context);
-        chainPathReplicationRule.apply(ruleString, replicationAgent);
+        chainPathReplicationRule.apply("", requestHandler, ruleString);
     }
 
     @Test
     public void testApplyWithNonMatchingStringAndRegisteredContext() throws 
Exception {
         ChainReplicateReplicationRule chainPathReplicationRule = new 
ChainReplicateReplicationRule();
         String ruleString = "chain on path: 1 2 3";
-        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
+        ReplicationRequestHandler requestHandler = 
mock(ReplicationRequestHandler.class);
         BundleContext context = mock(BundleContext.class);
         chainPathReplicationRule.activate(context);
-        chainPathReplicationRule.apply(ruleString, replicationAgent);
+        chainPathReplicationRule.apply("", requestHandler, ruleString);
     }
 
     @Test
     public void testUndoWithNonMatchingString() throws Exception {
         ChainReplicateReplicationRule chainPathReplicationRule = new 
ChainReplicateReplicationRule();
         String ruleString = "";
-        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
-        chainPathReplicationRule.undo(ruleString, replicationAgent);
+        ReplicationRequestHandler requestHandler = 
mock(ReplicationRequestHandler.class);
+        chainPathReplicationRule.apply("", requestHandler, ruleString);
     }
 
     @Test
     public void testUndoWithMatchingString() throws Exception {
         ChainReplicateReplicationRule chainPathReplicationRule = new 
ChainReplicateReplicationRule();
-        String ruleString = "chain on path: /foo/bar";
-        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
-        chainPathReplicationRule.undo(ruleString, replicationAgent);
+        chainPathReplicationRule.undo("");
     }
 
     @Test
     public void testUndoWithMatchingStringAndRegisteredContext() throws 
Exception {
         ChainReplicateReplicationRule chainPathReplicationRule = new 
ChainReplicateReplicationRule();
-        String ruleString = "chain on path: /foo/bar";
-        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
         BundleContext context = mock(BundleContext.class);
         chainPathReplicationRule.activate(context);
-        chainPathReplicationRule.undo(ruleString, replicationAgent);
+        chainPathReplicationRule.undo("");
     }
 
-    @Test
-    public void testUndoWithNonMatchingStringAndRegisteredContext() throws 
Exception {
-        ChainReplicateReplicationRule chainPathReplicationRule = new 
ChainReplicateReplicationRule();
-        String ruleString = "chain on path: 1 2 3";
-        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
-        BundleContext context = mock(BundleContext.class);
-        chainPathReplicationRule.activate(context);
-        chainPathReplicationRule.undo(ruleString, replicationAgent);
-    }
 }

Modified: 
sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/rule/impl/ScheduleReplicateReplicationRuleTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/rule/impl/ScheduleReplicateReplicationRuleTest.java?rev=1620322&r1=1620321&r2=1620322&view=diff
==============================================================================
--- 
sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/rule/impl/ScheduleReplicateReplicationRuleTest.java
 (original)
+++ 
sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/rule/impl/ScheduleReplicateReplicationRuleTest.java
 Mon Aug 25 13:19:09 2014
@@ -22,6 +22,7 @@ import java.lang.reflect.Field;
 import org.apache.sling.commons.scheduler.ScheduleOptions;
 import org.apache.sling.commons.scheduler.Scheduler;
 import org.apache.sling.replication.agent.ReplicationAgent;
+import org.apache.sling.replication.rule.ReplicationRequestHandler;
 import org.junit.Test;
 
 import static org.junit.Assert.assertFalse;
@@ -56,8 +57,8 @@ public class ScheduleReplicateReplicatio
     public void testApplyWithNonMatchingString() throws Exception {
         ScheduleReplicateReplicationRule scheduleReplicateReplicationRule = 
new ScheduleReplicateReplicationRule();
         String ruleString = "";
-        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
-        scheduleReplicateReplicationRule.apply(ruleString, replicationAgent);
+        ReplicationRequestHandler requestHandler = 
mock(ReplicationRequestHandler.class);
+        scheduleReplicateReplicationRule.apply("", requestHandler, ruleString);
     }
 
     @Test
@@ -71,8 +72,8 @@ public class ScheduleReplicateReplicatio
         schedulerField.set(scheduleReplicateReplicationRule, scheduler);
 
         String ruleString = "scheduled add on /system every 12 sec";
-        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
-        scheduleReplicateReplicationRule.apply(ruleString, replicationAgent);
+        ReplicationRequestHandler requestHandler = 
mock(ReplicationRequestHandler.class);
+        scheduleReplicateReplicationRule.apply("", requestHandler, ruleString);
     }
 
     @Test
@@ -86,8 +87,8 @@ public class ScheduleReplicateReplicatio
         schedulerField.set(scheduleReplicateReplicationRule, scheduler);
 
         String ruleString = "scheduled add on /system every 12 sec";
-        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
-        scheduleReplicateReplicationRule.apply(ruleString, replicationAgent);
+        ReplicationRequestHandler requestHandler = 
mock(ReplicationRequestHandler.class);
+        scheduleReplicateReplicationRule.apply("", requestHandler, ruleString);
     }
 
     @Test
@@ -101,25 +102,12 @@ public class ScheduleReplicateReplicatio
         schedulerField.set(scheduleReplicateReplicationRule, scheduler);
 
         String ruleString = "scheduled add on /system every 12 sec";
-        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
-        scheduleReplicateReplicationRule.apply(ruleString, replicationAgent);
-    }
+        ReplicationRequestHandler requestHandler = 
mock(ReplicationRequestHandler.class);
+        scheduleReplicateReplicationRule.apply("", requestHandler, ruleString);
 
-    @Test
-    public void testUndoWithNonMatchingString() throws Exception {
-        ScheduleReplicateReplicationRule scheduleReplicateReplicationRule = 
new ScheduleReplicateReplicationRule();
-        Field schedulerField = 
scheduleReplicateReplicationRule.getClass().getDeclaredField("scheduler");
-        schedulerField.setAccessible(true);
-        Scheduler scheduler = mock(Scheduler.class);
-        ScheduleOptions options = mock(ScheduleOptions.class);
-        when(scheduler.NOW(any(Integer.class), 
any(Integer.class))).thenReturn(options);
-        schedulerField.set(scheduleReplicateReplicationRule, scheduler);
-
-        String ruleString = "";
-        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
-        scheduleReplicateReplicationRule.undo(ruleString, replicationAgent);
     }
 
+
     @Test
     public void testUndoWithMatchingString() throws Exception {
         ScheduleReplicateReplicationRule scheduleReplicateReplicationRule = 
new ScheduleReplicateReplicationRule();
@@ -130,9 +118,7 @@ public class ScheduleReplicateReplicatio
         when(scheduler.NOW(any(Integer.class), 
any(Integer.class))).thenReturn(options);
         schedulerField.set(scheduleReplicateReplicationRule, scheduler);
 
-        String ruleString = "scheduled add on /system every 12 sec";
-        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
-        scheduleReplicateReplicationRule.undo(ruleString, replicationAgent);
+        scheduleReplicateReplicationRule.undo("");
     }
 
     @Test
@@ -145,23 +131,7 @@ public class ScheduleReplicateReplicatio
         when(scheduler.NOW(any(Integer.class), 
any(Integer.class))).thenReturn(options);
         schedulerField.set(scheduleReplicateReplicationRule, scheduler);
 
-        String ruleString = "scheduled add on /system every 12 sec";
-        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
-        scheduleReplicateReplicationRule.undo(ruleString, replicationAgent);
+        scheduleReplicateReplicationRule.undo("");
     }
 
-    @Test
-    public void testUndoWithNonMatchingStringAndRegisteredContext() throws 
Exception {
-        ScheduleReplicateReplicationRule scheduleReplicateReplicationRule = 
new ScheduleReplicateReplicationRule();
-        Field schedulerField = 
scheduleReplicateReplicationRule.getClass().getDeclaredField("scheduler");
-        schedulerField.setAccessible(true);
-        Scheduler scheduler = mock(Scheduler.class);
-        ScheduleOptions options = mock(ScheduleOptions.class);
-        when(scheduler.NOW(any(Integer.class), 
any(Integer.class))).thenReturn(options);
-        schedulerField.set(scheduleReplicateReplicationRule, scheduler);
-
-        String ruleString = "scheduled add on /system every 12 sec";
-        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
-        scheduleReplicateReplicationRule.undo(ruleString, replicationAgent);
-    }
 }

Modified: 
sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/rule/impl/TriggerPathReplicationRuleTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/rule/impl/TriggerPathReplicationRuleTest.java?rev=1620322&r1=1620321&r2=1620322&view=diff
==============================================================================
--- 
sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/rule/impl/TriggerPathReplicationRuleTest.java
 (original)
+++ 
sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/rule/impl/TriggerPathReplicationRuleTest.java
 Mon Aug 25 13:19:09 2014
@@ -19,6 +19,7 @@
 package org.apache.sling.replication.rule.impl;
 
 import org.apache.sling.replication.agent.ReplicationAgent;
+import org.apache.sling.replication.rule.ReplicationRequestHandler;
 import org.junit.Test;
 import org.osgi.framework.BundleContext;
 
@@ -52,71 +53,50 @@ public class TriggerPathReplicationRuleT
     public void testApplyWithNonMatchingString() throws Exception {
         TriggerPathReplicationRule triggerPathReplicationRule = new 
TriggerPathReplicationRule();
         String ruleString = "";
-        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
-        triggerPathReplicationRule.apply(ruleString, replicationAgent);
+        ReplicationRequestHandler requestHandler = 
mock(ReplicationRequestHandler.class);
+        triggerPathReplicationRule.apply("", requestHandler, ruleString);
     }
 
     @Test
     public void testApplyWithMatchingString() throws Exception {
         TriggerPathReplicationRule triggerPathReplicationRule = new 
TriggerPathReplicationRule();
         String ruleString = "trigger on path: /foo/bar";
-        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
-        triggerPathReplicationRule.apply(ruleString, replicationAgent);
+        ReplicationRequestHandler requestHandler = 
mock(ReplicationRequestHandler.class);
+        triggerPathReplicationRule.apply("", requestHandler, ruleString);
     }
 
     @Test
     public void testApplyWithMatchingStringAndRegisteredContext() throws 
Exception {
         TriggerPathReplicationRule triggerPathReplicationRule = new 
TriggerPathReplicationRule();
         String ruleString = "trigger on path: /foo/bar";
-        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
+        ReplicationRequestHandler requestHandler = 
mock(ReplicationRequestHandler.class);
         BundleContext context = mock(BundleContext.class);
         triggerPathReplicationRule.activate(context);
-        triggerPathReplicationRule.apply(ruleString, replicationAgent);
+        triggerPathReplicationRule.apply("", requestHandler, ruleString);
     }
 
     @Test
     public void testApplyWithNonMatchingStringAndRegisteredContext() throws 
Exception {
         TriggerPathReplicationRule triggerPathReplicationRule = new 
TriggerPathReplicationRule();
         String ruleString = "trigger on path: 1 2 3";
-        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
+        ReplicationRequestHandler requestHandler = 
mock(ReplicationRequestHandler.class);
         BundleContext context = mock(BundleContext.class);
         triggerPathReplicationRule.activate(context);
-        triggerPathReplicationRule.apply(ruleString, replicationAgent);
-    }
-
-    @Test
-    public void testUndoWithNonMatchingString() throws Exception {
-        TriggerPathReplicationRule triggerPathReplicationRule = new 
TriggerPathReplicationRule();
-        String ruleString = "";
-        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
-        triggerPathReplicationRule.undo(ruleString, replicationAgent);
+        triggerPathReplicationRule.apply("", requestHandler, ruleString);
     }
 
     @Test
     public void testUndoWithMatchingString() throws Exception {
         TriggerPathReplicationRule triggerPathReplicationRule = new 
TriggerPathReplicationRule();
-        String ruleString = "trigger on path: /foo/bar";
-        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
-        triggerPathReplicationRule.undo(ruleString, replicationAgent);
+        triggerPathReplicationRule.undo("");
     }
 
     @Test
     public void testUndoWithMatchingStringAndRegisteredContext() throws 
Exception {
         TriggerPathReplicationRule triggerPathReplicationRule = new 
TriggerPathReplicationRule();
-        String ruleString = "trigger on path: /foo/bar";
-        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
         BundleContext context = mock(BundleContext.class);
         triggerPathReplicationRule.activate(context);
-        triggerPathReplicationRule.undo(ruleString, replicationAgent);
+        triggerPathReplicationRule.undo("");
     }
 
-    @Test
-    public void testUndoWithNonMatchingStringAndRegisteredContext() throws 
Exception {
-        TriggerPathReplicationRule triggerPathReplicationRule = new 
TriggerPathReplicationRule();
-        String ruleString = "trigger on path: 1 2 3";
-        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
-        BundleContext context = mock(BundleContext.class);
-        triggerPathReplicationRule.activate(context);
-        triggerPathReplicationRule.undo(ruleString, replicationAgent);
-    }
 }

Modified: 
sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationUtils.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationUtils.java?rev=1620322&r1=1620321&r2=1620322&view=diff
==============================================================================
--- 
sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationUtils.java
 (original)
+++ 
sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationUtils.java
 Mon Aug 25 13:19:09 2014
@@ -59,11 +59,10 @@ public class ReplicationUtils {
             UrlEncodedFormEntity entity = new 
UrlEncodedFormEntity(valuePairList);
             request.withEntity(entity);
         }
-        String content = slingInstance.getRequestExecutor().execute(
+
+        return slingInstance.getRequestExecutor().execute(
                 request.withCredentials(slingInstance.getServerUsername(), 
slingInstance.getServerPassword())
         ).assertStatus(status).getContent();
-
-        return content;
     }
 
     private static String assertPostResource(SlingInstance slingInstance,


Reply via email to