http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpHeaderFilterStrategyRemovalTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpHeaderFilterStrategyRemovalTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpHeaderFilterStrategyRemovalTest.java new file mode 100644 index 0000000..8642bea --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpHeaderFilterStrategyRemovalTest.java @@ -0,0 +1,78 @@ +/** + * 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 static java.util.Collections.singleton; + +import org.apache.camel.EndpointInject; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.impl.JndiRegistry; +import org.junit.Test; + +import static org.apache.camel.Exchange.HTTP_QUERY; + +public class NettyHttpHeaderFilterStrategyRemovalTest extends BaseNettyTest { + + NettyHttpHeaderFilterStrategy headerFilterStrategy = new NettyHttpHeaderFilterStrategy(); + + @EndpointInject(uri = "mock:test") + MockEndpoint mockEndpoint; + + @Test + public void shouldRemoveStrategyOption() throws Exception { + String options = "headerFilterStrategy=#headerFilterStrategy"; + mockEndpoint.expectedMessageCount(1); + mockEndpoint.message(0).header(HTTP_QUERY).isNull(); + + template.sendBody("netty4-http:http://localhost:" + getPort() + "/?" + options, "message"); + + assertMockEndpointsSatisfied(); + } + + @Test + public void shouldResolveStrategyFromParameter() throws Exception { + String headerToFilter = "foo"; + headerFilterStrategy.setOutFilter(singleton(headerToFilter)); + String options = "headerFilterStrategy=#headerFilterStrategy"; + mockEndpoint.expectedMessageCount(1); + mockEndpoint.message(0).header(headerToFilter).isNull(); + + template.sendBodyAndHeader("netty4-http:http://localhost:" + getPort() + "/?" + options, "message", headerToFilter, "headerValue"); + + assertMockEndpointsSatisfied(); + } + + @Override + protected JndiRegistry createRegistry() throws Exception { + JndiRegistry registry = super.createRegistry(); + registry.bind("headerFilterStrategy", headerFilterStrategy); + return registry; + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("netty4-http:http://0.0.0.0:{{port}}/") + .to(mockEndpoint); + } + }; + } + +}
http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpHeaderFilterStrategyTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpHeaderFilterStrategyTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpHeaderFilterStrategyTest.java new file mode 100644 index 0000000..4fa8c69 --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpHeaderFilterStrategyTest.java @@ -0,0 +1,106 @@ +/** + * 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.Exchange; +import org.apache.camel.impl.DefaultCamelContext; +import org.apache.camel.impl.DefaultExchange; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class NettyHttpHeaderFilterStrategyTest { + + private NettyHttpHeaderFilterStrategy filter; + private Exchange exchange; + + @Before + public void setUp() { + filter = new NettyHttpHeaderFilterStrategy(); + exchange = new DefaultExchange(new DefaultCamelContext()); + } + + @Test + public void applyFilterToExternalHeaders() { + assertFalse(filter.applyFilterToExternalHeaders("content-length", 10, exchange)); + assertFalse(filter.applyFilterToExternalHeaders("Content-Length", 10, exchange)); + assertFalse(filter.applyFilterToExternalHeaders("content-type", "text/xml", exchange)); + assertFalse(filter.applyFilterToExternalHeaders("Content-Type", "text/xml", exchange)); + assertFalse(filter.applyFilterToExternalHeaders("cache-control", "no-cache", exchange)); + assertFalse(filter.applyFilterToExternalHeaders("Cache-Control", "no-cache", exchange)); + assertFalse(filter.applyFilterToExternalHeaders("connection", "close", exchange)); + assertFalse(filter.applyFilterToExternalHeaders("Connection", "close", exchange)); + assertFalse(filter.applyFilterToExternalHeaders("date", "close", exchange)); + assertFalse(filter.applyFilterToExternalHeaders("Data", "close", exchange)); + assertFalse(filter.applyFilterToExternalHeaders("pragma", "no-cache", exchange)); + assertFalse(filter.applyFilterToExternalHeaders("Pragma", "no-cache", exchange)); + assertFalse(filter.applyFilterToExternalHeaders("trailer", "Max-Forwards", exchange)); + assertFalse(filter.applyFilterToExternalHeaders("Trailer", "Max-Forwards", exchange)); + assertFalse(filter.applyFilterToExternalHeaders("transfer-encoding", "chunked", exchange)); + assertFalse(filter.applyFilterToExternalHeaders("Transfer-Encoding", "chunked", exchange)); + assertFalse(filter.applyFilterToExternalHeaders("upgrade", "HTTP/2.0", exchange)); + assertFalse(filter.applyFilterToExternalHeaders("Upgrade", "HTTP/2.0", exchange)); + assertFalse(filter.applyFilterToExternalHeaders("via", "1.1 nowhere.com", exchange)); + assertFalse(filter.applyFilterToExternalHeaders("Via", "1.1 nowhere.com", exchange)); + assertFalse(filter.applyFilterToExternalHeaders("warning", "199 Miscellaneous warning", exchange)); + assertFalse(filter.applyFilterToExternalHeaders("Warning", "199 Miscellaneous warning", exchange)); + + assertFalse(filter.applyFilterToExternalHeaders("CamelHeader", "test", exchange)); + assertFalse(filter.applyFilterToExternalHeaders("org.apache.camel.header", "test", exchange)); + + assertFalse(filter.applyFilterToExternalHeaders("notFilteredHeader", "test", exchange)); + + assertFalse(filter.applyFilterToExternalHeaders("host", "dummy.host.com", exchange)); + assertFalse(filter.applyFilterToExternalHeaders("Host", "dummy.host.com", exchange)); + } + + @Test + public void applyFilterToCamelHeaders() { + assertTrue(filter.applyFilterToCamelHeaders("content-length", 10, exchange)); + assertTrue(filter.applyFilterToCamelHeaders("Content-Length", 10, exchange)); + assertTrue(filter.applyFilterToCamelHeaders("content-type", "text/xml", exchange)); + assertTrue(filter.applyFilterToCamelHeaders("Content-Type", "text/xml", exchange)); + assertTrue(filter.applyFilterToCamelHeaders("cache-control", "no-cache", exchange)); + assertTrue(filter.applyFilterToCamelHeaders("Cache-Control", "no-cache", exchange)); + assertTrue(filter.applyFilterToCamelHeaders("connection", "close", exchange)); + assertTrue(filter.applyFilterToCamelHeaders("Connection", "close", exchange)); + assertTrue(filter.applyFilterToCamelHeaders("date", "close", exchange)); + assertTrue(filter.applyFilterToCamelHeaders("Date", "close", exchange)); + assertTrue(filter.applyFilterToCamelHeaders("pragma", "no-cache", exchange)); + assertTrue(filter.applyFilterToCamelHeaders("Pragma", "no-cache", exchange)); + assertTrue(filter.applyFilterToCamelHeaders("trailer", "Max-Forwards", exchange)); + assertTrue(filter.applyFilterToCamelHeaders("Trailer", "Max-Forwards", exchange)); + assertTrue(filter.applyFilterToCamelHeaders("transfer-encoding", "chunked", exchange)); + assertTrue(filter.applyFilterToCamelHeaders("Transfer-Encoding", "chunked", exchange)); + assertTrue(filter.applyFilterToCamelHeaders("upgrade", "HTTP/2.0", exchange)); + assertTrue(filter.applyFilterToCamelHeaders("Upgrade", "HTTP/2.0", exchange)); + assertTrue(filter.applyFilterToCamelHeaders("via", "1.1 nowhere.com", exchange)); + assertTrue(filter.applyFilterToCamelHeaders("Via", "1.1 nowhere.com", exchange)); + assertTrue(filter.applyFilterToCamelHeaders("warning", "199 Miscellaneous warning", exchange)); + assertTrue(filter.applyFilterToCamelHeaders("Warning", "199 Miscellaneous warning", exchange)); + + assertTrue(filter.applyFilterToCamelHeaders("CamelHeader", "test", exchange)); + assertTrue(filter.applyFilterToCamelHeaders("org.apache.camel.header", "test", exchange)); + + assertFalse(filter.applyFilterToCamelHeaders("notFilteredHeader", "test", exchange)); + + assertTrue(filter.applyFilterToCamelHeaders("host", "dummy.host.com", exchange)); + assertTrue(filter.applyFilterToCamelHeaders("Host", "dummy.host.com", exchange)); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpHeadersTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpHeadersTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpHeadersTest.java new file mode 100644 index 0000000..340ecff --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpHeadersTest.java @@ -0,0 +1,54 @@ +/** + * 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.Exchange; +import org.apache.camel.builder.RouteBuilder; +import org.junit.Test; + +public class NettyHttpHeadersTest extends BaseNettyTest { + + @Test + public void testHttpHeaders() throws Exception { + getMockEndpoint("mock:input").expectedBodiesReceived("Hello World"); + getMockEndpoint("mock:input").expectedHeaderReceived("beer", "yes"); + getMockEndpoint("mock:input").expectedHeaderReceived("host", "localhost"); + getMockEndpoint("mock:input").expectedHeaderReceived(Exchange.HTTP_METHOD, "POST"); + getMockEndpoint("mock:input").expectedHeaderReceived(Exchange.HTTP_URL, "http://localhost:" + getPort() + "/foo"); + getMockEndpoint("mock:input").expectedHeaderReceived(Exchange.HTTP_URI, "/foo"); + getMockEndpoint("mock:input").expectedHeaderReceived(Exchange.HTTP_QUERY, "beer=yes"); + getMockEndpoint("mock:input").expectedHeaderReceived(Exchange.HTTP_PATH, ""); + + String out = template.requestBody("netty4-http:http://localhost:{{port}}/foo?beer=yes", "Hello World", String.class); + assertEquals("Bye World", 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().constant("Bye World"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpMapHeadersFalseTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpMapHeadersFalseTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpMapHeadersFalseTest.java new file mode 100644 index 0000000..3bcf0e1 --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpMapHeadersFalseTest.java @@ -0,0 +1,70 @@ +/** + * 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.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpMethod; +import org.apache.commons.httpclient.methods.PostMethod; +import org.junit.Test; + +public class NettyHttpMapHeadersFalseTest extends BaseNettyTest { + + @Test + public void testHttpHeaderCase() throws Exception { + HttpClient client = new HttpClient(); + HttpMethod method = new PostMethod("http://localhost:" + getPort() + "/myapp/mytest"); + + method.setRequestHeader("clientHeader", "fooBAR"); + method.setRequestHeader("OTHER", "123"); + method.setRequestHeader("beer", "Carlsberg"); + + client.executeMethod(method); + + assertEquals("Bye World", method.getResponseBodyAsString()); + assertEquals("aBc123", method.getResponseHeader("MyCaseHeader").getValue()); + assertEquals("456DEf", method.getResponseHeader("otherCaseHeader").getValue()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() throws Exception { + from("netty4-http:http://localhost:{{port}}/myapp/mytest?mapHeaders=false").process(new Processor() { + public void process(Exchange exchange) throws Exception { + // these headers is not mapped + assertNull(exchange.getIn().getHeader("clientHeader")); + assertNull(exchange.getIn().getHeader("OTHER")); + assertNull(exchange.getIn().getHeader("beer")); + + // but we can find them in the http request from netty + assertEquals("fooBAR", exchange.getIn(NettyHttpMessage.class).getHttpRequest().headers().get("clientHeader")); + assertEquals("123", exchange.getIn(NettyHttpMessage.class).getHttpRequest().headers().get("OTHER")); + assertEquals("Carlsberg", exchange.getIn(NettyHttpMessage.class).getHttpRequest().headers().get("beer")); + + exchange.getOut().setBody("Bye World"); + exchange.getOut().setHeader("MyCaseHeader", "aBc123"); + exchange.getOut().setHeader("otherCaseHeader", "456DEf"); + } + }); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpMethodRestrictTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpMethodRestrictTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpMethodRestrictTest.java new file mode 100644 index 0000000..c955117 --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpMethodRestrictTest.java @@ -0,0 +1,74 @@ +/** + * 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.Exchange; +import org.apache.camel.Message; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.methods.GetMethod; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.StringRequestEntity; +import org.junit.Test; + +public class NettyHttpMethodRestrictTest extends BaseNettyTest { + + private String getUrl() { + return "http://localhost:" + getPort() + "/methodRestrict"; + } + + @Test + public void testProperHttpMethod() throws Exception { + HttpClient httpClient = new HttpClient(); + PostMethod httpPost = new PostMethod(getUrl()); + + StringRequestEntity reqEntity = new StringRequestEntity("This is a test", null, null); + httpPost.setRequestEntity(reqEntity); + + int status = httpClient.executeMethod(httpPost); + + assertEquals("Get a wrong response status", 200, status); + + String result = httpPost.getResponseBodyAsString(); + assertEquals("Get a wrong result", "This is a test response", result); + } + + @Test + public void testImproperHttpMethod() throws Exception { + HttpClient httpClient = new HttpClient(); + GetMethod httpGet = new GetMethod(getUrl()); + int status = httpClient.executeMethod(httpGet); + + assertEquals("Get a wrong response status", 405, status); + } + + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() throws Exception { + from("netty4-http://http://localhost:{{port}}/methodRestrict?httpMethodRestrict=POST").process(new Processor() { + public void process(Exchange exchange) throws Exception { + Message in = exchange.getIn(); + String request = in.getBody(String.class); + exchange.getOut().setBody(request + " response"); + } + }); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpOnExceptionHandledTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpOnExceptionHandledTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpOnExceptionHandledTest.java new file mode 100644 index 0000000..93e28b4 --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpOnExceptionHandledTest.java @@ -0,0 +1,56 @@ +/** + * 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.Exchange; +import org.apache.camel.builder.RouteBuilder; +import org.junit.Test; + +public class NettyHttpOnExceptionHandledTest extends BaseNettyTest { + + @Test + public void testOnExceptionHandled() throws Exception { + Exchange reply = template.request("netty4-http:http://localhost:{{port}}/myserver?throwExceptionOnFailure=false", null); + + assertNotNull(reply); + assertEquals("Dude something went wrong", reply.getOut().getBody(String.class)); + assertEquals(500, reply.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE)); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + // START SNIPPET: e1 + from("netty4-http:http://localhost:{{port}}/myserver") + // use onException to catch all exceptions and return a custom reply message + .onException(Exception.class) + .handled(true) + // create a custom failure response + .transform(constant("Dude something went wrong")) + // we must remember to set error code 500 as handled(true) + // otherwise would let Camel thing its a OK response (200) + .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(500)) + .end() + // now just force an exception immediately + .throwException(new IllegalArgumentException("I cannot do this")); + // END SNIPPET: e1 + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerBridgePathWithSpacesAtEndTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerBridgePathWithSpacesAtEndTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerBridgePathWithSpacesAtEndTest.java new file mode 100644 index 0000000..dfdbc23 --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerBridgePathWithSpacesAtEndTest.java @@ -0,0 +1,54 @@ +/** + * 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 NettyHttpProducerBridgePathWithSpacesAtEndTest extends BaseNettyTest { + + private int port1; + private int port2; + + @Test + public void testProxy() throws Exception { + String reply = template.requestBody("netty4-http:http://0.0.0.0:" + port1 + "/foo ", "World", String.class); + assertEquals("Bye World", reply); + + // and with more spaces + String reply2 = template.requestBody("netty4-http:http://0.0.0.0:" + port1 + "/foo /bar baz", "Camel", String.class); + assertEquals("Bye Camel", reply2); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + port1 = getPort(); + port2 = getNextPort(); + + from("netty4-http:http://0.0.0.0:" + port1 + "/foo ?matchOnUriPrefix=true") + .to("netty4-http:http://0.0.0.0:" + port2 + "/proxy foo ?bridgeEndpoint=true&throwExceptionOnFailure=false"); + + from("netty4-http:http://0.0.0.0:" + port2 + "/proxy foo ?matchOnUriPrefix=true") + .transform().simple("Bye ${body}"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerBridgeTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerBridgeTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerBridgeTest.java new file mode 100644 index 0000000..8592817 --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerBridgeTest.java @@ -0,0 +1,50 @@ +/** + * 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 NettyHttpProducerBridgeTest extends BaseNettyTest { + + private int port1; + private int port2; + + @Test + public void testProxy() throws Exception { + String reply = template.requestBody("netty4-http:http://0.0.0.0:" + port1 + "/foo", "World", String.class); + assertEquals("Bye World", reply); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + port1 = getPort(); + port2 = getNextPort(); + + from("netty4-http:http://0.0.0.0:" + port1 + "/foo") + .to("netty4-http:http://0.0.0.0:" + port2 + "/bar?bridgeEndpoint=true&throwExceptionOnFailure=false"); + + from("netty4-http:http://0.0.0.0:" + port2 + "/bar") + .transform().simple("Bye ${body}"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerConcurrentTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerConcurrentTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerConcurrentTest.java new file mode 100644 index 0000000..ad43848 --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerConcurrentTest.java @@ -0,0 +1,87 @@ +/** + * 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 java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +import org.apache.camel.builder.RouteBuilder; +import org.junit.Test; + +public class NettyHttpProducerConcurrentTest extends BaseNettyTest { + + @Test + public void testNoConcurrentProducers() throws Exception { + doSendMessages(1, 1); + } + + @Test + public void testConcurrentProducers() throws Exception { + doSendMessages(10, 5); + } + + private void doSendMessages(int files, int poolSize) throws Exception { + getMockEndpoint("mock:result").expectedMessageCount(files); + getMockEndpoint("mock:result").assertNoDuplicates(body()); + + ExecutorService executor = Executors.newFixedThreadPool(poolSize); + // we access the responses Map below only inside the main thread, + // so no need for a thread-safe Map implementation + Map<Integer, Future<String>> responses = new HashMap<Integer, Future<String>>(); + for (int i = 0; i < files; i++) { + final int index = i; + Future<String> out = executor.submit(new Callable<String>() { + public String call() throws Exception { + return template.requestBody("netty4-http:http://localhost:{{port}}/echo", "" + index, String.class); + } + }); + responses.put(index, out); + } + + assertMockEndpointsSatisfied(); + + assertEquals(files, responses.size()); + + // get all responses + Set<String> unique = new HashSet<String>(); + for (Future<String> future : responses.values()) { + unique.add(future.get()); + } + + // should be 'files' unique responses + assertEquals("Should be " + files + " unique responses", files, unique.size()); + executor.shutdownNow(); + } + + + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() throws Exception { + // expose a echo service + from("netty4-http:http://localhost:{{port}}/echo") + .transform(body().append(body())).to("mock:result"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerKeepAliveTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerKeepAliveTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerKeepAliveTest.java new file mode 100644 index 0000000..26c0835 --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerKeepAliveTest.java @@ -0,0 +1,64 @@ +/** + * 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.Ignore; +import org.junit.Test; + +public class NettyHttpProducerKeepAliveTest extends BaseNettyTest { + + @Test + public void testHttpKeepAlive() throws Exception { + getMockEndpoint("mock:input").expectedBodiesReceived("Hello World", "Hello Again"); + + String out = template.requestBody("netty4-http:http://localhost:{{port}}/foo?keepAlive=true", "Hello World", String.class); + assertEquals("Bye World", out); + + out = template.requestBody("netty4-http:http://localhost:{{port}}/foo?keepAlive=true", "Hello Again", String.class); + assertEquals("Bye World", out); + + assertMockEndpointsSatisfied(); + } + + @Test + @Ignore("Can fail on some CI servers") + public void testHttpKeepAliveFalse() throws Exception { + getMockEndpoint("mock:input").expectedBodiesReceived("Hello World", "Hello Again"); + + String out = template.requestBody("netty4-http:http://localhost:{{port}}/foo?keepAlive=false", "Hello World", String.class); + assertEquals("Bye World", out); + + out = template.requestBody("netty4-http:http://localhost:{{port}}/foo?keepAlive=false", "Hello Again", String.class); + assertEquals("Bye World", 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().constant("Bye World"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerQueryParamTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerQueryParamTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerQueryParamTest.java new file mode 100644 index 0000000..ee1be1d --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerQueryParamTest.java @@ -0,0 +1,75 @@ +/** + * 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 java.util.Map; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.junit.Test; + +public class NettyHttpProducerQueryParamTest extends BaseNettyTest { + + private String url = "netty4-http:http://0.0.0.0:" + getPort() + "/cheese?urlDecodeHeaders=true"; + + @Test + public void testQueryParameters() throws Exception { + Exchange exchange = template.request(url + ""e=Camel%20rocks", null); + assertNotNull(exchange); + + String body = exchange.getOut().getBody(String.class); + Map<?, ?> headers = exchange.getOut().getHeaders(); + + assertEquals("Bye World", body); + assertEquals("Carlsberg", headers.get("beer")); + } + + @Test + public void testQueryParametersWithHeader() throws Exception { + Exchange exchange = template.request(url, new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(Exchange.HTTP_QUERY, "quote=Camel rocks"); + } + }); + assertNotNull(exchange); + + String body = exchange.getOut().getBody(String.class); + Map<?, ?> headers = exchange.getOut().getHeaders(); + + assertEquals("Bye World", body); + assertEquals("Carlsberg", headers.get("beer")); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from(url).process(new Processor() { + public void process(Exchange exchange) throws Exception { + String quote = exchange.getIn().getHeader("quote", String.class); + assertEquals("Camel rocks", quote); + + exchange.getOut().setBody("Bye World"); + exchange.getOut().setHeader("beer", "Carlsberg"); + } + }); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerSendEmptyHeaderTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerSendEmptyHeaderTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerSendEmptyHeaderTest.java new file mode 100644 index 0000000..160d774 --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerSendEmptyHeaderTest.java @@ -0,0 +1,48 @@ +/** + * 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.apache.camel.component.mock.MockEndpoint; +import org.junit.Test; + +public class NettyHttpProducerSendEmptyHeaderTest extends BaseNettyTest { + + @Test + public void testHttpProducerSendEmptyHeader() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMessageCount(1); + mock.expectedHeaderReceived("foo", ""); + + template.sendBodyAndHeader("netty4-http:http://localhost:{{port}}/myapp/mytest", "Hello World", "foo", ""); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("netty4-http:http://localhost:{{port}}/myapp/mytest") + .convertBodyTo(String.class) + .to("mock:result"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerSimpleGetTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerSimpleGetTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerSimpleGetTest.java new file mode 100644 index 0000000..a5b3f76 --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerSimpleGetTest.java @@ -0,0 +1,69 @@ +/** + * 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.Exchange; +import org.apache.camel.builder.RouteBuilder; +import org.junit.Test; + +public class NettyHttpProducerSimpleGetTest extends BaseNettyTest { + + @Test + public void testHttpSimple() throws Exception { + getMockEndpoint("mock:input").expectedHeaderReceived(Exchange.HTTP_METHOD, "GET"); + + String out = template.requestBody("netty4-http:http://localhost:{{port}}/foo", null, String.class); + assertEquals("Bye World", out); + + assertMockEndpointsSatisfied(); + } + + @Test + public void testHttpSimpleHeader() throws Exception { + getMockEndpoint("mock:input").expectedHeaderReceived(Exchange.HTTP_METHOD, "GET"); + + String out = template.requestBodyAndHeader("netty4-http:http://localhost:{{port}}/foo", null, Exchange.HTTP_METHOD, "GET", String.class); + assertEquals("Bye World", out); + + assertMockEndpointsSatisfied(); + } + + @Test + public void testHttpSimpleHeaderAndBody() throws Exception { + // even if we have a body we force it to be GET + getMockEndpoint("mock:input").expectedBodiesReceived("Hello World"); + getMockEndpoint("mock:input").expectedHeaderReceived(Exchange.HTTP_METHOD, "GET"); + + String out = template.requestBodyAndHeader("netty4-http:http://localhost:{{port}}/foo", "Hello World", Exchange.HTTP_METHOD, "GET", String.class); + assertEquals("Bye World", 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().constant("Bye World"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerSimpleTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerSimpleTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerSimpleTest.java new file mode 100644 index 0000000..5bc428b --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerSimpleTest.java @@ -0,0 +1,76 @@ +/** + * 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 io.netty.handler.codec.http.HttpResponse; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; + +import org.junit.Test; + +public class NettyHttpProducerSimpleTest extends BaseNettyTest { + + @Test + public void testHttpSimple() throws Exception { + getMockEndpoint("mock:input").expectedBodiesReceived("Hello World"); + + String out = template.requestBody("netty4-http:http://localhost:{{port}}/foo", "Hello World", String.class); + assertEquals("Bye World", out); + + assertMockEndpointsSatisfied(); + } + + @Test + public void testHttpSimpleExchange() throws Exception { + getMockEndpoint("mock:input").expectedBodiesReceived("Hello World"); + + Exchange out = template.request("netty4-http:http://localhost:{{port}}/foo", new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + exchange.getIn().setBody("Hello World"); + } + }); + assertNotNull(out); + assertTrue(out.hasOut()); + + NettyHttpMessage response = out.getOut(NettyHttpMessage.class); + assertNotNull(response); + assertEquals(200, response.getHttpResponse().getStatus().code()); + + // we can also get the response as body + HttpResponse body = out.getOut().getBody(HttpResponse.class); + assertNotNull(body); + assertEquals(200, body.getStatus().code()); + + 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().constant("Bye World"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerTwoParametersWithSameKeyTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerTwoParametersWithSameKeyTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerTwoParametersWithSameKeyTest.java new file mode 100644 index 0000000..6b69a8e --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerTwoParametersWithSameKeyTest.java @@ -0,0 +1,100 @@ +/** + * 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 java.util.ArrayList; +import java.util.List; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.junit.Test; + +public class NettyHttpProducerTwoParametersWithSameKeyTest extends BaseNettyTest { + + @Test + public void testTwoParametersWithSameKey() throws Exception { + Exchange out = template.request("netty4-http:http://localhost:{{port}}/myapp?from=me&to=foo&to=bar", null); + + assertNotNull(out); + assertFalse("Should not fail", out.isFailed()); + assertEquals("OK", out.getOut().getBody(String.class)); + assertEquals("yes", out.getOut().getHeader("bar")); + + List<?> foo = out.getOut().getHeader("foo", List.class); + assertNotNull(foo); + assertEquals(2, foo.size()); + assertEquals("123", foo.get(0)); + assertEquals("456", foo.get(1)); + } + + @Test + public void testTwoHeadersWithSameKeyHeader() throws Exception { + Exchange out = template.request("netty4-http:http://localhost:{{port}}/myapp", new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getIn().setBody(null); + exchange.getIn().setHeader("from", "me"); + List<String> list = new ArrayList<String>(); + list.add("foo"); + list.add("bar"); + exchange.getIn().setHeader("to", list); + } + }); + + assertNotNull(out); + assertFalse("Should not fail", out.isFailed()); + assertEquals("OK", out.getOut().getBody(String.class)); + assertEquals("yes", out.getOut().getHeader("bar")); + + List<?> foo = out.getOut().getHeader("foo", List.class); + assertNotNull(foo); + assertEquals(2, foo.size()); + assertEquals("123", foo.get(0)); + assertEquals("456", foo.get(1)); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("netty4-http:http://localhost:{{port}}/myapp").process(new Processor() { + public void process(Exchange exchange) throws Exception { + String from = exchange.getIn().getHeader("from", String.class); + assertEquals("me", from); + + List<?> to = exchange.getIn().getHeader("to", List.class); + assertNotNull(to); + assertEquals(2, to.size()); + assertEquals("foo", to.get(0)); + assertEquals("bar", to.get(1)); + + // response + exchange.getOut().setBody("OK"); + // use multiple values for the foo header in the reply + List<Integer> list = new ArrayList<Integer>(); + list.add(123); + list.add(456); + exchange.getOut().setHeader("foo", list); + exchange.getOut().setHeader("bar", "yes"); + } + }); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerWithHeaderTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerWithHeaderTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerWithHeaderTest.java new file mode 100644 index 0000000..9515c8f --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerWithHeaderTest.java @@ -0,0 +1,60 @@ +/** + * 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.Exchange; +import org.apache.camel.builder.RouteBuilder; +import org.junit.Test; + +public class NettyHttpProducerWithHeaderTest extends BaseNettyTest { + + @Test + public void testHttpSimpleGet() throws Exception { + getMockEndpoint("mock:input").expectedHeaderReceived(Exchange.HTTP_METHOD, "GET"); + getMockEndpoint("mock:input").expectedHeaderReceived("myTraceId", "mockCorrelationID"); + + String out = template.requestBodyAndHeader("netty4-http:http://localhost:{{port}}/foo", null, "myTraceId", "mockCorrelationID", String.class); + assertEquals("Bye World", out); + + assertMockEndpointsSatisfied(); + } + + @Test + public void testHttpSimplePost() throws Exception { + getMockEndpoint("mock:input").expectedHeaderReceived(Exchange.HTTP_METHOD, "POST"); + getMockEndpoint("mock:input").expectedHeaderReceived("myTraceId", "mockCorrelationID"); + getMockEndpoint("mock:input").expectedBodiesReceived("Hello World"); + + String out = template.requestBodyAndHeader("netty4-http:http://localhost:{{port}}/foo", "Hello World", "myTraceId", "mockCorrelationID", String.class); + assertEquals("Bye World", 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().constant("Bye World"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpRawQueryTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpRawQueryTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpRawQueryTest.java new file mode 100644 index 0000000..2f90a0e --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpRawQueryTest.java @@ -0,0 +1,57 @@ +/** + * 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 java.net.URL; + +import org.apache.camel.EndpointInject; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.junit.Test; + +import static org.apache.camel.Exchange.HTTP_QUERY; +import static org.apache.camel.Exchange.HTTP_RAW_QUERY; + +public class NettyHttpRawQueryTest extends BaseNettyTest { + + @EndpointInject(uri = "mock:test") + MockEndpoint mockEndpoint; + + @Test + public void shouldAccessRawQuery() throws Exception { + String query = "param=x1%26y%3D2"; + mockEndpoint.expectedMessageCount(1); + mockEndpoint.message(0).header(HTTP_QUERY).isEqualTo("param=x1&y=2"); + mockEndpoint.message(0).header(HTTP_RAW_QUERY).isEqualTo(query); + + new URL("http://localhost:" + getPort() + "/?" + query).openConnection().getInputStream().close(); + + 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}}/") + .to(mockEndpoint); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpRedirectNoLocationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpRedirectNoLocationTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpRedirectNoLocationTest.java new file mode 100644 index 0000000..b8f0e66 --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpRedirectNoLocationTest.java @@ -0,0 +1,59 @@ +/** + * 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.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.RuntimeCamelException; +import org.apache.camel.builder.RouteBuilder; +import org.junit.Test; + +public class NettyHttpRedirectNoLocationTest extends BaseNettyTest { + + private int nextPort; + + @Test + public void testHttpRedirectNoLocation() throws Exception { + try { + template.requestBody("netty4-http:http://localhost:" + nextPort + "/test", "Hello World", String.class); + fail("Should have thrown an exception"); + } catch (RuntimeCamelException e) { + NettyHttpOperationFailedException cause = assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause()); + assertEquals(302, cause.getStatusCode()); + assertEquals(true, cause.isRedirectError()); + assertEquals(false, cause.hasRedirectLocation()); + assertEquals(null, cause.getRedirectLocation()); + } + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + nextPort = getNextPort(); + + from("netty4-http:http://localhost:" + nextPort + "/test") + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 302); + } + }); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpRedirectTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpRedirectTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpRedirectTest.java new file mode 100644 index 0000000..aea7b89 --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpRedirectTest.java @@ -0,0 +1,56 @@ +/** + * 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.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.RuntimeCamelException; +import org.apache.camel.builder.RouteBuilder; +import org.junit.Test; + +public class NettyHttpRedirectTest extends BaseNettyTest { + + @Test + public void testHttpRedirect() throws Exception { + try { + template.requestBody("netty4-http:http://localhost:{{port}}/test", "Hello World", String.class); + fail("Should have thrown an exception"); + } catch (RuntimeCamelException e) { + NettyHttpOperationFailedException cause = assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause()); + assertEquals(301, cause.getStatusCode()); + assertEquals(true, cause.isRedirectError()); + assertEquals(true, cause.hasRedirectLocation()); + assertEquals("http://localhost:" + getPort() + "/newtest", cause.getRedirectLocation()); + } + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("netty4-http:http://localhost:{{port}}/test") + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 301); + exchange.getOut().setHeader("location", "http://localhost:" + getPort() + "/newtest"); + } + }); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpRequestTimeoutTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpRequestTimeoutTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpRequestTimeoutTest.java new file mode 100644 index 0000000..12cb819 --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpRequestTimeoutTest.java @@ -0,0 +1,62 @@ +/** + * 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 io.netty.handler.timeout.ReadTimeoutException; + +import org.apache.camel.CamelExecutionException; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; + +import org.junit.Test; + +public class NettyHttpRequestTimeoutTest extends BaseNettyTest { + + @Test + public void testRequestTimeout() throws Exception { + try { + template.requestBody("netty4-http:http://localhost:{{port}}/timeout?requestTimeout=1000", "Hello Camel", String.class); + fail("Should have thrown exception"); + } catch (CamelExecutionException e) { + ReadTimeoutException cause = assertIsInstanceOf(ReadTimeoutException.class, e.getCause()); + assertNotNull(cause); + } + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("netty4-http:http://localhost:{{port}}/timeout") + .process(new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + String body = exchange.getIn().getBody(String.class); + + if (body.contains("Camel")) { + Thread.sleep(3000); + } + } + }) + .transform().constant("Bye World"); + + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpReturnDataNotInputStreamConvertableTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpReturnDataNotInputStreamConvertableTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpReturnDataNotInputStreamConvertableTest.java new file mode 100644 index 0000000..c4c867e --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpReturnDataNotInputStreamConvertableTest.java @@ -0,0 +1,53 @@ +/** + * 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.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.junit.Test; + +public class NettyHttpReturnDataNotInputStreamConvertableTest extends BaseNettyTest { + + @Test + public void testHttpReturnDataNotInputStreamConvertableTest() throws Exception { + String out = template.requestBody("netty4-http:http://localhost:{{port}}/test", "Hello World", String.class); + assertEquals("This is the response", out); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("netty4-http:http://localhost:{{port}}/test") + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getOut().setBody(new MyResponseBean()); + } + }); + } + }; + } + + private static class MyResponseBean { + @Override + public String toString() { + return "This is the response"; + } + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpReturnFaultTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpReturnFaultTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpReturnFaultTest.java new file mode 100644 index 0000000..f230710 --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpReturnFaultTest.java @@ -0,0 +1,58 @@ +/** + * 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.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.junit.Test; + +public class NettyHttpReturnFaultTest extends BaseNettyTest { + + @Test + public void testHttpFault() throws Exception { + Exchange exchange = template.request("netty4-http:http://localhost:{{port}}/test", new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + exchange.getIn().setBody("Hello World!"); + } + + }); + assertTrue(exchange.isFailed()); + NettyHttpOperationFailedException exception = exchange.getException(NettyHttpOperationFailedException.class); + assertNotNull(exception); + assertEquals(500, exception.getStatusCode()); + String message = context.getTypeConverter().convertTo(String.class, exception.getHttpContent().content()); + assertEquals("This is a fault", message); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("netty4-http:http://localhost:{{port}}/test") + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getOut().setFault(true); + exchange.getOut().setBody("This is a fault"); + } + }); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSSLTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSSLTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSSLTest.java new file mode 100644 index 0000000..94d8553 --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSSLTest.java @@ -0,0 +1,109 @@ +/** + * 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 java.net.URL; +import java.util.Properties; +import javax.net.ssl.SSLSession; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.netty4.NettyConstants; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.After; +import org.junit.Test; + +public class NettyHttpSSLTest extends BaseNettyTest { + + private static final String NULL_VALUE_MARKER = CamelTestSupport.class.getCanonicalName(); + + protected Properties originalValues = new Properties(); + + @Override + public void setUp() throws Exception { + // ensure jsse clients can validate the self signed dummy localhost cert, + // use the server keystore as the trust store for these tests + URL trustStoreUrl = this.getClass().getClassLoader().getResource("jsse/localhost.ks"); + setSystemProp("javax.net.ssl.trustStore", trustStoreUrl.toURI().getPath()); + + super.setUp(); + } + + @Override + @After + public void tearDown() throws Exception { + restoreSystemProperties(); + super.tearDown(); + } + + protected void setSystemProp(String key, String value) { + String originalValue = System.setProperty(key, value); + originalValues.put(key, originalValue != null ? originalValue : NULL_VALUE_MARKER); + } + + protected void restoreSystemProperties() { + for (Object key : originalValues.keySet()) { + Object value = originalValues.get(key); + if (NULL_VALUE_MARKER.equals(value)) { + System.getProperties().remove(key); + } else { + System.setProperty((String) key, (String) value); + } + } + } + + @Override + public boolean isUseRouteBuilder() { + return false; + } + + @Test + public void testSSLInOutWithNettyConsumer() throws Exception { + // ibm jdks dont have sun security algorithms + if (isJavaVendor("ibm")) { + return; + } + + getMockEndpoint("mock:input").expectedBodiesReceived("Hello World"); + + context.addRoutes(new RouteBuilder() { + public void configure() { + from("netty4-http:https://localhost:{{port}}?ssl=true&passphrase=changeit&keyStoreResource=jsse/localhost.ks&trustStoreResource=jsse/localhost.ks") + .to("mock:input") + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + SSLSession session = exchange.getIn().getHeader(NettyConstants.NETTY_SSL_SESSION, SSLSession.class); + if (session != null) { + exchange.getOut().setBody("Bye World"); + } else { + exchange.getOut().setBody("Cannot start conversion without SSLSession"); + } + } + }); + } + }); + context.start(); + + String out = template.requestBody("https://localhost:{{port}}", "Hello World", String.class); + assertEquals("Bye World", out); + + assertMockEndpointsSatisfied(); + } + +} + http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSameHostDifferentParametersTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSameHostDifferentParametersTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSameHostDifferentParametersTest.java new file mode 100644 index 0000000..2aac213 --- /dev/null +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSameHostDifferentParametersTest.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.netty4.http; + +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; +import org.junit.Test; + +public class NettyHttpSameHostDifferentParametersTest extends BaseNettyTest { + + @Test + public void testTwoRoutes() throws Exception { + getMockEndpoint("mock:foo").expectedMessageCount(2); + getMockEndpoint("mock:foo").message(0).header("param1").isEqualTo("value1"); + getMockEndpoint("mock:foo").message(1).header("param2").isEqualTo("value2"); + + String out = template.requestBody("netty4-http:http://localhost:{{port}}/foo?param1=value1", "Hello World", String.class); + assertEquals("param1=value1", out); + + out = template.requestBody("netty4-http:http://localhost:{{port}}/foo?param2=value2", "Hello Camel", String.class); + assertEquals("param2=value2", 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:foo") + .transform().header(Exchange.HTTP_QUERY); + } + }; + } + +}
