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 2014/03/18 11:04:50 UTC
[1/3] git commit: CAMEL-7304: Fixed interceptSendToEndpoint to match
uris as it needed to be normalized.
Repository: camel
Updated Branches:
refs/heads/camel-2.12.x 7569a4b18 -> b83f0b6d9
refs/heads/camel-2.13.x a0cde9b08 -> 65a58710c
refs/heads/master 46e67a149 -> fa165d6b9
CAMEL-7304: Fixed interceptSendToEndpoint to match uris as it needed to be normalized.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/fa165d6b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/fa165d6b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/fa165d6b
Branch: refs/heads/master
Commit: fa165d6b99491ca127eb6a4bc78c18b37a0d7304
Parents: 46e67a1
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 18 11:06:50 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 18 11:06:50 2014 +0100
----------------------------------------------------------------------
.../InterceptSendToEndpointDefinition.java | 27 ++++++++++-
...rceptSendToEndpointNormalizePatternTest.java | 49 ++++++++++++++++++++
2 files changed, 75 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/fa165d6b/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java b/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java
index 9b8bdc3..be2dcb9 100644
--- a/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java
@@ -22,6 +22,7 @@ import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
+import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.Predicate;
import org.apache.camel.Processor;
@@ -30,6 +31,7 @@ import org.apache.camel.processor.InterceptEndpointProcessor;
import org.apache.camel.spi.EndpointStrategy;
import org.apache.camel.spi.RouteContext;
import org.apache.camel.util.EndpointHelper;
+import org.apache.camel.util.URISupport;
/**
* Represents an XML <interceptToEndpoint/> element
@@ -95,7 +97,7 @@ public class InterceptSendToEndpointDefinition extends OutputDefinition<Intercep
if (endpoint instanceof InterceptSendToEndpoint) {
// endpoint already decorated
return endpoint;
- } else if (getUri() == null || EndpointHelper.matchEndpoint(routeContext.getCamelContext(), uri, getUri())) {
+ } else if (getUri() == null || matchPattern(routeContext.getCamelContext(), uri, getUri())) {
// only proxy if the uri is matched decorate endpoint with our proxy
// should be false by default
boolean skip = isSkipSendToOriginalEndpoint();
@@ -121,6 +123,29 @@ public class InterceptSendToEndpointDefinition extends OutputDefinition<Intercep
}
/**
+ * Does the uri match the pattern.
+ *
+ * @param camelContext the CamelContext
+ * @param uri the uri
+ * @param pattern the pattern, which can be an endpoint uri as well
+ * @return <tt>true</tt> if matched and we should intercept, <tt>false</tt> if not matched, and not intercept.
+ */
+ protected boolean matchPattern(CamelContext camelContext, String uri, String pattern) {
+ // match using the pattern as-is
+ boolean match = EndpointHelper.matchEndpoint(camelContext, uri, pattern);
+ if (!match) {
+ try {
+ // the pattern could be an uri, so we need to normalize it before matching again
+ pattern = URISupport.normalizeUri(pattern);
+ match = EndpointHelper.matchEndpoint(camelContext, uri, pattern);
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ return match;
+ }
+
+ /**
* Applies this interceptor only if the given predicate is true
*
* @param predicate the predicate
http://git-wip-us.apache.org/repos/asf/camel/blob/fa165d6b/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointNormalizePatternTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointNormalizePatternTest.java b/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointNormalizePatternTest.java
new file mode 100644
index 0000000..c05bea3
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointNormalizePatternTest.java
@@ -0,0 +1,49 @@
+/**
+ * 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.processor.intercept;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * Unit test for intercepting sending to endpoint
+ */
+public class InterceptSendToEndpointNormalizePatternTest extends ContextTestSupport {
+
+ public void testIntercept() throws Exception {
+ getMockEndpoint("mock:intercept").expectedMessageCount(1);
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ interceptSendToEndpoint("stub:foo?privateKeyFile=/user/.ssh.id_rsa").to("mock:intercept");
+
+ from("direct:start")
+ .to("stub:foo?privateKeyFile=/user/.ssh.id_rsa")
+ .to("mock:result");
+ }
+ };
+ }
+}
[3/3] git commit: CAMEL-7304: Fixed interceptSendToEndpoint to match
uris as it needed to be normalized.
Posted by da...@apache.org.
CAMEL-7304: Fixed interceptSendToEndpoint to match uris as it needed to be normalized.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b83f0b6d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b83f0b6d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b83f0b6d
Branch: refs/heads/camel-2.12.x
Commit: b83f0b6d98401b3797bf0e5160a3c6b73aca09be
Parents: 7569a4b
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 18 11:06:50 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 18 11:07:29 2014 +0100
----------------------------------------------------------------------
.../InterceptSendToEndpointDefinition.java | 27 ++++++++++-
...rceptSendToEndpointNormalizePatternTest.java | 49 ++++++++++++++++++++
2 files changed, 75 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/b83f0b6d/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java b/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java
index 9b8bdc3..be2dcb9 100644
--- a/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java
@@ -22,6 +22,7 @@ import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
+import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.Predicate;
import org.apache.camel.Processor;
@@ -30,6 +31,7 @@ import org.apache.camel.processor.InterceptEndpointProcessor;
import org.apache.camel.spi.EndpointStrategy;
import org.apache.camel.spi.RouteContext;
import org.apache.camel.util.EndpointHelper;
+import org.apache.camel.util.URISupport;
/**
* Represents an XML <interceptToEndpoint/> element
@@ -95,7 +97,7 @@ public class InterceptSendToEndpointDefinition extends OutputDefinition<Intercep
if (endpoint instanceof InterceptSendToEndpoint) {
// endpoint already decorated
return endpoint;
- } else if (getUri() == null || EndpointHelper.matchEndpoint(routeContext.getCamelContext(), uri, getUri())) {
+ } else if (getUri() == null || matchPattern(routeContext.getCamelContext(), uri, getUri())) {
// only proxy if the uri is matched decorate endpoint with our proxy
// should be false by default
boolean skip = isSkipSendToOriginalEndpoint();
@@ -121,6 +123,29 @@ public class InterceptSendToEndpointDefinition extends OutputDefinition<Intercep
}
/**
+ * Does the uri match the pattern.
+ *
+ * @param camelContext the CamelContext
+ * @param uri the uri
+ * @param pattern the pattern, which can be an endpoint uri as well
+ * @return <tt>true</tt> if matched and we should intercept, <tt>false</tt> if not matched, and not intercept.
+ */
+ protected boolean matchPattern(CamelContext camelContext, String uri, String pattern) {
+ // match using the pattern as-is
+ boolean match = EndpointHelper.matchEndpoint(camelContext, uri, pattern);
+ if (!match) {
+ try {
+ // the pattern could be an uri, so we need to normalize it before matching again
+ pattern = URISupport.normalizeUri(pattern);
+ match = EndpointHelper.matchEndpoint(camelContext, uri, pattern);
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ return match;
+ }
+
+ /**
* Applies this interceptor only if the given predicate is true
*
* @param predicate the predicate
http://git-wip-us.apache.org/repos/asf/camel/blob/b83f0b6d/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointNormalizePatternTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointNormalizePatternTest.java b/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointNormalizePatternTest.java
new file mode 100644
index 0000000..c05bea3
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointNormalizePatternTest.java
@@ -0,0 +1,49 @@
+/**
+ * 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.processor.intercept;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * Unit test for intercepting sending to endpoint
+ */
+public class InterceptSendToEndpointNormalizePatternTest extends ContextTestSupport {
+
+ public void testIntercept() throws Exception {
+ getMockEndpoint("mock:intercept").expectedMessageCount(1);
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ interceptSendToEndpoint("stub:foo?privateKeyFile=/user/.ssh.id_rsa").to("mock:intercept");
+
+ from("direct:start")
+ .to("stub:foo?privateKeyFile=/user/.ssh.id_rsa")
+ .to("mock:result");
+ }
+ };
+ }
+}
[2/3] git commit: CAMEL-7304: Fixed interceptSendToEndpoint to match
uris as it needed to be normalized.
Posted by da...@apache.org.
CAMEL-7304: Fixed interceptSendToEndpoint to match uris as it needed to be normalized.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/65a58710
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/65a58710
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/65a58710
Branch: refs/heads/camel-2.13.x
Commit: 65a58710cad9acf728c1a5c0b71b8f61b8e55f29
Parents: a0cde9b
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 18 11:06:50 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 18 11:07:19 2014 +0100
----------------------------------------------------------------------
.../InterceptSendToEndpointDefinition.java | 27 ++++++++++-
...rceptSendToEndpointNormalizePatternTest.java | 49 ++++++++++++++++++++
2 files changed, 75 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/65a58710/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java b/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java
index 9b8bdc3..be2dcb9 100644
--- a/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java
@@ -22,6 +22,7 @@ import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
+import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.Predicate;
import org.apache.camel.Processor;
@@ -30,6 +31,7 @@ import org.apache.camel.processor.InterceptEndpointProcessor;
import org.apache.camel.spi.EndpointStrategy;
import org.apache.camel.spi.RouteContext;
import org.apache.camel.util.EndpointHelper;
+import org.apache.camel.util.URISupport;
/**
* Represents an XML <interceptToEndpoint/> element
@@ -95,7 +97,7 @@ public class InterceptSendToEndpointDefinition extends OutputDefinition<Intercep
if (endpoint instanceof InterceptSendToEndpoint) {
// endpoint already decorated
return endpoint;
- } else if (getUri() == null || EndpointHelper.matchEndpoint(routeContext.getCamelContext(), uri, getUri())) {
+ } else if (getUri() == null || matchPattern(routeContext.getCamelContext(), uri, getUri())) {
// only proxy if the uri is matched decorate endpoint with our proxy
// should be false by default
boolean skip = isSkipSendToOriginalEndpoint();
@@ -121,6 +123,29 @@ public class InterceptSendToEndpointDefinition extends OutputDefinition<Intercep
}
/**
+ * Does the uri match the pattern.
+ *
+ * @param camelContext the CamelContext
+ * @param uri the uri
+ * @param pattern the pattern, which can be an endpoint uri as well
+ * @return <tt>true</tt> if matched and we should intercept, <tt>false</tt> if not matched, and not intercept.
+ */
+ protected boolean matchPattern(CamelContext camelContext, String uri, String pattern) {
+ // match using the pattern as-is
+ boolean match = EndpointHelper.matchEndpoint(camelContext, uri, pattern);
+ if (!match) {
+ try {
+ // the pattern could be an uri, so we need to normalize it before matching again
+ pattern = URISupport.normalizeUri(pattern);
+ match = EndpointHelper.matchEndpoint(camelContext, uri, pattern);
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ return match;
+ }
+
+ /**
* Applies this interceptor only if the given predicate is true
*
* @param predicate the predicate
http://git-wip-us.apache.org/repos/asf/camel/blob/65a58710/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointNormalizePatternTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointNormalizePatternTest.java b/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointNormalizePatternTest.java
new file mode 100644
index 0000000..c05bea3
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointNormalizePatternTest.java
@@ -0,0 +1,49 @@
+/**
+ * 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.processor.intercept;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * Unit test for intercepting sending to endpoint
+ */
+public class InterceptSendToEndpointNormalizePatternTest extends ContextTestSupport {
+
+ public void testIntercept() throws Exception {
+ getMockEndpoint("mock:intercept").expectedMessageCount(1);
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ interceptSendToEndpoint("stub:foo?privateKeyFile=/user/.ssh.id_rsa").to("mock:intercept");
+
+ from("direct:start")
+ .to("stub:foo?privateKeyFile=/user/.ssh.id_rsa")
+ .to("mock:result");
+ }
+ };
+ }
+}