You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/03/25 11:23:44 UTC
[1/6] camel git commit: Polished
Repository: camel
Updated Branches:
refs/heads/camel-2.15.x 5b80cceb9 -> 3e112488b
refs/heads/master f078028be -> 01567ab64
Polished
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/092ce410
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/092ce410
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/092ce410
Branch: refs/heads/master
Commit: 092ce4108d50be3482e5b5fd92006d48c833a796
Parents: 161ee7e
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Mar 25 10:58:26 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Mar 25 11:25:10 2015 +0100
----------------------------------------------------------------------
camel-core/src/main/java/org/apache/camel/util/StringHelper.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/092ce410/camel-core/src/main/java/org/apache/camel/util/StringHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/StringHelper.java b/camel-core/src/main/java/org/apache/camel/util/StringHelper.java
index e68b8bf..60919db 100644
--- a/camel-core/src/main/java/org/apache/camel/util/StringHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/StringHelper.java
@@ -161,11 +161,11 @@ public final class StringHelper {
}
// for the simple language the expression start token could be "${"
- if ("simple".equalsIgnoreCase(language) && expression.indexOf("${") >= 0) {
+ if ("simple".equalsIgnoreCase(language) && expression.contains("${")) {
return true;
}
- if (language != null && expression.indexOf("$" + language + "{") >= 0) {
+ if (language != null && expression.contains("$" + language + "{")) {
return true;
}
[5/6] camel git commit: CAMEL-6269: Added MainListener to make it
easier to do custom logic for the lifecycle of start|stop of the main
instance.
Posted by da...@apache.org.
CAMEL-6269: Added MainListener to make it easier to do custom logic for the lifecycle of start|stop of the main instance.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/01567ab6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/01567ab6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/01567ab6
Branch: refs/heads/master
Commit: 01567ab644034f30c77dd10e742c23f792cdcaac
Parents: 83c56bb
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Mar 25 11:21:56 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Mar 25 11:25:11 2015 +0100
----------------------------------------------------------------------
.../org/apache/camel/main/MainListener.java | 51 ++++++++++++++++++
.../apache/camel/main/MainListenerSupport.java | 39 ++++++++++++++
.../java/org/apache/camel/main/MainSupport.java | 55 +++++++++++++++++++-
.../java/org/apache/camel/main/MainExample.java | 15 ++++++
4 files changed, 158 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/01567ab6/camel-core/src/main/java/org/apache/camel/main/MainListener.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/main/MainListener.java b/camel-core/src/main/java/org/apache/camel/main/MainListener.java
new file mode 100644
index 0000000..3de7668
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/main/MainListener.java
@@ -0,0 +1,51 @@
+/**
+ * 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.main;
+
+/**
+ * A lifecycle listener to receive callbacks when the main is started and stopped.
+ */
+public interface MainListener {
+
+ /**
+ * Callback before the CamelContext(s) is being started.
+ *
+ * @param main the main instance
+ */
+ void beforeStart(MainSupport main);
+
+ /**
+ * Callback after the CamelContext(s) has been started.
+ *
+ * @param main the main instance
+ */
+ void afterStart(MainSupport main);
+
+ /**
+ * Callback before the CamelContext(s) is being stopped.
+ *
+ * @param main the main instance
+ */
+ void beforeStop(MainSupport main);
+
+ /**
+ * Callback after the CamelContext(s) has been stopped.
+ *
+ * @param main the main instance
+ */
+ void afterStop(MainSupport main);
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/01567ab6/camel-core/src/main/java/org/apache/camel/main/MainListenerSupport.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/main/MainListenerSupport.java b/camel-core/src/main/java/org/apache/camel/main/MainListenerSupport.java
new file mode 100644
index 0000000..6dda55b
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/main/MainListenerSupport.java
@@ -0,0 +1,39 @@
+/**
+ * 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.main;
+
+/**
+ * A useful base class for {@link org.apache.camel.main.MainListener} implementations.
+ */
+public class MainListenerSupport implements MainListener {
+
+ public void beforeStart(MainSupport main) {
+ // noop
+ }
+
+ public void afterStart(MainSupport main) {
+ // noop
+ }
+
+ public void beforeStop(MainSupport main) {
+ // noop
+ }
+
+ public void afterStop(MainSupport main) {
+ // noop
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/01567ab6/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/main/MainSupport.java b/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
index c328df8..726e0d6 100644
--- a/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
+++ b/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
@@ -46,6 +46,7 @@ import org.slf4j.LoggerFactory;
*/
public abstract class MainSupport extends ServiceSupport {
protected static final Logger LOG = LoggerFactory.getLogger(MainSupport.class);
+ protected final List<MainListener> listeners = new ArrayList<MainListener>();
protected final List<Option> options = new ArrayList<Option>();
protected final CountDownLatch latch = new CountDownLatch(1);
protected final AtomicBoolean completed = new AtomicBoolean(false);
@@ -119,6 +120,7 @@ public abstract class MainSupport extends ServiceSupport {
public void run() throws Exception {
if (!completed.get()) {
// if we have an issue starting then propagate the exception to caller
+ beforeStart();
start();
try {
afterStart();
@@ -126,6 +128,7 @@ public abstract class MainSupport extends ServiceSupport {
internalBeforeStop();
beforeStop();
stop();
+ afterStop();
} catch (Exception e) {
// however while running then just log errors
LOG.error("Failed: " + e, e);
@@ -143,19 +146,67 @@ public abstract class MainSupport extends ServiceSupport {
}
/**
+ * Adds a {@link org.apache.camel.main.MainListener} to receive callbacks when the main is started or stopping
+ *
+ * @param listener the listener
+ */
+ public void addMainListener(MainListener listener) {
+ listeners.add(listener);
+ }
+
+ /**
+ * Removes the {@link org.apache.camel.main.MainListener}
+ *
+ * @param listener the listener
+ */
+ public void removeMainListener(MainListener listener) {
+ listeners.remove(listener);
+ }
+
+ /**
+ * Callback to run custom logic before CamelContext is being started.
+ * <p/>
+ * It is recommended to use {@link org.apache.camel.main.MainListener} instead.
+ */
+ protected void beforeStart() throws Exception {
+ for (MainListener listener : listeners) {
+ listener.beforeStart(this);
+ }
+ }
+
+ /**
* Callback to run custom logic after CamelContext has been started.
+ * <p/>
+ * It is recommended to use {@link org.apache.camel.main.MainListener} instead.
*/
protected void afterStart() throws Exception {
- // noop
+ for (MainListener listener : listeners) {
+ listener.afterStart(this);
+ }
}
/**
* Callback to run custom logic before CamelContext is being stopped.
+ * <p/>
+ * It is recommended to use {@link org.apache.camel.main.MainListener} instead.
*/
protected void beforeStop() throws Exception {
- // noop
+ for (MainListener listener : listeners) {
+ listener.beforeStop(this);
+ }
}
+ /**
+ * Callback to run custom logic after CamelContext has been stopped.
+ * <p/>
+ * It is recommended to use {@link org.apache.camel.main.MainListener} instead.
+ */
+ protected void afterStop() throws Exception {
+ for (MainListener listener : listeners) {
+ listener.afterStop(this);
+ }
+ }
+
private void internalBeforeStop() {
try {
if (camelTemplate != null) {
http://git-wip-us.apache.org/repos/asf/camel/blob/01567ab6/camel-core/src/test/java/org/apache/camel/main/MainExample.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/main/MainExample.java b/camel-core/src/test/java/org/apache/camel/main/MainExample.java
index 8e30738..df64578 100644
--- a/camel-core/src/test/java/org/apache/camel/main/MainExample.java
+++ b/camel-core/src/test/java/org/apache/camel/main/MainExample.java
@@ -44,6 +44,8 @@ public class MainExample {
main.bind("foo", new MyBean());
// add routes
main.addRouteBuilder(new MyRouteBuilder());
+ // add event listener
+ main.addMainListener(new Events());
// run until you terminate the JVM
System.out.println("Starting Camel. Use ctrl + c to terminate the JVM.\n");
@@ -68,5 +70,18 @@ public class MainExample {
System.out.println("MyBean.calleMe method has been called");
}
}
+
+ public static class Events extends MainListenerSupport {
+
+ @Override
+ public void afterStart(MainSupport main) {
+ System.out.println("MainExample with Camel is now started!");
+ }
+
+ @Override
+ public void beforeStop(MainSupport main) {
+ System.out.println("MainExample with Camel is now being stopped!");
+ }
+ }
}
// END SNIPPET: e1
[4/6] camel git commit: CAMEL-5452: DoCatch now also emits the
failure handled event
Posted by da...@apache.org.
CAMEL-5452: DoCatch now also emits the failure handled event
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/83c56bb5
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/83c56bb5
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/83c56bb5
Branch: refs/heads/master
Commit: 83c56bb5d1e81072cb56aa16b2d334a37552075f
Parents: 092ce41
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Mar 25 11:01:00 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Mar 25 11:25:11 2015 +0100
----------------------------------------------------------------------
.../src/main/java/org/apache/camel/processor/CatchProcessor.java | 1 -
1 file changed, 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/83c56bb5/camel-core/src/main/java/org/apache/camel/processor/CatchProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/CatchProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/CatchProcessor.java
index f30954d..654cfa4 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/CatchProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/CatchProcessor.java
@@ -102,7 +102,6 @@ public class CatchProcessor extends DelegateAsyncProcessor implements Traceable,
boolean sync = processor.process(exchange, new AsyncCallback() {
public void done(boolean doneSync) {
if (handled) {
- ExchangeHelper.setFailureHandled(exchange);
// emit event that the failure was handled
EventHelper.notifyExchangeFailureHandled(exchange.getContext(), exchange, processor, false, null);
} else {
[3/6] camel git commit: CAMEL-5398: Optimize String.replaceAll with
helper method which is faster as not using regexp.
Posted by da...@apache.org.
CAMEL-5398: Optimize String.replaceAll with helper method which is faster as not using regexp.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/161ee7ed
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/161ee7ed
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/161ee7ed
Branch: refs/heads/master
Commit: 161ee7ed0c2ec1456e4b695d75e2bafbe778f45d
Parents: e218337
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Mar 25 10:33:38 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Mar 25 11:25:10 2015 +0100
----------------------------------------------------------------------
.../main/java/org/apache/camel/util/EndpointHelper.java | 2 +-
.../java/org/apache/camel/util/IntrospectionSupport.java | 3 ++-
.../src/main/java/org/apache/camel/util/StringHelper.java | 10 +++++++---
.../src/main/java/org/apache/camel/util/URISupport.java | 3 ++-
4 files changed, 12 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/161ee7ed/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java b/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
index 18181b3..0fd0dac 100644
--- a/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
@@ -318,7 +318,7 @@ public final class EndpointHelper {
* <code>mandatory</code> is <code>true</code>.
*/
public static <T> T resolveReferenceParameter(CamelContext context, String value, Class<T> type, boolean mandatory) {
- String valueNoHash = value.replaceAll("#", "");
+ String valueNoHash = StringHelper.replaceAll(value, "#", "");
if (mandatory) {
return CamelContextHelper.mandatoryLookup(context, valueNoHash, type);
} else {
http://git-wip-us.apache.org/repos/asf/camel/blob/161ee7ed/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java b/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
index 98caa8e..d04c310 100755
--- a/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
+++ b/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
@@ -497,7 +497,8 @@ public final class IntrospectionSupport {
Object ref = value;
// try and lookup the reference based on the method
if (context != null && refName != null && ref == null) {
- ref = CamelContextHelper.lookup(context, refName.replaceAll("#", ""));
+ String s = StringHelper.replaceAll(refName, "#", "");
+ ref = CamelContextHelper.lookup(context, s);
if (ref == null) {
// try the next method if nothing was found
continue;
http://git-wip-us.apache.org/repos/asf/camel/blob/161ee7ed/camel-core/src/main/java/org/apache/camel/util/StringHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/StringHelper.java b/camel-core/src/main/java/org/apache/camel/util/StringHelper.java
index 6b81015..e68b8bf 100644
--- a/camel-core/src/main/java/org/apache/camel/util/StringHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/StringHelper.java
@@ -73,8 +73,8 @@ public final class StringHelper {
return s;
}
- s = s.replaceAll("'", "");
- s = s.replaceAll("\"", "");
+ s = replaceAll(s, "'", "");
+ s = replaceAll(s, "\"", "");
return s;
}
@@ -121,7 +121,11 @@ public final class StringHelper {
return "";
}
// must replace amp first, so we dont replace < to amp later
- return text.replaceAll("&", "&").replaceAll("\"", """).replaceAll("<", "<").replaceAll(">", ">");
+ text = replaceAll(text, "&", "&");
+ text = replaceAll(text, "\"", """);
+ text = replaceAll(text, "<", "<");
+ text = replaceAll(text, ">", ">");
+ return text;
}
/**
http://git-wip-us.apache.org/repos/asf/camel/blob/161ee7ed/camel-core/src/main/java/org/apache/camel/util/URISupport.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/URISupport.java b/camel-core/src/main/java/org/apache/camel/util/URISupport.java
index 5962247..02d3447 100644
--- a/camel-core/src/main/java/org/apache/camel/util/URISupport.java
+++ b/camel-core/src/main/java/org/apache/camel/util/URISupport.java
@@ -258,7 +258,8 @@ public final class URISupport {
name = URLDecoder.decode(name, CHARSET);
if (!isRaw) {
// need to replace % with %25
- value = URLDecoder.decode(value.replaceAll("%", "%25"), CHARSET);
+ String s = StringHelper.replaceAll(value, "%", "%25");
+ value = URLDecoder.decode(s, CHARSET);
}
// does the key already exist?
[2/6] camel git commit: CAMEL-5452: DoCatch now also emits the
failure handled event
Posted by da...@apache.org.
CAMEL-5452: DoCatch now also emits the failure handled event
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e2183378
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e2183378
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e2183378
Branch: refs/heads/master
Commit: e2183378b12c13707600816339442737778b364e
Parents: f078028
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Mar 25 10:24:08 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Mar 25 11:25:10 2015 +0100
----------------------------------------------------------------------
.../event/ExchangeFailureHandledEvent.java | 2 +
.../apache/camel/processor/CatchProcessor.java | 7 ++-
.../java/org/apache/camel/spi/EventFactory.java | 2 +-
.../EventNotifierFailureHandledEventsTest.java | 45 ++++++++++++++++++++
4 files changed, 54 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/e2183378/camel-core/src/main/java/org/apache/camel/management/event/ExchangeFailureHandledEvent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/event/ExchangeFailureHandledEvent.java b/camel-core/src/main/java/org/apache/camel/management/event/ExchangeFailureHandledEvent.java
index 2c0dd7d..4aeae2c 100644
--- a/camel-core/src/main/java/org/apache/camel/management/event/ExchangeFailureHandledEvent.java
+++ b/camel-core/src/main/java/org/apache/camel/management/event/ExchangeFailureHandledEvent.java
@@ -55,6 +55,8 @@ public class ExchangeFailureHandledEvent extends AbstractExchangeEvent {
return handled;
}
+ public boolean isContinued() { return !handled; }
+
@Override
public String toString() {
if (isDeadLetterChannel()) {
http://git-wip-us.apache.org/repos/asf/camel/blob/e2183378/camel-core/src/main/java/org/apache/camel/processor/CatchProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/CatchProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/CatchProcessor.java
index 063a776..f30954d 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/CatchProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/CatchProcessor.java
@@ -24,6 +24,7 @@ import org.apache.camel.Predicate;
import org.apache.camel.Processor;
import org.apache.camel.Traceable;
import org.apache.camel.spi.IdAware;
+import org.apache.camel.util.EventHelper;
import org.apache.camel.util.ExchangeHelper;
import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
@@ -100,7 +101,11 @@ public class CatchProcessor extends DelegateAsyncProcessor implements Traceable,
boolean sync = processor.process(exchange, new AsyncCallback() {
public void done(boolean doneSync) {
- if (!handled) {
+ if (handled) {
+ ExchangeHelper.setFailureHandled(exchange);
+ // emit event that the failure was handled
+ EventHelper.notifyExchangeFailureHandled(exchange.getContext(), exchange, processor, false, null);
+ } else {
if (exchange.getException() == null) {
exchange.setException(exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class));
}
http://git-wip-us.apache.org/repos/asf/camel/blob/e2183378/camel-core/src/main/java/org/apache/camel/spi/EventFactory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/EventFactory.java b/camel-core/src/main/java/org/apache/camel/spi/EventFactory.java
index 25c9578..e42d178 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/EventFactory.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/EventFactory.java
@@ -161,7 +161,7 @@ public interface EventFactory {
/**
* Creates an {@link EventObject} when an {@link org.apache.camel.Exchange} has failed
- * but was handled by the Camel error handlers such as an dead letter channel.
+ * but was handled by the Camel error handlers such as an dead letter channel, or a doTry .. doCatch block.
*
* @param exchange the exchange
* @param failureHandler the failure handler such as moving the message to a dead letter queue
http://git-wip-us.apache.org/repos/asf/camel/blob/e2183378/camel-core/src/test/java/org/apache/camel/management/EventNotifierFailureHandledEventsTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/EventNotifierFailureHandledEventsTest.java b/camel-core/src/test/java/org/apache/camel/management/EventNotifierFailureHandledEventsTest.java
index f7db679..0b2e313 100644
--- a/camel-core/src/test/java/org/apache/camel/management/EventNotifierFailureHandledEventsTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/EventNotifierFailureHandledEventsTest.java
@@ -104,6 +104,8 @@ public class EventNotifierFailureHandledEventsTest extends ContextTestSupport {
ExchangeFailureHandledEvent e = assertIsInstanceOf(ExchangeFailureHandledEvent.class, events.get(8));
assertEquals("should be DLC", true, e.isDeadLetterChannel());
+ assertTrue("should be marked as failure handled", e.isHandled());
+ assertFalse("should not be continued", e.isContinued());
SendProcessor send = assertIsInstanceOf(SendProcessor.class, e.getFailureHandler());
assertEquals("mock://dead", send.getDestination().getEndpointUri());
assertEquals("mock://dead", e.getDeadLetterUri());
@@ -143,6 +145,49 @@ public class EventNotifierFailureHandledEventsTest extends ContextTestSupport {
ExchangeFailureHandledEvent e = assertIsInstanceOf(ExchangeFailureHandledEvent.class, events.get(8));
assertEquals("should NOT be DLC", false, e.isDeadLetterChannel());
+ assertTrue("should be marked as failure handled", e.isHandled());
+ assertFalse("should not be continued", e.isContinued());
+
+ // onException will handle the exception
+ assertIsInstanceOf(ExchangeCompletedEvent.class, events.get(9));
+ // and the last event should be the direct:start
+ assertIsInstanceOf(ExchangeSentEvent.class, events.get(10));
+ ExchangeSentEvent sent = (ExchangeSentEvent) events.get(10);
+ assertEquals("direct://start", sent.getEndpoint().getEndpointUri());
+ }
+
+ public void testExchangeDoTryDoCatch() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .doTry()
+ .throwException(new IllegalArgumentException("Damn"))
+ .doCatch(IllegalArgumentException.class)
+ .to("mock:dead")
+ .end();
+ }
+ });
+ context.start();
+
+ getMockEndpoint("mock:dead").expectedMessageCount(1);
+ template.sendBody("direct:start", "Hello World");
+ assertMockEndpointsSatisfied();
+
+ assertEquals(11, events.size());
+ assertIsInstanceOf(CamelContextStartingEvent.class, events.get(0));
+ assertIsInstanceOf(RouteAddedEvent.class, events.get(1));
+ assertIsInstanceOf(RouteStartedEvent.class, events.get(2));
+ assertIsInstanceOf(CamelContextStartedEvent.class, events.get(3));
+ assertIsInstanceOf(ExchangeSendingEvent.class, events.get(4));
+ assertIsInstanceOf(ExchangeCreatedEvent.class, events.get(5));
+ assertIsInstanceOf(ExchangeSendingEvent.class, events.get(6));
+ assertIsInstanceOf(ExchangeSentEvent.class, events.get(7));
+
+ ExchangeFailureHandledEvent e = assertIsInstanceOf(ExchangeFailureHandledEvent.class, events.get(8));
+ assertEquals("should NOT be DLC", false, e.isDeadLetterChannel());
+ assertFalse("should not be marked as failure handled as it was continued instead", e.isHandled());
+ assertTrue("should be continued", e.isContinued());
// onException will handle the exception
assertIsInstanceOf(ExchangeCompletedEvent.class, events.get(9));
[6/6] camel git commit: CAMEL-5398: Optimize String.replaceAll with
helper method which is faster as not using regexp.
Posted by da...@apache.org.
CAMEL-5398: Optimize String.replaceAll with helper method which is faster as not using regexp.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3e112488
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3e112488
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3e112488
Branch: refs/heads/camel-2.15.x
Commit: 3e112488b2f986a02ba723410e39434ec8b25e41
Parents: 5b80cce
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Mar 25 10:33:38 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Mar 25 11:25:45 2015 +0100
----------------------------------------------------------------------
.../main/java/org/apache/camel/util/EndpointHelper.java | 2 +-
.../java/org/apache/camel/util/IntrospectionSupport.java | 3 ++-
.../src/main/java/org/apache/camel/util/StringHelper.java | 10 +++++++---
.../src/main/java/org/apache/camel/util/URISupport.java | 3 ++-
4 files changed, 12 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/3e112488/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java b/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
index 18181b3..0fd0dac 100644
--- a/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
@@ -318,7 +318,7 @@ public final class EndpointHelper {
* <code>mandatory</code> is <code>true</code>.
*/
public static <T> T resolveReferenceParameter(CamelContext context, String value, Class<T> type, boolean mandatory) {
- String valueNoHash = value.replaceAll("#", "");
+ String valueNoHash = StringHelper.replaceAll(value, "#", "");
if (mandatory) {
return CamelContextHelper.mandatoryLookup(context, valueNoHash, type);
} else {
http://git-wip-us.apache.org/repos/asf/camel/blob/3e112488/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java b/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
index 98caa8e..d04c310 100755
--- a/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
+++ b/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
@@ -497,7 +497,8 @@ public final class IntrospectionSupport {
Object ref = value;
// try and lookup the reference based on the method
if (context != null && refName != null && ref == null) {
- ref = CamelContextHelper.lookup(context, refName.replaceAll("#", ""));
+ String s = StringHelper.replaceAll(refName, "#", "");
+ ref = CamelContextHelper.lookup(context, s);
if (ref == null) {
// try the next method if nothing was found
continue;
http://git-wip-us.apache.org/repos/asf/camel/blob/3e112488/camel-core/src/main/java/org/apache/camel/util/StringHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/StringHelper.java b/camel-core/src/main/java/org/apache/camel/util/StringHelper.java
index 6b81015..e68b8bf 100644
--- a/camel-core/src/main/java/org/apache/camel/util/StringHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/StringHelper.java
@@ -73,8 +73,8 @@ public final class StringHelper {
return s;
}
- s = s.replaceAll("'", "");
- s = s.replaceAll("\"", "");
+ s = replaceAll(s, "'", "");
+ s = replaceAll(s, "\"", "");
return s;
}
@@ -121,7 +121,11 @@ public final class StringHelper {
return "";
}
// must replace amp first, so we dont replace < to amp later
- return text.replaceAll("&", "&").replaceAll("\"", """).replaceAll("<", "<").replaceAll(">", ">");
+ text = replaceAll(text, "&", "&");
+ text = replaceAll(text, "\"", """);
+ text = replaceAll(text, "<", "<");
+ text = replaceAll(text, ">", ">");
+ return text;
}
/**
http://git-wip-us.apache.org/repos/asf/camel/blob/3e112488/camel-core/src/main/java/org/apache/camel/util/URISupport.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/URISupport.java b/camel-core/src/main/java/org/apache/camel/util/URISupport.java
index 5962247..02d3447 100644
--- a/camel-core/src/main/java/org/apache/camel/util/URISupport.java
+++ b/camel-core/src/main/java/org/apache/camel/util/URISupport.java
@@ -258,7 +258,8 @@ public final class URISupport {
name = URLDecoder.decode(name, CHARSET);
if (!isRaw) {
// need to replace % with %25
- value = URLDecoder.decode(value.replaceAll("%", "%25"), CHARSET);
+ String s = StringHelper.replaceAll(value, "%", "%25");
+ value = URLDecoder.decode(s, CHARSET);
}
// does the key already exist?