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/07/05 14:19:37 UTC

[camel] branch master updated: CAMEL-12571: Seda component fixed to fail if configured blockWhenFull option twice.

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new f6a75cf  CAMEL-12571: Seda component fixed to fail if configured blockWhenFull option twice.
f6a75cf is described below

commit f6a75cf7f8428a45885009dbf39618777b71e449
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Jul 5 16:19:18 2018 +0200

    CAMEL-12571: Seda component fixed to fail if configured blockWhenFull option twice.
---
 .../apache/camel/component/seda/SedaComponent.java |  2 +-
 .../org/apache/camel/impl/DefaultComponent.java    |  7 +++-
 .../SedaBlockWhenFullInvalidConfigurationTest.java | 48 ++++++++++++++++++++++
 3 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/camel-core/src/main/java/org/apache/camel/component/seda/SedaComponent.java b/camel-core/src/main/java/org/apache/camel/component/seda/SedaComponent.java
index 2ed80a2..d5697ad 100644
--- a/camel-core/src/main/java/org/apache/camel/component/seda/SedaComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/seda/SedaComponent.java
@@ -223,7 +223,7 @@ public class SedaComponent extends UriEndpointComponent {
         }
 
         // if blockWhenFull is set on endpoint, defaultBlockWhenFull is ignored.
-        boolean blockWhenFull = getAndRemoveParameter(parameters, "blockWhenFull", boolean.class, defaultBlockWhenFull);
+        boolean blockWhenFull = getAndRemoveParameter(parameters, "blockWhenFull", Boolean.class, defaultBlockWhenFull);
         // if offerTimeout is set on endpoint, defaultOfferTimeout is ignored.
         long offerTimeout = getAndRemoveParameter(parameters, "offerTimeout", long.class, defaultOfferTimeout);
         
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
index 8acd2e8..730d186 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
@@ -344,14 +344,17 @@ public abstract class DefaultComponent extends ServiceSupport implements Compone
      */
     public <T> T getAndRemoveParameter(Map<String, Object> parameters, String key, Class<T> type, T defaultValue) {
         Object value = parameters.remove(key);
-        if (value == null) {
+        if (value != null) {
+            // if we have a value then convert it
+            return CamelContextHelper.mandatoryConvertTo(getCamelContext(), type, value);
+        } else {
             value = defaultValue;
         }
         if (value == null) {
             return null;
         }
 
-        return CamelContextHelper.convertTo(getCamelContext(), type, value);
+        return CamelContextHelper.mandatoryConvertTo(getCamelContext(), type, value);
     }
 
     /**
diff --git a/camel-core/src/test/java/org/apache/camel/component/seda/SedaBlockWhenFullInvalidConfigurationTest.java b/camel-core/src/test/java/org/apache/camel/component/seda/SedaBlockWhenFullInvalidConfigurationTest.java
new file mode 100644
index 0000000..53b3258
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/seda/SedaBlockWhenFullInvalidConfigurationTest.java
@@ -0,0 +1,48 @@
+/**
+ * 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.component.seda;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.FailedToCreateRouteException;
+import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.builder.RouteBuilder;
+
+public class SedaBlockWhenFullInvalidConfigurationTest extends ContextTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    public void testInvalidConfiguration() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .to("seda:foo?blockWhenFull=true&blockWhenFull=true");
+            }
+        });
+        try {
+            context.start();
+            fail("Should fail");
+        } catch (FailedToCreateRouteException e) {
+            ResolveEndpointFailedException refe = assertIsInstanceOf(ResolveEndpointFailedException.class, e.getCause());
+            assertEquals("Value [true, true] converted to java.lang.Boolean cannot be null", refe.getCause().getMessage());
+        }
+
+    }
+}