Index: engine/src/main/java/org/camunda/bpm/engine/impl/bpmn/behavior/IntermediateThrowSignalEventActivityBehavior.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- engine/src/main/java/org/camunda/bpm/engine/impl/bpmn/behavior/IntermediateThrowSignalEventActivityBehavior.java	(revision 0e940143b3de58b85bf038a8eb5f3c337b8a2d6e)
+++ engine/src/main/java/org/camunda/bpm/engine/impl/bpmn/behavior/IntermediateThrowSignalEventActivityBehavior.java	(revision 686fb92a5e74ab8081b5ab2b7554ad76d83d9daa)
@@ -13,10 +13,13 @@
 
 package org.camunda.bpm.engine.impl.bpmn.behavior;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.camunda.bpm.engine.impl.ProcessEngineLogger;
 import org.camunda.bpm.engine.impl.bpmn.parser.EventSubscriptionDeclaration;
+import org.camunda.bpm.engine.impl.bpmn.parser.FoxFailedJobParseListener;
 import org.camunda.bpm.engine.impl.context.Context;
 import org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionManager;
 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity;
@@ -45,11 +48,23 @@
 
     for (SignalEventSubscriptionEntity signalEventSubscription : signalEventSubscriptions) {
       if(isActiveEventSubscription(signalEventSubscription)){
-        signalEventSubscription.eventReceived(null, signalDefinition.isAsync());
+        signalEventSubscription.eventReceived(composePayload(execution), signalDefinition.isAsync());
       }
     }
 
     leave(execution);
