CAMEL-7959: rest-dsl add support for onException,intercept etc
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/fe1d2808 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/fe1d2808 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/fe1d2808 Branch: refs/heads/camel-2.14.x Commit: fe1d2808fdf94d7722c31befab10ea1aa4105879 Parents: d4c2001 Author: Claus Ibsen <davscl...@apache.org> Authored: Sun Nov 30 10:10:09 2014 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Sun Nov 30 10:21:16 2014 +0100 ---------------------------------------------------------------------- .../apache/camel/impl/DefaultCamelContext.java | 2 +- .../xml/AbstractCamelContextFactoryBean.java | 21 +++++--- .../rest/SpringFromRestGetInterceptTest.java | 29 ++++++++++ .../rest/SpringFromRestGetOnExceptionTest.java | 29 ++++++++++ .../SpringFromRestGetRouteOnExceptionTest.java | 29 ++++++++++ .../rest/SpringFromRestGetInterceptTest.xml | 48 +++++++++++++++++ .../rest/SpringFromRestGetOnExceptionTest.xml | 56 ++++++++++++++++++++ .../SpringFromRestGetRouteOnExceptionTest.xml | 55 +++++++++++++++++++ .../rest/FromRestGetInterceptTest.java | 41 ++++++++++++++ .../rest/FromRestGetOnExceptionTest.java | 40 ++++++++++++++ .../rest/FromRestGetRouteOnExceptionTest.java | 26 +++++++++ .../component/rest/FromRestGetInterceptTest.xml | 46 ++++++++++++++++ .../rest/FromRestGetOnExceptionTest.xml | 54 +++++++++++++++++++ .../rest/FromRestGetRouteOnExceptionTest.xml | 53 ++++++++++++++++++ 14 files changed, 522 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/fe1d2808/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java index 388d1be..2d1dfb8 100644 --- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java +++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java @@ -712,7 +712,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon } // can either be routes or a single route - RoutesDefinition answer = null; + RoutesDefinition answer; if (result instanceof RouteDefinition) { RouteDefinition route = (RouteDefinition) result; answer = new RoutesDefinition(); http://git-wip-us.apache.org/repos/asf/camel/blob/fe1d2808/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java ---------------------------------------------------------------------- diff --git a/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java index 4dec4fd..f960c3a 100644 --- a/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java +++ b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java @@ -316,6 +316,21 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex // must init route refs before we prepare the routes below initRouteRefs(); + // must init rest refs before we add the rests + initRestRefs(); + + // and add the rests + getContext().addRestDefinitions(getRests()); + + // convert rests into routes so we reuse routes for runtime + for (RestDefinition rest : getRests()) { + List<RouteDefinition> routes = rest.asRouteDefinition(getContext()); + for (RouteDefinition route : routes) { + getRoutes().add(route); + } + } + + // do special preparation for some concepts such as interceptors and policies // this is needed as JAXB does not build exactly the same model definition as Spring DSL would do // using route builders. So we have here a little custom code to fix the JAXB gaps @@ -329,12 +344,6 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex findRouteBuilders(); installRoutes(); - // must init rest refs before we add the rests - initRestRefs(); - - // and add the rests - getContext().addRestDefinitions(getRests()); - // and we are now finished setting up the routes getContext().setupRoutes(true); } http://git-wip-us.apache.org/repos/asf/camel/blob/fe1d2808/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestGetInterceptTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestGetInterceptTest.java b/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestGetInterceptTest.java new file mode 100644 index 0000000..8746215 --- /dev/null +++ b/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestGetInterceptTest.java @@ -0,0 +1,29 @@ +/** + * 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.rest; + +import org.apache.camel.CamelContext; + +import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext; + +public class SpringFromRestGetInterceptTest extends FromRestGetInterceptTest { + + protected CamelContext createCamelContext() throws Exception { + return createSpringCamelContext(this, "org/apache/camel/component/rest/SpringFromRestGetInterceptTest.xml"); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/fe1d2808/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestGetOnExceptionTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestGetOnExceptionTest.java b/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestGetOnExceptionTest.java new file mode 100644 index 0000000..5c96561 --- /dev/null +++ b/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestGetOnExceptionTest.java @@ -0,0 +1,29 @@ +/** + * 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.rest; + +import org.apache.camel.CamelContext; + +import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext; + +public class SpringFromRestGetOnExceptionTest extends FromRestGetOnExceptionTest { + + protected CamelContext createCamelContext() throws Exception { + return createSpringCamelContext(this, "org/apache/camel/component/rest/SpringFromRestGetOnExceptionTest.xml"); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/fe1d2808/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestGetRouteOnExceptionTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestGetRouteOnExceptionTest.java b/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestGetRouteOnExceptionTest.java new file mode 100644 index 0000000..a386b4b --- /dev/null +++ b/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestGetRouteOnExceptionTest.java @@ -0,0 +1,29 @@ +/** + * 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.rest; + +import org.apache.camel.CamelContext; + +import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext; + +public class SpringFromRestGetRouteOnExceptionTest extends FromRestGetRouteOnExceptionTest { + + protected CamelContext createCamelContext() throws Exception { + return createSpringCamelContext(this, "org/apache/camel/component/rest/SpringFromRestGetRouteOnExceptionTest.xml"); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/fe1d2808/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetInterceptTest.xml ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetInterceptTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetInterceptTest.xml new file mode 100644 index 0000000..cf42c79 --- /dev/null +++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetInterceptTest.xml @@ -0,0 +1,48 @@ +<?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 + "> + + <!-- use a dummy rest consumer factory for the rest engine --> + <bean id="dummy-rest" class="org.apache.camel.component.rest.DummyRestConsumerFactory"/> + + <camelContext xmlns="http://camel.apache.org/schema/spring"> + + <intercept> + <to uri="mock:intercept"/> + </intercept> + + <rest path="/say/hello"> + <get> + <route> + <to uri="mock:hello"/> + <to uri="mock:bar"/> + <transform> + <constant>Bye World</constant> + </transform> + </route> + </get> + </rest> + + </camelContext> + +</beans> http://git-wip-us.apache.org/repos/asf/camel/blob/fe1d2808/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetOnExceptionTest.xml ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetOnExceptionTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetOnExceptionTest.xml new file mode 100644 index 0000000..e8d5a4b --- /dev/null +++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetOnExceptionTest.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="darn" class="java.lang.IllegalArgumentException"> + <constructor-arg index="0" value="Forced"/> + </bean> + + <!-- use a dummy rest consumer factory for the rest engine --> + <bean id="dummy-rest" class="org.apache.camel.component.rest.DummyRestConsumerFactory"/> + + <camelContext xmlns="http://camel.apache.org/schema/spring"> + + <onException> + <exception>java.lang.IllegalArgumentException</exception> + <handled> + <constant>true</constant> + </handled> + <transform> + <constant>Handled the error</constant> + </transform> + </onException> + + <rest path="/say/hello"> + <get> + <route> + <to uri="mock:hello"/> + <to uri="mock:bar"/> + <throwException ref="darn"/> + </route> + </get> + </rest> + + </camelContext> + +</beans> http://git-wip-us.apache.org/repos/asf/camel/blob/fe1d2808/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetRouteOnExceptionTest.xml ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetRouteOnExceptionTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetRouteOnExceptionTest.xml new file mode 100644 index 0000000..319f1de --- /dev/null +++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetRouteOnExceptionTest.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="darn" class="java.lang.IllegalArgumentException"> + <constructor-arg index="0" value="Forced"/> + </bean> + + <!-- use a dummy rest consumer factory for the rest engine --> + <bean id="dummy-rest" class="org.apache.camel.component.rest.DummyRestConsumerFactory"/> + + <camelContext xmlns="http://camel.apache.org/schema/spring"> + + <rest path="/say/hello"> + <get> + <route> + <onException> + <exception>java.lang.IllegalArgumentException</exception> + <handled> + <constant>true</constant> + </handled> + <transform> + <constant>Handled the error</constant> + </transform> + </onException> + <to uri="mock:hello"/> + <to uri="mock:bar"/> + <throwException ref="darn"/> + </route> + </get> + </rest> + + </camelContext> + +</beans> http://git-wip-us.apache.org/repos/asf/camel/blob/fe1d2808/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetInterceptTest.java ---------------------------------------------------------------------- diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetInterceptTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetInterceptTest.java new file mode 100644 index 0000000..ce766b4 --- /dev/null +++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetInterceptTest.java @@ -0,0 +1,41 @@ +/** + * 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.test.blueprint.component.rest; + +import org.apache.camel.test.blueprint.CamelBlueprintTestSupport; +import org.junit.Test; + +public class FromRestGetInterceptTest extends CamelBlueprintTestSupport { + + @Override + protected String getBlueprintDescriptor() { + return "org/apache/camel/test/blueprint/component/rest/FromRestGetInterceptTest.xml"; + } + + @Test + public void testFromRestModel() throws Exception { + getMockEndpoint("mock:hello").expectedMessageCount(1); + getMockEndpoint("mock:bar").expectedMessageCount(1); + getMockEndpoint("mock:intercept").expectedMessageCount(4); + + String out = template.requestBody("seda:get-say-hello", "I was here", String.class); + assertEquals("Bye World", out); + + assertMockEndpointsSatisfied(); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/fe1d2808/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetOnExceptionTest.java ---------------------------------------------------------------------- diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetOnExceptionTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetOnExceptionTest.java new file mode 100644 index 0000000..62a1072 --- /dev/null +++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetOnExceptionTest.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.test.blueprint.component.rest; + +import org.apache.camel.test.blueprint.CamelBlueprintTestSupport; +import org.junit.Test; + +public class FromRestGetOnExceptionTest extends CamelBlueprintTestSupport { + + @Override + protected String getBlueprintDescriptor() { + return "org/apache/camel/test/blueprint/component/rest/FromRestGetOnExceptionTest.xml"; + } + + @Test + public void testFromRestModel() throws Exception { + getMockEndpoint("mock:hello").expectedMessageCount(1); + + String out = template.requestBody("seda:get-say-hello", "I was here", String.class); + assertEquals("Handled the error", out); + + assertMockEndpointsSatisfied(); + } + + +} http://git-wip-us.apache.org/repos/asf/camel/blob/fe1d2808/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetRouteOnExceptionTest.java ---------------------------------------------------------------------- diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetRouteOnExceptionTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetRouteOnExceptionTest.java new file mode 100644 index 0000000..8248af5 --- /dev/null +++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetRouteOnExceptionTest.java @@ -0,0 +1,26 @@ +/** + * 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.test.blueprint.component.rest; + +public class FromRestGetRouteOnExceptionTest extends FromRestGetOnExceptionTest { + + @Override + protected String getBlueprintDescriptor() { + return "org/apache/camel/test/blueprint/component/rest/FromRestGetRouteOnExceptionTest.xml"; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/fe1d2808/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetInterceptTest.xml ---------------------------------------------------------------------- diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetInterceptTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetInterceptTest.xml new file mode 100644 index 0000000..5ae4fab --- /dev/null +++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetInterceptTest.xml @@ -0,0 +1,46 @@ +<?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. +--> +<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> + + <!-- use a dummy rest consumer factory for the rest engine --> + <bean id="dummy-rest" class="org.apache.camel.test.blueprint.component.rest.DummyRestConsumerFactory"/> + + <camelContext xmlns="http://camel.apache.org/schema/blueprint"> + + <intercept> + <to uri="mock:intercept"/> + </intercept> + + <rest path="/say/hello"> + <get> + <route> + <to uri="mock:hello"/> + <to uri="mock:bar"/> + <transform> + <constant>Bye World</constant> + </transform> + </route> + </get> + </rest> + + </camelContext> + +</blueprint> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/fe1d2808/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetOnExceptionTest.xml ---------------------------------------------------------------------- diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetOnExceptionTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetOnExceptionTest.xml new file mode 100644 index 0000000..9337fe3 --- /dev/null +++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetOnExceptionTest.xml @@ -0,0 +1,54 @@ +<?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. +--> +<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> + + <bean id="darn" class="java.lang.IllegalArgumentException"> + <argument index="0" value="Forced"/> + </bean> + + <!-- use a dummy rest consumer factory for the rest engine --> + <bean id="dummy-rest" class="org.apache.camel.test.blueprint.component.rest.DummyRestConsumerFactory"/> + + <camelContext xmlns="http://camel.apache.org/schema/blueprint"> + + <onException> + <exception>java.lang.IllegalArgumentException</exception> + <handled> + <constant>true</constant> + </handled> + <transform> + <constant>Handled the error</constant> + </transform> + </onException> + + <rest path="/say/hello"> + <get> + <route> + <to uri="mock:hello"/> + <to uri="mock:bar"/> + <throwException ref="darn"/> + </route> + </get> + </rest> + + </camelContext> + +</blueprint> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/fe1d2808/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetRouteOnExceptionTest.xml ---------------------------------------------------------------------- diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetRouteOnExceptionTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetRouteOnExceptionTest.xml new file mode 100644 index 0000000..810a3ae --- /dev/null +++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetRouteOnExceptionTest.xml @@ -0,0 +1,53 @@ +<?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. +--> +<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> + + <bean id="darn" class="java.lang.IllegalArgumentException"> + <argument index="0" value="Forced"/> + </bean> + + <!-- use a dummy rest consumer factory for the rest engine --> + <bean id="dummy-rest" class="org.apache.camel.test.blueprint.component.rest.DummyRestConsumerFactory"/> + + <camelContext xmlns="http://camel.apache.org/schema/blueprint"> + + <rest path="/say/hello"> + <get> + <route> + <onException> + <exception>java.lang.IllegalArgumentException</exception> + <handled> + <constant>true</constant> + </handled> + <transform> + <constant>Handled the error</constant> + </transform> + </onException> + <to uri="mock:hello"/> + <to uri="mock:bar"/> + <throwException ref="darn"/> + </route> + </get> + </rest> + + </camelContext> + +</blueprint> \ No newline at end of file