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/07/26 11:06:59 UTC
[1/3] camel git commit: CAMEL-10156: Improved bean method call to
validate if method name with parameters has valid number of parenthesis in
the syntax.
Repository: camel
Updated Branches:
refs/heads/camel-2.17.x 052807ad2 -> 0d4511a33
refs/heads/master 59c3420d8 -> ef0b438d4
CAMEL-10156: Improved bean method call to validate if method name with parameters has valid number of parenthesis in the syntax.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ef0b438d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ef0b438d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ef0b438d
Branch: refs/heads/master
Commit: ef0b438d4a3ab1a5e6bd530479aa32f71fef857d
Parents: 59c3420
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jul 26 11:30:59 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jul 26 13:03:23 2016 +0200
----------------------------------------------------------------------
.../apache/camel/component/bean/BeanInfo.java | 5 ++
.../bean/BeanParameterInvalidSyntaxTest.java | 80 ++++++++++++++++++++
2 files changed, 85 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/ef0b438d/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java b/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
index 5a3a0ef..752db1e 100644
--- a/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
+++ b/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
@@ -214,6 +214,11 @@ public class BeanInfo {
if (!methodName.endsWith(")")) {
throw new IllegalArgumentException("Method should end with parenthesis, was " + methodName);
}
+ // and there must be an even number of parenthesis in the syntax
+ // (we can use betweenOuterPair as it return null if the syntax is invalid)
+ if (ObjectHelper.betweenOuterPair(methodName, '(', ')') == null) {
+ throw new IllegalArgumentException("Method should have even pair of parenthesis, was " + methodName);
+ }
}
boolean emptyParameters = methodName.endsWith("()");
http://git-wip-us.apache.org/repos/asf/camel/blob/ef0b438d/camel-core/src/test/java/org/apache/camel/component/bean/BeanParameterInvalidSyntaxTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/bean/BeanParameterInvalidSyntaxTest.java b/camel-core/src/test/java/org/apache/camel/component/bean/BeanParameterInvalidSyntaxTest.java
new file mode 100644
index 0000000..024f326
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/bean/BeanParameterInvalidSyntaxTest.java
@@ -0,0 +1,80 @@
+/**
+ * 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.bean;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+
+public class BeanParameterInvalidSyntaxTest extends ContextTestSupport {
+
+ public void testBeanParameterInvalidSyntax() throws Exception {
+ getMockEndpoint("mock:result").expectedMessageCount(0);
+
+ try {
+ template.sendBody("direct:a", "World");
+ fail("Should have thrown exception");
+ } catch (CamelExecutionException e) {
+ IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+ assertEquals("Method should have even pair of parenthesis, was echo(${body}, 5))", iae.getMessage());
+ }
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndi = super.createRegistry();
+ jndi.bind("foo", new MyBean());
+ return jndi;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:a")
+ // invalid due extra parenthesis at the end
+ .to("bean:foo?method=echo(${body}, 5))")
+ .to("mock:result");
+ }
+ };
+ }
+
+ public static class MyBean {
+
+ public String echo(String body, int times) {
+ if (body == null) {
+ // use an empty string for no body
+ return "";
+ }
+
+ if (times > 0) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < times; i++) {
+ sb.append(body);
+ }
+ return sb.toString();
+ }
+
+ return body;
+ }
+
+ }
+}
[3/3] camel git commit: Fixed CS. This closes #1080
Posted by da...@apache.org.
Fixed CS. This closes #1080
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0d4511a3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0d4511a3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0d4511a3
Branch: refs/heads/camel-2.17.x
Commit: 0d4511a3368c9108293db998c43a6c5c428f00e4
Parents: 2b9a214
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Jul 25 17:15:42 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jul 26 13:03:42 2016 +0200
----------------------------------------------------------------------
.../component/restlet/DefaultRestletBinding.java | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/0d4511a3/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
index 31eb55e..be75a8e 100644
--- a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
+++ b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
@@ -195,23 +195,22 @@ public class DefaultRestletBinding implements RestletBinding, HeaderFilterStrate
}
}
- //Get outgoing custom http headers from the exchange if they exists
- Series<Header> restletHeaders = exchange.getIn().getHeader(HeaderConstants.ATTRIBUTE_HEADERS,Series.class);
+ // get outgoing custom http headers from the exchange if they exists
+ Series<Header> restletHeaders = exchange.getIn().getHeader(HeaderConstants.ATTRIBUTE_HEADERS, Series.class);
if (restletHeaders == null) {
- restletHeaders = new Series<>(Header.class);
+ restletHeaders = new Series<Header>(Header.class);
request.getAttributes().put(HeaderConstants.ATTRIBUTE_HEADERS, restletHeaders);
} else {
-
- //If the restlet headers already exists on the exchange, we need to filter them
- for(String name : restletHeaders.getNames()){
- if(headerFilterStrategy.applyFilterToCamelHeaders(name, restletHeaders.getValues(name), exchange)) {
+ // if the restlet headers already exists on the exchange, we need to filter them
+ for (String name : restletHeaders.getNames()) {
+ if (headerFilterStrategy.applyFilterToCamelHeaders(name, restletHeaders.getValues(name), exchange)) {
restletHeaders.removeAll(name);
}
}
request.getAttributes().put(HeaderConstants.ATTRIBUTE_HEADERS, restletHeaders);
-
- //Since the restlet headers already exists remove them from the exchange so they don't get added again below
- //We will get a new set of restlet headers on the response
+
+ // since the restlet headers already exists remove them from the exchange so they don't get added again below
+ // we will get a new set of restlet headers on the response
exchange.getIn().removeHeader(HeaderConstants.ATTRIBUTE_HEADERS);
}
[2/3] camel git commit: Filter existing restlet headers when building
restlet request
Posted by da...@apache.org.
Filter existing restlet headers when building restlet request
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2b9a2141
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2b9a2141
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2b9a2141
Branch: refs/heads/camel-2.17.x
Commit: 2b9a2141e62f3d5fa25babc6828265d6da6a7914
Parents: 052807a
Author: John Moon <jo...@transamerica.com>
Authored: Mon Jul 18 10:00:03 2016 -0400
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jul 26 13:03:42 2016 +0200
----------------------------------------------------------------------
.../component/restlet/DefaultRestletBinding.java | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/2b9a2141/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
index 482a97a..31eb55e 100644
--- a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
+++ b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
@@ -195,11 +195,24 @@ public class DefaultRestletBinding implements RestletBinding, HeaderFilterStrate
}
}
- //Get outgoing custom http headers
- Series<Header> restletHeaders = (Series)request.getAttributes().get(HeaderConstants.ATTRIBUTE_HEADERS);
+ //Get outgoing custom http headers from the exchange if they exists
+ Series<Header> restletHeaders = exchange.getIn().getHeader(HeaderConstants.ATTRIBUTE_HEADERS,Series.class);
if (restletHeaders == null) {
restletHeaders = new Series<>(Header.class);
request.getAttributes().put(HeaderConstants.ATTRIBUTE_HEADERS, restletHeaders);
+ } else {
+
+ //If the restlet headers already exists on the exchange, we need to filter them
+ for(String name : restletHeaders.getNames()){
+ if(headerFilterStrategy.applyFilterToCamelHeaders(name, restletHeaders.getValues(name), exchange)) {
+ restletHeaders.removeAll(name);
+ }
+ }
+ request.getAttributes().put(HeaderConstants.ATTRIBUTE_HEADERS, restletHeaders);
+
+ //Since the restlet headers already exists remove them from the exchange so they don't get added again below
+ //We will get a new set of restlet headers on the response
+ exchange.getIn().removeHeader(HeaderConstants.ATTRIBUTE_HEADERS);
}
// login and password are filtered by header filter strategy