Author: jstrachan
Date: Fri Jun 6 05:21:31 2008
New Revision: 663909
URL: http://svn.apache.org/viewvc?rev=663909&view=rev
Log:
improvement to the debugger interceptor to trace all exceptions that occur as
well
Added:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/ExceptionEvent.java
(with props)
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/DebugInterceptor.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Debugger.java
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/DebugInterceptor.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/DebugInterceptor.java?rev=663909&r1=663908&r2=663909&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/DebugInterceptor.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/DebugInterceptor.java
Fri Jun 6 05:21:31 2008
@@ -33,13 +33,16 @@
public class DebugInterceptor extends DelegateProcessor {
private final ProcessorType node;
private final List<Exchange> exchanges;
+ private final List<ExceptionEvent> exceptions;
private Predicate traceFilter;
private Breakpoint breakpoint = new Breakpoint();
+ private boolean traceExceptions = true;
- public DebugInterceptor(ProcessorType node, Processor target,
List<Exchange> exchanges) {
+ public DebugInterceptor(ProcessorType node, Processor target,
List<Exchange> exchanges, List<ExceptionEvent> exceptions) {
super(target);
this.node = node;
this.exchanges = exchanges;
+ this.exceptions = exceptions;
}
@Override
@@ -50,7 +53,17 @@
public void process(Exchange exchange) throws Exception {
checkForBreakpoint(exchange);
addTraceExchange(exchange);
- super.proceed(exchange);
+ try {
+ super.proceed(exchange);
+ }
+ catch (Exception e) {
+ onException(exchange, e);
+ throw e;
+ }
+ catch (Error e) {
+ onException(exchange, e);
+ throw e;
+ }
}
public ProcessorType getNode() {
@@ -61,6 +74,10 @@
return exchanges;
}
+ public List<ExceptionEvent> getExceptions() {
+ return exceptions;
+ }
+
public Breakpoint getBreakpoint() {
return breakpoint;
}
@@ -73,6 +90,14 @@
this.traceFilter = traceFilter;
}
+ public boolean isTraceExceptions() {
+ return traceExceptions;
+ }
+
+ public void setTraceExceptions(boolean traceExceptions) {
+ this.traceExceptions = traceExceptions;
+ }
+
/**
* Stategy method to wait for a breakpoint if one is set
*/
@@ -81,6 +106,20 @@
}
/**
+ * Fired when an exception is thrown when processing the underlying
processor
+ */
+ protected void onException(Exchange exchange, Throwable e) {
+ if (shouldTraceExceptionEvents(exchange, e)) {
+ exceptions.add(new ExceptionEvent(this, exchange, e));
+ }
+
+ }
+
+ private boolean shouldTraceExceptionEvents(Exchange exchange, Throwable e)
{
+ return isTraceExceptions();
+ }
+
+ /**
* Strategy method to store the exchange in a trace log if it is enabled
*/
protected void addTraceExchange(Exchange exchange) {
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Debugger.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Debugger.java?rev=663909&r1=663908&r2=663909&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Debugger.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Debugger.java
Fri Jun 6 05:21:31 2008
@@ -91,7 +91,7 @@
public Processor wrapProcessorInInterceptors(ProcessorType processorType,
Processor target) throws Exception {
String id = processorType.idOrCreate();
- DebugInterceptor interceptor = new DebugInterceptor(processorType,
target, createExchangeList());
+ DebugInterceptor interceptor = new DebugInterceptor(processorType,
target, createExchangeList(), createExceptionsList());
interceptors.put(id, interceptor);
if (LOG.isDebugEnabled()) {
LOG.debug("adding interceptor: " + interceptor);
@@ -109,4 +109,9 @@
return new ArrayList<Exchange>();
}
}
+
+ protected List<ExceptionEvent> createExceptionsList() {
+ // TODO allow some kinda LRU based fixed size list to be used?
+ return new ArrayList<ExceptionEvent>();
+ }
}
Added:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/ExceptionEvent.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/ExceptionEvent.java?rev=663909&view=auto
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/ExceptionEvent.java
(added)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/ExceptionEvent.java
Fri Jun 6 05:21:31 2008
@@ -0,0 +1,49 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.processor.interceptor;
+
+import org.apache.camel.Exchange;
+
+/**
+ * Represents an exception that occurred when processing an exchange
+ *
+ * @version $Revision: 1.1 $
+ */
+public class ExceptionEvent {
+ private final DebugInterceptor interceptor;
+ private final Exchange exchange;
+ private final Throwable exception;
+
+ public ExceptionEvent(DebugInterceptor interceptor, Exchange exchange,
Throwable exception) {
+ this.interceptor = interceptor;
+ this.exchange = exchange;
+ this.exception = exception;
+ }
+
+ public Throwable getException() {
+ return exception;
+ }
+
+ public Exchange getExchange() {
+ return exchange;
+ }
+
+ public DebugInterceptor getInterceptor() {
+ return interceptor;
+ }
+}
Propchange:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/ExceptionEvent.java
------------------------------------------------------------------------------
svn:eol-style = native