+  }
+
+  protected Object composePayload(ActivityExecution execution) {
+    Map<String, Object> result = new HashMap<String,Object>();
+    String value = execution.getActivity().getProperties().get(FoxFailedJobParseListener.FOX_FAILED_JOB_CONFIGURATION);
+    result.put(FoxFailedJobParseListener.FOX_FAILED_JOB_CONFIGURATION.getName(),value);
+    result.put("execution",execution.getId());
+    result.put("activity",execution.getActivity().getId());
+    result.put("processDefinition",execution.getProcessDefinitionId());
+    result.put("processBusinessKey",execution.getProcessBusinessKey());
+    result.put("processInstance",execution.getProcessInstanceId());
+    return result;
   }
 
   protected List<SignalEventSubscriptionEntity> findSignalEventSubscriptions(String signalName, String tenantId) {
Index: engine/src/main/java/org/camunda/bpm/engine/impl/cmd/FoxJobRetryCmd.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- engine/src/main/java/org/camunda/bpm/engine/impl/cmd/FoxJobRetryCmd.java	(revision 0e940143b3de58b85bf038a8eb5f3c337b8a2d6e)
+++ engine/src/main/java/org/camunda/bpm/engine/impl/cmd/FoxJobRetryCmd.java	(revision 686fb92a5e74ab8081b5ab2b7554ad76d83d9daa)
@@ -17,17 +17,15 @@
 import org.camunda.bpm.engine.impl.calendar.DurationHelper;
 import org.camunda.bpm.engine.impl.context.Context;
 import org.camunda.bpm.engine.impl.interceptor.CommandContext;
-import org.camunda.bpm.engine.impl.jobexecutor.AsyncContinuationJobHandler;
-import org.camunda.bpm.engine.impl.jobexecutor.JobExecutorLogger;
-import org.camunda.bpm.engine.impl.jobexecutor.TimerCatchIntermediateEventJobHandler;
+import org.camunda.bpm.engine.impl.jobexecutor.*;
 import org.camunda.bpm.engine.impl.jobexecutor.TimerEventJobHandler.TimerJobConfiguration;
-import org.camunda.bpm.engine.impl.jobexecutor.TimerExecuteNestedActivityJobHandler;
-import org.camunda.bpm.engine.impl.jobexecutor.TimerStartEventJobHandler;
 import org.camunda.bpm.engine.impl.persistence.deploy.DeploymentCache;
 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity;
 import org.camunda.bpm.engine.impl.persistence.entity.JobEntity;
+import org.camunda.bpm.engine.impl.persistence.entity.MessageEntity;
 import org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity;
 import org.camunda.bpm.engine.impl.pvm.process.ActivityImpl;
+import org.camunda.bpm.engine.impl.util.json.JSONObject;
 
 /**
  * @author Roman Smirnov
@@ -122,6 +120,14 @@
         activity = execution.getActivity();
       }
 
+    } else if (job instanceof MessageEntity) {
+
+      JSONObject eventPayload = new JSONObject(((MessageEntity)job).getEventPayload());
+      DeploymentCache deploymentCache = Context.getProcessEngineConfiguration().getDeploymentCache();
+      ProcessDefinitionEntity processDefinition = deploymentCache.getProcessDefinitionCache().get(eventPayload.getString("processDefinition"));
+      if(processDefinition != null) {
+        activity = processDefinition.findActivity(eventPayload.getString("activity"));
+      }
     } else {
       // noop, because activity type is not supported
     }
Index: engine/src/main/java/org/camunda/bpm/engine/impl/jobexecutor/EventSubscriptionJobDeclaration.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- engine/src/main/java/org/camunda/bpm/engine/impl/jobexecutor/EventSubscriptionJobDeclaration.java	(revision 0e940143b3de58b85bf038a8eb5f3c337b8a2d6e)
+++ engine/src/main/java/org/camunda/bpm/engine/impl/jobexecutor/EventSubscriptionJobDeclaration.java	(revision 686fb92a5e74ab8081b5ab2b7554ad76d83d9daa)
@@ -14,6 +14,7 @@
 
 import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 
 import org.camunda.bpm.engine.impl.bpmn.parser.BpmnParse;
 import org.camunda.bpm.engine.impl.bpmn.parser.EventSubscriptionDeclaration;
@@ -23,6 +24,8 @@
 import org.camunda.bpm.engine.impl.persistence.entity.MessageEntity;
 import org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity;
 import org.camunda.bpm.engine.impl.pvm.PvmActivity;
+import org.camunda.bpm.engine.impl.util.json.JSONArray;
+import org.camunda.bpm.engine.impl.util.json.JSONObject;
 import org.camunda.commons.utils.EnsureUtil;
 
 /**
@@ -36,6 +39,7 @@
   private static final long serialVersionUID = 1L;
 
   protected EventSubscriptionDeclaration eventSubscriptionDeclaration;
+  private Object payload;
 
   public EventSubscriptionJobDeclaration(EventSubscriptionDeclaration eventSubscriptionDeclaration) {
     super(ProcessEventJobHandler.TYPE);
@@ -61,9 +65,10 @@
     }
 
     // TODO: support payload
-    // if(payload != null) {
-    //   message.setEventPayload(payload);
-    // }
+    if(payload != null && payload instanceof Map) {
+       JSONObject jsonObject = new JSONObject((Map)payload);
+       message.setEventPayload(jsonObject.toString());
+     }
 
     return message;
   }
@@ -113,5 +118,11 @@
     return null;
   }
 
+  public Object getPayload() {
+    return payload;
+  }
 
+  public void setPayload(Object payload) {
+    this.payload = payload;
+  }
 }
Index: engine/src/main/java/org/camunda/bpm/engine/impl/persistence/entity/EventSubscriptionEntity.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- engine/src/main/java/org/camunda/bpm/engine/impl/persistence/entity/EventSubscriptionEntity.java	(revision 0e940143b3de58b85bf038a8eb5f3c337b8a2d6e)
+++ engine/src/main/java/org/camunda/bpm/engine/impl/persistence/entity/EventSubscriptionEntity.java	(revision 686fb92a5e74ab8081b5ab2b7554ad76d83d9daa)
@@ -17,6 +17,7 @@
 import java.io.Serializable;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.Map;
 
 import org.camunda.bpm.engine.impl.context.Context;
 import org.camunda.bpm.engine.impl.db.DbEntity;
@@ -36,6 +37,7 @@
 public abstract class EventSubscriptionEntity implements EventSubscription, DbEntity, HasDbRevision, Serializable {
 
   private static final long serialVersionUID = 1L;
+  private static final String EXECUTION = "execution";
 
   // persistent state ///////////////////////////
   protected String id;
@@ -93,6 +95,7 @@
       processEventSync(payload);
     }
     else {
+      asyncDeclaration.setPayload(payload);
       MessageEntity message = asyncDeclaration.createJobInstance(this);
       CommandContext commandContext = Context.getCommandContext();
       commandContext.getJobManager().send(message);
Index: engine/src/main/java/org/camunda/bpm/engine/impl/persistence/entity/MessageEntity.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- engine/src/main/java/org/camunda/bpm/engine/impl/persistence/entity/MessageEntity.java	(revision 0e940143b3de58b85bf038a8eb5f3c337b8a2d6e)
+++ engine/src/main/java/org/camunda/bpm/engine/impl/persistence/entity/MessageEntity.java	(revision 686fb92a5e74ab8081b5ab2b7554ad76d83d9daa)
@@ -27,6 +27,7 @@
   private static final long serialVersionUID = 1L;
 
   private String repeat = null;
+  private String eventPayload;
 
   public String getRepeat() {
     return repeat;
@@ -37,6 +38,14 @@
 
   public String getType() {
     return TYPE;
+  }
+
+  public void setEventPayload(String eventPayload) {
+    this.eventPayload = eventPayload;
+  }
+
+  public String getEventPayload() {
+    return eventPayload;
   }
 
   @Override
Index: engine/src/main/resources/org/camunda/bpm/engine/db/create/activiti.h2.create.engine.sql
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- engine/src/main/resources/org/camunda/bpm/engine/db/create/activiti.h2.create.engine.sql	(revision 0e940143b3de58b85bf038a8eb5f3c337b8a2d6e)
+++ engine/src/main/resources/org/camunda/bpm/engine/db/create/activiti.h2.create.engine.sql	(revision 686fb92a5e74ab8081b5ab2b7554ad76d83d9daa)
@@ -84,6 +84,7 @@
     PRIORITY_ bigint NOT NULL DEFAULT 0,
     SEQUENCE_COUNTER_ integer,
     TENANT_ID_ varchar(64),
+    EVENT_PAYLOAD_ varchar(4000),
     primary key (ID_)
 );
 
Index: engine/src/main/resources/org/camunda/bpm/engine/impl/mapping/entity/Job.xml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- engine/src/main/resources/org/camunda/bpm/engine/impl/mapping/entity/Job.xml	(revision 0e940143b3de58b85bf038a8eb5f3c337b8a2d6e)
+++ engine/src/main/resources/org/camunda/bpm/engine/impl/mapping/entity/Job.xml	(revision 686fb92a5e74ab8081b5ab2b7554ad76d83d9daa)
@@ -115,7 +115,9 @@
     </discriminator>
   </resultMap>
 
-  <resultMap id="messageResultMap" type="org.camunda.bpm.engine.impl.persistence.entity.MessageEntity" extends="jobResultMap"/>
+  <resultMap id="messageResultMap" type="org.camunda.bpm.engine.impl.persistence.entity.MessageEntity" extends="jobResultMap">
+    <result property="eventPayload" column="EVENT_PAYLOAD_" jdbcType="VARCHAR" />
+  </resultMap>
 
   <resultMap id="timerResultMap" type="org.camunda.bpm.engine.impl.persistence.entity.TimerEntity" extends="jobResultMap">
     <result property="repeat" column="REPEAT_" jdbcType="VARCHAR" />
@@ -466,6 +468,7 @@
             PRIORITY_,
             SEQUENCE_COUNTER_,
             TENANT_ID_,
+            EVENT_PAYLOAD_,
             REV_
             )
     values (#{id, jdbcType=VARCHAR},
@@ -489,6 +492,7 @@
             #{priority, jdbcType=BIGINT},
             #{sequenceCounter, jdbcType=BIGINT},
             #{tenantId, jdbcType=VARCHAR},
+            #{eventPayload, jdbcType=VARCHAR},
             1
     )
   </insert>
Index: engine/src/test/java/org/camunda/bpm/engine/test/bpmn/async/FoxJobRetryCmdTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- engine/src/test/java/org/camunda/bpm/engine/test/bpmn/async/FoxJobRetryCmdTest.java	(revision 0e940143b3de58b85bf038a8eb5f3c337b8a2d6e)
+++ engine/src/test/java/org/camunda/bpm/engine/test/bpmn/async/FoxJobRetryCmdTest.java	(revision 686fb92a5e74ab8081b5ab2b7554ad76d83d9daa)
@@ -181,10 +181,54 @@
 
   @Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/async/FoxJobRetryCmdTest.testFailedIntermediateThrowingSignalEvent.bpmn20.xml",
       "org/camunda/bpm/engine/test/bpmn/async/FoxJobRetryCmdTest.failingSignalStart.bpmn20.xml" })
-  public void FAILING_testFailedIntermediateThrowingSignalEvent() {
-    ProcessInstance pi = runtimeService.startProcessInstanceByKey("failedIntermediateThrowingSignalEvent");
+  public void testFailedIntermediateThrowingSignalEvent() {
+    runtimeService.startProcessInstanceByKey("failedIntermediateThrowingSignalEvent");
+    assertJobRetriesForActivity("failingSignalEvent");
+  }
 
-    assertJobRetriesForActivity(pi, "failingSignalEvent");
+  protected void assertJobRetriesForActivity(String activityId) {
+    waitForExecutedJobWithRetriesLeft(4);
+    stillOneJobWithExceptionAndRetriesLeft();
+
+    Job job = managementService.createJobQuery().singleResult();
+    assertNotNull(job);
+
+    assertEquals(4, job.getRetries());
+
+    ExecutionEntity execution = (ExecutionEntity) runtimeService.createExecutionQuery().processDefinitionKey(job.getProcessDefinitionKey()).singleResult();
+
+    waitForExecutedJobWithRetriesLeft(3);
+
+    job = refreshJob(job.getId());
+    assertEquals(3, job.getRetries());
+    stillOneJobWithExceptionAndRetriesLeft();
+
+
+
+    waitForExecutedJobWithRetriesLeft(2);
+
+    job = refreshJob(job.getId());
+    assertEquals(2, job.getRetries());
+    stillOneJobWithExceptionAndRetriesLeft();
+
+
+
+    waitForExecutedJobWithRetriesLeft(1);
+
+    job = refreshJob(job.getId());
+    assertEquals(1, job.getRetries());
+    stillOneJobWithExceptionAndRetriesLeft();
+
+
+    waitForExecutedJobWithRetriesLeft(0);
+
+    job = refreshJob(job.getId());
+    assertEquals(0, job.getRetries());
+    assertEquals(1, managementService.createJobQuery().withException().count());
+    assertEquals(0, managementService.createJobQuery().withRetriesLeft().count());
+    assertEquals(1, managementService.createJobQuery().noRetriesLeft().count());
+
+
   }
 
   @Deployment
Index: engine/src/test/resources/org/camunda/bpm/engine/test/bpmn/async/FoxJobRetryCmdTest.failingSignalStart.bpmn20.xml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- engine/src/test/resources/org/camunda/bpm/engine/test/bpmn/async/FoxJobRetryCmdTest.failingSignalStart.bpmn20.xml	(revision 0e940143b3de58b85bf038a8eb5f3c337b8a2d6e)
+++ engine/src/test/resources/org/camunda/bpm/engine/test/bpmn/async/FoxJobRetryCmdTest.failingSignalStart.bpmn20.xml	(revision 686fb92a5e74ab8081b5ab2b7554ad76d83d9daa)
@@ -1,25 +1,25 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <definitions id="definitions"
-  xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
-  xmlns:camunda="http://camunda.org/schema/1.0/bpmn"
-  xmlns:fox="http://www.camunda.com/fox"
-  targetNamespace="Examples">
+             xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
+             xmlns:camunda="http://camunda.org/schema/1.0/bpmn"
+             xmlns:fox="http://www.camunda.com/fox"
+             targetNamespace="Examples">
 
-  <signal id="signal" name="abort" />
+  <signal id="signal" name="abort"/>
 
   <process id="failingSignalProcess" isExecutable="true">
-    
+
     <startEvent id="signalStart">
-        <signalEventDefinition signalRef="signal" />
+      <signalEventDefinition signalRef="signal"/>
-      </startEvent>
-      
+    </startEvent>
+
-    <sequenceFlow sourceRef="signalStart" targetRef="failingServiceTask" />
+    <sequenceFlow sourceRef="signalStart" targetRef="failingServiceTask"/>
-  
+
-    <serviceTask id="failingServiceTask" camunda:class="org.camunda.bpm.engine.test.cmd.FailingDelegate"/>
+    <serviceTask id="failingServiceTask" camunda:class="org.camunda.bpm.engine.test.bpmn.async.FailingDelegate"/>
-    
+
-    <sequenceFlow sourceRef="failingServiceTask" targetRef="end" /> 
+    <sequenceFlow sourceRef="failingServiceTask" targetRef="end"/>
-       
+
-    <endEvent id="end" />
+    <endEvent id="end"/>
   </process>
 
 </definitions>
\ No newline at end of file
Index: engine/src/test/resources/org/camunda/bpm/engine/test/bpmn/async/FoxJobRetryCmdTest.testFailedIntermediateThrowingSignalEvent.bpmn20.xml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- engine/src/test/resources/org/camunda/bpm/engine/test/bpmn/async/FoxJobRetryCmdTest.testFailedIntermediateThrowingSignalEvent.bpmn20.xml	(revision 0e940143b3de58b85bf038a8eb5f3c337b8a2d6e)
+++ engine/src/test/resources/org/camunda/bpm/engine/test/bpmn/async/FoxJobRetryCmdTest.testFailedIntermediateThrowingSignalEvent.bpmn20.xml	(revision 686fb92a5e74ab8081b5ab2b7554ad76d83d9daa)
@@ -13,11 +13,16 @@
     
     <sequenceFlow sourceRef="theStart" targetRef="failingSignalEvent" />
     
-    <intermediateThrowEvent id="failingSignalEvent">
+    <intermediateThrowEvent id="failingSignalEvent" >
       <extensionElements>
         <camunda:failedJobRetryTimeCycle>R5/PT5M</camunda:failedJobRetryTimeCycle>
       </extensionElements>
-      <signalEventDefinition signalRef="signal" camunda:async="true" />
+      
+      <signalEventDefinition signalRef="signal" camunda:async="true" >
+        <extensionElements>
+          <camunda:failedJobRetryTimeCycle>R5/PT5M</camunda:failedJobRetryTimeCycle>
+        </extensionElements>
+      </signalEventDefinition>
     </intermediateThrowEvent>
         
     <sequenceFlow sourceRef="failingSignalEvent" targetRef="end" />
\ No newline at end of file
