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 a4bbf2e1795 CAMEL-18193: camel-language - Language component should
load resource from classpath by default
a4bbf2e1795 is described below
commit a4bbf2e17950dbd83db97e8163d421441b865712
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Jun 14 20:34:08 2022 +0200
CAMEL-18193: camel-language - Language component should load resource from
classpath by default
---
.../camel/component/language/LanguageComponent.java | 8 +++++---
.../language/ConstantLanguageBinaryResourceTest.java | 19 ++++++++++++++++---
.../LanguageLoadScriptFromFileCachedTest.java | 2 +-
3 files changed, 22 insertions(+), 7 deletions(-)
diff --git
a/components/camel-language/src/main/java/org/apache/camel/component/language/LanguageComponent.java
b/components/camel-language/src/main/java/org/apache/camel/component/language/LanguageComponent.java
index 3137878536f..a8258df04bc 100644
---
a/components/camel-language/src/main/java/org/apache/camel/component/language/LanguageComponent.java
+++
b/components/camel-language/src/main/java/org/apache/camel/component/language/LanguageComponent.java
@@ -17,12 +17,12 @@
package org.apache.camel.component.language;
import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
import java.util.Map;
import org.apache.camel.Endpoint;
import org.apache.camel.spi.Language;
import org.apache.camel.support.DefaultComponent;
-import org.apache.camel.support.ResourceHelper;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.StringHelper;
@@ -55,17 +55,19 @@ public class LanguageComponent extends DefaultComponent {
String resourceUri = null;
String resource = script;
if (resource != null) {
+ boolean resourcePrefix = false;
if (resource.startsWith(RESOURCE)) {
+ resourcePrefix = true;
resource = resource.substring(RESOURCE.length());
}
- if (ResourceHelper.hasScheme(resource)) {
+ if (resourcePrefix) {
// the script is a uri for a resource
resourceUri = resource;
// then the script should be null
script = null;
} else {
// the script is provided as text in the uri, so decode to
utf-8
- script = URLDecoder.decode(script, "UTF-8");
+ script = URLDecoder.decode(script, StandardCharsets.UTF_8);
// then the resource should be null
resourceUri = null;
}
diff --git
a/core/camel-core/src/test/java/org/apache/camel/language/ConstantLanguageBinaryResourceTest.java
b/core/camel-core/src/test/java/org/apache/camel/language/ConstantLanguageBinaryResourceTest.java
index 10b919e99d4..ae3b17d8d56 100644
---
a/core/camel-core/src/test/java/org/apache/camel/language/ConstantLanguageBinaryResourceTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/language/ConstantLanguageBinaryResourceTest.java
@@ -27,8 +27,19 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
public class ConstantLanguageBinaryResourceTest extends ContextTestSupport {
@Test
- public void testConstantBinary() throws Exception {
- byte[] data = template.requestBody("direct:start", "", byte[].class);
+ public void testConstantBinaryDefault() throws Exception {
+ byte[] data = template.requestBody("direct:default", "", byte[].class);
+ // should have X number of bytes
+ assertNotNull(data);
+ assertEquals(10249, data.length);
+
+ // store the logo
+ template.sendBodyAndHeader(fileUri(), data, Exchange.FILE_NAME,
"savedlogo.jpeg");
+ }
+
+ @Test
+ public void testConstantBinaryClasspath() throws Exception {
+ byte[] data = template.requestBody("direct:classpath", "",
byte[].class);
// should have X number of bytes
assertNotNull(data);
assertEquals(10249, data.length);
@@ -42,7 +53,9 @@ public class ConstantLanguageBinaryResourceTest extends
ContextTestSupport {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
-
from("direct:start").to("language:constant:resource:classpath:org/apache/camel/logo.jpeg?binary=true");
+
from("direct:default").to("language:constant:resource:org/apache/camel/logo.jpeg?binary=true");
+
+
from("direct:classpath").to("language:constant:resource:classpath:org/apache/camel/logo.jpeg?binary=true");
}
};
}
diff --git
a/core/camel-management/src/test/java/org/apache/camel/component/language/LanguageLoadScriptFromFileCachedTest.java
b/core/camel-management/src/test/java/org/apache/camel/component/language/LanguageLoadScriptFromFileCachedTest.java
index eb0797e66da..c3fcc6cfd6a 100644
---
a/core/camel-management/src/test/java/org/apache/camel/component/language/LanguageLoadScriptFromFileCachedTest.java
+++
b/core/camel-management/src/test/java/org/apache/camel/component/language/LanguageLoadScriptFromFileCachedTest.java
@@ -83,7 +83,7 @@ public class LanguageLoadScriptFromFileCachedTest extends
ContextTestSupport {
// START SNIPPET: e1
from("direct:start")
// use content cache to load the script once and cache
it (content cache and script cache both enabled)
- .to("language:simple:" +
fileUri("myscript.txt?contentCache=true&cacheScript=true"))
+ .to("language:simple:resource:" +
fileUri("myscript.txt?contentCache=true&cacheScript=true"))
.to("mock:result");
// END SNIPPET: e1
}