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