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 2020/10/22 08:03:55 UTC
[camel] 01/02: CAMEL-15733: camel-core - ToD remove multi language
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
commit a685c46bbfecd5d8a8f78fcd044acf6652eed690
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Oct 22 10:00:12 2020 +0200
CAMEL-15733: camel-core - ToD remove multi language
---
...DynamicLanguageSimpleAndXPathAndHeaderTest.java | 32 --------
.../SpringToDynamicLanguageSimpleAndXPathTest.java | 32 --------
...oDynamicLanguageSimpleAndXPathAndHeaderTest.xml | 36 ---------
.../SpringToDynamicLanguageSimpleAndXPathTest.xml | 36 ---------
.../src/main/docs/modules/eips/pages/toD-eip.adoc | 32 +-------
.../org/apache/camel/reifier/ToDynamicReifier.java | 88 ++--------------------
...DynamicLanguageSimpleAndXPathAndHeaderTest.java | 45 -----------
.../ToDynamicLanguageSimpleAndXPathTest.java | 45 -----------
.../camel/processor/ToDynamicRawAndXPathTest.java | 45 -----------
.../ROOT/pages/camel-3x-upgrade-guide-3_7.adoc | 5 ++
10 files changed, 16 insertions(+), 380 deletions(-)
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringToDynamicLanguageSimpleAndXPathAndHeaderTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringToDynamicLanguageSimpleAndXPathAndHeaderTest.java
deleted file mode 100644
index 2d5aa1e..0000000
--- a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringToDynamicLanguageSimpleAndXPathAndHeaderTest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.spring.processor;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.processor.ToDynamicLanguageSimpleAndXPathAndHeaderTest;
-
-import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
-
-public class SpringToDynamicLanguageSimpleAndXPathAndHeaderTest extends ToDynamicLanguageSimpleAndXPathAndHeaderTest {
-
- @Override
- protected CamelContext createCamelContext() throws Exception {
- return createSpringCamelContext(this,
- "org/apache/camel/spring/processor/SpringToDynamicLanguageSimpleAndXPathAndHeaderTest.xml");
- }
-
-}
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringToDynamicLanguageSimpleAndXPathTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringToDynamicLanguageSimpleAndXPathTest.java
deleted file mode 100644
index a854208..0000000
--- a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringToDynamicLanguageSimpleAndXPathTest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.spring.processor;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.processor.ToDynamicLanguageSimpleAndXPathTest;
-
-import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
-
-public class SpringToDynamicLanguageSimpleAndXPathTest extends ToDynamicLanguageSimpleAndXPathTest {
-
- @Override
- protected CamelContext createCamelContext() throws Exception {
- return createSpringCamelContext(this,
- "org/apache/camel/spring/processor/SpringToDynamicLanguageSimpleAndXPathTest.xml");
- }
-
-}
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringToDynamicLanguageSimpleAndXPathAndHeaderTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringToDynamicLanguageSimpleAndXPathAndHeaderTest.xml
deleted file mode 100644
index 6876e41..0000000
--- a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringToDynamicLanguageSimpleAndXPathAndHeaderTest.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- 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.
-
--->
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
- ">
-
- <!-- START SNIPPET: e1 -->
- <camelContext xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="direct:start"/>
- <toD uri="mock:+language:xpath:/order/@uri+language:header:sub"/>
- </route>
- </camelContext>
- <!-- END SNIPPET: e1 -->
-
-</beans>
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringToDynamicLanguageSimpleAndXPathTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringToDynamicLanguageSimpleAndXPathTest.xml
deleted file mode 100644
index 70479d3..0000000
--- a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringToDynamicLanguageSimpleAndXPathTest.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- 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.
-
--->
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
- ">
-
- <!-- START SNIPPET: e1 -->
- <camelContext xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="direct:start"/>
- <toD uri="mock:+language:xpath:/order/@uri"/>
- </route>
- </camelContext>
- <!-- END SNIPPET: e1 -->
-
-</beans>
diff --git a/core/camel-core-engine/src/main/docs/modules/eips/pages/toD-eip.adoc b/core/camel-core-engine/src/main/docs/modules/eips/pages/toD-eip.adoc
index 6979ed9..54997f8 100644
--- a/core/camel-core-engine/src/main/docs/modules/eips/pages/toD-eip.adoc
+++ b/core/camel-core-engine/src/main/docs/modules/eips/pages/toD-eip.adoc
@@ -1,7 +1,7 @@
[[toD-eip]]
= To D EIP
:docTitle: To D
-:description: Sends the message to a dynamic endpoint You can specify multiple languages in the uri separated by the plus sign, such as mock:language:xpath:/order/uri where mock: would be a prefix to a xpath expression. For more dynamic behavior use Recipient List or Dynamic Router EIP instead.
+:description: Sends the message to a single dynamic endpoint. For more dynamic behavior use Recipient List or Dynamic Router EIP instead.
:since:
:supportLevel: Stable
@@ -72,7 +72,7 @@ In the example above we compute an endpoint that has prefix "mock:" and
then the header foo is appended. So for example if the header foo has
value order, then the endpoint is computed as "mock:order".
-You can also use other languages than xref:components:languages:simple-language.adoc[Simple] such
+You can also use another language than xref:components:languages:simple-language.adoc[Simple] such
as xref:components:languages:xpath-language.adoc[XPath] - this requires to prefix with language: as
shown below (simple language is the default language). If you do not
specify language: then the endpoint is a component name. And in some
@@ -95,32 +95,6 @@ from("direct:start")
.toD("language:xpath:/order/@uri");
----
-You can also concat multiple xref:components::language-component.adoc[Language](s) together
-using the plus sign `+` such as shown below:
-
-[source,xml]
-----
-<route>
- <from uri="direct:start"/>
- <toD uri="jms:${header.base}+language:xpath:/order/@id"/>
-</route>
-----
-
-In the example above the uri is a combination
-of xref:components:languages:simple-language.adoc[Simple] language and xref:components:languages:simple-language.adoc[XPath] where
-the first part is simple (simple is default language). And then the plus
-sign separate to another language, where we specify the language name
-followed by a colon
-
-[source,java]
-----
-from("direct:start")
- .toD("jms:${header.base}+language:xpath:/order/@id");
-----
-
-You can concat as many languages as you want, just separate them with
-the plus sign
-
== Avoid creating endless dynamic endpoints which takes up resources
When using dynamic computed endpoints with `toD` then you may compute a lot of dynamic endpoints,
@@ -167,7 +141,7 @@ as documented next.
== Using optimised components
But a better solution would be if the HTTP component could be optimised to handle the variations of dynamic computed endpoint uris.
-This is with the following components, which have been optimised for `toD`:
+This is with among the following components, which have been optimised for `toD`:
- camel-http
- camel-jetty
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/reifier/ToDynamicReifier.java b/core/camel-core-engine/src/main/java/org/apache/camel/reifier/ToDynamicReifier.java
index 9861ef3..d68fb6f 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/reifier/ToDynamicReifier.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/reifier/ToDynamicReifier.java
@@ -16,22 +16,15 @@
*/
package org.apache.camel.reifier;
-import java.util.ArrayList;
-import java.util.List;
-
import org.apache.camel.ExchangePattern;
import org.apache.camel.Expression;
-import org.apache.camel.NoSuchLanguageException;
import org.apache.camel.Processor;
import org.apache.camel.Route;
-import org.apache.camel.builder.ExpressionBuilder;
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.model.ToDynamicDefinition;
import org.apache.camel.processor.SendDynamicProcessor;
import org.apache.camel.spi.Language;
-import org.apache.camel.util.Pair;
import org.apache.camel.util.StringHelper;
-import org.apache.camel.util.URISupport;
public class ToDynamicReifier<T extends ToDynamicDefinition> extends ProcessorReifier<T> {
@@ -70,84 +63,19 @@ public class ToDynamicReifier<T extends ToDynamicDefinition> extends ProcessorRe
}
protected Expression createExpression(String uri) {
- List<Expression> list = new ArrayList<>();
-
// make sure to parse property placeholders
uri = camelContext.resolvePropertyPlaceholders(uri);
- String[] parts = safeSplitRaw(uri);
- for (String part : parts) {
- // the part may have optional language to use, so you can mix
- // languages
- String value = StringHelper.after(part, "language:");
- if (value != null) {
- String before = StringHelper.before(value, ":");
- String after = StringHelper.after(value, ":");
- if (before != null && after != null) {
- // maybe its a language, must have language: as prefix
- try {
- Language partLanguage = camelContext.resolveLanguage(before);
- if (partLanguage != null) {
- Expression exp = partLanguage.createExpression(after);
- list.add(exp);
- continue;
- }
- } catch (NoSuchLanguageException e) {
- // ignore
- }
- }
- }
-
- // fallback and use simple language
- Language lan = camelContext.resolveLanguage("simple");
- Expression exp = lan.createExpression(part);
- list.add(exp);
- }
-
- Expression exp;
- if (list.size() == 1) {
- exp = list.get(0);
- } else {
- exp = ExpressionBuilder.concatExpression(list);
- }
-
- return exp;
- }
-
- // Utilities
- // -------------------------------------------------------------------------
-
- /**
- * We need to split the string safely for each + sign, but avoid splitting within RAW(...).
- */
- private static String[] safeSplitRaw(String s) {
- List<String> list = new ArrayList<>();
-
- if (!s.contains("+")) {
- // no plus sign so there is only one part, so no need to split
- list.add(s);
- } else {
- // there is a plus sign so we need to split in a safe manner
- List<Pair<Integer>> rawPairs = URISupport.scanRaw(s);
- StringBuilder sb = new StringBuilder();
- char[] chars = s.toCharArray();
- for (int i = 0; i < chars.length; i++) {
- char ch = chars[i];
- if (ch != '+' || URISupport.isRaw(i, rawPairs)) {
- sb.append(ch);
- } else {
- list.add(sb.toString());
- sb.setLength(0);
- }
- }
- // any leftover?
- if (sb.length() > 0) {
- list.add(sb.toString());
- sb.setLength(0);
- }
+ // we use simple language by default but you can configure a different language
+ String language = "simple";
+ if (uri.startsWith("language:")) {
+ String value = StringHelper.after(uri, "language:");
+ language = StringHelper.before(value, ":");
+ uri = StringHelper.after(value, ":");
}
- return list.toArray(new String[list.size()]);
+ Language lan = camelContext.resolveLanguage(language);
+ return lan.createExpression(uri);
}
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/ToDynamicLanguageSimpleAndXPathAndHeaderTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/ToDynamicLanguageSimpleAndXPathAndHeaderTest.java
deleted file mode 100644
index 793329f..0000000
--- a/core/camel-core/src/test/java/org/apache/camel/processor/ToDynamicLanguageSimpleAndXPathAndHeaderTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.processor;
-
-import org.apache.camel.ContextTestSupport;
-import org.apache.camel.builder.RouteBuilder;
-import org.junit.jupiter.api.Test;
-
-public class ToDynamicLanguageSimpleAndXPathAndHeaderTest extends ContextTestSupport {
-
- @Test
- public void testToDynamic() throws Exception {
- getMockEndpoint("mock:foo-123").expectedBodiesReceived("<order uri=\"foo\"/>");
- getMockEndpoint("mock:bar-456").expectedBodiesReceived("<order uri=\"bar\"/>");
-
- template.sendBodyAndHeader("direct:start", "<order uri=\"foo\"/>", "sub", "-123");
- template.sendBodyAndHeader("direct:start", "<order uri=\"bar\"/>", "sub", "-456");
-
- assertMockEndpointsSatisfied();
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- from("direct:start").toD("mock:+language:xpath:/order/@uri+language:header:sub");
- }
- };
- }
-}
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/ToDynamicLanguageSimpleAndXPathTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/ToDynamicLanguageSimpleAndXPathTest.java
deleted file mode 100644
index fde20aa..0000000
--- a/core/camel-core/src/test/java/org/apache/camel/processor/ToDynamicLanguageSimpleAndXPathTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.processor;
-
-import org.apache.camel.ContextTestSupport;
-import org.apache.camel.builder.RouteBuilder;
-import org.junit.jupiter.api.Test;
-
-public class ToDynamicLanguageSimpleAndXPathTest extends ContextTestSupport {
-
- @Test
- public void testToDynamic() throws Exception {
- getMockEndpoint("mock:foo").expectedBodiesReceived("<order uri=\"foo\"/>");
- getMockEndpoint("mock:bar").expectedBodiesReceived("<order uri=\"bar\"/>");
-
- template.sendBody("direct:start", "<order uri=\"foo\"/>");
- template.sendBody("direct:start", "<order uri=\"bar\"/>");
-
- assertMockEndpointsSatisfied();
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- from("direct:start").toD("mock:+language:xpath:/order/@uri");
- }
- };
- }
-}
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/ToDynamicRawAndXPathTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/ToDynamicRawAndXPathTest.java
deleted file mode 100644
index 880c927..0000000
--- a/core/camel-core/src/test/java/org/apache/camel/processor/ToDynamicRawAndXPathTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.processor;
-
-import org.apache.camel.ContextTestSupport;
-import org.apache.camel.builder.RouteBuilder;
-import org.junit.jupiter.api.Test;
-
-public class ToDynamicRawAndXPathTest extends ContextTestSupport {
-
- @Test
- public void testToDynamicRawAndPlus() throws Exception {
- getMockEndpoint("mock:RAW(se+ret)foo").expectedBodiesReceived("<order uri=\"foo\"/>");
- getMockEndpoint("mock:RAW(se+ret)bar").expectedBodiesReceived("<order uri=\"bar\"/>");
-
- template.sendBody("direct:start", "<order uri=\"foo\"/>");
- template.sendBody("direct:start", "<order uri=\"bar\"/>");
-
- assertMockEndpointsSatisfied();
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- from("direct:start").toD("mock:RAW(se+ret)+language:xpath:/order/@uri");
- }
- };
- }
-}
diff --git a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_7.adoc b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_7.adoc
index e3ca5d7..1233060 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_7.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_7.adoc
@@ -16,6 +16,11 @@ The class `org.apache.camel.impl.transformer.DataFormatTransformer` moved to `or
The class `org.apache.camel.impl.validator.ValidatorKey` moved to `org.apache.camel.impl.engine.ValidatorKey`.
The class `org.apache.camel.impl.transformer.TransformerKey` moved to `org.apache.camel.impl.engine.TransformerKey`.
+=== toD EIP
+
+Support for using multiple languages in the toD EIP has been removed as it was a rare feature in use, and is causing some
+problems for maintenance. toD uses simple language by default, but an alternative language can still be specified.
+
=== camel-couchbase
The original URI path has been changed, now the bucket part is simply a required option and it's not part of the URI anymore.