Repository: camel Updated Branches: refs/heads/camel-2.17.x bf56add3e -> af7f28c9b refs/heads/master 3b2b6e20a -> 05f13c00a
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/05f13c00 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/05f13c00 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/05f13c00 Branch: refs/heads/master Commit: 05f13c00aa26480a1c25df2a2851d77c2d2b74a0 Parents: 3b2b6e2 Author: Claus Ibsen <[email protected]> Authored: Tue Jun 28 20:24:10 2016 +0200 Committer: Claus Ibsen <[email protected]> Committed: Tue Jun 28 20:24:10 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/05f13c00/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/05f13c00/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 ca38795..917a3f3 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 @@ -106,14 +106,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/05f13c00/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/05f13c00/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/05f13c00/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/05f13c00/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
