CAMEL-9683: Started on camel-ribbon
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/28ba0e5f Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/28ba0e5f Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/28ba0e5f Branch: refs/heads/remoteServiceCall Commit: 28ba0e5f46eb2b85d8bd1a26e94b6b5cac248431 Parents: d164099 Author: Claus Ibsen <davscl...@apache.org> Authored: Mon May 16 11:11:23 2016 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Mon May 23 09:26:45 2016 +0200 ---------------------------------------------------------------------- .../blueprint/CamelContextFactoryBean.java | 2 + components/camel-ribbon/pom.xml | 2 +- .../SpringRibbonServiceCallRouteTest.java | 46 +++++++++++++ .../SpringRibbonServiceCallRouteTest.xml | 70 ++++++++++++++++++++ .../camel/spring/CamelContextFactoryBean.java | 2 + .../spring/handler/CamelNamespaceHandler.java | 2 + 6 files changed, 123 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/28ba0e5f/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java ---------------------------------------------------------------------- diff --git a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java index 0c6e832..f0c204c 100644 --- a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java +++ b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java @@ -56,6 +56,7 @@ import org.apache.camel.model.RestContextRefDefinition; import org.apache.camel.model.RouteBuilderDefinition; import org.apache.camel.model.RouteContextRefDefinition; import org.apache.camel.model.RouteDefinition; +import org.apache.camel.model.ServiceCallConfigurationDefinition; import org.apache.camel.model.ThreadPoolProfileDefinition; import org.apache.camel.model.dataformat.DataFormatsDefinition; import org.apache.camel.model.rest.RestConfigurationDefinition; @@ -142,6 +143,7 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Blu private CamelStreamCachingStrategyDefinition camelStreamCachingStrategy; @XmlElements({ @XmlElement(name = "hystrixConfiguration", type = HystrixConfigurationDefinition.class, required = false), + @XmlElement(name = "serviceCallConfiguration", type = ServiceCallConfigurationDefinition.class, required = false), @XmlElement(name = "template", type = CamelProducerTemplateFactoryBean.class, required = false), @XmlElement(name = "consumerTemplate", type = CamelConsumerTemplateFactoryBean.class, required = false), @XmlElement(name = "proxy", type = CamelProxyFactoryBean.class, required = false), http://git-wip-us.apache.org/repos/asf/camel/blob/28ba0e5f/components/camel-ribbon/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-ribbon/pom.xml b/components/camel-ribbon/pom.xml index 111826b..94f68fe 100644 --- a/components/camel-ribbon/pom.xml +++ b/components/camel-ribbon/pom.xml @@ -55,7 +55,7 @@ <!-- testing --> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-test</artifactId> + <artifactId>camel-test-spring</artifactId> <scope>test</scope> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/camel/blob/28ba0e5f/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/processor/SpringRibbonServiceCallRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/processor/SpringRibbonServiceCallRouteTest.java b/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/processor/SpringRibbonServiceCallRouteTest.java new file mode 100644 index 0000000..325984e --- /dev/null +++ b/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/processor/SpringRibbonServiceCallRouteTest.java @@ -0,0 +1,46 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.ribbon.processor; + +import org.apache.camel.test.spring.CamelSpringTestSupport; +import org.junit.Test; +import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class SpringRibbonServiceCallRouteTest extends CamelSpringTestSupport { + + @Override + protected AbstractApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/component/ribbon/processor/SpringRibbonServiceCallRouteTest.xml"); + } + + @Test + public void testServiceCall() throws Exception { + getMockEndpoint("mock:9090").expectedMessageCount(1); + getMockEndpoint("mock:9091").expectedMessageCount(1); + getMockEndpoint("mock:result").expectedMessageCount(2); + + String out = template.requestBody("direct:start", null, String.class); + String out2 = template.requestBody("direct:start", null, String.class); + assertEquals("9091", out); + assertEquals("9090", out2); + + assertMockEndpointsSatisfied(); + } + +} + http://git-wip-us.apache.org/repos/asf/camel/blob/28ba0e5f/components/camel-ribbon/src/test/resources/org/apache/camel/component/ribbon/processor/SpringRibbonServiceCallRouteTest.xml ---------------------------------------------------------------------- diff --git a/components/camel-ribbon/src/test/resources/org/apache/camel/component/ribbon/processor/SpringRibbonServiceCallRouteTest.xml b/components/camel-ribbon/src/test/resources/org/apache/camel/component/ribbon/processor/SpringRibbonServiceCallRouteTest.xml new file mode 100644 index 0000000..a439f23 --- /dev/null +++ b/components/camel-ribbon/src/test/resources/org/apache/camel/component/ribbon/processor/SpringRibbonServiceCallRouteTest.xml @@ -0,0 +1,70 @@ +<?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 + "> + + <!-- TODO: should be nicer to do in XML--> + <!-- setup a static ribbon server list with these 2 servers to start with --> + <bean id="servers" class="org.apache.camel.component.ribbon.processor.RibbonServiceCallStaticServerListStrategy"> + <constructor-arg index="0"> + <list> + <bean class="org.apache.camel.component.ribbon.processor.RibbonServer"> + <constructor-arg index="0" value="localhost"/> + <constructor-arg index="1" value="9090"/> + </bean> + <bean class="org.apache.camel.component.ribbon.processor.RibbonServer"> + <constructor-arg index="0" value="localhost"/> + <constructor-arg index="1" value="9091"/> + </bean> + </list> + </constructor-arg> + </bean> + + <camelContext xmlns="http://camel.apache.org/schema/spring"> + + <!-- service call configuration to use ribbon --> + <serviceCallConfiguration id="myConfig" serverListStrategyRef="servers"/> + + <route> + <from uri="direct:start"/> + <serviceCall name="myService" serviceCallConfigurationRef="myConfig"/> + <to uri="mock:result"/> + </route> + + <route> + <from uri="jetty:http://localhost:9090"/> + <to uri="mock:9090"/> + <transform> + <constant>9090</constant> + </transform> + </route> + + <route> + <from uri="jetty:http://localhost:9091"/> + <to uri="mock:9091"/> + <transform> + <constant>9091</constant> + </transform> + </route> + </camelContext> + +</beans> http://git-wip-us.apache.org/repos/asf/camel/blob/28ba0e5f/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java index 5f94f6b..f7518f7 100644 --- a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java +++ b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java @@ -55,6 +55,7 @@ import org.apache.camel.model.RestContextRefDefinition; import org.apache.camel.model.RouteBuilderDefinition; import org.apache.camel.model.RouteContextRefDefinition; import org.apache.camel.model.RouteDefinition; +import org.apache.camel.model.ServiceCallConfigurationDefinition; import org.apache.camel.model.ThreadPoolProfileDefinition; import org.apache.camel.model.dataformat.DataFormatsDefinition; import org.apache.camel.model.rest.RestConfigurationDefinition; @@ -152,6 +153,7 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Spr private CamelJMXAgentDefinition camelJMXAgent; @XmlElements({ @XmlElement(name = "hystrixConfiguration", type = HystrixConfigurationDefinition.class, required = false), + @XmlElement(name = "serviceCallConfiguration", type = ServiceCallConfigurationDefinition.class, required = false), @XmlElement(name = "template", type = CamelProducerTemplateFactoryBean.class, required = false), @XmlElement(name = "consumerTemplate", type = CamelConsumerTemplateFactoryBean.class, required = false), @XmlElement(name = "proxy", type = CamelProxyFactoryDefinition.class, required = false), http://git-wip-us.apache.org/repos/asf/camel/blob/28ba0e5f/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java b/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java index fd062a0..442e529 100644 --- a/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java +++ b/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java @@ -40,6 +40,7 @@ import org.apache.camel.impl.DefaultCamelContextNameStrategy; import org.apache.camel.model.FromDefinition; import org.apache.camel.model.HystrixConfigurationDefinition; import org.apache.camel.model.SendDefinition; +import org.apache.camel.model.ServiceCallConfigurationDefinition; import org.apache.camel.spi.CamelContextNameStrategy; import org.apache.camel.spi.NamespaceAware; import org.apache.camel.spring.CamelBeanPostProcessor; @@ -144,6 +145,7 @@ public class CamelNamespaceHandler extends NamespaceHandlerSupport { addBeanDefinitionParser("streamCaching", CamelStreamCachingStrategyDefinition.class, false, false); addBeanDefinitionParser("propertyPlaceholder", CamelPropertyPlaceholderDefinition.class, false, false); addBeanDefinitionParser("hystrixConfiguration", HystrixConfigurationDefinition.class, false, false); + addBeanDefinitionParser("serviceCallConfiguration", ServiceCallConfigurationDefinition.class, false, false); // errorhandler could be the sub element of camelContext or defined outside camelContext BeanDefinitionParser errorHandlerParser = new ErrorHandlerDefinitionParser();