You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2024/04/16 12:59:53 UTC
(camel) branch main updated (5a4421ab9f9 -> 08e6f734d6e)
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
from 5a4421ab9f9 CAMEL-20678: camel-google-sheets - Error setting scopes parameter (#13817)
new 793a8e8bd57 (chores) camel-core: removed unused operations in tests
new 0fbcc1e5a8b (chores) camel-core: cleaned up duplicated code
new 782c7e527cb (chores) camel-core: cleaned up duplicated code dealing with variable repositories
new 672316de1c0 (chores) camel-core: separate setup from test execution
new 08e6f734d6e (chores) camel-core: removed unused operations in tests
The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../apache/camel/impl/debugger/BacklogTracer.java | 12 +--
.../impl/converter/BaseTypeConverterRegistry.java | 16 ++-
.../camel/catalog/impl/AbstractCamelCatalog.java | 54 +++++------
.../aggregate/AggregationStrategyBeanInfo.java | 59 +++++-------
.../core/xml/AbstractCamelContextFactoryBean.java | 38 ++++----
...eOriginalMessageEndpointExceptionIssueTest.java | 16 +--
.../org/apache/camel/support/ExchangeHelper.java | 107 ++++++++++-----------
.../support/RestConsumerContextPathMatcher.java | 45 +++------
.../component/ApiMethodPropertiesHelper.java | 36 +++----
.../java/org/apache/camel/util/StringHelper.java | 18 +++-
.../java/org/apache/camel/xml/in/BaseParser.java | 38 +++-----
11 files changed, 194 insertions(+), 245 deletions(-)
(camel) 05/05: (chores) camel-core: removed unused operations in tests
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 08e6f734d6e9bff05b1a09178d760959c6ee67b4
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Apr 16 12:01:10 2024 +0200
(chores) camel-core: removed unused operations in tests
---
.../org/apache/camel/core/xml/AbstractCamelContextFactoryBeanTest.java | 1 -
1 file changed, 1 deletion(-)
diff --git a/core/camel-core-xml/src/test/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBeanTest.java b/core/camel-core-xml/src/test/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBeanTest.java
index eb25d91155a..d5ea5f4e382 100644
--- a/core/camel-core-xml/src/test/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBeanTest.java
+++ b/core/camel-core-xml/src/test/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBeanTest.java
@@ -43,7 +43,6 @@ import org.mockito.ArgumentCaptor;
import static java.util.Arrays.asList;
import static java.util.Arrays.stream;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.atLeastOnce;
(camel) 04/05: (chores) camel-core: separate setup from test execution
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 672316de1c0a9502d6799fa85d86da41b4333e78
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Mon Apr 15 17:50:01 2024 +0200
(chores) camel-core: separate setup from test execution
---
...ListUseOriginalMessageEndpointExceptionIssueTest.java | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/core/camel-core/src/test/java/org/apache/camel/issues/RecipientListUseOriginalMessageEndpointExceptionIssueTest.java b/core/camel-core/src/test/java/org/apache/camel/issues/RecipientListUseOriginalMessageEndpointExceptionIssueTest.java
index 74f06eacff6..f1d2caa98c5 100644
--- a/core/camel-core/src/test/java/org/apache/camel/issues/RecipientListUseOriginalMessageEndpointExceptionIssueTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/issues/RecipientListUseOriginalMessageEndpointExceptionIssueTest.java
@@ -20,8 +20,8 @@ import java.util.concurrent.TimeUnit;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
@@ -29,18 +29,18 @@ import org.junit.jupiter.api.Test;
*/
public class RecipientListUseOriginalMessageEndpointExceptionIssueTest extends ContextTestSupport {
- @Test
- public void testRecipientListUseOriginalMessageIssue() throws Exception {
- getMockEndpoint("mock:throwException").whenAnyExchangeReceived(new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- throw new Exception("Exception raised");
- }
+ @BeforeEach
+ void setupMocks() {
+ getMockEndpoint("mock:throwException").whenAnyExchangeReceived(exchange -> {
+ throw new Exception("Exception raised");
});
getMockEndpoint("mock:error").expectedMinimumMessageCount(1);
getMockEndpoint("mock:error").expectedFileExists(
testFile("outbox/hello.txt"), "A");
+ }
+ @Test
+ public void testRecipientListUseOriginalMessageIssue() throws Exception {
template.sendBodyAndHeader(fileUri("inbox"), "A",
Exchange.FILE_NAME, "hello.txt");
(camel) 03/05: (chores) camel-core: cleaned up duplicated code dealing with variable repositories
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 782c7e527cbb339c1c7caaa29cc535cfade4f25a
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Mon Apr 15 13:46:55 2024 +0200
(chores) camel-core: cleaned up duplicated code dealing with variable repositories
---
.../org/apache/camel/support/ExchangeHelper.java | 107 ++++++++++-----------
1 file changed, 50 insertions(+), 57 deletions(-)
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java
index a73db916db9..88674c95fa6 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java
@@ -1088,29 +1088,34 @@ public final class ExchangeHelper {
*/
public static void setVariable(Exchange exchange, String name, Object value) {
VariableRepository repo = null;
+ final String id = getRepositoryId(name);
+ if (id != null) {
+ repo = getVariableRepository(exchange, id);
+ name = resolveRepositoryName(exchange, name, id);
+ }
+ final VariableAware va = getVariableAware(exchange, repo);
+ va.setVariable(name, value);
+ }
+
+ private static String getRepositoryId(String name) {
String id = StringHelper.before(name, ":");
// header and exchange is reserved
- if ("header".equals(id) || "exchange".equals(id)) {
+ if (isReserved(id)) {
id = null;
}
- if (id != null) {
- VariableRepositoryFactory factory
- = exchange.getContext().getCamelContextExtension().getContextPlugin(VariableRepositoryFactory.class);
- repo = factory.getVariableRepository(id);
- if (repo == null) {
- throw new IllegalArgumentException("VariableRepository with id: " + id + " does not exist");
- }
- name = StringHelper.after(name, ":");
- // special for route, where we need to enrich the name with current route id if none given
- if ("route".equals(id) && !name.contains(":")) {
- String prefix = getAtRouteId(exchange);
- if (prefix != null) {
- name = prefix + ":" + name;
- }
+ return id;
+ }
+
+ private static String resolveRepositoryName(Exchange exchange, String name, String id) {
+ name = StringHelper.after(name, ":");
+ // special for route, where we need to enrich the name with current route id if none given
+ if ("route".equals(id) && !name.contains(":")) {
+ String prefix = getAtRouteId(exchange);
+ if (prefix != null) {
+ name = prefix + ":" + name;
}
}
- VariableAware va = repo != null ? repo : exchange;
- va.setVariable(name, value);
+ return name;
}
/**
@@ -1123,28 +1128,12 @@ public final class ExchangeHelper {
*/
public static void setVariableFromMessageBodyAndHeaders(Exchange exchange, String name, Message message) {
VariableRepository repo = null;
- String id = StringHelper.before(name, ":");
- // header and exchange is reserved
- if ("header".equals(id) || "exchange".equals(id)) {
- id = null;
- }
+ final String id = getRepositoryId(name);
if (id != null) {
- VariableRepositoryFactory factory
- = exchange.getContext().getCamelContextExtension().getContextPlugin(VariableRepositoryFactory.class);
- repo = factory.getVariableRepository(id);
- if (repo == null) {
- throw new IllegalArgumentException("VariableRepository with id: " + id + " does not exist");
- }
- name = StringHelper.after(name, ":");
- // special for route, where we need to enrich the name with current route id if none given
- if ("route".equals(id) && !name.contains(":")) {
- String prefix = getAtRouteId(exchange);
- if (prefix != null) {
- name = prefix + ":" + name;
- }
- }
+ repo = getVariableRepository(exchange, id);
+ name = resolveRepositoryName(exchange, name, id);
}
- VariableAware va = repo != null ? repo : exchange;
+ final VariableAware va = getVariableAware(exchange, repo);
// set body and headers as variables
Object body = message.getBody();
@@ -1189,31 +1178,35 @@ public final class ExchangeHelper {
*/
public static Object getVariable(Exchange exchange, String name) {
VariableRepository repo = null;
- String id = StringHelper.before(name, ":");
- // header and exchange is reserved
- if ("header".equals(id) || "exchange".equals(id)) {
- id = null;
- }
+ final String id = getRepositoryId(name);
if (id != null) {
- VariableRepositoryFactory factory
- = exchange.getContext().getCamelContextExtension().getContextPlugin(VariableRepositoryFactory.class);
- repo = factory.getVariableRepository(id);
- if (repo == null) {
- throw new IllegalArgumentException("VariableRepository with id: " + id + " does not exist");
- }
- name = StringHelper.after(name, ":");
- // special for route, where we need to enrich the name with current route id if none given
- if ("route".equals(id) && !name.contains(":")) {
- String prefix = getAtRouteId(exchange);
- if (prefix != null) {
- name = prefix + ":" + name;
- }
- }
+ repo = getVariableRepository(exchange, id);
+
+ name = resolveRepositoryName(exchange, name, id);
}
- VariableAware va = repo != null ? repo : exchange;
+ final VariableAware va = getVariableAware(exchange, repo);
return va.getVariable(name);
}
+ private static VariableRepository getVariableRepository(Exchange exchange, String id) {
+ VariableRepositoryFactory factory
+ = exchange.getContext().getCamelContextExtension().getContextPlugin(VariableRepositoryFactory.class);
+ VariableRepository repo = factory.getVariableRepository(id);
+ if (repo == null) {
+ throw new IllegalArgumentException("VariableRepository with id: " + id + " does not exist");
+ }
+ return repo;
+ }
+
+ private static boolean isReserved(String id) {
+ return "header".equals(id) || "exchange".equals(id);
+ }
+
+ private static VariableAware getVariableAware(Exchange exchange, VariableRepository repo) {
+ VariableAware va = repo != null ? repo : exchange;
+ return va;
+ }
+
/**
* Gets the variable, converted to the given type
*
(camel) 02/05: (chores) camel-core: cleaned up duplicated code
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 0fbcc1e5a8b2917fa11d31ee207b96329f0ef1a4
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Mon Apr 15 13:46:44 2024 +0200
(chores) camel-core: cleaned up duplicated code
---
.../apache/camel/impl/debugger/BacklogTracer.java | 12 ++---
.../impl/converter/BaseTypeConverterRegistry.java | 16 +++---
.../camel/catalog/impl/AbstractCamelCatalog.java | 54 +++++++++-----------
.../aggregate/AggregationStrategyBeanInfo.java | 59 +++++++++-------------
.../core/xml/AbstractCamelContextFactoryBean.java | 38 +++++++-------
.../support/RestConsumerContextPathMatcher.java | 45 ++++++-----------
.../component/ApiMethodPropertiesHelper.java | 36 ++++++-------
.../java/org/apache/camel/util/StringHelper.java | 18 +++++--
.../java/org/apache/camel/xml/in/BaseParser.java | 38 ++++++--------
9 files changed, 136 insertions(+), 180 deletions(-)
diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/debugger/BacklogTracer.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/debugger/BacklogTracer.java
index bc49984feef..000c36633f2 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/debugger/BacklogTracer.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/debugger/BacklogTracer.java
@@ -345,13 +345,7 @@ public final class BacklogTracer extends ServiceSupport implements org.apache.ca
public String dumpTracedMessagesAsXml(String nodeId) {
List<BacklogTracerEventMessage> events = dumpTracedMessages(nodeId);
- StringBuilder sb = new StringBuilder();
- sb.append("<").append(BacklogTracerEventMessage.ROOT_TAG).append("s>");
- for (BacklogTracerEventMessage event : events) {
- sb.append("\n").append(event.toXml(2));
- }
- sb.append("\n</").append(BacklogTracerEventMessage.ROOT_TAG).append("s>");
- return sb.toString();
+ return wrapAroundRootTag(events);
}
@Override
@@ -380,6 +374,10 @@ public final class BacklogTracer extends ServiceSupport implements org.apache.ca
public String dumpAllTracedMessagesAsXml() {
List<BacklogTracerEventMessage> events = dumpAllTracedMessages();
+ return wrapAroundRootTag(events);
+ }
+
+ private static String wrapAroundRootTag(List<BacklogTracerEventMessage> events) {
StringBuilder sb = new StringBuilder();
sb.append("<").append(BacklogTracerEventMessage.ROOT_TAG).append("s>");
for (BacklogTracerEventMessage event : events) {
diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java b/core/camel-base/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java
index aa58325cec6..792d9a21173 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java
@@ -199,13 +199,7 @@ public abstract class BaseTypeConverterRegistry extends CoreTypeConverterRegistr
protected Collection<URL> getLoaderUrls(String basePath) throws IOException {
List<URL> loaderResources = new ArrayList<>();
- for (ClassLoader classLoader : resolver.getClassLoaders()) {
- Enumeration<URL> resources = classLoader.getResources(basePath);
- while (resources.hasMoreElements()) {
- URL url = resources.nextElement();
- loaderResources.add(url);
- }
- }
+ addResources(basePath, loaderResources);
return loaderResources;
}
@@ -252,14 +246,18 @@ public abstract class BaseTypeConverterRegistry extends CoreTypeConverterRegistr
protected Collection<URL> getFallbackUrls() throws IOException {
List<URL> loaderResources = new ArrayList<>();
+ addResources(META_INF_SERVICES_FALLBACK_TYPE_CONVERTER, loaderResources);
+ return loaderResources;
+ }
+
+ private void addResources(String metaInfServicesFallbackTypeConverter, List<URL> loaderResources) throws IOException {
for (ClassLoader classLoader : resolver.getClassLoaders()) {
- Enumeration<URL> resources = classLoader.getResources(META_INF_SERVICES_FALLBACK_TYPE_CONVERTER);
+ Enumeration<URL> resources = classLoader.getResources(metaInfServicesFallbackTypeConverter);
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
loaderResources.add(url);
}
}
- return loaderResources;
}
protected void loadFallbackTypeConverters() throws IOException, ClassNotFoundException {
diff --git a/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java b/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java
index 170a17817aa..42fa7e23aae 100644
--- a/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java
+++ b/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java
@@ -61,6 +61,8 @@ import org.apache.camel.util.ReflectionHelper;
import org.apache.camel.util.StringHelper;
import org.apache.camel.util.URISupport;
+import static org.apache.camel.util.StringHelper.isDashed;
+
/**
* Base class for both the runtime RuntimeCamelCatalog from camel-core and the complete CamelCatalog from camel-catalog.
*/
@@ -1124,18 +1126,7 @@ public abstract class AbstractCamelCatalog {
String suffix = null;
int posDot = nOption.indexOf('.');
int posBracket = nOption.indexOf('[');
- if (posDot > 0 && posBracket > 0) {
- int first = Math.min(posDot, posBracket);
- suffix = nOption.substring(first);
- nOption = nOption.substring(0, first);
- } else if (posDot > 0) {
- suffix = nOption.substring(posDot);
- nOption = nOption.substring(0, posDot);
- } else if (posBracket > 0) {
- suffix = nOption.substring(posBracket);
- nOption = nOption.substring(0, posBracket);
- }
- doValidateConfigurationProperty(result, rows, name, value, longKey, nOption, suffix);
+ validateConfigurationProperty(posDot, posBracket, suffix, nOption, result, rows, name, value, longKey);
}
} else if (key.startsWith("main.")
|| key.startsWith("resilience4j.")
@@ -1163,25 +1154,31 @@ public abstract class AbstractCamelCatalog {
String suffix = null;
int posDot = nOption.indexOf('.', secondDot);
int posBracket = nOption.indexOf('[', secondDot);
- if (posDot > 0 && posBracket > 0) {
- int first = Math.min(posDot, posBracket);
- suffix = nOption.substring(first);
- nOption = nOption.substring(0, first);
- } else if (posDot > 0) {
- suffix = nOption.substring(posDot);
- nOption = nOption.substring(0, posDot);
- } else if (posBracket > 0) {
- suffix = nOption.substring(posBracket);
- nOption = nOption.substring(0, posBracket);
- }
-
- doValidateConfigurationProperty(result, rows, name, value, longKey, nOption, suffix);
+ validateConfigurationProperty(posDot, posBracket, suffix, nOption, result, rows, name, value, longKey);
}
}
return result;
}
+ private void validateConfigurationProperty(
+ int posDot, int posBracket, String suffix, String nOption, ConfigurationPropertiesValidationResult result,
+ Map<String, BaseOptionModel> rows, String name, String value, String longKey) {
+ if (posDot > 0 && posBracket > 0) {
+ int first = Math.min(posDot, posBracket);
+ suffix = nOption.substring(first);
+ nOption = nOption.substring(0, first);
+ } else if (posDot > 0) {
+ suffix = nOption.substring(posDot);
+ nOption = nOption.substring(0, posDot);
+ } else if (posBracket > 0) {
+ suffix = nOption.substring(posBracket);
+ nOption = nOption.substring(0, posBracket);
+ }
+
+ doValidateConfigurationProperty(result, rows, name, value, longKey, nOption, suffix);
+ }
+
private void doValidateConfigurationProperty(
ConfigurationPropertiesValidationResult result,
Map<String, BaseOptionModel> rows,
@@ -1606,14 +1603,9 @@ public abstract class AbstractCamelCatalog {
if (text == null) {
return null;
}
- int length = text.length();
- if (length == 0) {
- return text;
- }
- if (text.indexOf('-') == -1) {
+ if (!isDashed(text)) {
return text;
}
-
StringBuilder sb = new StringBuilder();
for (int i = 0; i < text.length(); i++) {
diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/aggregate/AggregationStrategyBeanInfo.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/aggregate/AggregationStrategyBeanInfo.java
index 130f38790b4..51bca24ceb0 100644
--- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/aggregate/AggregationStrategyBeanInfo.java
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/aggregate/AggregationStrategyBeanInfo.java
@@ -70,49 +70,36 @@ public class AggregationStrategyBeanInfo {
}
List<AggregationStrategyParameterInfo> oldParameters = new ArrayList<>();
- List<AggregationStrategyParameterInfo> newParameters = new ArrayList<>();
-
for (int i = 0; i < size / 2; i++) {
- Class<?> oldType = parameterTypes[i];
- if (oldParameters.isEmpty()) {
- // the first parameter is the body
- Expression oldBody = ExpressionBuilder.mandatoryBodyExpression(oldType);
- AggregationStrategyParameterInfo info = new AggregationStrategyParameterInfo(i, oldType, oldBody);
- oldParameters.add(info);
- } else if (oldParameters.size() == 1) {
- // the 2nd parameter is the headers
- Expression oldHeaders = ExpressionBuilder.headersExpression();
- AggregationStrategyParameterInfo info = new AggregationStrategyParameterInfo(i, oldType, oldHeaders);
- oldParameters.add(info);
- } else if (oldParameters.size() == 2) {
- // the 3rd parameter is the properties
- Expression oldProperties = ExpressionBuilder.exchangePropertiesExpression();
- AggregationStrategyParameterInfo info = new AggregationStrategyParameterInfo(i, oldType, oldProperties);
- oldParameters.add(info);
- }
+ addParameters(parameterTypes, i, oldParameters);
}
+ List<AggregationStrategyParameterInfo> newParameters = new ArrayList<>();
for (int i = size / 2; i < size; i++) {
- Class<?> newType = parameterTypes[i];
- if (newParameters.isEmpty()) {
- // the first parameter is the body
- Expression newBody = ExpressionBuilder.mandatoryBodyExpression(newType);
- AggregationStrategyParameterInfo info = new AggregationStrategyParameterInfo(i, newType, newBody);
- newParameters.add(info);
- } else if (newParameters.size() == 1) {
- // the 2nd parameter is the headers
- Expression newHeaders = ExpressionBuilder.headersExpression();
- AggregationStrategyParameterInfo info = new AggregationStrategyParameterInfo(i, newType, newHeaders);
- newParameters.add(info);
- } else if (newParameters.size() == 2) {
- // the 3rd parameter is the properties
- Expression newProperties = ExpressionBuilder.exchangePropertiesExpression();
- AggregationStrategyParameterInfo info = new AggregationStrategyParameterInfo(i, newType, newProperties);
- newParameters.add(info);
- }
+ addParameters(parameterTypes, i, newParameters);
}
return new AggregationStrategyMethodInfo(method, oldParameters, newParameters);
}
+ private static void addParameters(Class<?>[] parameterTypes, int i, List<AggregationStrategyParameterInfo> parameters) {
+ Class<?> parameterType = parameterTypes[i];
+ if (parameters.isEmpty()) {
+ // the first parameter is the body
+ Expression body = ExpressionBuilder.mandatoryBodyExpression(parameterType);
+ AggregationStrategyParameterInfo info = new AggregationStrategyParameterInfo(i, parameterType, body);
+ parameters.add(info);
+ } else if (parameters.size() == 1) {
+ // the 2nd parameter is the headers
+ Expression headersExpression = ExpressionBuilder.headersExpression();
+ AggregationStrategyParameterInfo info = new AggregationStrategyParameterInfo(i, parameterType, headersExpression);
+ parameters.add(info);
+ } else if (parameters.size() == 2) {
+ // the 3rd parameter is the properties
+ Expression properties = ExpressionBuilder.exchangePropertiesExpression();
+ AggregationStrategyParameterInfo info = new AggregationStrategyParameterInfo(i, parameterType, properties);
+ parameters.add(info);
+ }
+ }
+
}
diff --git a/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java b/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
index d31086ce978..ec41707d2a5 100644
--- a/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
+++ b/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
@@ -1400,16 +1400,8 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex
PackageScanDefinition packageScanDef = getPackageScan();
if (packageScanDef != null && !packageScanDef.getPackages().isEmpty()) {
// use package scan filter
- PatternBasedPackageScanFilter filter = new PatternBasedPackageScanFilter();
- // support property placeholders in include and exclude
- for (String include : packageScanDef.getIncludes()) {
- include = getContext().resolvePropertyPlaceholders(include);
- filter.addIncludePattern(include);
- }
- for (String exclude : packageScanDef.getExcludes()) {
- exclude = getContext().resolvePropertyPlaceholders(exclude);
- filter.addExcludePattern(exclude);
- }
+ final PatternBasedPackageScanFilter filter
+ = addPatterns(packageScanDef.getIncludes(), packageScanDef.getExcludes());
String[] normalized = normalizePackages(getContext(), packageScanDef.getPackages());
findRouteBuildersByPackageScan(normalized, filter, builders);
@@ -1419,16 +1411,8 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex
ContextScanDefinition contextScanDef = getContextScan();
if (contextScanDef != null) {
// use package scan filter
- PatternBasedPackageScanFilter filter = new PatternBasedPackageScanFilter();
- // support property placeholders in include and exclude
- for (String include : contextScanDef.getIncludes()) {
- include = getContext().resolvePropertyPlaceholders(include);
- filter.addIncludePattern(include);
- }
- for (String exclude : contextScanDef.getExcludes()) {
- exclude = getContext().resolvePropertyPlaceholders(exclude);
- filter.addExcludePattern(exclude);
- }
+ final PatternBasedPackageScanFilter filter
+ = addPatterns(contextScanDef.getIncludes(), contextScanDef.getExcludes());
// lets be false by default, to skip prototype beans
boolean includeNonSingletons = contextScanDef.getIncludeNonSingletons() != null
&& Boolean.parseBoolean(contextScanDef.getIncludeNonSingletons());
@@ -1436,6 +1420,20 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex
}
}
+ private PatternBasedPackageScanFilter addPatterns(List<String> contextScanDef, List<String> contextScanDef1) {
+ PatternBasedPackageScanFilter filter = new PatternBasedPackageScanFilter();
+ // support property placeholders in include and exclude
+ for (String include : contextScanDef) {
+ include = getContext().resolvePropertyPlaceholders(include);
+ filter.addIncludePattern(include);
+ }
+ for (String exclude : contextScanDef1) {
+ exclude = getContext().resolvePropertyPlaceholders(exclude);
+ filter.addExcludePattern(exclude);
+ }
+ return filter;
+ }
+
protected abstract void findRouteBuildersByPackageScan(
String[] packages, PackageScanFilter filter, List<RoutesBuilder> builders)
throws Exception;
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java b/core/camel-support/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java
index ba534ae8a44..100d0980e87 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java
@@ -89,19 +89,9 @@ public final class RestConsumerContextPathMatcher {
}
// remove starting/ending slashes
- if (requestPath.startsWith("/")) {
- requestPath = requestPath.substring(1);
- }
- if (requestPath.endsWith("/")) {
- requestPath = requestPath.substring(0, requestPath.length() - 1);
- }
+ requestPath = removePathSlashes(requestPath);
// remove starting/ending slashes
- if (consumerPath.startsWith("/")) {
- consumerPath = consumerPath.substring(1);
- }
- if (consumerPath.endsWith("/")) {
- consumerPath = consumerPath.substring(0, consumerPath.length() - 1);
- }
+ consumerPath = removePathSlashes(consumerPath);
if (matchOnUriPrefix && requestPath.toLowerCase(Locale.ENGLISH).startsWith(consumerPath.toLowerCase(Locale.ENGLISH))) {
return true;
@@ -326,19 +316,9 @@ public final class RestConsumerContextPathMatcher {
}
// remove starting/ending slashes
- if (requestPath.startsWith("/")) {
- requestPath = requestPath.substring(1);
- }
- if (requestPath.endsWith("/")) {
- requestPath = requestPath.substring(0, requestPath.length() - 1);
- }
+ requestPath = removePathSlashes(requestPath);
// remove starting/ending slashes
- if (consumerPath.startsWith("/")) {
- consumerPath = consumerPath.substring(1);
- }
- if (consumerPath.endsWith("/")) {
- consumerPath = consumerPath.substring(0, consumerPath.length() - 1);
- }
+ consumerPath = removePathSlashes(consumerPath);
// split using single char / is optimized in the jdk
String[] requestPaths = requestPath.split("/");
@@ -367,6 +347,16 @@ public final class RestConsumerContextPathMatcher {
return true;
}
+ private static String removePathSlashes(String path) {
+ if (path.startsWith("/")) {
+ path = path.substring(1);
+ }
+ if (path.endsWith("/")) {
+ path = path.substring(0, path.length() - 1);
+ }
+ return path;
+ }
+
/**
* Counts the number of uri template's curlyBraces in the path
*
@@ -377,12 +367,7 @@ public final class RestConsumerContextPathMatcher {
int curlyBraces = 0;
// remove starting/ending slashes
- if (consumerPath.startsWith("/")) {
- consumerPath = consumerPath.substring(1);
- }
- if (consumerPath.endsWith("/")) {
- consumerPath = consumerPath.substring(0, consumerPath.length() - 1);
- }
+ consumerPath = removePathSlashes(consumerPath);
String[] consumerPaths = consumerPath.split("/");
for (String p2 : consumerPaths) {
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/component/ApiMethodPropertiesHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/component/ApiMethodPropertiesHelper.java
index 85dc639d59c..2ad2be9c693 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/component/ApiMethodPropertiesHelper.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/component/ApiMethodPropertiesHelper.java
@@ -110,16 +110,7 @@ public abstract class ApiMethodPropertiesHelper<C> {
.resolvePropertyConfigurer(endpointConfiguration.getClass().getName(), context);
// use reflection free configurer (if possible)
if (configurer instanceof ExtendedPropertyConfigurerGetter) {
- ExtendedPropertyConfigurerGetter getter = (ExtendedPropertyConfigurerGetter) configurer;
- Set<String> all = getter.getAllOptions(endpointConfiguration).keySet();
- for (String name : all) {
- Object value = getter.getOptionValue(endpointConfiguration, name, true);
- if (value != null) {
- // lower case the first letter which is what the properties map expects
- String key = Character.toLowerCase(name.charAt(0)) + name.substring(1);
- properties.put(key, value);
- }
- }
+ useGetters(endpointConfiguration, properties, (ExtendedPropertyConfigurerGetter) configurer);
} else {
PluginHelper.getBeanIntrospection(context).getProperties(endpointConfiguration, properties,
null, false);
@@ -167,16 +158,7 @@ public abstract class ApiMethodPropertiesHelper<C> {
.resolvePropertyConfigurer(endpointConfiguration.getClass().getName(), context);
// use reflection free configurer (if possible)
if (configurer instanceof ExtendedPropertyConfigurerGetter) {
- ExtendedPropertyConfigurerGetter getter = (ExtendedPropertyConfigurerGetter) configurer;
- Set<String> all = getter.getAllOptions(endpointConfiguration).keySet();
- for (String name : all) {
- Object value = getter.getOptionValue(endpointConfiguration, name, true);
- if (value != null) {
- // lower case the first letter which is what the properties map expects
- String key = Character.toLowerCase(name.charAt(0)) + name.substring(1);
- properties.put(key, value);
- }
- }
+ useGetters(endpointConfiguration, properties, (ExtendedPropertyConfigurerGetter) configurer);
} else {
PluginHelper.getBeanIntrospection(context).getProperties(endpointConfiguration, properties,
null, false);
@@ -186,4 +168,18 @@ public abstract class ApiMethodPropertiesHelper<C> {
}
}
+ private static void useGetters(
+ Object endpointConfiguration, Map<String, Object> properties, ExtendedPropertyConfigurerGetter configurer) {
+ ExtendedPropertyConfigurerGetter getter = configurer;
+ Set<String> all = getter.getAllOptions(endpointConfiguration).keySet();
+ for (String name : all) {
+ Object value = getter.getOptionValue(endpointConfiguration, name, true);
+ if (value != null) {
+ // lower case the first letter which is what the properties map expects
+ String key = Character.toLowerCase(name.charAt(0)) + name.substring(1);
+ properties.put(key, value);
+ }
+ }
+ }
+
}
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java b/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java
index ca7b731f5af..c4c95c9b19d 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java
@@ -535,6 +535,17 @@ public final class StringHelper {
return dashToCamelCase(text, false);
}
+ /**
+ * Whether the string contains dashes or not
+ *
+ * @param text the string to check
+ * @return true if it contains dashes or false otherwise
+ */
+ public static boolean isDashed(String text) {
+ int length = text.length();
+ return length != 0 && text.indexOf('-') != -1;
+ }
+
/**
* Converts the string from dash format into camel case (hello-great-world -> helloGreatWorld)
*
@@ -546,15 +557,12 @@ public final class StringHelper {
if (text == null) {
return null;
}
- int length = text.length();
- if (length == 0) {
- return text;
- }
- if (text.indexOf('-') == -1) {
+ if (!isDashed(text)) {
return text;
}
// there is at least 1 dash so the capacity can be shorter
+ int length = text.length();
StringBuilder sb = new StringBuilder(length - 1);
boolean upper = false;
int singleQuotes = 0;
diff --git a/core/camel-xml-io/src/main/java/org/apache/camel/xml/in/BaseParser.java b/core/camel-xml-io/src/main/java/org/apache/camel/xml/in/BaseParser.java
index f114b3f3123..8570efbb7c2 100644
--- a/core/camel-xml-io/src/main/java/org/apache/camel/xml/in/BaseParser.java
+++ b/core/camel-xml-io/src/main/java/org/apache/camel/xml/in/BaseParser.java
@@ -128,17 +128,7 @@ public class BaseParser {
T definition, AttributeHandler<T> attributeHandler, ElementHandler<T> elementHandler, ValueHandler<T> valueHandler,
boolean supportsExternalNamespaces)
throws IOException, XmlPullParserException {
- if (definition instanceof LineNumberAware) {
- // we want to get the line number where the tag starts (in case its multi-line)
- int line = parser.getStartLineNumber();
- if (line == -1) {
- line = parser.getLineNumber();
- }
- ((LineNumberAware) definition).setLineNumber(line);
- if (resource != null) {
- ((LineNumberAware) definition).setLocation(resource.getLocation());
- }
- }
+ setLocation(definition);
if (definition instanceof NamespaceAware) {
final Map<String, String> namespaces = new LinkedHashMap<>();
for (int i = 0; i < parser.getNamespaceCount(parser.getDepth()); i++) {
@@ -218,17 +208,7 @@ public class BaseParser {
if (event == XmlPullParser.TEXT) {
if (!parser.isWhitespace()) {
T definition = definitionSupplier.get();
- if (definition instanceof LineNumberAware) {
- // we want to get the line number where the tag starts (in case its multi-line)
- int line = parser.getStartLineNumber();
- if (line == -1) {
- line = parser.getLineNumber();
- }
- ((LineNumberAware) definition).setLineNumber(line);
- if (resource != null) {
- ((LineNumberAware) definition).setLocation(resource.getLocation());
- }
- }
+ setLocation(definition);
valueHandler.accept(definition, parser.getText());
answer.add(definition);
}
@@ -258,6 +238,20 @@ public class BaseParser {
}
}
+ private <T> void setLocation(T definition) {
+ if (definition instanceof LineNumberAware) {
+ // we want to get the line number where the tag starts (in case its multi-line)
+ int line = parser.getStartLineNumber();
+ if (line == -1) {
+ line = parser.getLineNumber();
+ }
+ ((LineNumberAware) definition).setLineNumber(line);
+ if (resource != null) {
+ ((LineNumberAware) definition).setLocation(resource.getLocation());
+ }
+ }
+ }
+
protected Class<?> asClass(String val) throws XmlPullParserException {
try {
return Class.forName(val);
(camel) 01/05: (chores) camel-core: removed unused operations in tests
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 793a8e8bd57a7549392c05afa8f45ae2526824cd
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Mon Apr 15 13:10:12 2024 +0200
(chores) camel-core: removed unused operations in tests
---
.../org/apache/camel/core/xml/AbstractCamelContextFactoryBeanTest.java | 1 +
1 file changed, 1 insertion(+)
diff --git a/core/camel-core-xml/src/test/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBeanTest.java b/core/camel-core-xml/src/test/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBeanTest.java
index d5ea5f4e382..eb25d91155a 100644
--- a/core/camel-core-xml/src/test/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBeanTest.java
+++ b/core/camel-core-xml/src/test/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBeanTest.java
@@ -43,6 +43,7 @@ import org.mockito.ArgumentCaptor;
import static java.util.Arrays.asList;
import static java.util.Arrays.stream;
+
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.atLeastOnce;