CAMEL-9935: rest-dsl and http consumers should map empty/blank http query parameters as empty values (allow empty).
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f26ef892 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f26ef892 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f26ef892 Branch: refs/heads/camel-2.19.x Commit: f26ef892d8543b25954c00fe317a4f54f2ff54c9 Parents: be0558d Author: Claus Ibsen <davscl...@apache.org> Authored: Tue May 23 15:05:18 2017 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Tue May 23 15:05:45 2017 +0200 ---------------------------------------------------------------------- .../camel/http/common/DefaultHttpBinding.java | 2 +- .../jetty/HttpEmptyQueryParameterTest.java | 51 ++++++++++++++++++ .../netty4/http/DefaultNettyHttpBinding.java | 10 ++-- .../http/NettyHttpEmptyQueryParameterTest.java | 51 ++++++++++++++++++ .../RestletHttpEmptyQueryParameterTest.java | 55 ++++++++++++++++++++ .../UndertowHttpEmptyQueryParameterTest.java | 52 ++++++++++++++++++ 6 files changed, 215 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/f26ef892/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java ---------------------------------------------------------------------- diff --git a/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java b/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java index b64d1e7..4bf1b76 100644 --- a/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java +++ b/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java @@ -377,7 +377,7 @@ public class DefaultHttpBinding implements HttpBinding { String key = entry.getKey(); Object value = entry.getValue(); // use an iterator as there can be multiple values. (must not use a delimiter) - final Iterator<?> it = ObjectHelper.createIterator(value, null); + final Iterator<?> it = ObjectHelper.createIterator(value, null, true); while (it.hasNext()) { String headerValue = convertHeaderValueToString(exchange, it.next()); if (headerValue != null && headerFilterStrategy != null http://git-wip-us.apache.org/repos/asf/camel/blob/f26ef892/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HttpEmptyQueryParameterTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HttpEmptyQueryParameterTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HttpEmptyQueryParameterTest.java new file mode 100644 index 0000000..cbd76ab --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HttpEmptyQueryParameterTest.java @@ -0,0 +1,51 @@ +/** + * 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.jetty; + +import org.apache.camel.builder.RouteBuilder; +import org.junit.Test; + +public class HttpEmptyQueryParameterTest extends BaseJettyTest { + + @Test + public void testEmpty() throws Exception { + getMockEndpoint("mock:input").expectedHeaderReceived("id", 123); + String out = fluentTemplate.to("jetty:http://localhost:{{port}}/foo?id=123").request(String.class); + assertEquals("Header: 123", out); + assertMockEndpointsSatisfied(); + + resetMocks(); + + getMockEndpoint("mock:input").expectedHeaderReceived("id", ""); + out = fluentTemplate.to("jetty:http://localhost:{{port}}/foo?id=").request(String.class); + assertEquals("Header: ", out); + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("jetty:http://0.0.0.0:{{port}}/foo") + .to("mock:input") + .transform().simple("Header: ${header.id}"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/f26ef892/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultNettyHttpBinding.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultNettyHttpBinding.java b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultNettyHttpBinding.java index c27bdd6..3d92f21 100644 --- a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultNettyHttpBinding.java +++ b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultNettyHttpBinding.java @@ -170,7 +170,7 @@ public class DefaultNettyHttpBinding implements NettyHttpBinding, Cloneable { // add the headers one by one, and use the header filter strategy List<String> values = request.headers().getAll(name); - Iterator<?> it = ObjectHelper.createIterator(values); + Iterator<?> it = ObjectHelper.createIterator(values, ",", true); while (it.hasNext()) { Object extracted = it.next(); Object decoded = shouldUrlDecodeHeader(configuration, name, extracted, "UTF-8"); @@ -190,7 +190,7 @@ public class DefaultNettyHttpBinding implements NettyHttpBinding, Cloneable { for (Map.Entry<String, Object> entry : uriParameters.entrySet()) { String name = entry.getKey(); Object values = entry.getValue(); - Iterator<?> it = ObjectHelper.createIterator(values); + Iterator<?> it = ObjectHelper.createIterator(values, ",", true); while (it.hasNext()) { Object extracted = it.next(); Object decoded = shouldUrlDecodeHeader(configuration, name, extracted, "UTF-8"); @@ -212,7 +212,7 @@ public class DefaultNettyHttpBinding implements NettyHttpBinding, Cloneable { String charset = "UTF-8"; // Push POST form params into the headers to retain compatibility with DefaultHttpBinding - String body = null; + String body; ByteBuf buffer = request.content(); try { body = buffer.toString(Charset.forName(charset)); @@ -385,7 +385,7 @@ public class DefaultNettyHttpBinding implements NettyHttpBinding, Cloneable { } } - HttpResponse response = null; + HttpResponse response; if (buffer != null) { response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.valueOf(code), buffer); @@ -410,7 +410,7 @@ public class DefaultNettyHttpBinding implements NettyHttpBinding, Cloneable { String key = entry.getKey(); Object value = entry.getValue(); // use an iterator as there can be multiple values. (must not use a delimiter) - final Iterator<?> it = ObjectHelper.createIterator(value, null); + final Iterator<?> it = ObjectHelper.createIterator(value, null, true); while (it.hasNext()) { String headerValue = tc.convertTo(String.class, it.next()); if (headerValue != null && headerFilterStrategy != null http://git-wip-us.apache.org/repos/asf/camel/blob/f26ef892/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpEmptyQueryParameterTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpEmptyQueryParameterTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpEmptyQueryParameterTest.java new file mode 100644 index 0000000..fdf4af7 --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpEmptyQueryParameterTest.java @@ -0,0 +1,51 @@ +/** + * 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.netty4.http; + +import org.apache.camel.builder.RouteBuilder; +import org.junit.Test; + +public class NettyHttpEmptyQueryParameterTest extends BaseNettyTest { + + @Test + public void testEmpty() throws Exception { + getMockEndpoint("mock:input").expectedHeaderReceived("id", 123); + String out = fluentTemplate.to("netty4-http:http://localhost:{{port}}/foo?id=123").request(String.class); + assertEquals("Header: 123", out); + assertMockEndpointsSatisfied(); + + resetMocks(); + + getMockEndpoint("mock:input").expectedHeaderReceived("id", ""); + out = fluentTemplate.to("netty4-http:http://localhost:{{port}}/foo?id=").request(String.class); + assertEquals("Header: ", out); + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("netty4-http:http://0.0.0.0:{{port}}/foo") + .to("mock:input") + .transform().simple("Header: ${header.id}"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/f26ef892/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletHttpEmptyQueryParameterTest.java ---------------------------------------------------------------------- diff --git a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletHttpEmptyQueryParameterTest.java b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletHttpEmptyQueryParameterTest.java new file mode 100644 index 0000000..5b16e07 --- /dev/null +++ b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletHttpEmptyQueryParameterTest.java @@ -0,0 +1,55 @@ +/** + * 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.restlet; + +import org.apache.camel.builder.RouteBuilder; +import org.junit.Ignore; +import org.junit.Test; + +/** + * @version + */ +@Ignore("Need to add support for lenient properties to producer") +public class RestletHttpEmptyQueryParameterTest extends RestletTestSupport { + + @Test + public void testEmpty() throws Exception { + getMockEndpoint("mock:input").expectedHeaderReceived("id", 123); + String out = fluentTemplate.to("restlet:http://localhost:" + portNum + "/foo?id=123").request(String.class); + assertEquals("Header: 123", out); + assertMockEndpointsSatisfied(); + + resetMocks(); + + getMockEndpoint("mock:input").expectedHeaderReceived("id", ""); + out = fluentTemplate.to("restlet:http://localhost:" + portNum + "/foo?id=").request(String.class); + assertEquals("Header: ", out); + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("restlet:http://0.0.0.0:" + portNum + "/foo") + .to("mock:input") + .transform().simple("Header: ${header.id}"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/f26ef892/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/UndertowHttpEmptyQueryParameterTest.java ---------------------------------------------------------------------- diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/UndertowHttpEmptyQueryParameterTest.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/UndertowHttpEmptyQueryParameterTest.java new file mode 100644 index 0000000..b9151db --- /dev/null +++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/UndertowHttpEmptyQueryParameterTest.java @@ -0,0 +1,52 @@ +/** + * 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.undertow.rest; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.undertow.BaseUndertowTest; +import org.junit.Test; + +public class UndertowHttpEmptyQueryParameterTest extends BaseUndertowTest { + + @Test + public void testEmpty() throws Exception { + getMockEndpoint("mock:input").expectedHeaderReceived("id", 123); + String out = fluentTemplate.to("undertow:http://localhost:{{port}}/foo?id=123").request(String.class); + assertEquals("Header: 123", out); + assertMockEndpointsSatisfied(); + + resetMocks(); + + getMockEndpoint("mock:input").expectedHeaderReceived("id", ""); + out = fluentTemplate.to("undertow:http://localhost:{{port}}/foo?id=").request(String.class); + assertEquals("Header: ", out); + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("undertow:http://0.0.0.0:{{port}}/foo") + .to("mock:input") + .transform().simple("Header: ${header.id}"); + } + }; + } + +}