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 2016/08/30 10:01:02 UTC
camel git commit: Fixed potential NPE in fluent producer template if
no endpoint was configured
Repository: camel
Updated Branches:
refs/heads/master 1c70401e9 -> 3a26b7ba6
Fixed potential NPE in fluent producer template if no endpoint was configured
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3a26b7ba
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3a26b7ba
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3a26b7ba
Branch: refs/heads/master
Commit: 3a26b7ba66c14b897b29dc019e2e9586b61eedc9
Parents: 1c70401
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Aug 30 12:00:53 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Aug 30 12:00:53 2016 +0200
----------------------------------------------------------------------
.../builder/DefaultFluentProducerTemplate.java | 22 ++++++++++++++++++++
.../builder/FluentProducerTemplateTest.java | 18 ++++++++++++++++
2 files changed, 40 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/3a26b7ba/camel-core/src/main/java/org/apache/camel/builder/DefaultFluentProducerTemplate.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/DefaultFluentProducerTemplate.java b/camel-core/src/main/java/org/apache/camel/builder/DefaultFluentProducerTemplate.java
index 283e991..bac078e 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/DefaultFluentProducerTemplate.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/DefaultFluentProducerTemplate.java
@@ -219,6 +219,10 @@ public class DefaultFluentProducerTemplate extends ServiceSupport implements Flu
public <T> T request(Class<T> type) throws CamelExecutionException {
T result;
Endpoint target = endpoint != null ? endpoint : defaultEndpoint;
+ // we must have an endpoint to send to
+ if (target == null) {
+ throw new IllegalArgumentException("No endpoint configured on FluentProducerTemplate. You can configure an endpoint with to(uri)");
+ }
if (type == Exchange.class) {
result = (T)template().request(target, processorSupplier.get());
@@ -250,6 +254,12 @@ public class DefaultFluentProducerTemplate extends ServiceSupport implements Flu
@Override
public <T> Future<T> asyncRequest(Class<T> type) {
Endpoint target = endpoint != null ? endpoint : defaultEndpoint;
+
+ // we must have an endpoint to send to
+ if (target == null) {
+ throw new IllegalArgumentException("No endpoint configured on FluentProducerTemplate. You can configure an endpoint with to(uri)");
+ }
+
Future<T> result;
if (headers != null) {
result = template().asyncRequestBodyAndHeaders(target, body, headers, type);
@@ -267,6 +277,12 @@ public class DefaultFluentProducerTemplate extends ServiceSupport implements Flu
@Override
public Exchange send() throws CamelExecutionException {
Endpoint target = endpoint != null ? endpoint : defaultEndpoint;
+
+ // we must have an endpoint to send to
+ if (target == null) {
+ throw new IllegalArgumentException("No endpoint configured on FluentProducerTemplate. You can configure an endpoint with to(uri)");
+ }
+
return exchangeSupplier != null
? template().send(target, exchangeSupplier.get())
: template().send(target, processorSupplier.get());
@@ -275,6 +291,12 @@ public class DefaultFluentProducerTemplate extends ServiceSupport implements Flu
@Override
public Future<Exchange> asyncSend() {
Endpoint target = endpoint != null ? endpoint : defaultEndpoint;
+
+ // we must have an endpoint to send to
+ if (target == null) {
+ throw new IllegalArgumentException("No endpoint configured on FluentProducerTemplate. You can configure an endpoint with to(uri)");
+ }
+
return exchangeSupplier != null
? template().asyncSend(target, exchangeSupplier.get())
: template().asyncSend(target, processorSupplier.get());
http://git-wip-us.apache.org/repos/asf/camel/blob/3a26b7ba/camel-core/src/test/java/org/apache/camel/builder/FluentProducerTemplateTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/builder/FluentProducerTemplateTest.java b/camel-core/src/test/java/org/apache/camel/builder/FluentProducerTemplateTest.java
index 412e08d..4308fc6 100644
--- a/camel-core/src/test/java/org/apache/camel/builder/FluentProducerTemplateTest.java
+++ b/camel-core/src/test/java/org/apache/camel/builder/FluentProducerTemplateTest.java
@@ -29,6 +29,24 @@ import org.apache.camel.component.mock.MockEndpoint;
*/
public class FluentProducerTemplateTest extends ContextTestSupport {
+ public void testNoEndpoint() throws Exception {
+ FluentProducerTemplate fluent = context.createFluentProducerTemplate();
+
+ try {
+ fluent.withBody("Hello World").send();
+ fail("Should have thrown exception");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ try {
+ fluent.withBody("Hello World").request();
+ fail("Should have thrown exception");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
public void testFromCamelContext() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Bye World");