You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/09/05 15:13:21 UTC
[3/9] CAMEL-7782 Added camel-netty4-http component
http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSimpleBasicAuthConstraintMapperTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSimpleBasicAuthConstraintMapperTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSimpleBasicAuthConstraintMapperTest.java
new file mode 100644
index 0000000..2522682
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSimpleBasicAuthConstraintMapperTest.java
@@ -0,0 +1,90 @@
+/**
+ * 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.CamelExecutionException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+import org.junit.Ignore;
+import org.junit.Test;
+
+@Ignore("TODO fix it")
+public class NettyHttpSimpleBasicAuthConstraintMapperTest extends BaseNettyTest {
+
+ @Override
+ public void setUp() throws Exception {
+ System.setProperty("java.security.auth.login.config", "src/test/resources/myjaas.config");
+ super.setUp();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ System.clearProperty("java.security.auth.login.config");
+ super.tearDown();
+ }
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndi = super.createRegistry();
+
+ SecurityConstraintMapping matcher = new SecurityConstraintMapping();
+ matcher.addInclusion("/*");
+ matcher.addExclusion("/public/*");
+
+ jndi.bind("myConstraint", matcher);
+
+ return jndi;
+ }
+
+ @Test
+ public void testBasicAuth() throws Exception {
+ getMockEndpoint("mock:input").expectedBodiesReceived("Hello Public", "Hello World");
+
+ // we dont need auth for the public page
+ String out = template.requestBody("netty4-http:http://localhost:{{port}}/foo/public/hello.txt", "Hello Public", String.class);
+ assertEquals("Bye World", out);
+
+ try {
+ template.requestBody("netty4-http:http://localhost:{{port}}/foo", "Hello World", String.class);
+ fail("Should send back 401");
+ } catch (CamelExecutionException e) {
+ NettyHttpOperationFailedException cause = assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause());
+ assertEquals(401, cause.getStatusCode());
+ }
+
+ // username:password is scott:secret
+ String auth = "Basic c2NvdHQ6c2VjcmV0";
+ out = template.requestBodyAndHeader("netty4-http:http://localhost:{{port}}/foo", "Hello World", "Authorization", auth, 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?matchOnUriPrefix=true"
+ + "&securityConfiguration.realm=karaf&securityConfiguration.securityConstraint=#myConstraint")
+ .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/NettyHttpSimpleBasicAuthTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSimpleBasicAuthTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSimpleBasicAuthTest.java
new file mode 100644
index 0000000..bcdd107
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSimpleBasicAuthTest.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.CamelExecutionException;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class NettyHttpSimpleBasicAuthTest extends BaseNettyTest {
+
+ @Override
+ public void setUp() throws Exception {
+ System.setProperty("java.security.auth.login.config", "src/test/resources/myjaas.config");
+ super.setUp();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ System.clearProperty("java.security.auth.login.config");
+ super.tearDown();
+ }
+
+ @Test
+ public void testBasicAuth() throws Exception {
+ getMockEndpoint("mock:input").expectedBodiesReceived("Hello World");
+
+ // username:password is scott:secret
+ String auth = "Basic c2NvdHQ6c2VjcmV0";
+ String out = template.requestBodyAndHeader("netty4-http:http://localhost:{{port}}/foo", "Hello World", "Authorization", auth, String.class);
+ assertEquals("Bye World", out);
+
+ assertMockEndpointsSatisfied();
+
+ try {
+ template.requestBody("netty4-http:http://localhost:{{port}}/foo", "Hello World", String.class);
+ fail("Should send back 401");
+ } catch (CamelExecutionException e) {
+ NettyHttpOperationFailedException cause = assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause());
+ assertEquals(401, cause.getStatusCode());
+ }
+
+ }
+
+ @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?securityConfiguration.realm=karaf")
+ .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/NettyHttpSimpleTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSimpleTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSimpleTest.java
new file mode 100644
index 0000000..34cd59d
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSimpleTest.java
@@ -0,0 +1,46 @@
+/**
+ * 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 NettyHttpSimpleTest 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();
+ }
+
+ @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/NettyHttpSimpleUriParametersTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSimpleUriParametersTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSimpleUriParametersTest.java
new file mode 100644
index 0000000..f04385d
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSimpleUriParametersTest.java
@@ -0,0 +1,46 @@
+/**
+ * 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 NettyHttpSimpleUriParametersTest extends BaseNettyTest {
+
+ @Test
+ public void testHttpSimple() throws Exception {
+ getMockEndpoint("mock:input").expectedBodiesReceived("Hello World");
+
+ String out = template.requestBody("netty4-http:http://localhost:{{port}}/foo?name=bar", "Hello World", String.class);
+ assertEquals("Bye bar", 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("Bye ${header.name}");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpStreamCacheFileResponseTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpStreamCacheFileResponseTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpStreamCacheFileResponseTest.java
new file mode 100644
index 0000000..9fb7ea4
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpStreamCacheFileResponseTest.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.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Before;
+import org.junit.Test;
+
+public class NettyHttpStreamCacheFileResponseTest extends BaseNettyTest {
+
+ private String body = "12345678901234567890123456789012345678901234567890";
+ private String body2 = "Bye " + body;
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ deleteDirectory("target/cachedir");
+ createDirectory("target/cachedir");
+ super.setUp();
+ }
+
+ @Test
+ public void testStreamCacheToFileShouldBeDeletedInCaseOfResponse() throws Exception {
+ NotifyBuilder builder = new NotifyBuilder(context).whenDone(1).create();
+
+ String out = template.requestBody("http://localhost:{{port}}/myserver", body, String.class);
+ assertEquals(body2, out);
+
+ assertTrue(builder.matches(5, TimeUnit.SECONDS));
+
+ // the temporary files should have been deleted
+ File file = new File("target/cachedir");
+ String[] files = file.list();
+ assertEquals("There should be no files", 0, files.length);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // enable stream caching and use a low threshold so its forced to write to file
+ context.getStreamCachingStrategy().setSpoolDirectory("target/cachedir");
+ context.getStreamCachingStrategy().setSpoolThreshold(16);
+ context.setStreamCaching(true);
+
+ from("netty4-http://http://localhost:{{port}}/myserver")
+ // wrap the response in 2 input streams so it will force caching to disk
+ .transform().constant(new BufferedInputStream(new ByteArrayInputStream(body2.getBytes())))
+ .to("log:reply");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSuspendResume503Test.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSuspendResume503Test.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSuspendResume503Test.java
new file mode 100644
index 0000000..a9770f7
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSuspendResume503Test.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.builder.RouteBuilder;
+import org.junit.Test;
+
+public class NettyHttpSuspendResume503Test extends BaseNettyTest {
+
+ private String serverUri = "netty4-http:http://localhost:" + getPort() + "/cool?disconnect=true";
+
+ @Test
+ public void testNettySuspendResume() throws Exception {
+ // these tests does not run well on Windows
+ if (isPlatform("windows")) {
+ return;
+ }
+
+ context.getShutdownStrategy().setTimeout(50);
+
+ String reply = template.requestBody(serverUri, "World", String.class);
+ assertEquals("Bye World", reply);
+
+ // now suspend netty
+ NettyHttpConsumer consumer = (NettyHttpConsumer) context.getRoute("foo").getConsumer();
+ assertNotNull(consumer);
+
+ // suspend
+ consumer.suspend();
+
+ try {
+ template.requestBody(serverUri, "Moon", String.class);
+ fail("Should throw exception");
+ } catch (Exception e) {
+ NettyHttpOperationFailedException cause = assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause());
+ assertEquals(503, cause.getStatusCode());
+ }
+
+ // resume
+ consumer.resume();
+
+ Thread.sleep(2000);
+
+ // and send request which should be processed
+ reply = template.requestBody(serverUri, "Moon", String.class);
+ assertEquals("Bye Moon", reply);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from(serverUri).routeId("foo")
+ .transform(body().prepend("Bye "));
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSuspendResumeTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSuspendResumeTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSuspendResumeTest.java
new file mode 100644
index 0000000..99755cb
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSuspendResumeTest.java
@@ -0,0 +1,73 @@
+/**
+ * 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 NettyHttpSuspendResumeTest extends BaseNettyTest {
+
+ private String serverUri = "netty4-http:http://localhost:" + getPort() + "/cool?disconnect=true&send503whenSuspended=false";
+
+ @Test
+ public void testNettySuspendResume() throws Exception {
+ // these tests does not run well on Windows
+ if (isPlatform("windows")) {
+ return;
+ }
+
+ context.getShutdownStrategy().setTimeout(50);
+
+ String reply = template.requestBody(serverUri, "World", String.class);
+ assertEquals("Bye World", reply);
+
+ // now suspend netty
+ NettyHttpConsumer consumer = (NettyHttpConsumer) context.getRoute("foo").getConsumer();
+ assertNotNull(consumer);
+
+ // suspend
+ consumer.suspend();
+
+ try {
+ template.requestBody(serverUri, "Moon", String.class);
+ fail("Should throw exception");
+ } catch (Exception e) {
+ assertTrue(e.getCause().getMessage().startsWith("Cannot connect to localhost"));
+ }
+
+ // resume
+ consumer.resume();
+
+ Thread.sleep(2000);
+
+ // and send request which should be processed
+ reply = template.requestBody(serverUri, "Moon", String.class);
+ assertEquals("Bye Moon", reply);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from(serverUri).routeId("foo")
+ .transform(body().prepend("Bye "));
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTraceDisabledTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTraceDisabledTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTraceDisabledTest.java
new file mode 100644
index 0000000..53995eb
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTraceDisabledTest.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 org.apache.camel.builder.RouteBuilder;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.TraceMethod;
+import org.junit.Test;
+
+public class NettyHttpTraceDisabledTest extends BaseNettyTest {
+
+ private int portTraceOn = getNextPort();
+ private int portTraceOff = getNextPort();
+
+ @Test
+ public void testTraceDisabled() throws Exception {
+ HttpClient httpclient = new HttpClient();
+ TraceMethod trace = new TraceMethod("http://localhost:" + portTraceOff + "/myservice");
+ httpclient.executeMethod(trace);
+
+ // TRACE shouldn't be allowed by default
+ assertTrue(trace.getStatusCode() == 405);
+ trace.releaseConnection();
+ }
+
+ @Test
+ public void testTraceEnabled() throws Exception {
+ HttpClient httpclient = new HttpClient();
+ TraceMethod trace = new TraceMethod("http://localhost:" + portTraceOn + "/myservice");
+ httpclient.executeMethod(trace);
+
+ // TRACE is now allowed
+ assertTrue(trace.getStatusCode() == 200);
+ trace.releaseConnection();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("netty4-http:http://localhost:" + portTraceOff + "/myservice").to("log:foo");
+ from("netty4-http:http://localhost:" + portTraceOn + "/myservice?traceEnabled=true").to("log:bar");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTransferExceptionTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTransferExceptionTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTransferExceptionTest.java
new file mode 100644
index 0000000..90c9c56
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTransferExceptionTest.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.CamelExecutionException;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class NettyHttpTransferExceptionTest extends BaseNettyTest {
+
+ @Test
+ public void testHttpTransferException() throws Exception {
+ getMockEndpoint("mock:input").expectedBodiesReceived("Hello World");
+
+ try {
+ template.requestBody("netty4-http:http://localhost:{{port}}/foo?transferException=true", "Hello World", String.class);
+ fail("Should have failed");
+ } catch (CamelExecutionException e) {
+ IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+ assertEquals("Camel cannot do this", cause.getMessage());
+ }
+
+ 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?transferException=true")
+ .to("mock:input")
+ .throwException(new IllegalArgumentException("Camel cannot do this"));
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTwoRoutesBootstrapConfigurationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTwoRoutesBootstrapConfigurationTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTwoRoutesBootstrapConfigurationTest.java
new file mode 100644
index 0000000..f92c87a
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTwoRoutesBootstrapConfigurationTest.java
@@ -0,0 +1,93 @@
+/**
+ * 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.netty4.NettyServerBootstrapConfiguration;
+import org.apache.camel.impl.JndiRegistry;
+import org.junit.Test;
+
+public class NettyHttpTwoRoutesBootstrapConfigurationTest extends BaseNettyTest {
+
+ private NettyServerBootstrapConfiguration bootstrapConfiguration;
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndi = super.createRegistry();
+
+ // create NettyServerBootstrapConfiguration instance where we can configure the bootstrap
+ // option we want to use in our Camel routes. This allows us to configure this once,
+ // and also explicit
+ bootstrapConfiguration = new NettyServerBootstrapConfiguration();
+ bootstrapConfiguration.setBacklog(200);
+ bootstrapConfiguration.setConnectTimeout(5000);
+ bootstrapConfiguration.setKeepAlive(true);
+ bootstrapConfiguration.setWorkerCount(4);
+
+ // register the configuration in the registry with this key
+ jndi.bind("myBootstrapOptions", bootstrapConfiguration);
+ return jndi;
+ }
+
+ @Test
+ public void testTwoRoutes() throws Exception {
+ getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+ getMockEndpoint("mock:bar").expectedBodiesReceived("Hello Camel");
+
+ String out = template.requestBody("netty4-http:http://localhost:{{port}}/foo", "Hello World", String.class);
+ assertEquals("Bye World", out);
+
+ out = template.requestBody("netty4-http:http://localhost:{{port}}/bar", "Hello Camel", String.class);
+ assertEquals("Bye Camel", out);
+
+ assertMockEndpointsSatisfied();
+
+ // validate the options
+ NettyHttpConsumer consumer = (NettyHttpConsumer) context.getRoute("foo").getConsumer();
+ assertEquals(200, consumer.getConfiguration().getBacklog());
+ assertEquals(4, consumer.getConfiguration().getWorkerCount());
+ assertEquals(true, consumer.getConfiguration().isKeepAlive());
+ assertEquals(5000, consumer.getConfiguration().getConnectTimeout());
+
+ consumer = (NettyHttpConsumer) context.getRoute("bar").getConsumer();
+ assertEquals(200, consumer.getConfiguration().getBacklog());
+ assertEquals(4, consumer.getConfiguration().getWorkerCount());
+ assertEquals(true, consumer.getConfiguration().isKeepAlive());
+ assertEquals(5000, consumer.getConfiguration().getConnectTimeout());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // we want to use the same bootstrap options and want to configure this explicit, so we
+ // have a NettyServerBootstrapConfiguration instance in the registry, with the key = myBootstrapOptions
+ // which we then tell netty4-http to lookup and use
+
+ from("netty4-http:http://0.0.0.0:{{port}}/foo?bootstrapConfiguration=#myBootstrapOptions").routeId("foo")
+ .to("mock:foo")
+ .transform().constant("Bye World");
+
+ from("netty4-http:http://0.0.0.0:{{port}}/bar?bootstrapConfiguration=#myBootstrapOptions").routeId("bar")
+ .to("mock:bar")
+ .transform().constant("Bye Camel");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTwoRoutesMatchOnUriPrefixTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTwoRoutesMatchOnUriPrefixTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTwoRoutesMatchOnUriPrefixTest.java
new file mode 100644
index 0000000..2edb693
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTwoRoutesMatchOnUriPrefixTest.java
@@ -0,0 +1,77 @@
+/**
+ * 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.CamelExecutionException;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class NettyHttpTwoRoutesMatchOnUriPrefixTest extends BaseNettyTest {
+
+ @Test
+ public void testTwoRoutesMatchOnUriPrefix() throws Exception {
+ getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+ getMockEndpoint("mock:bar").expectedBodiesReceived("Hello Camel", "Hi Camel");
+
+ String out = template.requestBody("netty4-http:http://localhost:{{port}}/foo", "Hello World", String.class);
+ assertEquals("Bye World", out);
+
+ // the foo is not match on prefix so we cannot do /foo/beer
+ try {
+ template.requestBody("netty4-http:http://localhost:{{port}}/foo/beer", "Hello World", String.class);
+ fail("Should have thrown exception");
+ } catch (CamelExecutionException e) {
+ NettyHttpOperationFailedException cause = assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause());
+ assertEquals(404, cause.getStatusCode());
+ }
+
+ // .. and likewise baz is not a context-path we have mapped as input
+ try {
+ template.requestBody("netty4-http:http://localhost:{{port}}/baz", "Hello World", String.class);
+ fail("Should have thrown exception");
+ } catch (CamelExecutionException e) {
+ NettyHttpOperationFailedException cause = assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause());
+ assertEquals(404, cause.getStatusCode());
+ }
+
+ out = template.requestBody("netty4-http:http://localhost:{{port}}/bar", "Hello Camel", String.class);
+ assertEquals("Bye Camel", out);
+
+ // the bar is match on prefix so we can do /bar/beer
+ out = template.requestBody("netty4-http:http://localhost:{{port}}/bar/beer", "Hi Camel", String.class);
+ assertEquals("Bye Camel", 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().constant("Bye World");
+
+ from("netty4-http:http://0.0.0.0:{{port}}/bar?matchOnUriPrefix=true")
+ .to("mock:bar")
+ .transform().constant("Bye Camel");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTwoRoutesStopOneRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTwoRoutesStopOneRouteTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTwoRoutesStopOneRouteTest.java
new file mode 100644
index 0000000..39df3d9
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTwoRoutesStopOneRouteTest.java
@@ -0,0 +1,77 @@
+/**
+ * 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.CamelExecutionException;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class NettyHttpTwoRoutesStopOneRouteTest extends BaseNettyTest {
+
+ @Test
+ public void testTwoRoutes() throws Exception {
+ getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+ getMockEndpoint("mock:bar").expectedBodiesReceived("Hello Camel");
+
+ String out = template.requestBody("netty4-http:http://localhost:{{port}}/foo", "Hello World", String.class);
+ assertEquals("Bye World", out);
+
+ out = template.requestBody("netty4-http:http://localhost:{{port}}/bar", "Hello Camel", String.class);
+ assertEquals("Bye Camel", out);
+
+ assertMockEndpointsSatisfied();
+
+ // stop foo route
+ context.stopRoute("foo");
+
+ resetMocks();
+
+ getMockEndpoint("mock:foo").expectedMessageCount(0);
+ getMockEndpoint("mock:bar").expectedBodiesReceived("Hello Camel");
+
+ // the foo route is stopped so this service is no longer there
+ try {
+ template.requestBody("netty4-http:http://localhost:{{port}}/foo", "Hello World", String.class);
+ fail("Should have thrown exception");
+ } catch (CamelExecutionException e) {
+ NettyHttpOperationFailedException cause = assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause());
+ assertEquals(404, cause.getStatusCode());
+ }
+
+ out = template.requestBody("netty4-http:http://localhost:{{port}}/bar", "Hello Camel", String.class);
+ assertEquals("Bye Camel", 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").routeId("foo")
+ .to("mock:foo")
+ .transform().constant("Bye World");
+
+ from("netty4-http:http://0.0.0.0:{{port}}/bar").routeId("bar")
+ .to("mock:bar")
+ .transform().constant("Bye Camel");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTwoRoutesTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTwoRoutesTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTwoRoutesTest.java
new file mode 100644
index 0000000..0322d0e
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTwoRoutesTest.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 NettyHttpTwoRoutesTest extends BaseNettyTest {
+
+ @Test
+ public void testTwoRoutes() throws Exception {
+ getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+ getMockEndpoint("mock:bar").expectedBodiesReceived("Hello Camel");
+
+ String out = template.requestBody("netty4-http:http://localhost:{{port}}/foo", "Hello World", String.class);
+ assertEquals("Bye World", out);
+
+ out = template.requestBody("netty4-http:http://localhost:{{port}}/bar", "Hello Camel", String.class);
+ assertEquals("Bye Camel", 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().constant("Bye World");
+
+ from("netty4-http:http://0.0.0.0:{{port}}/bar")
+ .to("mock:bar")
+ .transform().constant("Bye Camel");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTwoRoutesValidateBootstrapConfigurationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTwoRoutesValidateBootstrapConfigurationTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTwoRoutesValidateBootstrapConfigurationTest.java
new file mode 100644
index 0000000..ed5fada
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpTwoRoutesValidateBootstrapConfigurationTest.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.builder.RouteBuilder;
+import org.junit.Test;
+
+public class NettyHttpTwoRoutesValidateBootstrapConfigurationTest extends BaseNettyTest {
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ @Test
+ public void testTwoRoutes() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("netty4-http:http://0.0.0.0:{{port}}/foo?option.child.keepAlive=false")
+ .to("mock:foo")
+ .transform().constant("Bye World");
+
+ // we cannot have a 2nd route on same port with different option that the 1st route
+ from("netty4-http:http://0.0.0.0:{{port}}/bar?option.child.keepAlive=true")
+ .to("mock:bar")
+ .transform().constant("Bye Camel");
+ }
+ });
+ try {
+ context.start();
+ fail("Should have thrown exception");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().startsWith("Bootstrap configuration must be identical when adding additional consumer"));
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpXMLXPathResponseTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpXMLXPathResponseTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpXMLXPathResponseTest.java
new file mode 100644
index 0000000..60e6ed2
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpXMLXPathResponseTest.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.builder.RouteBuilder;
+import org.junit.Test;
+
+public class NettyHttpXMLXPathResponseTest extends BaseNettyTest {
+
+ @Test
+ public void testHttpXML() throws Exception {
+ String out = template.requestBody("netty4-http:http://localhost:{{port}}/foo", "<person><name>Claus</name></person>", String.class);
+ assertEquals("<name>Claus</name>", out);
+
+ out = template.requestBody("netty4-http:http://localhost:{{port}}/foo", "<person><name>James</name></person>", String.class);
+ assertEquals("James", out);
+
+ out = template.requestBody("netty4-http:http://localhost:{{port}}/foo", "<person><name>Jonathan</name></person>", String.class);
+ assertEquals("Dont understand <person><name>Jonathan</name></person>", out);
+ }
+
+ @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")
+ .choice()
+ .when().xpath("/person/name = 'Claus'")
+ .transform(xpath("/person/name"))
+ .when().xpath("/person/name = 'James'")
+ .transform(xpath("/person/name/text()"))
+ .otherwise()
+ .transform(simple("Dont understand ${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/NettyHttpXMLXPathTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpXMLXPathTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpXMLXPathTest.java
new file mode 100644
index 0000000..df0963d
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpXMLXPathTest.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.builder.RouteBuilder;
+import org.junit.Test;
+
+public class NettyHttpXMLXPathTest extends BaseNettyTest {
+
+ @Test
+ public void testHttpXML() throws Exception {
+ String out = template.requestBody("netty4-http:http://localhost:{{port}}/foo", "<person><name>Claus</name></person>", String.class);
+ assertEquals("<quote>Camel rocks</quote>", out);
+
+ out = template.requestBody("netty4-http:http://localhost:{{port}}/foo", "<person><name>James</name></person>", String.class);
+ assertEquals("<quote>Camel really rocks</quote>", out);
+
+ out = template.requestBody("netty4-http:http://localhost:{{port}}/foo", "<person><name>Jonathan</name></person>", String.class);
+ assertEquals("<quote>Try Camel now</quote>", out);
+ }
+
+ @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")
+ .choice()
+ .when().xpath("/person/name = 'Claus'")
+ .transform(constant("<quote>Camel rocks</quote>"))
+ .when().xpath("/person/name = 'James'")
+ .transform(constant("<quote>Camel really rocks</quote>"))
+ .otherwise()
+ .transform(constant("<quote>Try Camel now</quote>"));
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyRecipientListHttpBaseTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyRecipientListHttpBaseTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyRecipientListHttpBaseTest.java
new file mode 100644
index 0000000..7ca68b8
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyRecipientListHttpBaseTest.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.builder.RouteBuilder;
+import org.junit.Test;
+
+public class NettyRecipientListHttpBaseTest extends BaseNettyTest {
+
+ @Test
+ public void testRecipientListHttpBase() throws Exception {
+ getMockEndpoint("mock:foo").expectedHeaderValuesReceivedInAnyOrder(Exchange.HTTP_PATH, "/bar", "/baz", "/bar/baz", "/baz/bar");
+ getMockEndpoint("mock:foo").expectedHeaderValuesReceivedInAnyOrder("num", "1", "2", "3", "4");
+
+ template.sendBodyAndHeader("direct:start", "A", Exchange.HTTP_PATH, "/foo/bar?num=1");
+ template.sendBodyAndHeader("direct:start", "B", Exchange.HTTP_PATH, "/foo/baz?num=2");
+ template.sendBodyAndHeader("direct:start", "C", Exchange.HTTP_PATH, "/foo/bar/baz?num=3");
+ template.sendBodyAndHeader("direct:start", "D", Exchange.HTTP_PATH, "/foo/baz/bar?num=4");
+
+ 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?matchOnUriPrefix=true")
+ .to("mock:foo")
+ .transform(body().prepend("Bye "));
+
+ from("direct:start")
+ .recipientList().constant("netty4-http:http://0.0.0.0:{{port}}");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyRouteSimpleTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyRouteSimpleTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyRouteSimpleTest.java
new file mode 100644
index 0000000..da7abf5
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyRouteSimpleTest.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 NettyRouteSimpleTest extends BaseNettyTest {
+
+ @Test
+ public void testHttpSimple() throws Exception {
+ getMockEndpoint("mock:input1").expectedBodiesReceived("Hello World");
+ getMockEndpoint("mock:input2").expectedBodiesReceived("Hello World");
+
+ String out = template.requestBody("netty4-http:http://localhost:{{port}}/foo", "Hello World", String.class);
+ assertEquals("Bye World", out);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ int port2 = getNextPort();
+
+ @Override
+ public void configure() throws Exception {
+ from("netty4-http:http://0.0.0.0:{{port}}/foo")
+ .to("mock:input1")
+ .to("netty4-http:http://0.0.0.0:" + port2 + "/bar");
+ from("netty4-http:http://0.0.0.0:" + port2 + "/bar")
+ .to("mock:input2")
+ .transform().constant("Bye World");
+ }
+ };
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettySharedHttpServerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettySharedHttpServerTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettySharedHttpServerTest.java
new file mode 100644
index 0000000..de659a7
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettySharedHttpServerTest.java
@@ -0,0 +1,90 @@
+/**
+ * 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.impl.DefaultClassResolver;
+import org.apache.camel.impl.JndiRegistry;
+import org.junit.Test;
+
+public class NettySharedHttpServerTest extends BaseNettyTest {
+
+ private NettySharedHttpServer nettySharedHttpServer;
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ nettySharedHttpServer = new DefaultNettySharedHttpServer();
+ nettySharedHttpServer.setClassResolver(new DefaultClassResolver());
+
+ NettySharedHttpServerBootstrapConfiguration configuration = new NettySharedHttpServerBootstrapConfiguration();
+ configuration.setPort(getPort());
+ configuration.setHost("localhost");
+ configuration.setBacklog(20);
+ configuration.setKeepAlive(true);
+ configuration.setCompression(true);
+ nettySharedHttpServer.setNettyServerBootstrapConfiguration(configuration);
+
+ nettySharedHttpServer.start();
+
+ JndiRegistry jndi = super.createRegistry();
+ jndi.bind("myNettyServer", nettySharedHttpServer);
+ return jndi;
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ nettySharedHttpServer.stop();
+ super.tearDown();
+ }
+
+ @Test
+ public void testTwoRoutes() throws Exception {
+ getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+ getMockEndpoint("mock:bar").expectedBodiesReceived("Hello Camel");
+
+ String out = template.requestBody("netty4-http:http://localhost:{{port}}/foo", "Hello World", String.class);
+ assertEquals("Bye World", out);
+
+ out = template.requestBody("netty4-http:http://localhost:{{port}}/bar", "Hello Camel", String.class);
+ assertEquals("Bye Camel", out);
+
+ assertEquals(2, nettySharedHttpServer.getConsumersSize());
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // we are using a shared netty http server, so the port number is not needed to be defined in the uri
+ from("netty4-http:http://localhost/foo?nettySharedHttpServer=#myNettyServer")
+ .log("Foo route using thread ${threadName}")
+ .to("mock:foo")
+ .transform().constant("Bye World");
+
+ // we are using a shared netty http server, so the port number is not needed to be defined in the uri
+ from("netty4-http:http://localhost/bar?nettySharedHttpServer=#myNettyServer")
+ .log("Bar route using thread ${threadName}")
+ .to("mock:bar")
+ .transform().constant("Bye Camel");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyUseRawHttpResponseTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyUseRawHttpResponseTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyUseRawHttpResponseTest.java
new file mode 100644
index 0000000..512c1e7
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyUseRawHttpResponseTest.java
@@ -0,0 +1,63 @@
+/**
+ * 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.DefaultFullHttpResponse;
+import io.netty.handler.codec.http.HttpHeaders;
+import io.netty.handler.codec.http.HttpResponse;
+import io.netty.handler.codec.http.HttpResponseStatus;
+import io.netty.handler.codec.http.HttpVersion;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.netty4.NettyConverter;
+import org.junit.Test;
+
+public class NettyUseRawHttpResponseTest extends BaseNettyTest {
+
+ @Test
+ public void testAccessHttpRequest() 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();
+ }
+
+ @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")
+ .process(new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ HttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK,
+ NettyConverter.toByteBuffer("Bye World".getBytes()));
+ response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, 9);
+
+ exchange.getOut().setBody(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/SecurityConstraintMappingTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/SecurityConstraintMappingTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/SecurityConstraintMappingTest.java
new file mode 100644
index 0000000..70ea109
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/SecurityConstraintMappingTest.java
@@ -0,0 +1,108 @@
+/**
+ * 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 junit.framework.TestCase;
+
+public class SecurityConstraintMappingTest extends TestCase {
+
+ public void testDefault() {
+ SecurityConstraintMapping matcher = new SecurityConstraintMapping();
+
+ assertNotNull(matcher.restricted("/"));
+ assertNotNull(matcher.restricted("/foo"));
+ }
+
+ public void testFoo() {
+ SecurityConstraintMapping matcher = new SecurityConstraintMapping();
+ matcher.addInclusion("/foo");
+
+ assertNull(matcher.restricted("/"));
+ assertNotNull(matcher.restricted("/foo"));
+ assertNull(matcher.restricted("/foobar"));
+ assertNull(matcher.restricted("/foo/bar"));
+ }
+
+ public void testFooWildcard() {
+ SecurityConstraintMapping matcher = new SecurityConstraintMapping();
+ matcher.addInclusion("/foo*");
+
+ assertNull(matcher.restricted("/"));
+ assertNotNull(matcher.restricted("/foo"));
+ assertNotNull(matcher.restricted("/foobar"));
+ assertNotNull(matcher.restricted("/foo/bar"));
+ }
+
+ public void testFooBar() {
+ SecurityConstraintMapping matcher = new SecurityConstraintMapping();
+ matcher.addInclusion("/foo");
+ matcher.addInclusion("/bar");
+
+ assertNull(matcher.restricted("/"));
+ assertNotNull(matcher.restricted("/foo"));
+ assertNull(matcher.restricted("/foobar"));
+ assertNull(matcher.restricted("/foo/bar"));
+
+ assertNotNull(matcher.restricted("/bar"));
+ assertNull(matcher.restricted("/barbar"));
+ assertNull(matcher.restricted("/bar/bar"));
+ }
+
+ public void testFooBarWildcard() {
+ SecurityConstraintMapping matcher = new SecurityConstraintMapping();
+ matcher.addInclusion("/foo*");
+ matcher.addInclusion("/bar*");
+
+ assertNull(matcher.restricted("/"));
+ assertNotNull(matcher.restricted("/foo"));
+ assertNotNull(matcher.restricted("/foobar"));
+ assertNotNull(matcher.restricted("/foo/bar"));
+
+ assertNotNull(matcher.restricted("/bar"));
+ assertNotNull(matcher.restricted("/barbar"));
+ assertNotNull(matcher.restricted("/bar/bar"));
+ }
+
+ public void testFooExclusion() {
+ SecurityConstraintMapping matcher = new SecurityConstraintMapping();
+ matcher.addInclusion("/foo/*");
+ matcher.addExclusion("/foo/public/*");
+
+ assertNull(matcher.restricted("/"));
+ assertNotNull(matcher.restricted("/foo"));
+ assertNotNull(matcher.restricted("/foo/bar"));
+ assertNull(matcher.restricted("/foo/public"));
+ assertNull(matcher.restricted("/foo/public/open"));
+ }
+
+ public void testDefaultExclusion() {
+ // everything is restricted unless its from the public
+ SecurityConstraintMapping matcher = new SecurityConstraintMapping();
+ matcher.addExclusion("/public/*");
+ matcher.addExclusion("/index");
+ matcher.addExclusion("/index.html");
+
+ assertNotNull(matcher.restricted("/"));
+ assertNotNull(matcher.restricted("/foo"));
+ assertNotNull(matcher.restricted("/foo/bar"));
+ assertNull(matcher.restricted("/public"));
+ assertNull(matcher.restricted("/public/open"));
+ assertNull(matcher.restricted("/index"));
+ assertNull(matcher.restricted("/index.html"));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/SpringNettyHttpBasicAuthTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/SpringNettyHttpBasicAuthTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/SpringNettyHttpBasicAuthTest.java
new file mode 100644
index 0000000..826b984
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/SpringNettyHttpBasicAuthTest.java
@@ -0,0 +1,118 @@
+/**
+ * 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 javax.annotation.Resource;
+
+import junit.framework.TestCase;
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"/org/apache/camel/component/netty4/http/SpringNettyHttpBasicAuthTest.xml"})
+public class SpringNettyHttpBasicAuthTest extends TestCase {
+
+ @Produce
+ private ProducerTemplate template;
+
+ @EndpointInject(uri = "mock:input")
+ private MockEndpoint mockEndpoint;
+
+ private Integer port;
+
+ public Integer getPort() {
+ return port;
+ }
+
+ @Resource(name = "dynaPort")
+ public void setPort(Integer port) {
+ this.port = port;
+ }
+
+ @BeforeClass
+ public static void setUpJaas() throws Exception {
+ System.setProperty("java.security.auth.login.config", "src/test/resources/myjaas.config");
+ }
+
+ @AfterClass
+ public static void tearDownJaas() throws Exception {
+ System.clearProperty("java.security.auth.login.config");
+ }
+
+ @Test
+ public void testAdminAuth() throws Exception {
+ mockEndpoint.reset();
+
+ mockEndpoint.expectedBodiesReceived("Hello Public", "Hello Foo", "Hello Admin");
+
+ // public do not need authentication
+ String out = template.requestBody("netty4-http:http://localhost:" + port + "/foo/public/welcome", "Hello Public", String.class);
+ assertEquals("Bye /foo/public/welcome", out);
+
+ // username:password is scott:secret
+ String auth = "Basic c2NvdHQ6c2VjcmV0";
+ out = template.requestBodyAndHeader("netty4-http:http://localhost:" + port + "/foo", "Hello Foo", "Authorization", auth, String.class);
+ assertEquals("Bye /foo", out);
+
+ out = template.requestBodyAndHeader("netty4-http:http://localhost:" + port + "/foo/admin/users", "Hello Admin", "Authorization", auth, String.class);
+ assertEquals("Bye /foo/admin/users", out);
+
+ mockEndpoint.assertIsSatisfied();
+
+ try {
+ template.requestBody("netty4-http:http://localhost:" + port + "/foo", "Hello Foo", String.class);
+ fail("Should send back 401");
+ } catch (CamelExecutionException e) {
+ NettyHttpOperationFailedException cause = (NettyHttpOperationFailedException) e.getCause();
+ assertEquals(401, cause.getStatusCode());
+ }
+
+
+ }
+
+ @Test
+ public void testGuestAuth() throws Exception {
+ // username:password is guest:secret
+ String auth = "Basic Z3Vlc3Q6c2VjcmV0";
+ String out = template.requestBodyAndHeader("netty4-http:http://localhost:" + port + "/foo/guest/hello", "Hello Guest", "Authorization", auth, String.class);
+ assertEquals("Bye /foo/guest/hello", out);
+
+ // but we can access foo as that is any roles
+ out = template.requestBodyAndHeader("netty4-http:http://localhost:" + port + "/foo", "Hello Foo", "Authorization", auth, String.class);
+ assertEquals("Bye /foo", out);
+
+ // accessing admin is restricted for guest user
+ try {
+ template.requestBodyAndHeader("netty4-http:http://localhost:" + port + "/foo/admin/users", "Hello Admin", "Authorization", auth, String.class);
+ fail("Should send back 401");
+ } catch (CamelExecutionException e) {
+ NettyHttpOperationFailedException cause = (NettyHttpOperationFailedException) e.getCause();
+ assertEquals(401, cause.getStatusCode());
+ }
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/SpringNettyHttpSSLTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/SpringNettyHttpSSLTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/SpringNettyHttpSSLTest.java
new file mode 100644
index 0000000..57a99fd
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/SpringNettyHttpSSLTest.java
@@ -0,0 +1,79 @@
+/**
+ * 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 javax.annotation.Resource;
+
+import junit.framework.TestCase;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"/org/apache/camel/component/netty4/http/SpringNettyHttpSSLTest.xml"})
+public class SpringNettyHttpSSLTest extends TestCase {
+
+ @Produce
+ private ProducerTemplate template;
+
+ @EndpointInject(uri = "mock:input")
+ private MockEndpoint mockEndpoint;
+
+ private Integer port;
+
+ public Integer getPort() {
+ return port;
+ }
+
+ @Resource(name = "dynaPort")
+ public void setPort(Integer port) {
+ this.port = port;
+ }
+
+ @BeforeClass
+ public static void setUpJaas() 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 = NettyHttpSSLTest.class.getClassLoader().getResource("jsse/localhost.ks");
+ System.setProperty("javax.net.ssl.trustStore", trustStoreUrl.toURI().getPath());
+ }
+
+ @AfterClass
+ public static void tearDownJaas() throws Exception {
+ System.clearProperty("java.security.auth.login.config");
+ }
+
+ @Test
+ public void testSSLInOutWithNettyConsumer() throws Exception {
+ mockEndpoint.expectedBodiesReceived("Hello World");
+
+ String out = template.requestBody("https://localhost:" + getPort(), "Hello World", String.class);
+ assertEquals("Bye World", out);
+
+ mockEndpoint.assertIsSatisfied();
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/CountryPojo.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/CountryPojo.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/CountryPojo.java
new file mode 100644
index 0000000..709080a
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/CountryPojo.java
@@ -0,0 +1,40 @@
+/**
+ * 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.rest;
+
+public class CountryPojo {
+
+ private String iso;
+ private String country;
+
+ public String getIso() {
+ return iso;
+ }
+
+ public void setIso(String iso) {
+ this.iso = iso;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCountry(String country) {
+ this.country = country;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/db88eeda/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestNettyHttpBindingModeAutoWithJsonTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestNettyHttpBindingModeAutoWithJsonTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestNettyHttpBindingModeAutoWithJsonTest.java
new file mode 100644
index 0000000..1a3c6aa
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestNettyHttpBindingModeAutoWithJsonTest.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.rest;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.netty4.http.BaseNettyTest;
+import org.apache.camel.model.rest.RestBindingMode;
+import org.junit.Test;
+
+public class RestNettyHttpBindingModeAutoWithJsonTest extends BaseNettyTest {
+
+ @Test
+ public void testBindingMode() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:input");
+ mock.expectedMessageCount(1);
+ mock.message(0).body().isInstanceOf(UserPojo.class);
+
+ String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
+ template.sendBody("netty4-http:http://localhost:" + getPort() + "/users/new", body);
+
+ assertMockEndpointsSatisfied();
+
+ UserPojo user = mock.getReceivedExchanges().get(0).getIn().getBody(UserPojo.class);
+ assertNotNull(user);
+ assertEquals(123, user.getId());
+ assertEquals("Donald Duck", user.getName());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ restConfiguration().component("netty4-http").host("localhost").port(getPort()).bindingMode(RestBindingMode.auto);
+
+ // use the rest DSL to define the rest services
+ rest("/users/")
+ .post("new").consumes("application/json").type(UserPojo.class)
+ .to("mock:input");
+ }
+ };
+ }
+
+}