1
2
3
4
5
6
7 package org.mule.interceptor;
8
9 import org.mule.api.MuleEvent;
10 import org.mule.api.MuleException;
11 import org.mule.api.construct.FlowConstruct;
12 import org.mule.api.construct.FlowConstructAware;
13 import org.mule.api.interceptor.Interceptor;
14 import org.mule.management.stats.ProcessingTime;
15 import org.mule.processor.AbstractInterceptingMessageProcessor;
16
17
18
19
20
21 public abstract class AbstractEnvelopeInterceptor extends AbstractInterceptingMessageProcessor
22 implements Interceptor, FlowConstructAware
23 {
24
25 protected FlowConstruct flowConstruct;
26
27
28
29
30 public abstract MuleEvent before(MuleEvent event) throws MuleException;
31
32
33
34
35 public abstract MuleEvent after(MuleEvent event) throws MuleException;
36
37
38
39
40 public abstract MuleEvent last(MuleEvent event, ProcessingTime time, long startTime, boolean exceptionWasThrown) throws MuleException;
41
42 public MuleEvent process(MuleEvent event) throws MuleException
43 {
44 boolean exceptionWasThrown = true;
45 long startTime = System.currentTimeMillis();
46 ProcessingTime time = event.getProcessingTime();
47 MuleEvent resultEvent = event;
48 try
49 {
50 resultEvent = before(event);
51 resultEvent = processNext(resultEvent);
52 resultEvent = after(resultEvent);
53 exceptionWasThrown = false;
54 }
55 finally
56 {
57 resultEvent = last(resultEvent, time, startTime, exceptionWasThrown);
58 }
59 return resultEvent;
60 }
61
62 public void setFlowConstruct(FlowConstruct flowConstruct)
63 {
64 this.flowConstruct = flowConstruct;
65 }
66 }