You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2015/04/17 03:38:56 UTC
[1/3] camel git commit: CAMEL-7849 support encrypted properties
inside and outside
Repository: camel
Updated Branches:
refs/heads/camel-2.14.x 7e74779d2 -> feb4ac9ad
refs/heads/camel-2.15.x bb59db2d8 -> fd0e71941
CAMEL-7849 support encrypted properties inside and outside <camelContext>
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/42003088
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/42003088
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/42003088
Branch: refs/heads/camel-2.14.x
Commit: 42003088d86e0678b6247938cf6f1c8ba2d9faae
Parents: 7e74779
Author: Willem Jiang <wi...@gmail.com>
Authored: Thu Apr 9 21:53:44 2015 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Fri Apr 10 09:59:15 2015 +0800
----------------------------------------------------------------------
.../SpringJasyptBridgePropertiesTest.java | 2 +-
.../org/apache/camel/component/jasypt/Test.java | 30 ++++++++++++++++++++
.../jasypt/SpringJasyptBridgePropertiesTest.xml | 5 ++++
.../BridgePropertyPlaceholderConfigurer.java | 11 +++++++
4 files changed, 47 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/42003088/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesTest.java b/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesTest.java
index 2191521..0697d76 100644
--- a/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesTest.java
+++ b/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesTest.java
@@ -28,7 +28,7 @@ public class SpringJasyptBridgePropertiesTest extends CamelSpringTestSupport {
@Test
public void testJasyptProperties() throws Exception {
- getMockEndpoint("mock:tiger").expectedBodiesReceived("Hello World");
+ getMockEndpoint("mock:tiger").expectedBodiesReceived("Hello World tiger");
template.sendBody("direct:start", "Hello World");
http://git-wip-us.apache.org/repos/asf/camel/blob/42003088/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/Test.java
----------------------------------------------------------------------
diff --git a/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/Test.java b/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/Test.java
new file mode 100644
index 0000000..fa4abc7
--- /dev/null
+++ b/components/camel-jasypt/src/test/java/org/apache/camel/component/jasypt/Test.java
@@ -0,0 +1,30 @@
+/**
+ * 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.jasypt;
+
+public class Test {
+ private String data = "";
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ public String handleRequst(String request) {
+ return request + " " + data;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/42003088/components/camel-jasypt/src/test/resources/org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-jasypt/src/test/resources/org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesTest.xml b/components/camel-jasypt/src/test/resources/org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesTest.xml
index 11ec9cf..895b4a2 100644
--- a/components/camel-jasypt/src/test/resources/org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesTest.xml
+++ b/components/camel-jasypt/src/test/resources/org/apache/camel/component/jasypt/SpringJasyptBridgePropertiesTest.xml
@@ -32,10 +32,15 @@
<property name="location" value="classpath:org/apache/camel/component/jasypt/myproperties.properties"/>
<property name="parser" ref="jasyptParser"/>
</bean>
+
+ <bean id="test" class="org.apache.camel.component.jasypt.Test">
+ <property name="data" value="${cool.password}" />
+ </bean>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start"/>
+ <to uri="bean:test" />
<to uri="{{cool.result}}"/>
</route>
</camelContext>
http://git-wip-us.apache.org/repos/asf/camel/blob/42003088/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java b/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java
index 8cc2812..b8ae494 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java
@@ -112,6 +112,17 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf
super.setIgnoreResourceNotFound(ignoreResourceNotFound);
this.ignoreResourceNotFound = ignoreResourceNotFound;
}
+
+ @Override
+ protected String resolvePlaceholder(String placeholder, Properties props) {
+ String value = props.getProperty(placeholder);
+ if (parser != null) {
+ // Just apply the parser to the place holder value to avoid configuring the other placeholder configure twice for the inside and outside camel context
+ return parser.parseProperty(placeholder, value, props);
+ } else {
+ return value;
+ }
+ }
@Override
public Properties resolveProperties(CamelContext context, boolean ignoreMissingLocation, String... uri) throws Exception {
[2/3] camel git commit: CAMEL-8649 Fixed the %2520 issue of RAW()
Posted by ni...@apache.org.
CAMEL-8649 Fixed the %2520 issue of RAW()
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/fd0e7194
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/fd0e7194
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/fd0e7194
Branch: refs/heads/camel-2.15.x
Commit: fd0e71941909c9d124d8fed711549b1b4f268189
Parents: bb59db2
Author: Willem Jiang <wi...@gmail.com>
Authored: Fri Apr 17 00:12:09 2015 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Fri Apr 17 09:36:49 2015 +0800
----------------------------------------------------------------------
.../java/org/apache/camel/util/URISupport.java | 8 +-
.../camel/util/UnsafeUriCharactersEncoder.java | 64 ++++++++++-
.../component/file/FileURLDecodingTest.java | 105 +++++++++++++++++++
.../org/apache/camel/util/URISupportTest.java | 8 +-
4 files changed, 180 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/fd0e7194/camel-core/src/main/java/org/apache/camel/util/URISupport.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/URISupport.java b/camel-core/src/main/java/org/apache/camel/util/URISupport.java
index 02d3447..45f831c 100644
--- a/camel-core/src/main/java/org/apache/camel/util/URISupport.java
+++ b/camel-core/src/main/java/org/apache/camel/util/URISupport.java
@@ -452,8 +452,10 @@ public final class URISupport {
if (value != null) {
rc.append("=");
if (value.startsWith(RAW_TOKEN_START) && value.endsWith(RAW_TOKEN_END)) {
- // do not encode RAW parameters
- rc.append(value);
+ // do not encode RAW parameters unless it has %
+ // need to replace % with %25 to avoid losing "%" when decoding
+ String s = StringHelper.replaceAll(value, "%", "%25");
+ rc.append(s);
} else {
rc.append(URLEncoder.encode(value, CHARSET));
}
@@ -509,7 +511,7 @@ public final class URISupport {
*/
public static String normalizeUri(String uri) throws URISyntaxException, UnsupportedEncodingException {
- URI u = new URI(UnsafeUriCharactersEncoder.encode(uri));
+ URI u = new URI(UnsafeUriCharactersEncoder.encode(uri, true));
String path = u.getSchemeSpecificPart();
String scheme = u.getScheme();
http://git-wip-us.apache.org/repos/asf/camel/blob/fd0e7194/camel-core/src/main/java/org/apache/camel/util/UnsafeUriCharactersEncoder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/UnsafeUriCharactersEncoder.java b/camel-core/src/main/java/org/apache/camel/util/UnsafeUriCharactersEncoder.java
index 9b9445d..e0775a0 100644
--- a/camel-core/src/main/java/org/apache/camel/util/UnsafeUriCharactersEncoder.java
+++ b/camel-core/src/main/java/org/apache/camel/util/UnsafeUriCharactersEncoder.java
@@ -16,7 +16,12 @@
*/
package org.apache.camel.util;
+import java.util.ArrayList;
import java.util.BitSet;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
/**
* Encoder for unsafe URI characters.
@@ -78,6 +83,63 @@ public final class UnsafeUriCharactersEncoder {
}
public static String encode(String s, BitSet unsafeCharacters) {
+ return encode(s, unsafeCharacters, false);
+ }
+
+ public static String encode(String s, boolean checkRaw) {
+ return encode(s, unsafeCharactersRfc1738, checkRaw);
+ }
+
+ public static String encodeHttpURI(String s, boolean checkRaw) {
+ return encode(s, unsafeCharactersHttp, checkRaw);
+ }
+
+ private static List<Pair> checkRAW(String s) {
+ Pattern pattern = Pattern.compile("RAW\\([^\\)]+\\)");
+ Matcher matcher = pattern.matcher(s);
+ List<Pair> answer = new ArrayList<Pair>();
+ // Check all occurrences
+ while (matcher.find()) {
+ answer.add(new Pair(matcher.start(), matcher.end()));
+ }
+ return answer;
+ }
+
+ private static boolean isRaw(int index, List<Pair>pairs) {
+ for (Pair pair : pairs) {
+ if (index < pair.left) {
+ return false;
+ } else {
+ if (index >= pair.left) {
+ if (index <= pair.right) {
+ return true;
+ } else {
+ continue;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ private static class Pair {
+ int left;
+ int right;
+ public Pair(int left, int right) {
+ this.left = left;
+ this.right = right;
+ }
+ }
+
+ // Just skip the encode for isRAW part
+ public static String encode(String s, BitSet unsafeCharacters, boolean checkRaw) {
+ List<Pair> rawPairs;
+ if (checkRaw) {
+ rawPairs = checkRAW(s);
+ } else {
+ rawPairs = new ArrayList<Pair>();
+ }
+
int n = s == null ? 0 : s.length();
if (n == 0) {
return s;
@@ -108,7 +170,7 @@ public final class UnsafeUriCharactersEncoder {
char next = i + 1 < chars.length ? chars[i + 1] : ' ';
char next2 = i + 2 < chars.length ? chars[i + 2] : ' ';
- if (isHexDigit(next) && isHexDigit(next2)) {
+ if (isHexDigit(next) && isHexDigit(next2) && !isRaw(i, rawPairs)) {
// its already encoded (decimal encoded) so just append as is
sb.append(ch);
} else {
http://git-wip-us.apache.org/repos/asf/camel/blob/fd0e7194/camel-core/src/test/java/org/apache/camel/component/file/FileURLDecodingTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/file/FileURLDecodingTest.java b/camel-core/src/test/java/org/apache/camel/component/file/FileURLDecodingTest.java
new file mode 100644
index 0000000..9f7c0c6
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/file/FileURLDecodingTest.java
@@ -0,0 +1,105 @@
+/**
+ * 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.file;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.nio.file.Paths;
+
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+
+public class FileURLDecodingTest extends ContextTestSupport {
+
+ static final String TARGET_DIR = "target/files";
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ deleteDirectory(TARGET_DIR);
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ context.stop();
+ super.tearDown();
+ }
+
+ public void testSimpleFile() throws Exception {
+ assertTargetFile("data.txt", "data.txt");
+ }
+
+ public void testFilePlus() throws Exception {
+ assertTargetFile("data+.txt", "data .txt");
+ }
+
+ public void testFileSpace() throws Exception {
+ assertTargetFile("data%20.txt", "data .txt");
+ }
+
+ public void testFile2B() throws Exception {
+ assertTargetFile("data%2B.txt", "data .txt");
+ }
+ public void testFileRaw2B() throws Exception {
+ assertTargetFile("RAW(data%2B.txt)", "data%2B.txt");
+ }
+
+ public void testFileRawPlus() throws Exception {
+ assertTargetFile("RAW(data+.txt)", "data+.txt");
+ }
+
+ public void testFileRawSpace() throws Exception {
+ assertTargetFile("RAW(data%20.txt)", "data%20.txt");
+ }
+
+ public void testFileRaw2520() throws Exception {
+ assertTargetFile("RAW(data%2520.txt)", "data%2520.txt");
+ }
+
+ public void testFileWithTwoHundredPercent() throws Exception {
+ assertTargetFile("RAW(data%%.txt)", "data%%.txt");
+ }
+
+
+ private void assertTargetFile(final String encoded, final String expected) throws Exception {
+
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").to("file:" + TARGET_DIR + "?fileName=" + encoded);
+ }
+ });
+
+ context.start();
+
+ String result = template.requestBody("direct:start", "Kermit", String.class);
+ assertEquals("Kermit", result);
+
+ BufferedReader br = new BufferedReader(new FileReader(Paths.get(TARGET_DIR, expected).toFile()));
+ assertEquals("Kermit", br.readLine());
+ br.close();
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/fd0e7194/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java b/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java
index 8f25f8b..4291f3c 100644
--- a/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java
+++ b/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java
@@ -254,7 +254,8 @@ public class URISupportTest extends ContextTestSupport {
assertEquals("xmpp://camel-user@localhost:123/test-user@localhost?password=RAW(++?w0rd)&serviceName=some+chat", out);
String out2 = URISupport.normalizeUri("xmpp://camel-user@localhost:123/test-user@localhost?password=RAW(foo %% bar)&serviceName=some chat");
- assertEquals("xmpp://camel-user@localhost:123/test-user@localhost?password=RAW(foo %% bar)&serviceName=some+chat", out2);
+ // Just make sure the RAW parameter can be resolved rightly, we need to replace the % into %25
+ assertEquals("xmpp://camel-user@localhost:123/test-user@localhost?password=RAW(foo %25%25 bar)&serviceName=some+chat", out2);
}
public void testParseQuery() throws Exception {
@@ -272,6 +273,11 @@ public class URISupportTest extends ContextTestSupport {
assertEquals(2, map.size());
assertEquals("RAW(++?)w&rd)", map.get("password"));
assertEquals("somechat", map.get("serviceName"));
+
+ map = URISupport.parseQuery("password=RAW(%2520w&rd)&serviceName=somechat");
+ assertEquals(2, map.size());
+ assertEquals("RAW(%2520w&rd)", map.get("password"));
+ assertEquals("somechat", map.get("serviceName"));
}
public void testResolveRawParameterValues() throws Exception {
[3/3] camel git commit: CAMEL-8649 Fixed the %2520 issue of RAW()
Posted by ni...@apache.org.
CAMEL-8649 Fixed the %2520 issue of RAW()
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/feb4ac9a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/feb4ac9a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/feb4ac9a
Branch: refs/heads/camel-2.14.x
Commit: feb4ac9adbddf8715d685ce5056bde46db7e54c9
Parents: 4200308
Author: Willem Jiang <wi...@gmail.com>
Authored: Fri Apr 17 00:12:09 2015 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Fri Apr 17 09:38:36 2015 +0800
----------------------------------------------------------------------
.../java/org/apache/camel/util/URISupport.java | 8 +-
.../camel/util/UnsafeUriCharactersEncoder.java | 64 ++++++++++-
.../component/file/FileURLDecodingTest.java | 105 +++++++++++++++++++
.../org/apache/camel/util/URISupportTest.java | 8 +-
4 files changed, 180 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/feb4ac9a/camel-core/src/main/java/org/apache/camel/util/URISupport.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/URISupport.java b/camel-core/src/main/java/org/apache/camel/util/URISupport.java
index 1742432..a251df3 100644
--- a/camel-core/src/main/java/org/apache/camel/util/URISupport.java
+++ b/camel-core/src/main/java/org/apache/camel/util/URISupport.java
@@ -429,8 +429,10 @@ public final class URISupport {
if (value != null) {
rc.append("=");
if (value.startsWith(RAW_TOKEN_START) && value.endsWith(RAW_TOKEN_END)) {
- // do not encode RAW parameters
- rc.append(value);
+ // do not encode RAW parameters unless it has %
+ // need to replace % with %25 to avoid losing "%" when decoding
+ String s = StringHelper.replaceAll(value, "%", "%25");
+ rc.append(s);
} else {
rc.append(URLEncoder.encode(value, CHARSET));
}
@@ -467,7 +469,7 @@ public final class URISupport {
*/
public static String normalizeUri(String uri) throws URISyntaxException, UnsupportedEncodingException {
- URI u = new URI(UnsafeUriCharactersEncoder.encode(uri));
+ URI u = new URI(UnsafeUriCharactersEncoder.encode(uri, true));
String path = u.getSchemeSpecificPart();
String scheme = u.getScheme();
http://git-wip-us.apache.org/repos/asf/camel/blob/feb4ac9a/camel-core/src/main/java/org/apache/camel/util/UnsafeUriCharactersEncoder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/UnsafeUriCharactersEncoder.java b/camel-core/src/main/java/org/apache/camel/util/UnsafeUriCharactersEncoder.java
index 9b9445d..e0775a0 100644
--- a/camel-core/src/main/java/org/apache/camel/util/UnsafeUriCharactersEncoder.java
+++ b/camel-core/src/main/java/org/apache/camel/util/UnsafeUriCharactersEncoder.java
@@ -16,7 +16,12 @@
*/
package org.apache.camel.util;
+import java.util.ArrayList;
import java.util.BitSet;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
/**
* Encoder for unsafe URI characters.
@@ -78,6 +83,63 @@ public final class UnsafeUriCharactersEncoder {
}
public static String encode(String s, BitSet unsafeCharacters) {
+ return encode(s, unsafeCharacters, false);
+ }
+
+ public static String encode(String s, boolean checkRaw) {
+ return encode(s, unsafeCharactersRfc1738, checkRaw);
+ }
+
+ public static String encodeHttpURI(String s, boolean checkRaw) {
+ return encode(s, unsafeCharactersHttp, checkRaw);
+ }
+
+ private static List<Pair> checkRAW(String s) {
+ Pattern pattern = Pattern.compile("RAW\\([^\\)]+\\)");
+ Matcher matcher = pattern.matcher(s);
+ List<Pair> answer = new ArrayList<Pair>();
+ // Check all occurrences
+ while (matcher.find()) {
+ answer.add(new Pair(matcher.start(), matcher.end()));
+ }
+ return answer;
+ }
+
+ private static boolean isRaw(int index, List<Pair>pairs) {
+ for (Pair pair : pairs) {
+ if (index < pair.left) {
+ return false;
+ } else {
+ if (index >= pair.left) {
+ if (index <= pair.right) {
+ return true;
+ } else {
+ continue;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ private static class Pair {
+ int left;
+ int right;
+ public Pair(int left, int right) {
+ this.left = left;
+ this.right = right;
+ }
+ }
+
+ // Just skip the encode for isRAW part
+ public static String encode(String s, BitSet unsafeCharacters, boolean checkRaw) {
+ List<Pair> rawPairs;
+ if (checkRaw) {
+ rawPairs = checkRAW(s);
+ } else {
+ rawPairs = new ArrayList<Pair>();
+ }
+
int n = s == null ? 0 : s.length();
if (n == 0) {
return s;
@@ -108,7 +170,7 @@ public final class UnsafeUriCharactersEncoder {
char next = i + 1 < chars.length ? chars[i + 1] : ' ';
char next2 = i + 2 < chars.length ? chars[i + 2] : ' ';
- if (isHexDigit(next) && isHexDigit(next2)) {
+ if (isHexDigit(next) && isHexDigit(next2) && !isRaw(i, rawPairs)) {
// its already encoded (decimal encoded) so just append as is
sb.append(ch);
} else {
http://git-wip-us.apache.org/repos/asf/camel/blob/feb4ac9a/camel-core/src/test/java/org/apache/camel/component/file/FileURLDecodingTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/file/FileURLDecodingTest.java b/camel-core/src/test/java/org/apache/camel/component/file/FileURLDecodingTest.java
new file mode 100644
index 0000000..9f7c0c6
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/file/FileURLDecodingTest.java
@@ -0,0 +1,105 @@
+/**
+ * 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.file;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.nio.file.Paths;
+
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+
+public class FileURLDecodingTest extends ContextTestSupport {
+
+ static final String TARGET_DIR = "target/files";
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ deleteDirectory(TARGET_DIR);
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ context.stop();
+ super.tearDown();
+ }
+
+ public void testSimpleFile() throws Exception {
+ assertTargetFile("data.txt", "data.txt");
+ }
+
+ public void testFilePlus() throws Exception {
+ assertTargetFile("data+.txt", "data .txt");
+ }
+
+ public void testFileSpace() throws Exception {
+ assertTargetFile("data%20.txt", "data .txt");
+ }
+
+ public void testFile2B() throws Exception {
+ assertTargetFile("data%2B.txt", "data .txt");
+ }
+ public void testFileRaw2B() throws Exception {
+ assertTargetFile("RAW(data%2B.txt)", "data%2B.txt");
+ }
+
+ public void testFileRawPlus() throws Exception {
+ assertTargetFile("RAW(data+.txt)", "data+.txt");
+ }
+
+ public void testFileRawSpace() throws Exception {
+ assertTargetFile("RAW(data%20.txt)", "data%20.txt");
+ }
+
+ public void testFileRaw2520() throws Exception {
+ assertTargetFile("RAW(data%2520.txt)", "data%2520.txt");
+ }
+
+ public void testFileWithTwoHundredPercent() throws Exception {
+ assertTargetFile("RAW(data%%.txt)", "data%%.txt");
+ }
+
+
+ private void assertTargetFile(final String encoded, final String expected) throws Exception {
+
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").to("file:" + TARGET_DIR + "?fileName=" + encoded);
+ }
+ });
+
+ context.start();
+
+ String result = template.requestBody("direct:start", "Kermit", String.class);
+ assertEquals("Kermit", result);
+
+ BufferedReader br = new BufferedReader(new FileReader(Paths.get(TARGET_DIR, expected).toFile()));
+ assertEquals("Kermit", br.readLine());
+ br.close();
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/feb4ac9a/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java b/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java
index cdefcec..7e66b9e 100644
--- a/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java
+++ b/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java
@@ -255,7 +255,8 @@ public class URISupportTest extends ContextTestSupport {
assertEquals("xmpp://camel-user@localhost:123/test-user@localhost?password=RAW(++?w0rd)&serviceName=some+chat", out);
String out2 = URISupport.normalizeUri("xmpp://camel-user@localhost:123/test-user@localhost?password=RAW(foo %% bar)&serviceName=some chat");
- assertEquals("xmpp://camel-user@localhost:123/test-user@localhost?password=RAW(foo %% bar)&serviceName=some+chat", out2);
+ // Just make sure the RAW parameter can be resolved rightly, we need to replace the % into %25
+ assertEquals("xmpp://camel-user@localhost:123/test-user@localhost?password=RAW(foo %25%25 bar)&serviceName=some+chat", out2);
}
public void testParseQuery() throws Exception {
@@ -273,6 +274,11 @@ public class URISupportTest extends ContextTestSupport {
assertEquals(2, map.size());
assertEquals("RAW(++?)w&rd)", map.get("password"));
assertEquals("somechat", map.get("serviceName"));
+
+ map = URISupport.parseQuery("password=RAW(%2520w&rd)&serviceName=somechat");
+ assertEquals(2, map.size());
+ assertEquals("RAW(%2520w&rd)", map.get("password"));
+ assertEquals("somechat", map.get("serviceName"));
}
public void testResolveRawParameterValues() throws Exception {