http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerPutContentTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerPutContentTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerPutContentTest.java new file mode 100644 index 0000000..9fcf814 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerPutContentTest.java @@ -0,0 +1,81 @@ +/** + * 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 java.io.File; +import java.io.InputStream; + +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.apache.camel.component.mock.MockEndpoint; +import org.junit.Test; + +/** + * @version + */ +public class JettyHttpProducerPutContentTest extends BaseJettyTest { + + @Test + public void testHttpProducerPutContentTest() throws Exception { + // these tests do not run well on Windows + if (isPlatform("windows")) { + return; + } + + // give Jetty time to startup properly + Thread.sleep(1000); + + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMinimumMessageCount(1); + mock.message(0).body().isInstanceOf(InputStream.class); + mock.message(0).header("Content-Type").isEqualTo("image/jpeg"); + + Exchange out = template.send("jetty://http://localhost:{{port}}/myapp/myservice", new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getIn().setBody(new File("src/test/data/logo.jpeg")); + exchange.getIn().setHeader("Content-Type", "image/jpeg"); + exchange.getIn().setHeader(Exchange.HTTP_METHOD, org.apache.camel.component.http.HttpMethods.PUT); + } + }); + + assertMockEndpointsSatisfied(); + + assertEquals("OK", out.getOut().getBody(String.class)); + assertEquals("text/plain", out.getOut().getHeader("Content-Type")); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() throws Exception { + from("jetty:http://localhost:{{port}}/myapp/myservice") + .to("mock:result") + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + String body = exchange.getIn().getBody(String.class); + assertNotNull("Body should not be null", body); + assertTrue("CamelHttpMethod is not PUT", exchange.getIn().getHeader("CamelHttpMethod").equals("PUT")); + assertTrue("Content-Type is not image/jpeg", exchange.getIn().getHeader("Content-Type").equals("image/jpeg")); + } + }) + .transform(constant("OK")).setHeader("Content-Type", constant("text/plain")); + } + }; + } +}
http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerQueryParamTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerQueryParamTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerQueryParamTest.java new file mode 100644 index 0000000..b9a4db7 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerQueryParamTest.java @@ -0,0 +1,95 @@ +/** + * 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 java.util.Map; + +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 JettyHttpProducerQueryParamTest extends BaseJettyTest { + + private String url = "jetty://http://0.0.0.0:" + getPort() + "/cheese"; + + @Test + public void testQueryParameters() throws Exception { + // these tests does not run well on Windows + if (isPlatform("windows")) { + return; + } + + // give Jetty time to startup properly + Thread.sleep(1000); + + Exchange exchange = template.request(url + "?quote=Camel%20rocks", null); + assertNotNull(exchange); + + String body = exchange.getOut().getBody(String.class); + Map<?, ?> headers = exchange.getOut().getHeaders(); + + assertEquals("Bye World", body); + assertEquals("Carlsberg", headers.get("beer")); + } + + @Test + public void testQueryParametersWithHeader() throws Exception { + // these tests does not run well on Windows + if (isPlatform("windows")) { + return; + } + + // give Jetty time to startup properly + Thread.sleep(1000); + + Exchange exchange = template.request(url, new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(Exchange.HTTP_QUERY, "quote=Camel rocks"); + } + }); + assertNotNull(exchange); + + String body = exchange.getOut().getBody(String.class); + Map<?, ?> headers = exchange.getOut().getHeaders(); + + assertEquals("Bye World", body); + assertEquals("Carlsberg", headers.get("beer")); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from(url).process(new Processor() { + public void process(Exchange exchange) throws Exception { + String quote = exchange.getIn().getHeader("quote", String.class); + assertEquals("Camel rocks", quote); + + exchange.getOut().setBody("Bye World"); + exchange.getOut().setHeader("beer", "Carlsberg"); + } + }); + } + }; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerRedirectTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerRedirectTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerRedirectTest.java new file mode 100644 index 0000000..74c4159 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerRedirectTest.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.jetty.jettyproducer; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.RuntimeCamelException; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.http.HttpOperationFailedException; +import org.apache.camel.component.jetty.BaseJettyTest; +import org.junit.Test; + +/** + * @version + */ +public class JettyHttpProducerRedirectTest extends BaseJettyTest { + + @Test + public void testHttpRedirect() throws Exception { + try { + template.requestBody("jetty:http://localhost:{{port}}/test", "Hello World", String.class); + fail("Should have thrown an exception"); + } catch (RuntimeCamelException e) { + HttpOperationFailedException cause = assertThrowable(HttpOperationFailedException.class, e.getCause()); + assertEquals(301, cause.getStatusCode()); + assertEquals(true, cause.isRedirectError()); + assertEquals(true, cause.hasRedirectLocation()); + assertEquals("http://localhost:" + getPort() + "/test", cause.getUri()); + assertEquals("http://localhost:" + getPort() + "/newtest", cause.getRedirectLocation()); + } + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("jetty://http://localhost:{{port}}/test") + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 301); + exchange.getOut().setHeader("Location", "http://localhost:" + getPort() + "/newtest"); + } + }); + } + }; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSendEmptyHeaderTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSendEmptyHeaderTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSendEmptyHeaderTest.java new file mode 100644 index 0000000..6bc0e17 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSendEmptyHeaderTest.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.jetty.jettyproducer; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jetty.BaseJettyTest; +import org.apache.camel.component.mock.MockEndpoint; +import org.junit.Test; + +/** + * + */ +public class JettyHttpProducerSendEmptyHeaderTest extends BaseJettyTest { + + @Test + public void testHttpProducerSendEmptyHeader() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMessageCount(1); + String expectedValue = isJetty8() ? "" : null; + mock.expectedHeaderReceived("foo", expectedValue); + + template.sendBodyAndHeader("jetty:http://localhost:{{port}}/myapp/mytest", "Hello World", "foo", ""); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + allowNullHeaders(); + from("jetty:http://localhost:{{port}}/myapp/mytest") + .convertBodyTo(String.class) + .to("mock:result"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSendFileTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSendFileTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSendFileTest.java new file mode 100644 index 0000000..017ef9c --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSendFileTest.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.jetty.jettyproducer; + +import java.io.File; +import java.io.InputStream; + +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.apache.camel.component.mock.MockEndpoint; +import org.junit.Test; + +/** + * @version + */ +public class JettyHttpProducerSendFileTest extends BaseJettyTest { + + @Test + public void testSendImage() throws Exception { + // these tests does not run well on Windows + if (isPlatform("windows")) { + return; + } + + // give Jetty time to startup properly + Thread.sleep(1000); + + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMinimumMessageCount(1); + mock.message(0).body().isInstanceOf(InputStream.class); + mock.message(0).header("Content-Type").isEqualTo("image/jpeg"); + + Exchange out = template.send("jetty://http://localhost:{{port}}/myapp/myservice", new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getIn().setBody(new File("src/test/data/logo.jpeg")); + exchange.getIn().setHeader("Content-Type", "image/jpeg"); + } + }); + + assertMockEndpointsSatisfied(); + + assertEquals("OK", out.getOut().getBody(String.class)); + assertEquals("text/plain", out.getOut().getHeader("Content-Type")); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() throws Exception { + from("jetty:http://localhost:{{port}}/myapp/myservice") + .to("mock:result") + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + String body = exchange.getIn().getBody(String.class); + assertNotNull("Body should not be null", body); + } + }) + .transform(constant("OK")).setHeader("Content-Type", constant("text/plain")); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSimulate404ErrorTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSimulate404ErrorTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSimulate404ErrorTest.java new file mode 100644 index 0000000..72a3edd --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSimulate404ErrorTest.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.jettyproducer; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.http.HttpOperationFailedException; +import org.apache.camel.component.jetty.BaseJettyTest; +import org.junit.Test; + +/** + * @version + */ +public class JettyHttpProducerSimulate404ErrorTest extends BaseJettyTest { + + private String url = "jetty://http://0.0.0.0:" + getPort() + "/bar"; + + @Test + public void test404() throws Exception { + // these tests does not run well on Windows + if (isPlatform("windows")) { + return; + } + + // give Jetty time to startup properly + Thread.sleep(1000); + + try { + template.sendBody(url, null); + fail("Should have thrown exception"); + } catch (Exception e) { + HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause()); + assertEquals(404, cause.getStatusCode()); + assertEquals("http://0.0.0.0:" + getPort() + "/bar", cause.getUri()); + assertEquals("Page not found", cause.getResponseBody()); + assertNotNull(cause.getResponseHeaders()); + } + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from(url).process(new Processor() { + public void process(Exchange exchange) throws Exception { + Thread.sleep(1000); + + exchange.getOut().setBody("Page not found"); + exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 404); + } + }); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSlowResponseTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSlowResponseTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSlowResponseTest.java new file mode 100644 index 0000000..c4cfd99 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSlowResponseTest.java @@ -0,0 +1,84 @@ +/** + * 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 javax.servlet.http.HttpServletResponse; + +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.apache.camel.component.mock.MockEndpoint; +import org.junit.Test; + +/** + * @version + */ +public class JettyHttpProducerSlowResponseTest extends BaseJettyTest { + + private String url = "jetty://http://0.0.0.0:" + getPort() + "/foo"; + + @Test + public void testSlowReply() throws Exception { + // these tests does not run well on Windows + if (isPlatform("windows")) { + return; + } + + // give Jetty time to startup properly + Thread.sleep(1000); + + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMessageCount(1); + + Exchange exchange = template.request(url, null); + + assertMockEndpointsSatisfied(); + + assertNotNull(exchange); + + String reply = exchange.getOut().getBody(String.class); + assertEquals("Bye World", reply); + + assertEquals(5, exchange.getOut().getHeaders().size()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from(url).process(new Processor() { + public void process(Exchange exchange) throws Exception { + HttpServletResponse res = exchange.getIn().getBody(HttpServletResponse.class); + res.setStatus(200); + res.setHeader("customer", "gold"); + + // write empty string to force flushing + res.getWriter().write(""); + res.flushBuffer(); + + Thread.sleep(1000); + + res.getWriter().write("Bye World"); + res.flushBuffer(); + } + }).to("mock:result"); + } + }; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSuspendResumeTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSuspendResumeTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSuspendResumeTest.java new file mode 100644 index 0000000..0aa9e44 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSuspendResumeTest.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.jetty.jettyproducer; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.http.HttpConsumer; +import org.apache.camel.component.http.HttpOperationFailedException; +import org.apache.camel.component.jetty.BaseJettyTest; +import org.junit.Test; + +/** + * @version + */ +public class JettyHttpProducerSuspendResumeTest extends BaseJettyTest { + + private String serverUri = "jetty://http://localhost:" + getPort() + "/cool"; + + @Test + public void testJettySuspendResume() 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 jetty + HttpConsumer consumer = (HttpConsumer) context.getRoute("route1").getConsumer(); + assertNotNull(consumer); + + // suspend + consumer.suspend(); + + try { + template.requestBody(serverUri, "Moon", String.class); + fail("Should throw exception"); + } catch (Exception e) { + HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause()); + assertEquals(503, cause.getStatusCode()); + } + + // resume + consumer.resume(); + + // 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).id("route1") + .transform(body().prepend("Bye ")); + } + }; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSuspendTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSuspendTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSuspendTest.java new file mode 100644 index 0000000..dc67337 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSuspendTest.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.builder.RouteBuilder; +import org.apache.camel.component.http.HttpConsumer; +import org.apache.camel.component.http.HttpOperationFailedException; +import org.apache.camel.component.jetty.BaseJettyTest; +import org.junit.Test; + +/** + * @version + */ +public class JettyHttpProducerSuspendTest extends BaseJettyTest { + + private String serverUri = "jetty://http://localhost:" + getPort() + "/cool"; + + @Test + public void testJettySuspend() 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 jetty + HttpConsumer consumer = (HttpConsumer) context.getRoute("route1").getConsumer(); + assertNotNull(consumer); + + // suspend + consumer.suspend(); + + try { + template.requestBody(serverUri, "Moon", String.class); + fail("Should throw exception"); + } catch (Exception e) { + HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause()); + assertEquals(503, cause.getStatusCode()); + } + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from(serverUri).id("route1") + .transform(body().prepend("Bye ")); + } + }; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSuspendWhileInProgressTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSuspendWhileInProgressTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSuspendWhileInProgressTest.java new file mode 100644 index 0000000..3edec66 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSuspendWhileInProgressTest.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.jettyproducer; + +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + +import org.apache.camel.RuntimeCamelException; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.http.HttpOperationFailedException; +import org.apache.camel.component.jetty.BaseJettyTest; +import org.junit.Ignore; +import org.junit.Test; + +/** + * @version + */ +@Ignore +public class JettyHttpProducerSuspendWhileInProgressTest extends BaseJettyTest { + + private String serverUri = "jetty://http://localhost:" + getPort() + "/cool"; + + @Test + public void testJettySuspendWhileInProgress() throws Exception { + // these tests does not run well on AIX or Windows + if (isPlatform("aix") || isPlatform("windows")) { + return; + } + + context.getShutdownStrategy().setTimeout(50); + + // send a request/reply and have future handle so we can shutdown while in progress + Future<String> reply = template.asyncRequestBodyAndHeader(serverUri, null, "name", "Camel", String.class); + + // shutdown camel while in progress, wait 2 sec so the first req has been received in Camel route + Executors.newSingleThreadExecutor().execute(new Runnable() { + public void run() { + try { + Thread.sleep(2000); + context.stop(); + } catch (Exception e) { + // ignore + } + } + }); + + // wait a bit more before sending next + Thread.sleep(5000); + + // now send a new req/reply + Future<String> reply2 = template.asyncRequestBodyAndHeader(serverUri, null, "name", "Tiger", String.class); + + // the first should wait to have its reply returned + assertEquals("Bye Camel", reply.get(20, TimeUnit.SECONDS)); + + // the 2nd should have a 503 returned as we are shutting down + try { + reply2.get(20, TimeUnit.SECONDS); + fail("Should throw exception"); + } catch (Exception e) { + RuntimeCamelException rce = assertIsInstanceOf(RuntimeCamelException.class, e.getCause()); + HttpOperationFailedException hofe = assertIsInstanceOf(HttpOperationFailedException.class, rce.getCause()); + assertEquals(503, hofe.getStatusCode()); + } + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() throws Exception { + from(serverUri) + .log("Got data will wait 10 sec with reply") + .delay(10000) + .transform(simple("Bye ${header.name}")); + } + }; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSynchronousFalseTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSynchronousFalseTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSynchronousFalseTest.java new file mode 100644 index 0000000..551fcec --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSynchronousFalseTest.java @@ -0,0 +1,78 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.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 JettyHttpProducerSynchronousFalseTest extends BaseJettyTest { + + private static String beforeThreadName; + private static String afterThreadName; + private String url = "jetty://http://0.0.0.0:" + getPort() + "/sync?synchronous=false"; + + @Test + public void testSynchronous() throws Exception { + // these tests does not run well on Windows + if (isPlatform("windows")) { + return; + } + + // give Jetty time to startup properly + Thread.sleep(1000); + + getMockEndpoint("mock:result").expectedMessageCount(1); + + template.sendBody("direct:start", null); + + assertMockEndpointsSatisfied(); + + assertFalse("Should use different threads", beforeThreadName.equalsIgnoreCase(afterThreadName)); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .to("log:before") + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + beforeThreadName = Thread.currentThread().getName(); + } + }) + .to(url) + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + afterThreadName = Thread.currentThread().getName(); + } + }) + .to("log:after") + .to("mock:result"); + + from(url).transform(constant("Bye World")); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSynchronousTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSynchronousTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSynchronousTest.java new file mode 100644 index 0000000..c7d45df --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerSynchronousTest.java @@ -0,0 +1,78 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.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 JettyHttpProducerSynchronousTest extends BaseJettyTest { + + private static String beforeThreadName; + private static String afterThreadName; + private String url = "jetty://http://0.0.0.0:" + getPort() + "/sync?synchronous=true"; + + @Test + public void testSynchronous() throws Exception { + // these tests does not run well on Windows + if (isPlatform("windows")) { + return; + } + + // give Jetty time to startup properly + Thread.sleep(1000); + + getMockEndpoint("mock:result").expectedMessageCount(1); + + template.sendBody("direct:start", null); + + assertMockEndpointsSatisfied(); + + assertTrue("Should use same threads", beforeThreadName.equalsIgnoreCase(afterThreadName)); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .to("log:before") + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + beforeThreadName = Thread.currentThread().getName(); + } + }) + .to(url) + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + afterThreadName = Thread.currentThread().getName(); + } + }) + .to("log:after") + .to("mock:result"); + + from(url).transform(constant("Bye World")); + } + }; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerTimeoutTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerTimeoutTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerTimeoutTest.java new file mode 100644 index 0000000..0192953 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerTimeoutTest.java @@ -0,0 +1,68 @@ +/** + * 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.ExchangeTimedOutException; +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 JettyHttpProducerTimeoutTest extends BaseJettyTest { + + private String url = "jetty://http://0.0.0.0:" + getPort() + "/timeout?httpClient.timeout=2000"; + + @Test + public void testTimeout() throws Exception { + // these tests does not run well on Windows + if (isPlatform("windows")) { + return; + } + + // give Jetty time to startup properly + Thread.sleep(1000); + final MyInputStream is = new MyInputStream("Content".getBytes()); + + Exchange reply = template.request(url, new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + exchange.getIn().setBody(is); + } + }); + Exception e = reply.getException(); + assertNotNull("Should have thrown an exception", e); + ExchangeTimedOutException cause = assertThrowable(ExchangeTimedOutException.class, e); + assertEquals(2000, cause.getTimeout()); + assertTrue("The input stream should be closed", is.isClosed()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from(url).delay(5000).transform(constant("Bye World")); + } + }; + } + + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerTransferExceptionTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerTransferExceptionTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerTransferExceptionTest.java new file mode 100644 index 0000000..1c59c4f --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerTransferExceptionTest.java @@ -0,0 +1,50 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.jetty.jettyproducer; + +import org.apache.camel.CamelExecutionException; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jetty.BaseJettyTest; +import org.junit.Test; + +/** + * @version + */ +public class JettyHttpProducerTransferExceptionTest extends BaseJettyTest { + + @Test + public void testTransferException() throws Exception { + try { + template.requestBody("jetty:http://localhost:{{port}}/myapp/myservice?transferException=true", ""); + fail("Should have thrown exception"); + } catch (CamelExecutionException e) { + IllegalArgumentException cause = assertThrowable(IllegalArgumentException.class, e.getCause()); + assertEquals("Damn", cause.getMessage()); + } + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("jetty:http://localhost:{{port}}/myapp/myservice?transferException=true") + .throwException(new IllegalArgumentException("Damn")); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpsProducerRouteSetupWithSystemPropsTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpsProducerRouteSetupWithSystemPropsTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpsProducerRouteSetupWithSystemPropsTest.java new file mode 100644 index 0000000..d6ca246 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpsProducerRouteSetupWithSystemPropsTest.java @@ -0,0 +1,69 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.jetty.jettyproducer; + +import java.net.URL; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.junit.Before; + +public class JettyHttpsProducerRouteSetupWithSystemPropsTest extends JettyProducerHttpsRouteTest { + + @Override + @Before + public void setUp() throws Exception { + // these tests does not run well on Windows + if (isPlatform("windows")) { + return; + } + + // give Jetty time to startup properly + Thread.sleep(1000); + + // ensure jsse clients can validate the self signed dummy localhost cert, + // use the server keystore as the trust store for these tests + URL trustStoreUrl = this.getClass().getClassLoader().getResource("jsse/localhost.ks"); + setSystemProp("javax.net.ssl.trustStore", trustStoreUrl.getPath()); + + // setup SSL using system properties + setSystemProp("org.eclipse.jetty.ssl.keystore", trustStoreUrl.getPath()); + setSystemProp("org.eclipse.jetty.ssl.keypassword", pwd); + setSystemProp("org.eclipse.jetty.ssl.password", pwd); + + super.setUp(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() { + from("jetty:https://localhost:" + port1 + "/test").to("mock:a"); + + Processor proc = new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getOut().setBody("<b>Hello World</b>"); + } + }; + from("jetty:https://localhost:" + port1 + "/hello").process(proc); + + from("jetty:https://localhost:" + port2 + "/test").to("mock:b"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpsProducerSslContextInUriTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpsProducerSslContextInUriTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpsProducerSslContextInUriTest.java new file mode 100644 index 0000000..7236389 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpsProducerSslContextInUriTest.java @@ -0,0 +1,87 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.jetty.jettyproducer; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jetty.JettyHttpComponent; +import org.apache.camel.impl.JndiRegistry; +import org.apache.camel.util.jsse.KeyManagersParameters; +import org.apache.camel.util.jsse.KeyStoreParameters; +import org.apache.camel.util.jsse.SSLContextParameters; + +public class JettyHttpsProducerSslContextInUriTest extends JettyProducerHttpsRouteTest { + + @Override + protected JndiRegistry createRegistry() throws Exception { + KeyStoreParameters ksp = new KeyStoreParameters(); + ksp.setResource(this.getClass().getClassLoader().getResource("jsse/localhost.ks").toString()); + ksp.setPassword(pwd); + + KeyManagersParameters kmp = new KeyManagersParameters(); + kmp.setKeyPassword(pwd); + kmp.setKeyStore(ksp); + + //TrustManagersParameters tmp = new TrustManagersParameters(); + //tmp.setKeyStore(ksp); + + SSLContextParameters sslContextParameters = new SSLContextParameters(); + sslContextParameters.setKeyManagers(kmp); + //sslContextParameters.setTrustManagers(tmp); + + JndiRegistry registry = super.createRegistry(); + registry.bind("sslContextParameters", sslContextParameters); + + return registry; + } + + protected void invokeHttpEndpoint() throws IOException { + template.sendBodyAndHeader(getHttpProducerScheme() + "localhost:" + port1 + "/test?sslContextParametersRef=sslContextParameters", expectedBody, "Content-Type", + "application/xml"); + template.sendBodyAndHeader(getHttpProducerScheme() + "localhost:" + port2 + "/test?sslContextParametersRef=sslContextParameters", expectedBody, "Content-Type", + "application/xml"); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() throws URISyntaxException { + JettyHttpComponent componentJetty = (JettyHttpComponent) context.getComponent("jetty"); + componentJetty.setSslPassword(pwd); + componentJetty.setSslKeyPassword(pwd); + URL keyStoreUrl = this.getClass().getClassLoader().getResource("jsse/localhost.ks"); + componentJetty.setKeystore(keyStoreUrl.toURI().getPath()); + + from("jetty:https://localhost:" + port1 + "/test?sslContextParametersRef=sslContextParameters").to("mock:a"); + + Processor proc = new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getOut().setBody("<b>Hello World</b>"); + } + }; + from("jetty:https://localhost:" + port1 + "/hello?sslContextParametersRef=sslContextParameters").process(proc); + + from("jetty:https://localhost:" + port2 + "/test?sslContextParametersRef=sslContextParameters").to("mock:b"); + } + }; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyProducerHandle404Test.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyProducerHandle404Test.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyProducerHandle404Test.java new file mode 100644 index 0000000..870eff9 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyProducerHandle404Test.java @@ -0,0 +1,32 @@ +/** + * 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.component.jetty.JettyHandle404Test; + +/** + * Based on end user on forum how to get the 404 error code in his enrich aggregator + * + * @version + */ +public class JettyProducerHandle404Test extends JettyHandle404Test { + + public String getProducerUrl() { + return "jetty://http://localhost:{{port}}/myserver?user=Camel"; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyProducerHttpsRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyProducerHttpsRouteTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyProducerHttpsRouteTest.java new file mode 100644 index 0000000..bb39070 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyProducerHttpsRouteTest.java @@ -0,0 +1,49 @@ +/** + * 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.RuntimeCamelException; +import org.apache.camel.component.jetty.HttpsRouteTest; +import org.apache.camel.component.mock.MockEndpoint; +import org.junit.Test; + +public class JettyProducerHttpsRouteTest extends HttpsRouteTest { + + public String getHttpProducerScheme() { + return "jetty://https://"; + } + + @Test + public void testEndpointWithoutHttps() throws Exception { + // these tests does not run well on Windows + if (isPlatform("windows")) { + return; + } + + // give Jetty time to startup properly + Thread.sleep(1000); + + MockEndpoint mockEndpoint = resolveMandatoryEndpoint("mock:a", MockEndpoint.class); + try { + template.sendBodyAndHeader("jetty://http://localhost:" + port1 + "/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()); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/MyCoolBean.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/MyCoolBean.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/MyCoolBean.java new file mode 100644 index 0000000..b93fb26 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/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.jettyproducer; + +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/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/MyInputStream.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/MyInputStream.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/MyInputStream.java new file mode 100644 index 0000000..94fa5d0 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/jettyproducer/MyInputStream.java @@ -0,0 +1,35 @@ +/** + * 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 java.io.ByteArrayInputStream; + +public class MyInputStream extends ByteArrayInputStream { + private boolean closed; + + public MyInputStream(byte[] buf) { + super(buf); + } + + public void close() { + closed = true; + } + + public boolean isClosed() { + return closed; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/manual/JettyManual.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/manual/JettyManual.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/manual/JettyManual.java new file mode 100644 index 0000000..a012ded --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/manual/JettyManual.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.jetty.manual; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.AvailablePortFinder; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Ignore; +import org.junit.Test; + +/** + * Used for manual unit test, eg to curl to upload a file with: + * curl -F data=@src/test/data/plain.txt http://localhost:9080/myapp/myservice + * + * @version + */ +public class JettyManual extends CamelTestSupport { + + @Test + @Ignore + public void testManual() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMinimumMessageCount(1); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() throws Exception { + from("jetty:http://localhost:" + AvailablePortFinder.getNextAvailable() + "/ myapp / myservice") + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + String body = exchange.getIn().getBody(String.class); + assertNotNull("Body should not be null", body); + } + }) + .transform(constant("OK")).setHeader("Content-Type", constant("text/plain")) + .to("mock:result"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/proxy/HttpClientProxyTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/proxy/HttpClientProxyTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/proxy/HttpClientProxyTest.java new file mode 100644 index 0000000..e2e245f --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/proxy/HttpClientProxyTest.java @@ -0,0 +1,87 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.jetty.proxy; + +import java.lang.reflect.UndeclaredThrowableException; + +import org.apache.camel.CamelExecutionException; +import org.apache.camel.builder.ProxyBuilder; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.http.HttpOperationFailedException; +import org.apache.camel.component.jetty.BaseJettyTest; +import org.junit.Test; + +/** + * @version + */ +public class HttpClientProxyTest extends BaseJettyTest { + + @Test + public void testHttpClientNoProxyOk() throws Exception { + String out = template.requestBody("direct:cool", "World", String.class); + assertEquals("Hello World", out); + } + + @Test + public void testHttpClientNoProxyException() throws Exception { + try { + template.requestBody("direct:cool", "Kaboom", String.class); + fail("Should have thrown exception"); + } catch (CamelExecutionException e) { + HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause()); + assertEquals(500, cause.getStatusCode()); + assertNotNull(cause.getResponseBody()); + assertTrue(cause.getResponseBody().contains("MyAppException")); + } + } + + @Test + public void testHttpClientProxyOk() throws Exception { + MyCoolService proxy = new ProxyBuilder(context).endpoint("direct:cool").build(MyCoolService.class); + String out = proxy.hello("World"); + + assertEquals("Hello World", out); + } + + @Test + public void testHttpClientProxyException() throws Exception { + MyCoolService proxy = new ProxyBuilder(context).endpoint("direct:cool").build(MyCoolService.class); + try { + proxy.hello("Kaboom"); + fail("Should have thrown exception"); + } catch (UndeclaredThrowableException e) { + HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause()); + assertEquals(500, cause.getStatusCode()); + assertNotNull(cause.getResponseBody()); + assertTrue(cause.getResponseBody().contains("MyAppException")); + } + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:cool") + .to("http://localhost:{{port}}/myapp/myservice"); + + from("jetty:http://localhost:{{port}}/myapp/myservice") + .bean(MyCoolServiceBean.class); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/proxy/HttpClientProxyTransferExceptionTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/proxy/HttpClientProxyTransferExceptionTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/proxy/HttpClientProxyTransferExceptionTest.java new file mode 100644 index 0000000..4d15059 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/proxy/HttpClientProxyTransferExceptionTest.java @@ -0,0 +1,80 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.jetty.proxy; + +import org.apache.camel.CamelExecutionException; +import org.apache.camel.builder.ProxyBuilder; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jetty.BaseJettyTest; +import org.junit.Test; + +/** + * @version + */ +public class HttpClientProxyTransferExceptionTest extends BaseJettyTest { + + @Test + public void testHttpClientNoProxyOk() throws Exception { + String out = template.requestBody("direct:cool", "World", String.class); + assertEquals("Hello World", out); + } + + @Test + public void testHttpClientNoProxyException() throws Exception { + try { + template.requestBody("direct:cool", "Kaboom"); + fail("Should have thrown an exception"); + } catch (CamelExecutionException e) { + MyAppException cause = assertIsInstanceOf(MyAppException.class, e.getCause()); + assertNotNull(cause); + assertEquals("Kaboom", cause.getName()); + } + } + + @Test + public void testHttpClientProxyOk() throws Exception { + MyCoolService proxy = new ProxyBuilder(context).endpoint("direct:cool").build(MyCoolService.class); + String out = proxy.hello("World"); + + assertEquals("Hello World", out); + } + + @Test + public void testHttpClientProxyException() throws Exception { + MyCoolService proxy = new ProxyBuilder(context).endpoint("direct:cool").build(MyCoolService.class); + try { + proxy.hello("Kaboom"); + fail("Should have thrown exception"); + } catch (MyAppException e) { + assertEquals("Kaboom", e.getName()); + } + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:cool") + .to("http://localhost:{{port}}/myapp/myservice?transferException=true"); + + from("jetty:http://localhost:{{port}}/myapp/myservice?transferException=true") + .bean(MyCoolServiceBean.class); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/proxy/JettyChuckedFalseTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/proxy/JettyChuckedFalseTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/proxy/JettyChuckedFalseTest.java new file mode 100644 index 0000000..ebcc556 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/proxy/JettyChuckedFalseTest.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.proxy; + +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jetty.BaseJettyTest; +import org.apache.camel.converter.stream.CachedOutputStream; +import org.apache.camel.util.IOHelper; +import org.junit.Test; + +public class JettyChuckedFalseTest extends BaseJettyTest { + + @Test + public void runningTest() throws Exception { + Exchange exchange = template.request("http://localhost:{{port}}/test", new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + // we do nothing here, so http producer will send a GET method request + } + + }); + Message out = exchange.getOut(); + // make sure we have the content-length header + String len = out.getHeader(Exchange.CONTENT_LENGTH, String.class); + assertEquals("We should have the content-length header here.", "20", len); + String response = out.getBody(String.class); + assertEquals("Get a wrong response", "This is hello world.", response); + } + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + + from("jetty:http://localhost:{{port}}/test?matchOnUriPrefix=true&chunked=false") + .to("http://localhost:{{port2}}/other?bridgeEndpoint=true"); + + from("jetty:http://localhost:{{port2}}/other").process(new Processor() { + + @Override + public void process(Exchange exchange) throws Exception { + exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "image/jpeg"); + CachedOutputStream stream = new CachedOutputStream(exchange); + stream.write("This is hello world.".getBytes()); + exchange.getOut().setBody(stream.getInputStream()); + IOHelper.close(stream); + } + }); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/proxy/MyAppException.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/proxy/MyAppException.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/proxy/MyAppException.java new file mode 100644 index 0000000..ba20cfa --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/proxy/MyAppException.java @@ -0,0 +1,35 @@ +/** + * 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.proxy; + +/** + * @version + */ +public class MyAppException extends Exception { + + private static final long serialVersionUID = 1L; + private final String name; + + public MyAppException(String msg, String name) { + super(msg); + this.name = name; + } + + public String getName() { + return name; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/proxy/MyCoolService.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/proxy/MyCoolService.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/proxy/MyCoolService.java new file mode 100644 index 0000000..0b2bdea --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/proxy/MyCoolService.java @@ -0,0 +1,25 @@ +/** + * 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.proxy; + +/** + * @version + */ +public interface MyCoolService { + + String hello(String name) throws MyAppException; +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/proxy/MyCoolServiceBean.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/proxy/MyCoolServiceBean.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/proxy/MyCoolServiceBean.java new file mode 100644 index 0000000..7746a6b --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/proxy/MyCoolServiceBean.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.proxy; + +/** + * @version + */ +public class MyCoolServiceBean implements MyCoolService { + + public String hello(String name) throws MyAppException { + if ("Kaboom".equals(name)) { + throw new MyAppException("Invalid name", "Kaboom"); + } + + return "Hello " + name; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/CountryPojo.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/CountryPojo.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/CountryPojo.java new file mode 100644 index 0000000..022da99 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/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.jetty.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; + } + +}