camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject [04/23] camel git commit: CAMEL-8239 Split jetty8 and jetty9 support into separate modules
Date Thu, 15 Jan 2015 08:48:40 GMT
http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/MultiThreadedHttpGetTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/MultiThreadedHttpGetTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/MultiThreadedHttpGetTest.java
new file mode 100644
index 0000000..d1f77db
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/MultiThreadedHttpGetTest.java
@@ -0,0 +1,120 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty;
+
+import java.io.InputStream;
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.http.HttpComponent;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.commons.httpclient.HttpConnectionManager;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.junit.Test;
+
+/**
+ * @version 
+ */
+public class MultiThreadedHttpGetTest extends BaseJettyTest {
+
+    @Test
+    public void testHttpGetWithConversion() throws Exception {
+
+        // In this scenario response stream is converted to String
+        // so the stream has to be read to the end. When this happens
+        // the associated connection is released automatically.
+
+        String endpointName = "seda:withConversion?concurrentConsumers=5";
+        sendMessagesTo(endpointName, 5);
+    }
+
+    @Test
+    public void testHttpGetWithoutConversion() throws Exception {
+
+        // This is needed as by default there are 2 parallel
+        // connections to some host and there is nothing that
+        // closes the http connection here.
+        // Need to set the httpConnectionManager 
+        HttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();
+        httpConnectionManager.getParams().setDefaultMaxConnectionsPerHost(5);
+        context.getComponent("http", HttpComponent.class).setHttpConnectionManager(httpConnectionManager);
+       
+
+        String endpointName = "seda:withoutConversion?concurrentConsumers=5";
+        sendMessagesTo(endpointName, 5);
+    }
+
+    @Test
+    public void testHttpGetWithExplicitStreamClose() throws Exception {
+
+        // We close connections explicitely at the very end of the flow
+        // (camel doesn't know when the stream is not needed any more)
+
+        MockEndpoint mockEndpoint = resolveMandatoryEndpoint("mock:results", MockEndpoint.class);
+
+        for (int i = 0; i < 5; i++) {
+            mockEndpoint.expectedMessageCount(1);
+            template.sendBody("seda:withoutConversion?concurrentConsumers=5", null);
+            mockEndpoint.assertIsSatisfied();
+            Object response = mockEndpoint.getReceivedExchanges().get(0).getIn().getBody();
+            InputStream responseStream = assertIsInstanceOf(InputStream.class, response);
+            responseStream.close();
+            mockEndpoint.reset();
+        }
+    }
+
+    protected void sendMessagesTo(String endpointName, int count) throws InterruptedException {
+        MockEndpoint mockEndpoint = resolveMandatoryEndpoint("mock:results", MockEndpoint.class);
+        mockEndpoint.expectedMessageCount(count);
+
+        for (int i = 0; i < count; i++) {
+            template.sendBody(endpointName, null);
+        }
+
+        mockEndpoint.assertIsSatisfied();
+        List<Exchange> list = mockEndpoint.getReceivedExchanges();
+        for (Exchange exchange : list) {
+            String body = exchange.getIn().getBody(String.class);
+
+            log.debug("Body: " + body);
+            assertNotNull("Should have a body!", body);
+            assertTrue("body should contain: <html", body.contains("<html"));
+        }
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                from("seda:withConversion?concurrentConsumers=5").to("http://localhost:{{port}}/search")
+                        .convertBodyTo(String.class).to("mock:results");
+
+                from("seda:withoutConversion?concurrentConsumers=5").to("http://localhost:{{port}}/search")
+                        .to("mock:results");
+
+                from("jetty:http://localhost:{{port}}/search").process(new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        exchange.getOut().setBody("<html>Bye World</html>");
+                    }
+                });
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/MyErrorHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/MyErrorHandler.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/MyErrorHandler.java
new file mode 100644
index 0000000..917ae35
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/MyErrorHandler.java
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.jetty.server.handler.ErrorHandler;
+
+public class MyErrorHandler extends ErrorHandler {
+    
+    protected void writeErrorPageBody(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks)
+        throws IOException {
+        String uri = request.getRequestURI();
+        
+        writeErrorPageMessage(request, writer, code, message, uri);
+        if (showStacks) {
+            writeErrorPageStacks(request, writer);
+        }
+        writer.write("<hr /><i><small>MyErrorHandler</small></i>");
+        for (int i = 0; i < 20; i++) {
+            writer.write("<br/>                                                \n");
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/MyUrlRewrite.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/MyUrlRewrite.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/MyUrlRewrite.java
new file mode 100644
index 0000000..8ca31d4
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/MyUrlRewrite.java
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty;
+
+import org.apache.camel.Producer;
+import org.apache.camel.component.http.UrlRewrite;
+
+/**
+ *
+ */
+public class MyUrlRewrite implements UrlRewrite {
+
+    @Override
+    public String rewrite(String url, String relativeUrl, Producer producer) {
+        return url.replaceAll("foo", "bar");
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/SimpleJettyChunkedFalseTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/SimpleJettyChunkedFalseTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/SimpleJettyChunkedFalseTest.java
new file mode 100644
index 0000000..56114d2
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/SimpleJettyChunkedFalseTest.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.jetty;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class SimpleJettyChunkedFalseTest extends BaseJettyTest {
+
+    @Test
+    public void testSimple() throws Exception {
+        String result = template.requestBody("http://localhost:{{port}}/myapp", "Camel", String.class);
+        assertEquals("Hello Camel", result);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("jetty:http://localhost:{{port}}/myapp?chunked=false")
+                    .transform(body().prepend("Hello "));
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/SimpleJettyTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/SimpleJettyTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/SimpleJettyTest.java
new file mode 100644
index 0000000..aa06352
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/SimpleJettyTest.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.jetty;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class SimpleJettyTest extends BaseJettyTest {
+
+    @Test
+    public void testSimple() throws Exception {
+        String result = template.requestBody("http://localhost:{{port}}/myapp", "Camel", String.class);
+        assertEquals("Hello Camel", result);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("jetty:http://localhost:{{port}}/myapp")
+                    .transform(body().prepend("Hello "));
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java
new file mode 100644
index 0000000..fe4154f
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java
@@ -0,0 +1,135 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty;
+
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import javax.annotation.Resource;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.test.junit4.TestSupport;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"/org/apache/camel/component/jetty/jetty-https.xml"})
+public class SpringHttpsRouteTest {
+    private static final String NULL_VALUE_MARKER = CamelTestSupport.class.getCanonicalName();
+    protected String expectedBody = "<hello>world!</hello>";
+    protected String pwd = "changeit";
+    protected Properties originalValues = new Properties();
+    protected transient Log log = LogFactory.getLog(TestSupport.class);
+
+    @EndpointInject(uri = "mock:a")
+    MockEndpoint mockEndpoint;
+    
+    @Produce
+    private ProducerTemplate template;
+
+    private Integer port;
+
+    @Before
+    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 = Thread.currentThread().getContextClassLoader().getResource("jsse/localhost.ks");
+        setSystemProp("javax.net.ssl.trustStore", trustStoreUrl.getPath());
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        restoreSystemProperties();
+    }
+
+    private void setSystemProp(String key, String value) {
+        String originalValue = System.setProperty(key, value);
+        originalValues.put(key, originalValue != null ? originalValue : NULL_VALUE_MARKER);
+    }
+
+    private 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);
+            }
+        }
+    }
+
+    @Test
+    public void testEndpoint() throws Exception {
+        mockEndpoint.reset();
+        mockEndpoint.expectedBodiesReceived(expectedBody);
+
+        template.sendBodyAndHeader("https://localhost:" + port + "/test", expectedBody, "Content-Type", "application/xml");
+
+        mockEndpoint.assertIsSatisfied();
+        List<Exchange> list = mockEndpoint.getReceivedExchanges();
+        Exchange exchange = list.get(0);
+        Assert.assertNotNull("exchange", exchange);
+
+        Message in = exchange.getIn();
+        assertNotNull("in", in);
+
+        Map<String, Object> headers = in.getHeaders();
+
+        log.info("Headers: " + headers);
+
+        assertTrue("Should be more than one header but was: " + headers, headers.size() > 0);
+    }
+
+    @Test
+    public void testEndpointWithoutHttps() {
+        mockEndpoint.reset();
+        try {
+            template.sendBodyAndHeader("http://localhost:" + port + "/test", expectedBody, "Content-Type", "application/xml");
+            fail("expect exception on access to https endpoint via http");
+        } catch (RuntimeCamelException expected) {
+        }
+        assertTrue("mock endpoint was not called", mockEndpoint.getExchanges().isEmpty());
+    }
+
+    public Integer getPort() {
+        return port;
+    }
+
+    @Resource(name = "dynaPort")
+    public void setPort(Integer port) {
+        this.port = port;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/SpringJettyNoConnectionRedeliveryTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/SpringJettyNoConnectionRedeliveryTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/SpringJettyNoConnectionRedeliveryTest.java
new file mode 100644
index 0000000..3b26744
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/SpringJettyNoConnectionRedeliveryTest.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.jetty;
+
+import java.net.ConnectException;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.test.spring.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version
+ */
+public class SpringJettyNoConnectionRedeliveryTest extends CamelSpringTestSupport {
+
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/component/jetty/jetty-noconnection-redelivery.xml");
+    }
+
+    @Test
+    public void testConnectionOk() throws Exception {
+        String reply = template.requestBody("direct:start", "World", String.class);
+        assertEquals("Bye World", reply);
+    }
+
+    @Test
+    public void testConnectionNotOk() throws Exception {
+        // stop Jetty route so there should not be a connection
+        context.stopRoute("jetty");
+
+        Exchange exchange = template.request("direct:start", new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody("Moon");
+            }
+        });
+
+        assertTrue(exchange.isFailed());
+
+        // there should be a connect exception as cause
+        ConnectException ce = exchange.getException(ConnectException.class);
+        assertNotNull(ce);
+
+        assertEquals(true, exchange.getIn().getHeader(Exchange.REDELIVERED));
+        assertEquals(4, exchange.getIn().getHeader(Exchange.REDELIVERY_COUNTER));
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/SpringJettyNoConnectionTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/SpringJettyNoConnectionTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/SpringJettyNoConnectionTest.java
new file mode 100644
index 0000000..fd5eae0
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/SpringJettyNoConnectionTest.java
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty;
+
+import java.net.ConnectException;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.test.spring.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version 
+ */
+public class SpringJettyNoConnectionTest extends CamelSpringTestSupport {
+
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/component/jetty/jetty-noconnection.xml");
+    }
+
+    @Test
+    public void testConnectionOk() throws Exception {
+        String reply = template.requestBody("direct:start", "World", String.class);
+        assertEquals("Bye World", reply);
+    }
+
+    @Test
+    public void testConnectionNotOk() throws Exception {
+        // stop Jetty route so there should not be a connection
+        context.stopRoute("jetty");
+
+        try {
+            template.requestBody("direct:start", "Moon", String.class);
+            fail("Should have thrown an exception");
+        } catch (CamelExecutionException e) {
+            assertIsInstanceOf(ConnectException.class, e.getCause());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/TwoCamelContextWithJettyRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/TwoCamelContextWithJettyRouteTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/TwoCamelContextWithJettyRouteTest.java
new file mode 100644
index 0000000..420ec91
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/TwoCamelContextWithJettyRouteTest.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.jetty;
+
+import java.net.ConnectException;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.Test;
+
+public class TwoCamelContextWithJettyRouteTest extends BaseJettyTest {
+
+    private int port1;
+    private int port2;
+
+    @Test
+    public void testTwoServerPorts() throws Exception {
+        // create another camelContext
+        CamelContext contextB = new DefaultCamelContext();
+        contextB.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("jetty://http://localhost:" + port2 + "/myotherapp").process(new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        String in = exchange.getIn().getBody(String.class);
+                        exchange.getOut().setBody("Hi " + in);
+                    }
+                });
+            }
+        });
+        contextB.start();
+        
+        String reply = template.requestBody("direct:a", "World", String.class);
+        assertEquals("Bye World", reply);
+
+        reply = template.requestBody("direct:b", "Camel", String.class);
+        assertEquals("Hi Camel", reply);
+        
+        contextB.stop();
+        
+        reply = template.requestBody("direct:a", "Earth", String.class);
+        assertEquals("Bye Earth", reply);
+        
+        try {
+            reply = template.requestBody("direct:b", "Moon", String.class);
+            // expert the exception here
+            fail("Expert the exception here");
+        } catch (Exception ex) {
+            assertTrue("Should get the ConnectException", ex.getCause() instanceof ConnectException);
+        }
+        
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                port1 = getPort();
+                port2 = getNextPort();
+
+                from("direct:a").to("http://localhost:" + port1 + "/myapp");
+
+                from("direct:b").to("http://localhost:" + port2 + "/myotherapp");
+
+                from("jetty://http://localhost:" + port1 + "/myapp").process(new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        String in = exchange.getIn().getBody(String.class);
+                        exchange.getOut().setBody("Bye " + in);
+                    }
+                });
+            }
+        };
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncCBRTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncCBRTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncCBRTest.java
new file mode 100644
index 0000000..e3f41c9
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncCBRTest.java
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty.async;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jetty.BaseJettyTest;
+import org.junit.Test;
+
+/**
+ * @version 
+ */
+public class JettyAsyncCBRTest extends BaseJettyTest {
+
+    @Test
+    public void testJettyAsync() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+        String reply = template.requestBody("http://localhost:{{port}}/myservice", "Hello Camel", String.class);
+        assertEquals("Bye World", reply);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                context.addComponent("async", new MyAsyncComponent());
+
+                from("jetty:http://localhost:{{port}}/myservice")
+                    .convertBodyTo(String.class)
+                    .choice()
+                        .when(body().contains("Camel"))
+                            .to("async:bye:world")
+                        .end()
+                    .to("mock:result");
+            }
+        };
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncContinuationDisabledTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncContinuationDisabledTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncContinuationDisabledTest.java
new file mode 100644
index 0000000..acca758
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncContinuationDisabledTest.java
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty.async;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jetty.BaseJettyTest;
+import org.junit.Test;
+
+/**
+ * @version 
+ */
+public class JettyAsyncContinuationDisabledTest extends BaseJettyTest {
+
+    @Test
+    public void testJettyAsyncContinuationDisabled() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+        String out = template.requestBody("http://localhost:{{port}}/myservice", null, String.class);
+        assertEquals("Bye World", out);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                context.addComponent("async", new MyAsyncComponent());
+
+                from("jetty:http://localhost:{{port}}/myservice?useContinuation=false")
+                    .to("async:bye:world")
+                    .to("mock:result");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncContinuationTimeoutOkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncContinuationTimeoutOkTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncContinuationTimeoutOkTest.java
new file mode 100644
index 0000000..023d79c
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncContinuationTimeoutOkTest.java
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty.async;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jetty.BaseJettyTest;
+import org.junit.Test;
+
+/**
+ * @version 
+ */
+public class JettyAsyncContinuationTimeoutOkTest extends BaseJettyTest {
+
+    @Test
+    public void testJettyAsyncTimeoutOk() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+        String reply = template.requestBody("http://localhost:{{port}}/myservice", null, String.class);
+        assertEquals("Bye World", reply);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                context.addComponent("async", new MyAsyncComponent());
+
+                from("jetty:http://localhost:{{port}}/myservice?continuationTimeout=3000")
+                    .to("async:bye:world")
+                    .to("mock:result");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncContinuationTimeoutTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncContinuationTimeoutTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncContinuationTimeoutTest.java
new file mode 100644
index 0000000..91c7535
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncContinuationTimeoutTest.java
@@ -0,0 +1,67 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty.async;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.http.HttpOperationFailedException;
+import org.apache.camel.component.jetty.BaseJettyTest;
+import org.apache.camel.util.StopWatch;
+import org.junit.Test;
+
+/**
+ * @version 
+ */
+public class JettyAsyncContinuationTimeoutTest extends BaseJettyTest {
+
+    @Test
+    public void testJettyAsyncTimeout() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+        StopWatch watch = new StopWatch();
+        try {
+            template.requestBody("http://localhost:{{port}}/myservice", null, String.class);
+            fail("Should have thrown an exception");
+        } catch (CamelExecutionException e) {
+            log.info("Timeout hit and client got reply with failure status code");
+
+            long taken = watch.stop();
+
+            HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
+            assertEquals(503, cause.getStatusCode());
+
+            // should be approx 3-4 sec.
+            assertTrue("Timeout should occur faster than " + taken, taken < 4500);
+        }
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                context.addComponent("async", new MyAsyncComponent());
+
+                from("jetty:http://localhost:{{port}}/myservice?continuationTimeout=3000")
+                    .to("async:bye:world?delay=6000")
+                    .to("mock:result");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncDefaultContinuationTimeoutTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncDefaultContinuationTimeoutTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncDefaultContinuationTimeoutTest.java
new file mode 100644
index 0000000..c85d716
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncDefaultContinuationTimeoutTest.java
@@ -0,0 +1,71 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty.async;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.http.HttpOperationFailedException;
+import org.apache.camel.component.jetty.BaseJettyTest;
+import org.apache.camel.util.StopWatch;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * @version 
+ */
+@Ignore("This test takes a long time to run, so run it manually")
+public class JettyAsyncDefaultContinuationTimeoutTest extends BaseJettyTest {
+
+    @Test
+    public void testJettyAsyncTimeout() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+        StopWatch watch = new StopWatch();
+        try {
+            template.requestBody("http://localhost:{{port}}/myservice", null, String.class);
+            fail("Should have thrown an exception");
+        } catch (CamelExecutionException e) {
+            log.info("Timeout hit and client got reply with failure status code");
+
+            long taken = watch.stop();
+
+            HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
+            assertEquals(503, cause.getStatusCode());
+
+            // should be approx 30-34 sec.
+            assertTrue("Timeout should occur faster than " + taken, taken < 34000);
+        }
+
+        assertMockEndpointsSatisfied(2, TimeUnit.MINUTES);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                context.addComponent("async", new MyAsyncComponent());
+
+                from("jetty:http://localhost:{{port}}/myservice")
+                    .to("async:bye:world?delay=45s")
+                    .to("mock:result");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncFilterTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncFilterTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncFilterTest.java
new file mode 100644
index 0000000..07614f7
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncFilterTest.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.jetty.async;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jetty.BaseJettyTest;
+import org.junit.Test;
+
+/**
+ * @version 
+ */
+public class JettyAsyncFilterTest extends BaseJettyTest {
+
+    @Test
+    public void testJettyAsync() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+        String reply = template.requestBody("http://localhost:{{port}}/myservice", "Hello Camel", String.class);
+        assertEquals("Bye World", reply);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                context.addComponent("async", new MyAsyncComponent());
+
+                from("jetty:http://localhost:{{port}}/myservice")
+                    .convertBodyTo(String.class)
+                    .filter(body().contains("Camel"))
+                        .to("async:bye:world")
+                    .end()
+                    .to("mock:result");
+            }
+        };
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncTest.java
new file mode 100644
index 0000000..e082076
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncTest.java
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty.async;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jetty.BaseJettyTest;
+import org.junit.Test;
+
+/**
+ * @version 
+ */
+public class JettyAsyncTest extends BaseJettyTest {
+
+    @Test
+    public void testJettyAsync() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+        String reply = template.requestBody("http://localhost:{{port}}/myservice", null, String.class);
+        assertEquals("Bye World", reply);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                context.addComponent("async", new MyAsyncComponent());
+
+                from("jetty:http://localhost:{{port}}/myservice")
+                    .to("async:bye:world")
+                    .to("mock:result");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncThrottleTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncThrottleTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncThrottleTest.java
new file mode 100644
index 0000000..890e3dd
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncThrottleTest.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.jetty.async;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jetty.BaseJettyTest;
+import org.junit.Test;
+
+/**
+ * CAMEL-4795, there should be no exceptions in the logs (before the fix there was a NPE)
+ *
+ * @version
+ */
+public class JettyAsyncThrottleTest extends BaseJettyTest {
+
+    @Test
+    public void testJettyAsync() throws Exception {
+        getMockEndpoint("mock:result").expectedMessageCount(5);
+
+        template.asyncRequestBody("jetty:http://localhost:{{port}}/myservice", null);
+        template.asyncRequestBody("jetty:http://localhost:{{port}}/myservice", null);
+        template.asyncRequestBody("jetty:http://localhost:{{port}}/myservice", null);
+        template.asyncRequestBody("jetty:http://localhost:{{port}}/myservice", null);
+        template.asyncRequestBody("jetty:http://localhost:{{port}}/myservice", null);
+
+        assertMockEndpointsSatisfied();
+        
+        for (int i = 0; i < 5; i++) {
+            Exchange exchange = getMockEndpoint("mock:result").getReceivedExchanges().get(i);
+            log.info("Reply " + exchange);
+        }
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                int port2 = getNextPort();
+                int port3 = getNextPort();
+
+                from("jetty:http://localhost:{{port}}/myservice")
+                    .removeHeaders("*")
+                    .throttle(2).asyncDelayed()
+                        .loadBalance().failover()
+                            .to("jetty:http://localhost:" + port2 + "/foo")
+                            .to("jetty:http://localhost:" + port3 + "/bar")
+                        .end()
+                    .to("mock:result");
+
+                from("jetty:http://localhost:" + port2 + "/foo")
+                    .transform().constant("foo")
+                    .to("mock:foo");
+
+                from("jetty:http://localhost:" + port3 + "/bar")
+                    .transform().constant("bar")
+                    .to("mock:bar");
+            }
+        };
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncTransformTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncTransformTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncTransformTest.java
new file mode 100644
index 0000000..7755f36
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncTransformTest.java
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty.async;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jetty.BaseJettyTest;
+import org.junit.Test;
+
+/**
+ * @version 
+ */
+public class JettyAsyncTransformTest extends BaseJettyTest {
+
+    @Test
+    public void testJettyAsync() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+        String reply = template.requestBody("http://localhost:{{port}}/myservice", null, String.class);
+        assertEquals("Bye World", reply);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                context.addComponent("async", new MyAsyncComponent());
+
+                from("jetty:http://localhost:{{port}}/myservice")
+                    .to("log:foo")
+                    .convertBodyTo(String.class)
+                    .transform(constant("Hello World"))
+                    .to("async:hi:world")
+                    .transform(constant("Bye World"))
+                    .to("mock:result");
+            }
+        };
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncTryCatchFinallyTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncTryCatchFinallyTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncTryCatchFinallyTest.java
new file mode 100644
index 0000000..8993de4
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncTryCatchFinallyTest.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.jetty.async;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jetty.BaseJettyTest;
+import org.junit.Test;
+
+/**
+ * @version 
+ */
+public class JettyAsyncTryCatchFinallyTest extends BaseJettyTest {
+
+    @Test
+    public void testJettyAsync() throws Exception {
+        getMockEndpoint("mock:try").expectedBodiesReceived("Hello Camel");
+        getMockEndpoint("mock:catch").expectedBodiesReceived("Hello Camel");
+        getMockEndpoint("mock:finally").expectedBodiesReceived("Bye Camel");
+        getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+        String reply = template.requestBody("http://localhost:{{port}}/myservice", "Hello Camel", String.class);
+        assertEquals("Bye World", reply);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                context.addComponent("async", new MyAsyncComponent());
+
+                from("jetty:http://localhost:{{port}}/myservice")
+                    .convertBodyTo(String.class)
+                    .doTry()
+                        .to("mock:try")
+                        .throwException(new IllegalArgumentException("Damn"))
+                    .doCatch(IllegalArgumentException.class)
+                        .to("mock:catch")
+                        .to("async:bye:camel")
+                    .doFinally()
+                        .to("mock:finally")
+                        .to("async:bye:world")
+                    .end()
+                    .to("mock:result");
+            }
+        };
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/MyAsyncComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/MyAsyncComponent.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/MyAsyncComponent.java
new file mode 100644
index 0000000..7daa4d4
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/MyAsyncComponent.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.jetty.async;
+
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+
+/**
+ * @version 
+ */
+public class MyAsyncComponent extends DefaultComponent {
+
+    @Override
+    protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+        MyAsyncEndpoint answer = new MyAsyncEndpoint(uri, this);
+        answer.setReply(prepareReply(remaining));
+        setProperties(answer, parameters);
+        return answer;
+    }
+
+    private String prepareReply(String value) {
+        // to make URIs valid we make the conventions of using ':' for ' ' and 
+        // capitalize words
+        String[] words = value.split(":");
+        String result = "";
+        for (String word : words) {
+            result += result.isEmpty() ? "" : " ";
+            result += word.substring(0, 1).toUpperCase() + word.substring(1);
+        }
+        return result;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/MyAsyncEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/MyAsyncEndpoint.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/MyAsyncEndpoint.java
new file mode 100644
index 0000000..de729cc
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/MyAsyncEndpoint.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.jetty.async;
+
+import org.apache.camel.Component;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultEndpoint;
+
+/**
+ * @version 
+ */
+public class MyAsyncEndpoint extends DefaultEndpoint {
+
+    private String reply;
+    private long delay = 1000;
+    private int failFirstAttempts;
+
+    public MyAsyncEndpoint(String endpointUri, Component component) {
+        super(endpointUri, component);
+    }
+
+    public Producer createProducer() throws Exception {
+        return new MyAsyncProducer(this);
+    }
+
+    public Consumer createConsumer(Processor processor) throws Exception {
+        throw new UnsupportedOperationException("Consumer not supported");
+    }
+
+    public boolean isSingleton() {
+        return false;
+    }
+
+    public String getReply() {
+        return reply;
+    }
+
+    public void setReply(String reply) {
+        this.reply = reply;
+    }
+
+    public long getDelay() {
+        return delay;
+    }
+
+    public void setDelay(long delay) {
+        this.delay = delay;
+    }
+
+    public int getFailFirstAttempts() {
+        return failFirstAttempts;
+    }
+
+    public void setFailFirstAttempts(int failFirstAttempts) {
+        this.failFirstAttempts = failFirstAttempts;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/MyAsyncProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/MyAsyncProducer.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/MyAsyncProducer.java
new file mode 100644
index 0000000..2af5747
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/async/MyAsyncProducer.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.jetty.async;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.CamelExchangeException;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultAsyncProducer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @version 
+ */
+public class MyAsyncProducer extends DefaultAsyncProducer {
+
+    private static final Logger LOG = LoggerFactory.getLogger(MyAsyncProducer.class);
+    private final ExecutorService executor = Executors.newCachedThreadPool();
+    private final AtomicInteger counter = new AtomicInteger();
+
+    public MyAsyncProducer(MyAsyncEndpoint endpoint) {
+        super(endpoint);
+    }
+
+    public MyAsyncEndpoint getEndpoint() {
+        return (MyAsyncEndpoint) super.getEndpoint();
+    }
+
+    public boolean process(final Exchange exchange, final AsyncCallback callback) {
+        executor.submit(new Callable<Object>() {
+            public Object call() throws Exception {
+                LOG.info("Simulating a task which takes " + getEndpoint().getDelay() + " millis to reply");
+                Thread.sleep(getEndpoint().getDelay());
+
+                int count = counter.incrementAndGet();
+                if (getEndpoint().getFailFirstAttempts() >= count) {
+                    LOG.info("Simulating a failure at attempt " + count);
+                    exchange.setException(new CamelExchangeException("Simulated error at attempt " + count, exchange));
+                } else {
+                    String reply = getEndpoint().getReply();
+                    exchange.getOut().setBody(reply);
+                    LOG.info("Setting reply " + reply);
+                }
+
+                LOG.info("Callback done(false)");
+                callback.done(false);
+                return null;
+            }
+        });
+
+        // indicate from this point forward its being routed asynchronously
+        LOG.info("Task submitted, now tell Camel routing engine to that this Exchange is being continued asynchronously");
+        return false;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/file/JettyFileConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/file/JettyFileConsumerTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/file/JettyFileConsumerTest.java
new file mode 100644
index 0000000..69a5b00
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/file/JettyFileConsumerTest.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.jetty.file;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jetty.BaseJettyTest;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JettyFileConsumerTest extends BaseJettyTest {
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        deleteDirectory("target/binary");
+        deleteDirectory("target/test");
+        super.setUp();
+    }
+
+    private void testingSendingFile(File src) throws Exception {
+        deleteDirectory("target/test");
+        FileInputStream fis = new FileInputStream(src);
+        String response = template.requestBody("http://localhost:{{port}}/myapp/myservice", fis, String.class);
+        assertEquals("Response should be OK ", "OK", response);
+        File des = new File("target/test/temp.xml");
+        assertTrue("The uploaded file should exists", des.exists());
+        assertEquals("This two file should have same size", src.length(), des.length());
+    }
+
+    @Test
+    public void testSending4K() throws Exception {
+        File src = new File("src/test/resources/log4j.properties");
+        testingSendingFile(src);
+    }
+    
+    @Test
+    public void testSending18k() throws Exception {
+        File src = new File("src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java");
+        testingSendingFile(src);
+    }
+    
+    @Test
+    public void testSendBinaryFile() throws Exception {
+        deleteDirectory("target/test");
+        File jpg = new File("src/test/resources/java.jpg");
+        String response = template.requestBody("http://localhost:{{port}}/myapp/myservice2", jpg, String.class);
+        assertEquals("Response should be OK ", "OK", response);
+        File des = new File("target/test/java.jpg");
+        assertTrue("The uploaded file should exists", des.exists());
+        assertEquals("This two file should have same size", jpg.length(), des.length());
+    }
+    
+    @Test
+    public void testSendBinaryFileUsingCamelRoute() throws Exception {
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+
+        File jpg = new File("src/test/resources/java.jpg");
+        template.sendBodyAndHeader("file://target/binary", jpg, Exchange.FILE_NAME, "java.jpg");
+
+        assertMockEndpointsSatisfied();
+        Thread.sleep(1000);
+
+        File des = new File("target/test/java.jpg");
+        assertTrue("The uploaded file should exists", des.exists());
+        assertEquals("This two file should have same size", jpg.length(), des.length());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("jetty:http://localhost:{{port}}/myapp/myservice")
+                    .to("file://target/test?fileName=temp.xml")
+                    .setBody(constant("OK"));
+                
+                from("jetty:http://localhost:{{port}}/myapp/myservice2")
+                    .to("log:foo?showAll=true")
+                    .to("file://target/test?fileName=java.jpg")
+                    .setBody(constant("OK"));
+
+                from("file://target/binary?noop=true")
+                    .to("http://localhost:{{port}}/myapp/myservice2")
+                    .to("mock:result");
+            }
+        };
+    }   
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/javabody/HttpJavaBodyTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/javabody/HttpJavaBodyTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/javabody/HttpJavaBodyTest.java
new file mode 100644
index 0000000..b55d938
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/javabody/HttpJavaBodyTest.java
@@ -0,0 +1,126 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty.javabody;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.http.HttpConstants;
+import org.apache.camel.component.jetty.BaseJettyTest;
+import org.junit.Test;
+
+/**
+ * @version 
+ */
+public class HttpJavaBodyTest extends BaseJettyTest {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    @Test
+    public void testHttpSendJavaBodyAndReceiveString() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("jetty:http://localhost:{{port}}/myapp/myservice")
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws Exception {
+                            MyCoolBean cool = exchange.getIn().getBody(MyCoolBean.class);
+                            assertNotNull(cool);
+
+                            assertEquals(123, cool.getId());
+                            assertEquals("Camel", cool.getName());
+
+                            // we send back plain test
+                            exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "text/plain");
+                            exchange.getOut().setBody("OK");
+                        }
+                    });
+            }
+        });
+        context.start();
+
+        MyCoolBean cool = new MyCoolBean(123, "Camel");
+
+        String reply = template.requestBodyAndHeader("http://localhost:{{port}}/myapp/myservice", cool,
+                Exchange.CONTENT_TYPE, HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT, String.class);
+
+        assertEquals("OK", reply);
+    }
+
+    @Test
+    public void testHttpSendJavaBodyAndReceiveJavaBody() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("jetty:http://localhost:{{port}}/myapp/myservice")
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws Exception {
+                            MyCoolBean cool = exchange.getIn().getBody(MyCoolBean.class);
+                            assertNotNull(cool);
+
+                            assertEquals(123, cool.getId());
+                            assertEquals("Camel", cool.getName());
+
+                            MyCoolBean reply = new MyCoolBean(456, "Camel rocks");
+                            exchange.getOut().setBody(reply);
+                            exchange.getOut().setHeader(Exchange.CONTENT_TYPE, HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT);
+                        }
+                    });
+            }
+        });
+        context.start();
+
+        MyCoolBean cool = new MyCoolBean(123, "Camel");
+
+        MyCoolBean reply = template.requestBodyAndHeader("http://localhost:{{port}}/myapp/myservice", cool,
+                Exchange.CONTENT_TYPE, HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT, MyCoolBean.class);
+
+        assertEquals(456, reply.getId());
+        assertEquals("Camel rocks", reply.getName());
+    }
+
+    @Test
+    public void testHttpSendStringAndReceiveJavaBody() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("jetty:http://localhost:{{port}}/myapp/myservice")
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws Exception {
+                            String body = exchange.getIn().getBody(String.class);
+                            assertNotNull(body);
+                            assertEquals("Hello World", body);
+
+                            MyCoolBean reply = new MyCoolBean(456, "Camel rocks");
+                            exchange.getOut().setBody(reply);
+                            exchange.getOut().setHeader(Exchange.CONTENT_TYPE, HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT);
+                        }
+                    });
+            }
+        });
+        context.start();
+
+        MyCoolBean reply = template.requestBody("http://localhost:{{port}}/myapp/myservice", "Hello World", MyCoolBean.class);
+
+        assertEquals(456, reply.getId());
+        assertEquals("Camel rocks", reply.getName());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/javabody/MyCoolBean.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/javabody/MyCoolBean.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/javabody/MyCoolBean.java
new file mode 100644
index 0000000..0700fca
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/javabody/MyCoolBean.java
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty.javabody;
+
+import java.io.Serializable;
+
+/**
+ * @version 
+ */
+public class MyCoolBean implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+    private final int id;
+    private final String name;
+
+    public MyCoolBean(int id, String name) {
+        this.id = id;
+        this.name = name;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public String getName() {
+        return name;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/HttpJettyProducerRecipientListCustomThreadPoolTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/HttpJettyProducerRecipientListCustomThreadPoolTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/HttpJettyProducerRecipientListCustomThreadPoolTest.java
new file mode 100644
index 0000000..1036a35
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/HttpJettyProducerRecipientListCustomThreadPoolTest.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.jetty.jettyproducer;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jetty.BaseJettyTest;
+import org.junit.Test;
+
+/**
+ * @version 
+ */
+public class HttpJettyProducerRecipientListCustomThreadPoolTest extends BaseJettyTest {
+
+    @Test
+    public void testRecipientList() throws Exception {
+        // these tests does not run well on Windows
+        if (isPlatform("windows")) {
+            return;
+        }
+
+        // give Jetty time to startup properly
+        Thread.sleep(1000);
+
+        Exchange a = template.request("direct:a", new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader("slip", "jetty://http://localhost:" + getPort() + "/myapp?foo=123&bar=cheese&httpClientMinThreads=4&httpClientMaxThreads=8");
+            }
+        });
+        assertNotNull(a);
+
+        assertEquals("Bye cheese", a.getOut().getBody(String.class));
+        assertEquals(246, a.getOut().getHeader("foo", Integer.class).intValue());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:a").recipientList(header("slip"));
+
+                from("jetty://http://localhost:{{port}}/myapp").process(new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        int foo = exchange.getIn().getHeader("foo", Integer.class);
+                        String bar = exchange.getIn().getHeader("bar", String.class);
+
+                        exchange.getOut().setHeader("foo", foo * 2);
+                        exchange.getOut().setBody("Bye " + bar);
+                    }
+                });
+            }
+        };
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/HttpJettyProducerRecipientListTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/HttpJettyProducerRecipientListTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/HttpJettyProducerRecipientListTest.java
new file mode 100644
index 0000000..89d817e
--- /dev/null
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/HttpJettyProducerRecipientListTest.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.jetty.jettyproducer;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jetty.BaseJettyTest;
+import org.junit.Test;
+
+/**
+ * @version 
+ */
+public class HttpJettyProducerRecipientListTest extends BaseJettyTest {
+
+    @Test
+    public void testRecipientList() throws Exception {
+        // these tests does not run well on Windows
+        if (isPlatform("windows")) {
+            return;
+        }
+
+        // give Jetty time to startup properly
+        Thread.sleep(1000);
+
+        Exchange a = template.request("direct:a", new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader("slip", "jetty://http://localhost:" + getPort() + "/myapp?foo=123&bar=cheese");
+            }
+        });
+        assertNotNull(a);
+
+        assertEquals("Bye cheese", a.getOut().getBody(String.class));
+        assertEquals(246, a.getOut().getHeader("foo", Integer.class).intValue());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:a").recipientList(header("slip"));
+
+                from("jetty://http://localhost:{{port}}/myapp").process(new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        int foo = exchange.getIn().getHeader("foo", Integer.class);
+                        String bar = exchange.getIn().getHeader("bar", String.class);
+
+                        exchange.getOut().setHeader("foo", foo * 2);
+                        exchange.getOut().setBody("Bye " + bar);
+                    }
+                });
+            }
+        };
+    }
+}
\ No newline at end of file


Mime
View raw message