001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.spring; 018 019import javax.xml.bind.annotation.XmlAccessType; 020import javax.xml.bind.annotation.XmlAccessorType; 021import javax.xml.bind.annotation.XmlAttribute; 022import javax.xml.bind.annotation.XmlElement; 023import javax.xml.bind.annotation.XmlRootElement; 024 025import org.apache.camel.LoggingLevel; 026import org.apache.camel.model.IdentifiedType; 027import org.apache.camel.processor.RedeliveryPolicy; 028import org.apache.camel.spi.Metadata; 029 030/** 031 * Error handler settings 032 * 033 * @version 034 */ 035@Metadata(label = "spring,configuration,error") 036@XmlRootElement(name = "errorHandler") 037@XmlAccessorType(XmlAccessType.FIELD) 038public class ErrorHandlerDefinition extends IdentifiedType { 039 @XmlAttribute @Metadata(defaultValue = "DefaultErrorHandler", required = "true") 040 private ErrorHandlerType type = ErrorHandlerType.DefaultErrorHandler; 041 @XmlAttribute 042 private String deadLetterUri; 043 @XmlAttribute 044 private String deadLetterHandleNewException; 045 @XmlAttribute @Metadata(defaultValue = "ERROR") 046 private LoggingLevel level; 047 @XmlAttribute @Metadata(defaultValue = "WARN") 048 private LoggingLevel rollbackLoggingLevel; 049 @XmlAttribute 050 private String logName; 051 @XmlAttribute 052 private Boolean useOriginalMessage; 053 @XmlAttribute 054 private String transactionTemplateRef; 055 @XmlAttribute 056 private String transactionManagerRef; 057 @XmlAttribute 058 private String onRedeliveryRef; 059 @XmlAttribute 060 private String onExceptionOccurredRef; 061 @XmlAttribute 062 private String onPrepareFailureRef; 063 @XmlAttribute 064 private String retryWhileRef; 065 @XmlAttribute 066 private String redeliveryPolicyRef; 067 @XmlAttribute 068 private String executorServiceRef; 069 @XmlElement 070 private CamelRedeliveryPolicyFactoryBean redeliveryPolicy; 071 072 public ErrorHandlerType getType() { 073 return type; 074 } 075 076 /** 077 * The type of the error handler 078 */ 079 public void setType(ErrorHandlerType type) { 080 this.type = type; 081 } 082 083 public String getDeadLetterUri() { 084 return deadLetterUri; 085 } 086 087 /** 088 * The dead letter endpoint uri for the Dead Letter error handler. 089 */ 090 public void setDeadLetterUri(String deadLetterUri) { 091 this.deadLetterUri = deadLetterUri; 092 } 093 094 public String getDeadLetterHandleNewException() { 095 return deadLetterHandleNewException; 096 } 097 098 /** 099 * Whether the dead letter channel should handle (and ignore) any new exception that may been thrown during sending the 100 * message to the dead letter endpoint. 101 * <p/> 102 * The default value is <tt>true</tt> which means any such kind of exception is handled and ignored. Set this to <tt>false</tt> 103 * to let the exception be propagated back on the {@link org.apache.camel.Exchange}. This can be used in situations 104 * where you use transactions, and want to use Camel's dead letter channel to deal with exceptions during routing, 105 * but if the dead letter channel itself fails because of a new exception being thrown, then by setting this to <tt>false</tt> 106 * the new exceptions is propagated back and set on the {@link org.apache.camel.Exchange}, which allows the transaction 107 * to detect the exception, and rollback. 108 */ 109 public void setDeadLetterHandleNewException(String deadLetterHandleNewException) { 110 this.deadLetterHandleNewException = deadLetterHandleNewException; 111 } 112 113 public LoggingLevel getLevel() { 114 return level; 115 } 116 117 /** 118 * Logging level to use when using the logging error handler type. 119 */ 120 public void setLevel(LoggingLevel level) { 121 this.level = level; 122 } 123 124 public LoggingLevel getRollbackLoggingLevel() { 125 return rollbackLoggingLevel; 126 } 127 128 /** 129 * Sets the logging level to use for logging transactional rollback. 130 * <p/> 131 * This option is default WARN. 132 */ 133 public void setRollbackLoggingLevel(LoggingLevel rollbackLoggingLevel) { 134 this.rollbackLoggingLevel = rollbackLoggingLevel; 135 } 136 137 public String getLogName() { 138 return logName; 139 } 140 141 /** 142 * Name of the logger to use for the logging error handler 143 */ 144 public void setLogName(String logName) { 145 this.logName = logName; 146 } 147 148 public Boolean getUseOriginalMessage() { 149 return useOriginalMessage; 150 } 151 152 /** 153 * Will use the original input message when an {@link org.apache.camel.Exchange} is moved to the dead letter queue. 154 * <p/> 155 * <b>Notice:</b> this only applies when all redeliveries attempt have failed and the {@link org.apache.camel.Exchange} is doomed for failure. 156 * <br/> 157 * Instead of using the current inprogress {@link org.apache.camel.Exchange} IN body we use the original IN body instead. This allows 158 * you to store the original input in the dead letter queue instead of the inprogress snapshot of the IN body. 159 * For instance if you route transform the IN body during routing and then failed. With the original exchange 160 * store in the dead letter queue it might be easier to manually re submit the {@link org.apache.camel.Exchange} again as the IN body 161 * is the same as when Camel received it. So you should be able to send the {@link org.apache.camel.Exchange} to the same input. 162 * <p/> 163 * By default this feature is off. 164 */ 165 public void setUseOriginalMessage(Boolean useOriginalMessage) { 166 this.useOriginalMessage = useOriginalMessage; 167 } 168 169 public String getTransactionTemplateRef() { 170 return transactionTemplateRef; 171 } 172 173 /** 174 * References to the {@link org.springframework.transaction.support.TransactionTemplate} to use with the transaction error handler. 175 */ 176 public void setTransactionTemplateRef(String transactionTemplateRef) { 177 this.transactionTemplateRef = transactionTemplateRef; 178 } 179 180 public String getTransactionManagerRef() { 181 return transactionManagerRef; 182 } 183 184 /** 185 * References to the {@link org.springframework.transaction.PlatformTransactionManager} to use with the transaction error handler. 186 */ 187 public void setTransactionManagerRef(String transactionManagerRef) { 188 this.transactionManagerRef = transactionManagerRef; 189 } 190 191 public String getOnRedeliveryRef() { 192 return onRedeliveryRef; 193 } 194 195 /** 196 * Sets a reference to a processor that should be processed <b>before</b> a redelivery attempt. 197 * <p/> 198 * Can be used to change the {@link org.apache.camel.Exchange} <b>before</b> its being redelivered. 199 */ 200 public void setOnRedeliveryRef(String onRedeliveryRef) { 201 this.onRedeliveryRef = onRedeliveryRef; 202 } 203 204 public String getOnExceptionOccurredRef() { 205 return onExceptionOccurredRef; 206 } 207 208 /** 209 * Sets a reference to a processor that should be processed <b>just after</b> an exception occurred. 210 * Can be used to perform custom logging about the occurred exception at the exact time it happened. 211 * <p/> 212 * Important: Any exception thrown from this processor will be ignored. 213 */ 214 public void setOnExceptionOccurredRef(String onExceptionOccurredRef) { 215 this.onExceptionOccurredRef = onExceptionOccurredRef; 216 } 217 218 public String getOnPrepareFailureRef() { 219 return onPrepareFailureRef; 220 } 221 222 /** 223 * Sets a reference to a processor to prepare the {@link org.apache.camel.Exchange} before 224 * handled by the failure processor / dead letter channel. This allows for example to enrich the message 225 * before sending to a dead letter queue. 226 */ 227 public void setOnPrepareFailureRef(String onPrepareFailureRef) { 228 this.onPrepareFailureRef = onPrepareFailureRef; 229 } 230 231 public String getRetryWhileRef() { 232 return retryWhileRef; 233 } 234 235 /** 236 * Sets a reference to an retry while expression. 237 * <p/> 238 * Will continue retrying until expression evaluates to <tt>false</tt>. 239 */ 240 public void setRetryWhileRef(String retryWhileRef) { 241 this.retryWhileRef = retryWhileRef; 242 } 243 244 public String getRedeliveryPolicyRef() { 245 return redeliveryPolicyRef; 246 } 247 248 /** 249 * Sets a reference to a {@link RedeliveryPolicy} to be used for redelivery settings. 250 */ 251 public void setRedeliveryPolicyRef(String redeliveryPolicyRef) { 252 this.redeliveryPolicyRef = redeliveryPolicyRef; 253 } 254 255 public String getExecutorServiceRef() { 256 return executorServiceRef; 257 } 258 259 /** 260 * Sets a reference to a thread pool to be used by the error handler 261 */ 262 public void setExecutorServiceRef(String executorServiceRef) { 263 this.executorServiceRef = executorServiceRef; 264 } 265 266 public CamelRedeliveryPolicyFactoryBean getRedeliveryPolicy() { 267 return redeliveryPolicy; 268 } 269 270 /** 271 * Sets the redelivery settings 272 */ 273 public void setRedeliveryPolicy(CamelRedeliveryPolicyFactoryBean redeliveryPolicy) { 274 this.redeliveryPolicy = redeliveryPolicy; 275 } 276}