| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
package org.apache.camel.model; |
| 18 |
|
|
| 19 |
|
import java.util.ArrayList; |
| 20 |
|
import java.util.List; |
| 21 |
|
import java.util.Collection; |
| 22 |
|
import javax.xml.bind.annotation.XmlAccessType; |
| 23 |
|
import javax.xml.bind.annotation.XmlAccessorType; |
| 24 |
|
import javax.xml.bind.annotation.XmlElement; |
| 25 |
|
import javax.xml.bind.annotation.XmlElementRef; |
| 26 |
|
import javax.xml.bind.annotation.XmlRootElement; |
| 27 |
|
import javax.xml.bind.annotation.XmlTransient; |
| 28 |
|
|
| 29 |
|
import org.apache.camel.Processor; |
| 30 |
|
import org.apache.camel.Route; |
| 31 |
|
import org.apache.camel.builder.ErrorHandlerBuilder; |
| 32 |
|
import org.apache.camel.impl.RouteContext; |
| 33 |
|
import org.apache.camel.processor.CatchProcessor; |
| 34 |
|
import org.apache.camel.processor.RedeliveryPolicy; |
| 35 |
|
import org.apache.camel.util.ObjectHelper; |
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
@XmlRootElement(name = "onException") |
| 41 |
|
@XmlAccessorType(XmlAccessType.FIELD) |
| 42 |
0 |
public class ExceptionType extends ProcessorType { |
| 43 |
|
@XmlElementRef |
| 44 |
18 |
private List<InterceptorType> interceptors = new ArrayList<InterceptorType>(); |
| 45 |
|
@XmlElement(name = "exception") |
| 46 |
18 |
private List<String> exceptions = new ArrayList<String>(); |
| 47 |
|
@XmlElement(name = "redeliveryPolicy", required = false) |
| 48 |
|
private RedeliveryPolicyType redeliveryPolicy; |
| 49 |
|
@XmlElementRef |
| 50 |
18 |
private List<ProcessorType> outputs = new ArrayList<ProcessorType>(); |
| 51 |
|
@XmlTransient |
| 52 |
|
private List<Class> exceptionClasses; |
| 53 |
|
@XmlTransient |
| 54 |
|
private Processor errorHandler; |
| 55 |
|
|
| 56 |
0 |
public ExceptionType() { |
| 57 |
0 |
} |
| 58 |
|
|
| 59 |
0 |
public ExceptionType(List<Class> exceptionClasses) { |
| 60 |
0 |
this.exceptionClasses = exceptionClasses; |
| 61 |
0 |
} |
| 62 |
|
|
| 63 |
18 |
public ExceptionType(Class exceptionType) { |
| 64 |
18 |
exceptionClasses = new ArrayList<Class>(); |
| 65 |
18 |
exceptionClasses.add(exceptionType); |
| 66 |
18 |
} |
| 67 |
|
|
| 68 |
|
@Override |
| 69 |
|
public String toString() { |
| 70 |
0 |
return "Exception[ " + getExceptionClasses() + " -> " + getOutputs() + "]"; |
| 71 |
|
} |
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
public RedeliveryPolicy createRedeliveryPolicy(RedeliveryPolicy parentPolicy) { |
| 80 |
12 |
if (redeliveryPolicy != null) { |
| 81 |
6 |
return redeliveryPolicy.createRedeliveryPolicy(parentPolicy); |
| 82 |
|
} |
| 83 |
6 |
else if (errorHandler != null) { |
| 84 |
|
|
| 85 |
6 |
RedeliveryPolicy answer = parentPolicy.copy(); |
| 86 |
6 |
answer.setMaximumRedeliveries(0); |
| 87 |
6 |
return answer; |
| 88 |
|
} |
| 89 |
0 |
return parentPolicy; |
| 90 |
|
} |
| 91 |
|
|
| 92 |
|
public void addRoutes(RouteContext routeContext, Collection<Route> routes) throws Exception { |
| 93 |
|
|
| 94 |
18 |
errorHandler = routeContext.createProcessor(this); |
| 95 |
18 |
ErrorHandlerBuilder builder = routeContext.getRoute().getErrorHandlerBuilder(); |
| 96 |
18 |
builder.addErrorHandlers(this); |
| 97 |
18 |
} |
| 98 |
|
|
| 99 |
|
@Override |
| 100 |
|
public CatchProcessor createProcessor(RouteContext routeContext) throws Exception { |
| 101 |
0 |
Processor childProcessor = routeContext.createProcessor(this); |
| 102 |
0 |
return new CatchProcessor(getExceptionClasses(), childProcessor); |
| 103 |
|
} |
| 104 |
|
|
| 105 |
|
|
| 106 |
|
|
| 107 |
|
|
| 108 |
|
public ExceptionType backOffMultiplier(double backOffMultiplier) { |
| 109 |
0 |
getOrCreateRedeliveryPolicy().backOffMultiplier(backOffMultiplier); |
| 110 |
0 |
return this; |
| 111 |
|
} |
| 112 |
|
|
| 113 |
|
public ExceptionType collisionAvoidanceFactor(double collisionAvoidanceFactor) { |
| 114 |
0 |
getOrCreateRedeliveryPolicy().collisionAvoidanceFactor(collisionAvoidanceFactor); |
| 115 |
0 |
return this; |
| 116 |
|
} |
| 117 |
|
|
| 118 |
|
public ExceptionType collisionAvoidancePercent(short collisionAvoidancePercent) { |
| 119 |
0 |
getOrCreateRedeliveryPolicy().collisionAvoidancePercent(collisionAvoidancePercent); |
| 120 |
0 |
return this; |
| 121 |
|
} |
| 122 |
|
|
| 123 |
|
public ExceptionType initialRedeliveryDelay(long initialRedeliveryDelay) { |
| 124 |
0 |
getOrCreateRedeliveryPolicy().initialRedeliveryDelay(initialRedeliveryDelay); |
| 125 |
0 |
return this; |
| 126 |
|
} |
| 127 |
|
|
| 128 |
|
public ExceptionType maximumRedeliveries(int maximumRedeliveries) { |
| 129 |
6 |
getOrCreateRedeliveryPolicy().maximumRedeliveries(maximumRedeliveries); |
| 130 |
6 |
return this; |
| 131 |
|
} |
| 132 |
|
|
| 133 |
|
public ExceptionType useCollisionAvoidance() { |
| 134 |
0 |
getOrCreateRedeliveryPolicy().useCollisionAvoidance(); |
| 135 |
0 |
return this; |
| 136 |
|
} |
| 137 |
|
|
| 138 |
|
public ExceptionType useExponentialBackOff() { |
| 139 |
0 |
getOrCreateRedeliveryPolicy().useExponentialBackOff(); |
| 140 |
0 |
return this; |
| 141 |
|
} |
| 142 |
|
|
| 143 |
|
|
| 144 |
|
|
| 145 |
|
|
| 146 |
|
public List<InterceptorType> getInterceptors() { |
| 147 |
0 |
return interceptors; |
| 148 |
|
} |
| 149 |
|
|
| 150 |
|
public void setInterceptors(List<InterceptorType> interceptors) { |
| 151 |
0 |
this.interceptors = interceptors; |
| 152 |
0 |
} |
| 153 |
|
|
| 154 |
|
public List<ProcessorType> getOutputs() { |
| 155 |
36 |
return outputs; |
| 156 |
|
} |
| 157 |
|
|
| 158 |
|
public void setOutputs(List<ProcessorType> outputs) { |
| 159 |
0 |
this.outputs = outputs; |
| 160 |
0 |
} |
| 161 |
|
|
| 162 |
|
public List<Class> getExceptionClasses() { |
| 163 |
24 |
if (exceptionClasses == null) { |
| 164 |
0 |
exceptionClasses = createExceptionClasses(); |
| 165 |
|
} |
| 166 |
24 |
return exceptionClasses; |
| 167 |
|
} |
| 168 |
|
|
| 169 |
|
public void setExceptionClasses(List<Class> exceptionClasses) { |
| 170 |
0 |
this.exceptionClasses = exceptionClasses; |
| 171 |
0 |
} |
| 172 |
|
|
| 173 |
|
public List<String> getExceptions() { |
| 174 |
0 |
return exceptions; |
| 175 |
|
} |
| 176 |
|
|
| 177 |
|
public void setExceptions(List<String> exceptions) { |
| 178 |
0 |
this.exceptions = exceptions; |
| 179 |
0 |
} |
| 180 |
|
|
| 181 |
|
public Processor getErrorHandler() { |
| 182 |
36 |
return errorHandler; |
| 183 |
|
} |
| 184 |
|
|
| 185 |
|
public RedeliveryPolicyType getRedeliveryPolicy() { |
| 186 |
0 |
return redeliveryPolicy; |
| 187 |
|
} |
| 188 |
|
|
| 189 |
|
public void setRedeliveryPolicy(RedeliveryPolicyType redeliveryPolicy) { |
| 190 |
0 |
this.redeliveryPolicy = redeliveryPolicy; |
| 191 |
0 |
} |
| 192 |
|
|
| 193 |
|
|
| 194 |
|
|
| 195 |
|
protected RedeliveryPolicyType getOrCreateRedeliveryPolicy() { |
| 196 |
6 |
if (redeliveryPolicy == null) { |
| 197 |
6 |
redeliveryPolicy = new RedeliveryPolicyType(); |
| 198 |
|
} |
| 199 |
6 |
return redeliveryPolicy; |
| 200 |
|
} |
| 201 |
|
|
| 202 |
|
protected List<Class> createExceptionClasses() { |
| 203 |
0 |
List<String> list = getExceptions(); |
| 204 |
0 |
List<Class> answer = new ArrayList<Class>(list.size()); |
| 205 |
0 |
for (String name : list) { |
| 206 |
0 |
Class type = ObjectHelper.loadClass(name, getClass().getClassLoader()); |
| 207 |
0 |
answer.add(type); |
| 208 |
0 |
} |
| 209 |
0 |
return answer; |
| 210 |
|
} |
| 211 |
|
} |