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 0dd4512 CAMEL-13525: Only allow setting routeId once per route in
Java DSL
0dd4512 is described below
commit 0dd4512bcdf0cb418191742a8907ac95dab9c50e
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Jun 6 15:31:39 2019 +0200
CAMEL-13525: Only allow setting routeId once per route in Java DSL
---
.../apache/camel/model/ProcessorDefinition.java | 3 ++
.../org/apache/camel/model/RouteDefinition.java | 3 ++
.../camel/impl/RouteSetRouteIdTwoTimesTest.java | 46 ++++++++++++++++++++++
3 files changed, 52 insertions(+)
diff --git
a/core/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
b/core/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index 37ea037..78ae6f0 100644
---
a/core/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++
b/core/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -694,6 +694,9 @@ public abstract class ProcessorDefinition<Type extends
ProcessorDefinition<Type>
RouteDefinition route = ProcessorDefinitionHelper.getRoute(def);
if (route != null) {
+ if (route.hasCustomIdAssigned()) {
+ throw new IllegalArgumentException("You can only set routeId
one time per route.");
+ }
route.setId(id);
}
diff --git
a/core/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
b/core/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
index c1b4305..3617ead 100644
--- a/core/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
+++ b/core/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
@@ -197,6 +197,9 @@ public class RouteDefinition extends
ProcessorDefinition<RouteDefinition> {
* @return the builder
*/
public RouteDefinition routeId(String id) {
+ if (hasCustomIdAssigned()) {
+ throw new IllegalArgumentException("You can only set routeId one
time per route.");
+ }
setId(id);
return this;
}
diff --git
a/core/camel-core/src/test/java/org/apache/camel/impl/RouteSetRouteIdTwoTimesTest.java
b/core/camel-core/src/test/java/org/apache/camel/impl/RouteSetRouteIdTwoTimesTest.java
new file mode 100644
index 0000000..7feea89
--- /dev/null
+++
b/core/camel-core/src/test/java/org/apache/camel/impl/RouteSetRouteIdTwoTimesTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.impl;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.TestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class RouteSetRouteIdTwoTimesTest extends TestSupport {
+
+ @Test
+ public void testRouteIdTwice() throws Exception {
+ CamelContext context = new DefaultCamelContext();
+ try {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:hello").routeId("foo")
+ .to("mock:result")
+ .to("mock:bar").routeId("bar");
+ }
+ });
+ fail("Should have thrown exception");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+}