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 2018/03/12 16:37:28 UTC
[camel] branch camel-2.20.x updated: CAMEL-12348: camel-core -
Potential NPE in ExchangeHelper.isStreamCaching
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-2.20.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-2.20.x by this push:
new 7b1a6f8 CAMEL-12348: camel-core - Potential NPE in ExchangeHelper.isStreamCaching
7b1a6f8 is described below
commit 7b1a6f88e1272308b240752f16aacfa832975584
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Mar 12 17:36:28 2018 +0100
CAMEL-12348: camel-core - Potential NPE in ExchangeHelper.isStreamCaching
---
.../src/main/java/org/apache/camel/impl/DefaultCamelContext.java | 8 +++++---
.../src/main/java/org/apache/camel/util/ExchangeHelper.java | 8 +++++---
.../src/test/java/org/apache/camel/util/ExchangeHelperTest.java | 8 +++++++-
3 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 7ac8b82..02ba4b9 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -904,9 +904,11 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
}
public Route getRoute(String id) {
- for (Route route : getRoutes()) {
- if (route.getId().equals(id)) {
- return route;
+ if (id != null) {
+ for (Route route : getRoutes()) {
+ if (route.getId().equals(id)) {
+ return route;
+ }
}
}
return null;
diff --git a/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java b/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
index 3e6ecb6..cc35c68 100644
--- a/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
@@ -40,6 +40,7 @@ import org.apache.camel.NoSuchEndpointException;
import org.apache.camel.NoSuchHeaderException;
import org.apache.camel.NoSuchPropertyException;
import org.apache.camel.NoTypeConversionAvailableException;
+import org.apache.camel.Route;
import org.apache.camel.TypeConversionException;
import org.apache.camel.TypeConverter;
import org.apache.camel.impl.DefaultExchange;
@@ -687,10 +688,11 @@ public final class ExchangeHelper {
* @return <tt>true</tt> if enabled, <tt>false</tt> otherwise
*/
public static boolean isStreamCachingEnabled(final Exchange exchange) {
- if (exchange.getFromRouteId() == null) {
- return exchange.getContext().getStreamCachingStrategy().isEnabled();
+ Route route = exchange.getContext().getRoute(exchange.getFromRouteId());
+ if (route != null) {
+ return route.getRouteContext().isStreamCaching();
} else {
- return exchange.getContext().getRoute(exchange.getFromRouteId()).getRouteContext().isStreamCaching();
+ return exchange.getContext().getStreamCachingStrategy().isEnabled();
}
}
diff --git a/camel-core/src/test/java/org/apache/camel/util/ExchangeHelperTest.java b/camel-core/src/test/java/org/apache/camel/util/ExchangeHelperTest.java
index 5a2d4d8..ab6ebfb 100644
--- a/camel-core/src/test/java/org/apache/camel/util/ExchangeHelperTest.java
+++ b/camel-core/src/test/java/org/apache/camel/util/ExchangeHelperTest.java
@@ -177,11 +177,17 @@ public class ExchangeHelperTest extends ContextTestSupport {
assertEquals("text/xml", ExchangeHelper.getContentType(exchange));
}
- public void testGetContentEncpding() throws Exception {
+ public void testGetContentEncoding() throws Exception {
exchange.getIn().setHeader(Exchange.CONTENT_ENCODING, "iso-8859-1");
assertEquals("iso-8859-1", ExchangeHelper.getContentEncoding(exchange));
}
+ public void testIsStreamCaching() throws Exception {
+ assertFalse(ExchangeHelper.isStreamCachingEnabled(exchange));
+ exchange.getContext().getStreamCachingStrategy().setEnabled(true);
+ assertTrue(ExchangeHelper.isStreamCachingEnabled(exchange));
+ }
+
@Override
protected void setUp() throws Exception {
super.setUp();
--
To stop receiving notification emails like this one, please contact
davsclaus@apache.org.