Repository: camel Updated Branches: refs/heads/camel-2.11.x 827b0b027 -> 0c872dc03 refs/heads/camel-2.12.x f02b9bec7 -> 7b415b426 refs/heads/master 9640e23f1 -> fdf9871fb
CAMEL-7219: Fixed language component to be able to load resources from classpath. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/80c7935d Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/80c7935d Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/80c7935d Branch: refs/heads/master Commit: 80c7935dd5462aede67ba97e8b83639a3dde4280 Parents: 9640e23 Author: Claus Ibsen <davscl...@apache.org> Authored: Tue Feb 18 17:54:22 2014 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Tue Feb 18 17:54:34 2014 +0100 ---------------------------------------------------------------------- .../component/language/LanguageComponent.java | 4 ++ ...geResourceLoadConstantFromClasspathTest.java | 46 ++++++++++++++++++++ .../apache/camel/component/language/hello.txt | 1 + 3 files changed, 51 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/80c7935d/camel-core/src/main/java/org/apache/camel/component/language/LanguageComponent.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/component/language/LanguageComponent.java b/camel-core/src/main/java/org/apache/camel/component/language/LanguageComponent.java index 24a9e07..2942ae3 100644 --- a/camel-core/src/main/java/org/apache/camel/component/language/LanguageComponent.java +++ b/camel-core/src/main/java/org/apache/camel/component/language/LanguageComponent.java @@ -61,9 +61,13 @@ public class LanguageComponent extends UriEndpointComponent { if (ResourceHelper.hasScheme(resource)) { // 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"); + // then the resource should be null + resourceUri = null; } } http://git-wip-us.apache.org/repos/asf/camel/blob/80c7935d/camel-core/src/test/java/org/apache/camel/component/language/LanguageResourceLoadConstantFromClasspathTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/component/language/LanguageResourceLoadConstantFromClasspathTest.java b/camel-core/src/test/java/org/apache/camel/component/language/LanguageResourceLoadConstantFromClasspathTest.java new file mode 100644 index 0000000..aa98835 --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/component/language/LanguageResourceLoadConstantFromClasspathTest.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.component.language; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.builder.RouteBuilder; + +/** + * @version + */ +public class LanguageResourceLoadConstantFromClasspathTest extends ContextTestSupport { + + public void testLanguage() throws Exception { + getMockEndpoint("mock:result").expectedBodiesReceived("Hello this is some text."); + + template.sendBody("direct:start", "World"); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .to("language:constant:resource:classpath:org/apache/camel/component/language/hello.txt") + .to("mock:result"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/80c7935d/camel-core/src/test/resources/org/apache/camel/component/language/hello.txt ---------------------------------------------------------------------- diff --git a/camel-core/src/test/resources/org/apache/camel/component/language/hello.txt b/camel-core/src/test/resources/org/apache/camel/component/language/hello.txt new file mode 100644 index 0000000..b75dc3d --- /dev/null +++ b/camel-core/src/test/resources/org/apache/camel/component/language/hello.txt @@ -0,0 +1 @@ +Hello this is some text. \ No newline at end of file