You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/06/28 18:25:22 UTC
[2/2] camel git commit: CAMEL-10095: The XML DSL will preserve double
spaces in the context-path of uri attributes when removing white space noise,
when uri's are configured using mutli lines.
CAMEL-10095: The XML DSL will preserve double spaces in the context-path of uri attributes when removing white space noise, when uri's are configured using mutli lines.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/af7f28c9
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/af7f28c9
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/af7f28c9
Branch: refs/heads/camel-2.17.x
Commit: af7f28c9b98c96a861078cdea611907cabea575e
Parents: bf56add
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jun 28 20:24:10 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jun 28 20:24:43 2016 +0200
----------------------------------------------------------------------
.../handler/CamelNamespaceHandler.java | 19 ++++++++++++-------
.../spring/handler/CamelNamespaceHandler.java | 20 ++++++++++++--------
.../properties/SpringAttributeNewLineTest.java | 3 +++
.../properties/SpringAttributeNewLineTest.xml | 5 +++++
.../test/blueprint/AttributeNewLineTest.java | 3 +++
.../test/blueprint/AttributeNewLineTest.xml | 5 +++++
6 files changed, 40 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/af7f28c9/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
index 63d6724..29a7576 100644
--- a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
+++ b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
@@ -150,13 +150,18 @@ public class CamelNamespaceHandler implements NamespaceHandler {
for (int i = 0; i < map.getLength(); i++) {
Node att = map.item(i);
if (att.getNodeName().equals("uri") || att.getNodeName().endsWith("Uri")) {
- String value = att.getNodeValue();
- // remove all double spaces
- String changed = value.replaceAll("\\s{2,}", "");
-
- if (!value.equals(changed)) {
- LOG.debug("Removed whitespace noise from attribute {} -> {}", value, changed);
- att.setNodeValue(changed);
+ final String value = att.getNodeValue();
+ String before = ObjectHelper.before(value, "?");
+ String after = ObjectHelper.after(value, "?");
+
+ if (before != null && after != null) {
+ // remove all double spaces in the uri parameters
+ String changed = after.replaceAll("\\s{2,}", "");
+ if (!after.equals(changed)) {
+ String newAtr = before.trim() + "?" + changed.trim();
+ LOG.debug("Removed whitespace noise from attribute {} -> {}", value, newAtr);
+ att.setNodeValue(newAtr);
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/af7f28c9/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java b/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
index 4979254..c7ad9ba 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
@@ -101,14 +101,18 @@ public class CamelNamespaceHandler extends NamespaceHandlerSupport {
for (int i = 0; i < map.getLength(); i++) {
Node att = map.item(i);
if (att.getNodeName().equals("uri") || att.getNodeName().endsWith("Uri")) {
-
- String value = att.getNodeValue();
- // remove all double spaces
- String changed = value.replaceAll("\\s{2,}", "");
-
- if (!value.equals(changed)) {
- LOG.debug("Removed whitespace noise from attribute {} -> {}", value, changed);
- att.setNodeValue(changed);
+ final String value = att.getNodeValue();
+ String before = ObjectHelper.before(value, "?");
+ String after = ObjectHelper.after(value, "?");
+
+ if (before != null && after != null) {
+ // remove all double spaces in the uri parameters
+ String changed = after.replaceAll("\\s{2,}", "");
+ if (!after.equals(changed)) {
+ String newAtr = before.trim() + "?" + changed.trim();
+ LOG.debug("Removed whitespace noise from attribute {} -> {}", value, newAtr);
+ att.setNodeValue(newAtr);
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/af7f28c9/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringAttributeNewLineTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringAttributeNewLineTest.java b/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringAttributeNewLineTest.java
index 96aa640..2b63c10 100644
--- a/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringAttributeNewLineTest.java
+++ b/components/camel-spring/src/test/java/org/apache/camel/component/properties/SpringAttributeNewLineTest.java
@@ -38,6 +38,9 @@ public class SpringAttributeNewLineTest extends SpringTestSupport {
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
+
+ Object stub = context.hasEndpoint("stub:GET /v1/phonebook/companies/{companyCode}?oauth=OPTIONAL");
+ assertNotNull("Should have stub endpoint with double spaces", stub);
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/af7f28c9/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringAttributeNewLineTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringAttributeNewLineTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringAttributeNewLineTest.xml
index ca56aa2..0265b01 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringAttributeNewLineTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/properties/SpringAttributeNewLineTest.xml
@@ -37,6 +37,11 @@
<to uri="mock:bar"/>
</route>
+ <route>
+ <from uri="stub:GET /v1/phonebook/companies/{companyCode}?oauth=OPTIONAL"/>
+ <to uri="mock:stub"/>
+ </route>
+
</camelContext>
</beans>
http://git-wip-us.apache.org/repos/asf/camel/blob/af7f28c9/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/AttributeNewLineTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/AttributeNewLineTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/AttributeNewLineTest.java
index 9e74889..b037829 100644
--- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/AttributeNewLineTest.java
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/AttributeNewLineTest.java
@@ -32,6 +32,9 @@ public class AttributeNewLineTest extends CamelBlueprintTestSupport {
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
+
+ Object stub = context.hasEndpoint("stub:GET /v1/phonebook/companies/{companyCode}?oauth=OPTIONAL");
+ assertNotNull("Should have stub endpoint with double spaces", stub);
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/af7f28c9/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/AttributeNewLineTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/AttributeNewLineTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/AttributeNewLineTest.xml
index 79fc8fd..70db87d 100644
--- a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/AttributeNewLineTest.xml
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/AttributeNewLineTest.xml
@@ -35,6 +35,11 @@
<to uri="mock:bar"/>
</route>
+ <route>
+ <from uri="stub:GET /v1/phonebook/companies/{companyCode}?oauth=OPTIONAL"/>
+ <to uri="mock:stub"/>
+ </route>
+
</camelContext>
</blueprint>
\ No newline at end of file