This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new c42c7b61677 CAMEL-22441: components with supportFileReference should
support resource: prefix
c42c7b61677 is described below
commit c42c7b6167790a0daf58a2bfc2d24ecb3206e5ab
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Sep 24 09:44:03 2025 +0200
CAMEL-22441: components with supportFileReference should support resource:
prefix
---
.../org/apache/camel/main/MainSupportModelConfigurer.java | 12 ++++--------
.../main/java/org/apache/camel/support/LanguageSupport.java | 9 +++------
.../main/java/org/apache/camel/support/ResourceHelper.java | 7 ++++++-
3 files changed, 13 insertions(+), 15 deletions(-)
diff --git
a/core/camel-main/src/main/java/org/apache/camel/main/MainSupportModelConfigurer.java
b/core/camel-main/src/main/java/org/apache/camel/main/MainSupportModelConfigurer.java
index 71cec05b929..117d75e87b6 100644
---
a/core/camel-main/src/main/java/org/apache/camel/main/MainSupportModelConfigurer.java
+++
b/core/camel-main/src/main/java/org/apache/camel/main/MainSupportModelConfigurer.java
@@ -28,7 +28,6 @@ import
org.apache.camel.model.Resilience4jConfigurationDefinition;
import org.apache.camel.spi.ThreadPoolProfile;
import org.apache.camel.spi.VariableRepository;
import org.apache.camel.spi.VariableRepositoryFactory;
-import org.apache.camel.support.LanguageSupport;
import org.apache.camel.support.PropertyBindingSupport;
import org.apache.camel.support.ResourceHelper;
import org.apache.camel.util.IOHelper;
@@ -110,13 +109,10 @@ public final class MainSupportModelConfigurer {
VariableRepository repo =
camelContext.getCamelContextExtension().getContextPlugin(VariableRepositoryFactory.class)
.getVariableRepository(id);
// it may be a resource to load from disk then
- if (value.startsWith(LanguageSupport.RESOURCE)) {
- value = value.substring(9);
- if (ResourceHelper.hasScheme(value)) {
- InputStream is =
ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext, value);
- value = IOHelper.loadText(is);
- IOHelper.close(is);
- }
+ if (ResourceHelper.hasScheme(value)) {
+ InputStream is =
ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext, value);
+ value = IOHelper.loadText(is);
+ IOHelper.close(is);
}
// digits should favour an int/long value true|false should be a
boolean anything else is string
Object val;
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/LanguageSupport.java
b/core/camel-support/src/main/java/org/apache/camel/support/LanguageSupport.java
index 8872fa13969..0794b2d22d2 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/LanguageSupport.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/LanguageSupport.java
@@ -33,8 +33,6 @@ import org.apache.camel.util.TimeUtils;
*/
public abstract class LanguageSupport implements Language, IsSingleton,
CamelContextAware {
- public static final String RESOURCE = "resource:";
-
private static final String[] SIMPLE_FUNCTION_START = new String[] { "${",
"$simple{" };
private CamelContext camelContext;
@@ -68,10 +66,9 @@ public abstract class LanguageSupport implements Language,
IsSingleton, CamelCon
protected String loadResource(String expression) throws
ExpressionIllegalSyntaxException {
// we can only load static resources (if they are dynamic then simple
will load them on-demand)
if (camelContext != null && expression != null &&
isStaticResource(expression)) {
- String uri = expression.substring(RESOURCE.length());
InputStream is = null;
try {
- is =
ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext, uri);
+ is =
ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext, expression);
expression =
camelContext.getTypeConverter().mandatoryConvertTo(String.class, is);
} catch (Exception e) {
throw new ExpressionIllegalSyntaxException(expression, e);
@@ -86,14 +83,14 @@ public abstract class LanguageSupport implements Language,
IsSingleton, CamelCon
* Does the expression refer to a static resource.
*/
protected boolean isStaticResource(String expression) {
- return expression.startsWith(RESOURCE) &&
!hasSimpleFunction(expression);
+ return expression.startsWith(ResourceHelper.RESOURCE) &&
!hasSimpleFunction(expression);
}
/**
* Does the expression refer to a dynamic resource which uses simple
functions.
*/
protected boolean isDynamicResource(String expression) {
- return expression.startsWith(RESOURCE) &&
hasSimpleFunction(expression);
+ return expression.startsWith(ResourceHelper.RESOURCE) &&
hasSimpleFunction(expression);
}
/**
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/ResourceHelper.java
b/core/camel-support/src/main/java/org/apache/camel/support/ResourceHelper.java
index 33acc4f15c6..bdfbd86a797 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/ResourceHelper.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/ResourceHelper.java
@@ -51,6 +51,8 @@ import org.slf4j.LoggerFactory;
*/
public final class ResourceHelper {
+ public static final String RESOURCE = "resource:";
+
private static final Logger LOG =
LoggerFactory.getLogger(ResourceHelper.class);
private ResourceHelper() {
@@ -68,7 +70,7 @@ public final class ResourceHelper {
return false;
}
- return uri.startsWith("file:") || uri.startsWith("classpath:") ||
uri.startsWith("ref:") ||
+ return uri.startsWith(RESOURCE) || uri.startsWith("file:") ||
uri.startsWith("classpath:") || uri.startsWith("ref:") ||
uri.startsWith("bean:") || uri.startsWith("http:") ||
uri.startsWith("https:");
}
@@ -191,6 +193,9 @@ public final class ResourceHelper {
* @return the {@link Resource}. Or <tt>null</tt> if not found
*/
public static Resource resolveResource(CamelContext camelContext, String
uri) {
+ if (uri.startsWith(RESOURCE)) {
+ uri = uri.substring(RESOURCE.length());
+ }
final ResourceLoader loader =
PluginHelper.getResourceLoader(camelContext);
return loader.resolveResource(uri);
}