Repository: camel Updated Branches: refs/heads/temp-jetty9-2 [created] 0d96e56d2
http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/JettyRestRedirectTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/JettyRestRedirectTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/JettyRestRedirectTest.java new file mode 100644 index 0000000..4838ec0 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/JettyRestRedirectTest.java @@ -0,0 +1,57 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.jetty.rest; + +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; + +public class JettyRestRedirectTest extends BaseJettyTest { + + @Test + public void testRedirectInvocation() throws Exception { + String response = template.requestBody("jetty:http://localhost:" + getPort2() + "/metadata/profile/tag?httpClient.supportRedirect=true", "<hello>Camel</hello>", String.class); + assertEquals("It should support the redirect out of box.", "Mock profile", response); + } + + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + + return new RouteBuilder() { + public void configure() { + restConfiguration().component("jetty").host("localhost").scheme("http").port(getPort2()); + rest("/metadata/profile") + .get("/{id}").to("direct:profileLookup") + .post("/tag").to("direct:tag"); + + from("direct:profileLookup").transform().constant("Mock profile"); + from("direct:tag").log("${headers}").process(new Processor() { + @Override + public void process(Exchange ex) throws Exception { + ex.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 302); + ex.getOut().setHeader("location", "/metadata/profile/1"); + } + }).log("${headers}").transform().constant("Redirecting..."); + } + }; + } + +} + http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyBindingModeAutoWithJsonTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyBindingModeAutoWithJsonTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyBindingModeAutoWithJsonTest.java new file mode 100644 index 0000000..43ec8f3 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyBindingModeAutoWithJsonTest.java @@ -0,0 +1,59 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.jetty.rest; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jetty.BaseJettyTest; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.model.rest.RestBindingMode; +import org.junit.Test; + +public class RestJettyBindingModeAutoWithJsonTest extends BaseJettyTest { + + @Test + public void testBindingMode() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:input"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(UserPojo.class); + + String body = "{\"id\": 123, \"name\": \"Donald Duck\"}"; + template.sendBody("http://localhost:" + getPort() + "/users/new", body); + + assertMockEndpointsSatisfied(); + + UserPojo user = mock.getReceivedExchanges().get(0).getIn().getBody(UserPojo.class); + assertNotNull(user); + assertEquals(123, user.getId()); + assertEquals("Donald Duck", user.getName()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + restConfiguration().component("jetty").host("localhost").port(getPort()).bindingMode(RestBindingMode.auto); + + // use the rest DSL to define the rest services + rest("/users/") + .post("new").consumes("application/json").type(UserPojo.class) + .to("mock:input"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyBindingModeAutoWithXmlTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyBindingModeAutoWithXmlTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyBindingModeAutoWithXmlTest.java new file mode 100644 index 0000000..2db5138 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyBindingModeAutoWithXmlTest.java @@ -0,0 +1,59 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.jetty.rest; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jetty.BaseJettyTest; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.model.rest.RestBindingMode; +import org.junit.Test; + +public class RestJettyBindingModeAutoWithXmlTest extends BaseJettyTest { + + @Test + public void testBindingMode() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:input"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(UserJaxbPojo.class); + + String body = "<user name=\"Donald Duck\" id=\"123\"></user>"; + template.sendBody("http://localhost:" + getPort() + "/users/new", body); + + assertMockEndpointsSatisfied(); + + UserJaxbPojo user = mock.getReceivedExchanges().get(0).getIn().getBody(UserJaxbPojo.class); + assertNotNull(user); + assertEquals(123, user.getId()); + assertEquals("Donald Duck", user.getName()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + restConfiguration().component("jetty").host("localhost").port(getPort()).bindingMode(RestBindingMode.auto); + + // use the rest DSL to define the rest services + rest("/users/") + .post("new").consumes("application/xml").type(UserJaxbPojo.class) + .to("mock:input"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyBindingModeJsonTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyBindingModeJsonTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyBindingModeJsonTest.java new file mode 100644 index 0000000..103cdc4 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyBindingModeJsonTest.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.rest; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jetty.BaseJettyTest; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.model.rest.RestBindingMode; +import org.junit.Test; + +public class RestJettyBindingModeJsonTest extends BaseJettyTest { + + @Test + public void testBindingMode() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:input"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(UserJaxbPojo.class); + + String body = "{\"id\": 123, \"name\": \"Donald Duck\"}"; + template.sendBody("http://localhost:" + getPort() + "/users/new", body); + + assertMockEndpointsSatisfied(); + + UserJaxbPojo user = mock.getReceivedExchanges().get(0).getIn().getBody(UserJaxbPojo.class); + assertNotNull(user); + assertEquals(123, user.getId()); + assertEquals("Donald Duck", user.getName()); + } + + @Test + public void testBindingModeWrong() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:input"); + mock.expectedMessageCount(0); + + // we bind to json, but send in xml, which is not possible + String body = "<user name=\"Donald Duck\" id=\"123\"></user>"; + try { + template.sendBody("http://localhost:" + getPort() + "/users/new", body); + fail("Should have thrown exception"); + } catch (Exception e) { + // expected + } + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + restConfiguration().component("jetty").host("localhost").port(getPort()).bindingMode(RestBindingMode.json); + + // use the rest DSL to define the rest services + rest("/users/") + .post("new").type(UserJaxbPojo.class) + .to("mock:input"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyBindingModeXmlTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyBindingModeXmlTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyBindingModeXmlTest.java new file mode 100644 index 0000000..18ce442 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyBindingModeXmlTest.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.rest; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jetty.BaseJettyTest; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.model.rest.RestBindingMode; +import org.junit.Test; + +public class RestJettyBindingModeXmlTest extends BaseJettyTest { + + @Test + public void testBindingMode() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:input"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(UserJaxbPojo.class); + + String body = "<user name=\"Donald Duck\" id=\"123\"></user>"; + template.sendBody("http://localhost:" + getPort() + "/users/new", body); + + assertMockEndpointsSatisfied(); + + UserJaxbPojo user = mock.getReceivedExchanges().get(0).getIn().getBody(UserJaxbPojo.class); + assertNotNull(user); + assertEquals(123, user.getId()); + assertEquals("Donald Duck", user.getName()); + } + + @Test + public void testBindingModeWrong() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:input"); + mock.expectedMessageCount(0); + + // we bind to xml, but send in json, which is not possible + String body = "{\"id\": 123, \"name\": \"Donald Duck\"}"; + try { + template.sendBody("http://localhost:" + getPort() + "/users/new", body); + fail("Should have thrown exception"); + } catch (Exception e) { + // expected + } + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + restConfiguration().component("jetty").host("localhost").port(getPort()).bindingMode(RestBindingMode.xml); + + // use the rest DSL to define the rest services + rest("/users/") + .post("new").type(UserJaxbPojo.class) + .to("mock:input"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyGetTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyGetTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyGetTest.java new file mode 100644 index 0000000..5022681 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyGetTest.java @@ -0,0 +1,66 @@ +/** + * 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; + +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.jetty.JettyRestHttpBinding; +import org.apache.camel.impl.JndiRegistry; +import org.junit.Test; + +public class RestJettyGetTest extends BaseJettyTest { + + + @Override + protected JndiRegistry createRegistry() throws Exception { + JndiRegistry jndi = super.createRegistry(); + jndi.bind("mybinding", new JettyRestHttpBinding()); + return jndi; + } + + @Test + public void testJettyProducerGet() throws Exception { + String out = template.requestBody("http://localhost:" + getPort() + "/users/123/basic", null, String.class); + assertEquals("123;Donald Duck", out); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + // configure to use jetty on localhost with the given port + restConfiguration().component("jetty").host("localhost").port(getPort()).endpointProperty("httpBindingRef", "#mybinding"); + + // use the rest DSL to define the rest services + rest("/users/") + .get("{id}/basic") + .route() + .to("mock:input") + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + String id = exchange.getIn().getHeader("id", String.class); + exchange.getOut().setBody(id + ";Donald Duck"); + } + }); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPojoInOutTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPojoInOutTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPojoInOutTest.java new file mode 100644 index 0000000..3f9dd28 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPojoInOutTest.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.rest; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jetty.BaseJettyTest; +import org.apache.camel.model.rest.RestBindingMode; +import org.junit.Test; + +public class RestJettyPojoInOutTest extends BaseJettyTest { + + @Test + public void testJettyPojoInOut() throws Exception { + String body = "{\"id\": 123, \"name\": \"Donald Duck\"}"; + String out = template.requestBody("http://localhost:" + getPort() + "/users/lives", body, String.class); + + assertNotNull(out); + assertEquals("{\"iso\":\"EN\",\"country\":\"England\"}", out); + } + + @Test + public void testJettyGetRequest() throws Exception { + String out = template.requestBody("http://localhost:" + getPort() + "/users/lives", null, String.class); + + assertNotNull(out); + assertEquals("{\"iso\":\"EN\",\"country\":\"England\"}", out); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + // configure to use jetty on localhost with the given port + // and enable auto binding mode + restConfiguration().component("jetty").host("localhost").port(getPort()).bindingMode(RestBindingMode.auto); + + // use the rest DSL to define the rest services + rest("/users/") + // just return the default country here + .get("lives").to("direct:start") + .post("lives").type(UserPojo.class).outType(CountryPojo.class) + .route() + .bean(new UserService(), "livesWhere"); + + CountryPojo country = new CountryPojo(); + country.setIso("EN"); + country.setCountry("England"); + from("direct:start").transform().constant(country); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPostJsonJaxbPojoTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPostJsonJaxbPojoTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPostJsonJaxbPojoTest.java new file mode 100644 index 0000000..d71db72 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPostJsonJaxbPojoTest.java @@ -0,0 +1,61 @@ +/** + * 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; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jetty.BaseJettyTest; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.model.rest.RestBindingMode; +import org.junit.Test; + +public class RestJettyPostJsonJaxbPojoTest extends BaseJettyTest { + + @Test + public void testPostJaxbPojo() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:input"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(UserJaxbPojo.class); + + String body = "{\"id\": 123, \"name\": \"Donald Duck\"}"; + template.sendBody("http://localhost:" + getPort() + "/users/new", body); + + assertMockEndpointsSatisfied(); + + UserJaxbPojo user = mock.getReceivedExchanges().get(0).getIn().getBody(UserJaxbPojo.class); + assertNotNull(user); + assertEquals(123, user.getId()); + assertEquals("Donald Duck", user.getName()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + // configure to use jetty on localhost with the given port + // and enable auto binding mode + restConfiguration().component("jetty").host("localhost").port(getPort()).bindingMode(RestBindingMode.auto); + + // use the rest DSL to define the rest services + rest("/users/") + .post("new").type(UserJaxbPojo.class) + .to("mock:input"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPostJsonPojoListTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPostJsonPojoListTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPostJsonPojoListTest.java new file mode 100644 index 0000000..2817cda --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPostJsonPojoListTest.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.rest; + +import java.util.List; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jetty.BaseJettyTest; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.model.rest.RestBindingMode; +import org.junit.Test; + +public class RestJettyPostJsonPojoListTest extends BaseJettyTest { + + @Test + public void testPostPojoList() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:input"); + mock.expectedMessageCount(1); + + String body = "[ {\"id\": 123, \"name\": \"Donald Duck\"}, {\"id\": 456, \"name\": \"John Doe\"} ]"; + template.sendBody("http://localhost:" + getPort() + "/users/new", body); + + assertMockEndpointsSatisfied(); + + List list = mock.getReceivedExchanges().get(0).getIn().getBody(List.class); + assertNotNull(list); + assertEquals(2, list.size()); + + UserPojo user = (UserPojo) list.get(0); + assertEquals(123, user.getId()); + assertEquals("Donald Duck", user.getName()); + user = (UserPojo) list.get(1); + assertEquals(456, user.getId()); + assertEquals("John Doe", user.getName()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + // configure to use jetty on localhost with the given port + // and enable auto binding mode + restConfiguration().component("jetty").host("localhost").port(getPort()).bindingMode(RestBindingMode.auto); + + // use the rest DSL to define the rest services + rest("/users/") + .post("new").typeList(UserPojo.class) + .to("mock:input"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPostJsonPojoTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPostJsonPojoTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPostJsonPojoTest.java new file mode 100644 index 0000000..51ea5ee --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPostJsonPojoTest.java @@ -0,0 +1,61 @@ +/** + * 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; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jetty.BaseJettyTest; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.model.rest.RestBindingMode; +import org.junit.Test; + +public class RestJettyPostJsonPojoTest extends BaseJettyTest { + + @Test + public void testPostPojo() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:input"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(UserPojo.class); + + String body = "{\"id\": 123, \"name\": \"Donald Duck\"}"; + template.sendBody("http://localhost:" + getPort() + "/users/new", body); + + assertMockEndpointsSatisfied(); + + UserPojo user = mock.getReceivedExchanges().get(0).getIn().getBody(UserPojo.class); + assertNotNull(user); + assertEquals(123, user.getId()); + assertEquals("Donald Duck", user.getName()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + // configure to use jetty on localhost with the given port + // and enable auto binding mode + restConfiguration().component("jetty").host("localhost").port(getPort()).bindingMode(RestBindingMode.auto); + + // use the rest DSL to define the rest services + rest("/users/") + .post("new").type(UserPojo.class) + .to("mock:input"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPostXmlJaxbPojoTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPostXmlJaxbPojoTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPostXmlJaxbPojoTest.java new file mode 100644 index 0000000..c070725 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPostXmlJaxbPojoTest.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.rest; + +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jetty.BaseJettyTest; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.model.rest.RestBindingMode; +import org.junit.Test; + +public class RestJettyPostXmlJaxbPojoTest extends BaseJettyTest { + + @Test + public void testPostJaxbPojo() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:input"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(UserJaxbPojo.class); + + String body = "<user name=\"Donald Duck\" id=\"123\"></user>"; + template.sendBodyAndHeader("http://localhost:" + getPort() + "/users/new", body, Exchange.CONTENT_TYPE, "text/xml"); + + assertMockEndpointsSatisfied(); + + UserJaxbPojo user = mock.getReceivedExchanges().get(0).getIn().getBody(UserJaxbPojo.class); + assertNotNull(user); + assertEquals(123, user.getId()); + assertEquals("Donald Duck", user.getName()); + } + + @Test + public void testPostJaxbPojoNoContentType() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:input"); + mock.expectedMessageCount(1); + mock.message(0).body().isInstanceOf(UserJaxbPojo.class); + + String body = "<user name=\"Donald Duck\" id=\"456\"></user>"; + template.sendBody("http://localhost:" + getPort() + "/users/new", body); + + assertMockEndpointsSatisfied(); + + UserJaxbPojo user = mock.getReceivedExchanges().get(0).getIn().getBody(UserJaxbPojo.class); + assertNotNull(user); + assertEquals(456, user.getId()); + assertEquals("Donald Duck", user.getName()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + // configure to use jetty on localhost with the given port + // and enable auto binding mode + restConfiguration().component("jetty").host("localhost").port(getPort()).bindingMode(RestBindingMode.auto); + + // use the rest DSL to define the rest services + rest("/users/") + .post("new").type(UserJaxbPojo.class) + .to("mock:input"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestPathMatchingTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestPathMatchingTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestPathMatchingTest.java new file mode 100644 index 0000000..5e0d726 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestPathMatchingTest.java @@ -0,0 +1,85 @@ +/** + * 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; + +import junit.framework.TestCase; +import org.apache.camel.component.jetty.JettyRestServletResolveConsumerStrategy; + +public class RestPathMatchingTest extends TestCase { + + private JettyRestServletResolveConsumerStrategy matcher = new JettyRestServletResolveConsumerStrategy(); + + public void testRestPathMatcher() throws Exception { + assertTrue(matcher.matchRestPath("/foo/", "/foo/", true)); + assertTrue(matcher.matchRestPath("/foo/", "foo/", true)); + assertTrue(matcher.matchRestPath("/foo/", "foo", true)); + assertTrue(matcher.matchRestPath("foo/", "foo", true)); + assertTrue(matcher.matchRestPath("foo", "foo", true)); + assertTrue(matcher.matchRestPath("foo/", "foo", true)); + assertTrue(matcher.matchRestPath("/foo/", "foo", true)); + + assertTrue(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2014", true)); + assertTrue(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2014", true)); + assertTrue(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2014/", true)); + assertTrue(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2014/", true)); + assertTrue(matcher.matchRestPath("/foo/1234/list/2014", "/foo/{user}/list/{year}", true)); + + assertFalse(matcher.matchRestPath("/foo/", "/bar/", true)); + assertFalse(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2015", true)); + assertFalse(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2015", true)); + assertFalse(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2015/", true)); + assertFalse(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2015/", true)); + assertFalse(matcher.matchRestPath("/foo/1234/list/2014", "/foo/{user}/list/", true)); + + assertTrue(matcher.matchRestPath("/foo/1/list/2", "/foo/{user}/list/{year}", true)); + assertTrue(matcher.matchRestPath("/foo/1234567890/list/2", "/foo/{user}/list/{year}", true)); + assertTrue(matcher.matchRestPath("/foo/1234567890/list/1234567890", "/foo/{user}/list/{year}", true)); + + assertTrue(matcher.matchRestPath("/123/list/2014", "/{user}/list/{year}", true)); + assertTrue(matcher.matchRestPath("/1234567890/list/2014", "/{user}/list/{year}", true)); + } + + public void testRestPathMatcherNoWildcard() throws Exception { + assertTrue(matcher.matchRestPath("/foo/", "/foo/", false)); + assertTrue(matcher.matchRestPath("/foo/", "foo/", false)); + assertTrue(matcher.matchRestPath("/foo/", "foo", false)); + assertTrue(matcher.matchRestPath("foo/", "foo", false)); + assertTrue(matcher.matchRestPath("foo", "foo", false)); + assertTrue(matcher.matchRestPath("foo/", "foo", false)); + assertTrue(matcher.matchRestPath("/foo/", "foo", false)); + + assertTrue(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2014", false)); + assertTrue(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2014", false)); + assertTrue(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2014/", false)); + assertTrue(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2014/", false)); + assertTrue(matcher.matchRestPath("/foo/1234/list/2014", "/foo/{user}/list/{year}", true)); + + assertFalse(matcher.matchRestPath("/foo/", "/bar/", false)); + assertFalse(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2015", false)); + assertFalse(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2015", false)); + assertFalse(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2015/", false)); + assertFalse(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2015/", false)); + assertFalse(matcher.matchRestPath("/foo/1234/list/2014", "/foo/{user}/list/", false)); + + assertFalse(matcher.matchRestPath("/foo/1/list/2", "/foo/{user}/list/{year}", false)); + assertFalse(matcher.matchRestPath("/foo/1234567890/list/2", "/foo/{user}/list/{year}", false)); + assertFalse(matcher.matchRestPath("/foo/1234567890/list/1234567890", "/foo/{user}/list/{year}", false)); + + assertFalse(matcher.matchRestPath("/123/list/2014", "/{user}/list/{year}", false)); + assertFalse(matcher.matchRestPath("/1234567890/list/2014", "/{user}/list/{year}", false)); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/UserJaxbPojo.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/UserJaxbPojo.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/UserJaxbPojo.java new file mode 100644 index 0000000..cc7d85c --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/UserJaxbPojo.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.rest; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "user") +@XmlAccessorType(XmlAccessType.FIELD) +public class UserJaxbPojo { + + @XmlAttribute + private int id; + @XmlAttribute + private String name; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/UserPojo.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/UserPojo.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/UserPojo.java new file mode 100644 index 0000000..caf65e7 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/UserPojo.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 UserPojo { + + private int id; + private String name; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/UserService.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/UserService.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/UserService.java new file mode 100644 index 0000000..7665b40 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/UserService.java @@ -0,0 +1,33 @@ +/** + * 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 UserService { + + public CountryPojo livesWhere(UserPojo user) { + CountryPojo answer = new CountryPojo(); + if (user.getId() < 500) { + answer.setIso("EN"); + answer.setCountry("England"); + } else { + answer.setIso("SE"); + answer.setCountry("Sweden"); + } + return answer; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/resources/java.jpg ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/resources/java.jpg b/components/camel-jetty9/src/test/resources/java.jpg new file mode 100644 index 0000000..dc59bee Binary files /dev/null and b/components/camel-jetty9/src/test/resources/java.jpg differ http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/resources/jsse/localhost-alias.ks ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/resources/jsse/localhost-alias.ks b/components/camel-jetty9/src/test/resources/jsse/localhost-alias.ks new file mode 100644 index 0000000..33fb9b6 Binary files /dev/null and b/components/camel-jetty9/src/test/resources/jsse/localhost-alias.ks differ http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/resources/jsse/localhost.ks ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/resources/jsse/localhost.ks b/components/camel-jetty9/src/test/resources/jsse/localhost.ks new file mode 100644 index 0000000..f285418 Binary files /dev/null and b/components/camel-jetty9/src/test/resources/jsse/localhost.ks differ http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/resources/log4j.properties b/components/camel-jetty9/src/test/resources/log4j.properties new file mode 100644 index 0000000..7be001b --- /dev/null +++ b/components/camel-jetty9/src/test/resources/log4j.properties @@ -0,0 +1,47 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +# +# The logging properties used during tests.. +# +# +# The logging properties used for eclipse testing, We want to see debug output on the console. +# +log4j.rootLogger=INFO, file + +# uncomment the following to enable camel debugging +#log4j.logger.org.apache.camel.component.jetty=TRACE +#log4j.logger.org.apache.camel.component.jetty.CamelContinuationServlet=TRACE +#log4j.logger.org.apache.camel.component.http.CamelServlet=TRACE +#log4j.logger.org.apache.camel.component.jetty.JettyContentExchange=DEBUG +#log4j.logger.org.apache.camel.component.http=TRACE +#log4j.logger.org.apache.camel=DEBUG +#log4j.logger.org.apache.camel.impl.converter.PropertyEditorTypeConverter=TRACE + +#log4j.logger.org.eclipse.jetty=TRACE + +# CONSOLE appender not used by default +log4j.appender.out=org.apache.log4j.ConsoleAppender +log4j.appender.out.layout=org.apache.log4j.PatternLayout +#log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n +log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n + +# File appender +log4j.appender.file=org.apache.log4j.FileAppender +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n +log4j.appender.file.file=target/camel-jetty-test.log http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/resources/myRealm.properties ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/resources/myRealm.properties b/components/camel-jetty9/src/test/resources/myRealm.properties new file mode 100644 index 0000000..2f8f01e --- /dev/null +++ b/components/camel-jetty9/src/test/resources/myRealm.properties @@ -0,0 +1,18 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +donald: duck, user \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/resources/org/apache/camel/component/jetty/JettyComponentSpringConfiguredTest.xml ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/resources/org/apache/camel/component/jetty/JettyComponentSpringConfiguredTest.xml b/components/camel-jetty9/src/test/resources/org/apache/camel/component/jetty/JettyComponentSpringConfiguredTest.xml new file mode 100644 index 0000000..0c3f98c --- /dev/null +++ b/components/camel-jetty9/src/test/resources/org/apache/camel/component/jetty/JettyComponentSpringConfiguredTest.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd + "> + + <bean id="jetty2" class="org.apache.camel.component.jetty9.JettyHttpComponent9"> + <property name="enableJmx" value="true"/> + <property name="minThreads" value="10"/> + <property name="maxThreads" value="50"/> + </bean> + + <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> + + <route> + <from uri="jetty2:http://localhost:9090/myapp"/> + <transform> + <simple>Hello ${body}</simple> + </transform> + </route> + + </camelContext> + +</beans> http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/resources/org/apache/camel/component/jetty/jetty-https.xml ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/resources/org/apache/camel/component/jetty/jetty-https.xml b/components/camel-jetty9/src/test/resources/org/apache/camel/component/jetty/jetty-https.xml new file mode 100644 index 0000000..c8e4ae4 --- /dev/null +++ b/components/camel-jetty9/src/test/resources/org/apache/camel/component/jetty/jetty-https.xml @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd + "> + <bean id="jetty" class="org.apache.camel.component.jetty9.JettyHttpComponent9"> + <property name="sslPassword" value="changeit"/> + <property name="sslKeyPassword" value="changeit"/> + <property name="keystore" value="src/test/resources/jsse/localhost.ks"/> + </bean> + + + <bean id="dynaPort" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> + <property name="targetClass"> + <value>org.apache.camel.test.AvailablePortFinder</value> + </property> + <property name="targetMethod"> + <value>getNextAvailable</value> + </property> + <property name="arguments"> + <list> + <value>9000</value> + </list> + </property> + </bean> + + + <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> + <endpoint id="input1" uri="jetty:https://localhost:#{dynaPort}/test"/> + + <route> + <from ref="input1"/> + <to uri="mock:a"/> + </route> + </camelContext> + +</beans> http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/resources/org/apache/camel/component/jetty/jetty-noconnection-redelivery.xml ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/resources/org/apache/camel/component/jetty/jetty-noconnection-redelivery.xml b/components/camel-jetty9/src/test/resources/org/apache/camel/component/jetty/jetty-noconnection-redelivery.xml new file mode 100644 index 0000000..210fecd --- /dev/null +++ b/components/camel-jetty9/src/test/resources/org/apache/camel/component/jetty/jetty-noconnection-redelivery.xml @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd + "> + + <bean id="dynaPort" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> + <property name="targetClass"> + <value>org.apache.camel.test.AvailablePortFinder</value> + </property> + <property name="targetMethod"> + <value>getNextAvailable</value> + </property> + <property name="arguments"> + <list> + <value>9000</value> + </list> + </property> + </bean> + + + <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> + <endpoint id="httpEndpoint" uri="http://localhost:#{dynaPort}/hi"/> + <endpoint id="jettyEndpoint" uri="jetty:http://localhost:#{dynaPort}/hi"/> + + <route> + <from uri="direct:start"/> + <onException> + <exception>java.net.ConnectException</exception> + <redeliveryPolicy maximumRedeliveries="4" redeliveryDelay="100" maximumRedeliveryDelay="5000" + backOffMultiplier="2" useExponentialBackOff="true"/> + </onException> + <to ref="httpEndpoint"/> + </route> + + <route id="jetty"> + + <from ref="jettyEndpoint"/> + <transform><simple>Bye ${body}</simple></transform> + </route> + + </camelContext> + +</beans> http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty9/src/test/resources/org/apache/camel/component/jetty/jetty-noconnection.xml ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/resources/org/apache/camel/component/jetty/jetty-noconnection.xml b/components/camel-jetty9/src/test/resources/org/apache/camel/component/jetty/jetty-noconnection.xml new file mode 100644 index 0000000..db38b86 --- /dev/null +++ b/components/camel-jetty9/src/test/resources/org/apache/camel/component/jetty/jetty-noconnection.xml @@ -0,0 +1,56 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd + "> + + + <bean id="dynaPort" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> + <property name="targetClass"> + <value>org.apache.camel.test.AvailablePortFinder</value> + </property> + <property name="targetMethod"> + <value>getNextAvailable</value> + </property> + <property name="arguments"> + <list> + <value>5000</value> + </list> + </property> + </bean> + + <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> + <endpoint id="httpEndpoint" uri="http://localhost:#{dynaPort}/hi"/> + <endpoint id="jettyEndpoint" uri="jetty:http://localhost:#{dynaPort}/hi"/> + + <route> + <from uri="direct:start"/> + <to ref="httpEndpoint"/> + </route> + + <route id="jetty"> + <from ref="jettyEndpoint"/> + <transform><simple>Bye ${body}</simple></transform> + </route> + + </camelContext> + +</beans> http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-quickfix/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-quickfix/pom.xml b/components/camel-quickfix/pom.xml index 25639d5..cf2274e 100644 --- a/components/camel-quickfix/pom.xml +++ b/components/camel-quickfix/pom.xml @@ -54,7 +54,7 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-jetty</artifactId> + <artifactId>camel-jetty8</artifactId> <scope>test</scope> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-restlet/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-restlet/pom.xml b/components/camel-restlet/pom.xml index 3b2e24c..14014ec 100644 --- a/components/camel-restlet/pom.xml +++ b/components/camel-restlet/pom.xml @@ -77,7 +77,7 @@ <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-jetty</artifactId> + <artifactId>camel-jetty8</artifactId> <scope>test</scope> </dependency> http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-swagger/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-swagger/pom.xml b/components/camel-swagger/pom.xml index 4e89ac0..d331c67 100644 --- a/components/camel-swagger/pom.xml +++ b/components/camel-swagger/pom.xml @@ -83,7 +83,7 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-jetty</artifactId> + <artifactId>camel-jetty8</artifactId> <scope>test</scope> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-urlrewrite/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-urlrewrite/pom.xml b/components/camel-urlrewrite/pom.xml index 71489ce..b6e0766 100644 --- a/components/camel-urlrewrite/pom.xml +++ b/components/camel-urlrewrite/pom.xml @@ -73,7 +73,7 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-jetty</artifactId> + <artifactId>camel-jetty8</artifactId> <scope>test</scope> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-xmlrpc/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-xmlrpc/pom.xml b/components/camel-xmlrpc/pom.xml index a14ea21..91bf383 100644 --- a/components/camel-xmlrpc/pom.xml +++ b/components/camel-xmlrpc/pom.xml @@ -77,7 +77,7 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-jetty</artifactId> + <artifactId>camel-jetty8</artifactId> <scope>test</scope> </dependency> </dependencies> http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/pom.xml ---------------------------------------------------------------------- diff --git a/components/pom.xml b/components/pom.xml index ccf874d..6d546d6 100644 --- a/components/pom.xml +++ b/components/pom.xml @@ -47,7 +47,9 @@ <module>camel-scala</module> <module>camel-http</module> <module>camel-http4</module> - <module>camel-jetty</module> + <module>camel-jetty-common</module> + <module>camel-jetty8</module> + <module>camel-jetty9</module> <module>camel-cxf</module> <module>camel-cxf-transport</module> <module>camel-web-standalone</module> http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/examples/camel-example-cxf/pom.xml ---------------------------------------------------------------------- diff --git a/examples/camel-example-cxf/pom.xml b/examples/camel-example-cxf/pom.xml index 8290da4..8dc1dad 100644 --- a/examples/camel-example-cxf/pom.xml +++ b/examples/camel-example-cxf/pom.xml @@ -66,7 +66,7 @@ <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-jetty</artifactId> + <artifactId>camel-jetty8</artifactId> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/parent/pom.xml ---------------------------------------------------------------------- diff --git a/parent/pom.xml b/parent/pom.xml index db4fbb4..11ee805 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -951,7 +951,17 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-jetty</artifactId> + <artifactId>camel-jetty-common</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-jetty8</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-jetty9</artifactId> <version>${project.version}</version> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/tests/camel-itest/pom.xml ---------------------------------------------------------------------- diff --git a/tests/camel-itest/pom.xml b/tests/camel-itest/pom.xml index c46ea74..1ed274e 100644 --- a/tests/camel-itest/pom.xml +++ b/tests/camel-itest/pom.xml @@ -74,7 +74,7 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-jetty</artifactId> + <artifactId>camel-jetty8</artifactId> <scope>test</scope> </dependency> <dependency>