Repository: camel Updated Branches: refs/heads/master c92845358 -> a811f4004
http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallConfigurationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallConfigurationTest.java b/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallConfigurationTest.java new file mode 100644 index 0000000..cb992a4 --- /dev/null +++ b/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallConfigurationTest.java @@ -0,0 +1,76 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.spring.cloud; + +import org.apache.camel.cloud.LoadBalancer; +import org.apache.camel.cloud.ServiceChooser; +import org.apache.camel.cloud.ServiceDiscovery; +import org.apache.camel.cloud.ServiceFilter; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ApplicationContext; +import org.springframework.core.env.Environment; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +@DirtiesContext +@RunWith(SpringRunner.class) +@SpringBootApplication +@SpringBootTest( + classes = { + CamelAutoConfiguration.class, + CamelCloudAutoConfiguration.class, + ServiceCallServiceChooserAutoConfiguration.class + }, + properties = { + "camel.cloud.servicecall.enabled=false", + "camel.cloud.servicecall.service-discovery.enabled=false", + "camel.cloud.servicecall.service-filter.enabled=false", + "camel.cloud.servicecall.service-chooser.enabled=true", + "camel.cloud.servicecall.load-balancer.enabled=false", + "debug=false" + } +) +public class CamelCloudServiceCallConfigurationTest { + @Autowired + private ApplicationContext ctx; + + @Test + public void doTest() throws Exception { + Environment env = ctx.getEnvironment(); + + assertFalse(env.getProperty("camel.cloud.servicecall.enabled", Boolean.class)); + assertFalse(env.getProperty("camel.cloud.servicecall.service-discovery.enabled", Boolean.class)); + assertFalse(env.getProperty("camel.cloud.servicecall.service-filter.enabled", Boolean.class)); + assertTrue(env.getProperty("camel.cloud.servicecall.service-chooser.enabled", Boolean.class)); + assertFalse(env.getProperty("camel.cloud.servicecall.load-balancer.enabled", Boolean.class)); + + assertTrue(ctx.getBeansOfType(ServiceDiscovery.class).isEmpty()); + assertTrue(ctx.getBeansOfType(ServiceFilter.class).isEmpty()); + assertFalse(ctx.getBeansOfType(ServiceChooser.class).isEmpty()); + assertTrue(ctx.getBeansOfType(LoadBalancer.class).isEmpty()); + } +} + http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallRibbonTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallRibbonTest.java b/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallRibbonTest.java new file mode 100644 index 0000000..b038a19 --- /dev/null +++ b/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallRibbonTest.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.spring.cloud; + +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringRunner; + +@DirtiesContext +@RunWith(SpringRunner.class) +@SpringBootApplication +@SpringBootTest( + classes = { + CamelAutoConfiguration.class, + CamelCloudAutoConfiguration.class, + CamelCloudServiceCallRibbonTest.TestConfiguration.class + }, + properties = { + "ribbon.eureka.enabled=false", + "ribbon.listOfServers=localhost:9090,localhost:9091", + "ribbon.ServerListRefreshInterval=15000", + "debug=false" + } +) +public class CamelCloudServiceCallRibbonTest { + @Autowired + private ProducerTemplate template; + + @Test + public void testServiceCall() throws Exception { + Assert.assertEquals("9090", template.requestBody("direct:start", null, String.class)); + Assert.assertEquals("9091", template.requestBody("direct:start", null, String.class)); + } + + // ************************** + // Configuration + // ************************** + + @Configuration + public static class TestConfiguration { + @Bean + public RouteBuilder myRouteBuilder() { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .serviceCall() + .name("service-call"); + + from("jetty:http://localhost:9090") + .transform().constant("9090"); + from("jetty:http://localhost:9091") + .transform().constant("9091"); + } + }; + } + } + +} + http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallTest.java b/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallTest.java new file mode 100644 index 0000000..5e26e74 --- /dev/null +++ b/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallTest.java @@ -0,0 +1,86 @@ +/** + * 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.spring.cloud; + +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringRunner; + +@DirtiesContext +@RunWith(SpringRunner.class) +@SpringBootApplication +@SpringBootTest( + classes = { + CamelAutoConfiguration.class, + CamelCloudAutoConfiguration.class, + CamelCloudServiceCallTest.TestConfiguration.class + }, + properties = { + "camel.cloud.servicecall.load-balancer.enabled=false", + "camel.cloud.servicecall.service-discovery.services[custom-svc-list]=localhost:9090,localhost:9091", + "ribbon.enabled=false", + "debug=false" + } +) +public class CamelCloudServiceCallTest { + @Autowired + private ProducerTemplate template; + + @Test + public void testServiceCall() throws Exception { + Assert.assertEquals("9090", template.requestBody("direct:start", null, String.class)); + Assert.assertEquals("9091", template.requestBody("direct:start", null, String.class)); + } + + // ************************** + // Configuration + // ************************** + + @Configuration + public static class TestConfiguration { + @Bean + public RouteBuilder myRouteBuilder() { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .serviceCall() + .name("custom-svc-list/hello"); + from("jetty:http://localhost:9090/hello") + .transform() + .constant("9090"); + from("jetty:http://localhost:9091/hello") + .transform() + .constant("9091"); + } + }; + } + } + +} + http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/processor/remote/CamelCloudDiscoveryClient.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/processor/remote/CamelCloudDiscoveryClient.java b/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/processor/remote/CamelCloudDiscoveryClient.java deleted file mode 100644 index 136ba62..0000000 --- a/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/processor/remote/CamelCloudDiscoveryClient.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * 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.spring.cloud.processor.remote; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import org.springframework.cloud.client.DefaultServiceInstance; -import org.springframework.cloud.client.ServiceInstance; -import org.springframework.cloud.client.discovery.DiscoveryClient; - -public class CamelCloudDiscoveryClient implements DiscoveryClient { - private final String description; - private final Map<String, List<ServiceInstance>> services; - - public CamelCloudDiscoveryClient(String description) { - this(description, Collections.emptyMap()); - } - - public CamelCloudDiscoveryClient(String description, Map<String, List<ServiceInstance>> services) { - this.description = description; - this.services = new LinkedHashMap<>(services); - } - - @Override - public String description() { - return description; - } - - @Override - public ServiceInstance getLocalServiceInstance() { - return null; - } - - @Override - public List<ServiceInstance> getInstances(String serviceId) { - return services.get(serviceId); - } - - @Override - public List<String> getServices() { - return new ArrayList<>(services.keySet()); - } - - public CamelCloudDiscoveryClient addServiceInstance(String serviceId, ServiceInstance instance) { - services.computeIfAbsent(serviceId, key -> new LinkedList<>()).add(instance); - return this; - } - - public CamelCloudDiscoveryClient addServiceInstance(String serviceId, String host, int port) { - return addServiceInstance(serviceId, new DefaultServiceInstance(serviceId, host, port, false)); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/processor/remote/CamelCloudServiceCallConfigurationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/processor/remote/CamelCloudServiceCallConfigurationTest.java b/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/processor/remote/CamelCloudServiceCallConfigurationTest.java deleted file mode 100644 index 6952c29..0000000 --- a/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/processor/remote/CamelCloudServiceCallConfigurationTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * 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.spring.cloud.processor.remote; - -import org.apache.camel.spi.ServiceCallLoadBalancer; -import org.apache.camel.spi.ServiceCallServerListStrategy; -import org.apache.camel.spring.boot.CamelAutoConfiguration; -import org.apache.camel.spring.cloud.CamelCloudAutoConfiguration; -import org.apache.camel.spring.cloud.servicecall.CamelCloudServiceCallAutoConfiguration; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.ApplicationContext; -import org.springframework.core.env.Environment; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -@DirtiesContext -@RunWith(SpringRunner.class) -@SpringBootApplication -@SpringBootTest( - classes = { - CamelAutoConfiguration.class, - CamelCloudAutoConfiguration.class, - CamelCloudServiceCallAutoConfiguration.class - }, - properties = { - "camel.cloud.servicecall.enabled=false", - "camel.cloud.servicecall.load-balancer.enabled=true", - "camel.cloud.servicecall.server-list-strategy.enabled=false" - } -) -public class CamelCloudServiceCallConfigurationTest { - @Autowired - private ApplicationContext ctx; - - @Test - public void doTest() throws Exception { - Environment env = ctx.getEnvironment(); - - assertFalse(env.getProperty("camel.cloud.servicecall.enabled", Boolean.class)); - assertTrue(env.getProperty("camel.cloud.servicecall.load-balancer.enabled", Boolean.class)); - assertFalse(env.getProperty("camel.cloud.servicecall.server-list-strategy.enabled", Boolean.class)); - - assertFalse(ctx.getBeansOfType(ServiceCallLoadBalancer.class).isEmpty()); - assertTrue(ctx.getBeansOfType(ServiceCallServerListStrategy.class).isEmpty()); - } -} - http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/processor/remote/CamelCloudServiceCallRibbonTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/processor/remote/CamelCloudServiceCallRibbonTest.java b/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/processor/remote/CamelCloudServiceCallRibbonTest.java deleted file mode 100644 index 42f3565..0000000 --- a/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/processor/remote/CamelCloudServiceCallRibbonTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * 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.spring.cloud.processor.remote; - -import org.apache.camel.ProducerTemplate; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.spring.boot.CamelAutoConfiguration; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; - -@DirtiesContext -@RunWith(SpringRunner.class) -@SpringBootApplication -@SpringBootTest( - classes = { - CamelAutoConfiguration.class, - CamelCloudServiceCallRibbonTest.TestConfiguration.class - }, - properties = { - "ribbon.eureka.enabled=false", - "ribbon.listOfServers=localhost:9090,localhost:9091", - "ribbon.ServerListRefreshInterval=15000" - } -) -public class CamelCloudServiceCallRibbonTest { - @Autowired - private ProducerTemplate template; - - @Test - public void testServiceCall() throws Exception { - Assert.assertEquals("9090", template.requestBody("direct:start", null, String.class)); - Assert.assertEquals("9091", template.requestBody("direct:start", null, String.class)); - } - - // ************************** - // Configuration - // ************************** - - @Configuration - public static class TestConfiguration { - @Bean - public RouteBuilder myRouteBuilder() { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:start") - .serviceCall() - .name("service-call"); - - from("jetty:http://localhost:9090") - .transform().constant("9090"); - from("jetty:http://localhost:9091") - .transform().constant("9091"); - } - }; - } - } - -} - http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/processor/remote/CamelCloudServiceCallTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/processor/remote/CamelCloudServiceCallTest.java b/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/processor/remote/CamelCloudServiceCallTest.java deleted file mode 100644 index 37e9f2f..0000000 --- a/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/processor/remote/CamelCloudServiceCallTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/** - * 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.spring.cloud.processor.remote; - -import org.apache.camel.ProducerTemplate; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.spring.boot.CamelAutoConfiguration; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.cloud.client.discovery.DiscoveryClient; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; - -@DirtiesContext -@RunWith(SpringRunner.class) -@SpringBootApplication -@SpringBootTest( - classes = { - CamelAutoConfiguration.class, - CamelCloudServiceCallTest.TestConfiguration.class - }, - properties = { - "ribbon.enabled=false" - } -) -public class CamelCloudServiceCallTest { - private static final int[] PORTS = new int[] { - 9090, 9091, 9092, 9093 - }; - - @Autowired - private ProducerTemplate template; - - @Test - public void testServiceCall() throws Exception { - for (int port : PORTS) { - Assert.assertEquals(Integer.toString(port), template.requestBody("direct:start", null, String.class)); - } - } - - // ************************** - // Configuration - // ************************** - - @Configuration - public static class TestConfiguration { - @Bean - public DiscoveryClient myDiscoveryClient1() { - CamelCloudDiscoveryClient client = new CamelCloudDiscoveryClient("myDiscoveryClient1"); - for (int port : PORTS) { - client.addServiceInstance("custom-server-list", "localhost", port); - } - - return client; - } - - @Bean - public RouteBuilder myRouteBuilder() { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:start") - .serviceCall() - .name("custom-server-list/hello") - .loadBalancer("random-load-balancer"); - - for (int port : PORTS) { - fromF("jetty:http://localhost:%d/hello", port) - .transform() - .constant(Integer.toString(port)); - } - } - }; - } - } - -} - http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-spring-dm/src/main/java/org/apache/camel/osgi/CamelNamespaceHandler.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-dm/src/main/java/org/apache/camel/osgi/CamelNamespaceHandler.java b/components/camel-spring-dm/src/main/java/org/apache/camel/osgi/CamelNamespaceHandler.java index 41fcf6c..35d3511 100644 --- a/components/camel-spring-dm/src/main/java/org/apache/camel/osgi/CamelNamespaceHandler.java +++ b/components/camel-spring-dm/src/main/java/org/apache/camel/osgi/CamelNamespaceHandler.java @@ -38,6 +38,7 @@ public class CamelNamespaceHandler extends org.apache.camel.spring.handler.Camel classes.add(org.apache.camel.model.language.ExpressionDefinition.class); classes.add(org.apache.camel.model.loadbalancer.RoundRobinLoadBalancerDefinition.class); classes.add(org.apache.camel.model.rest.RestDefinition.class); + classes.add(org.apache.camel.model.cloud.ServiceCallDefinition.class); return classes; } http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/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 9e11f6c..215206f 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 @@ -37,6 +37,7 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.properties.PropertiesComponent; import org.apache.camel.component.properties.PropertiesLocation; import org.apache.camel.core.xml.AbstractCamelContextFactoryBean; +import org.apache.camel.core.xml.AbstractCamelFactoryBean; import org.apache.camel.core.xml.CamelJMXAgentDefinition; import org.apache.camel.core.xml.CamelPropertyPlaceholderDefinition; import org.apache.camel.core.xml.CamelProxyFactoryDefinition; @@ -56,12 +57,8 @@ import org.apache.camel.model.RouteBuilderDefinition; import org.apache.camel.model.RouteContextRefDefinition; import org.apache.camel.model.RouteDefinition; import org.apache.camel.model.ThreadPoolProfileDefinition; +import org.apache.camel.model.cloud.ServiceCallConfigurationDefinition; import org.apache.camel.model.dataformat.DataFormatsDefinition; -import org.apache.camel.model.remote.ConsulConfigurationDefinition; -import org.apache.camel.model.remote.DnsConfigurationDefinition; -import org.apache.camel.model.remote.EtcdConfigurationDefinition; -import org.apache.camel.model.remote.KubernetesConfigurationDefinition; -import org.apache.camel.model.remote.RibbonConfigurationDefinition; import org.apache.camel.model.rest.RestConfigurationDefinition; import org.apache.camel.model.rest.RestDefinition; import org.apache.camel.model.transformer.TransformersDefinition; @@ -156,18 +153,16 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Spr @XmlElement(name = "jmxAgent", type = CamelJMXAgentDefinition.class) private CamelJMXAgentDefinition camelJMXAgent; @XmlElements({ - @XmlElement(name = "hystrixConfiguration", type = HystrixConfigurationDefinition.class), - @XmlElement(name = "consulConfiguration", type = ConsulConfigurationDefinition.class), - @XmlElement(name = "dnsConfiguration", type = DnsConfigurationDefinition.class), - @XmlElement(name = "etcdConfiguration", type = EtcdConfigurationDefinition.class), - @XmlElement(name = "kubernetesConfiguration", type = KubernetesConfigurationDefinition.class), - @XmlElement(name = "ribbonConfiguration", type = RibbonConfigurationDefinition.class), @XmlElement(name = "template", type = CamelProducerTemplateFactoryBean.class), @XmlElement(name = "fluentTemplate", type = CamelFluentProducerTemplateFactoryBean.class), @XmlElement(name = "consumerTemplate", type = CamelConsumerTemplateFactoryBean.class), @XmlElement(name = "proxy", type = CamelProxyFactoryDefinition.class), @XmlElement(name = "export", type = CamelServiceExporterDefinition.class), @XmlElement(name = "errorHandler", type = ErrorHandlerDefinition.class)}) + private List<AbstractCamelFactoryBean<?>> beansFactory; + @XmlElements({ + @XmlElement(name = "serviceCallConfiguration", type = ServiceCallConfigurationDefinition.class), + @XmlElement(name = "hystrixConfiguration", type = HystrixConfigurationDefinition.class)}) private List<?> beans; @XmlElement(name = "routeBuilder") private List<RouteBuilderDefinition> builderRefs = new ArrayList<RouteBuilderDefinition>(); @@ -895,13 +890,22 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Spr this.redeliveryPolicies = redeliveryPolicies; } - public List<?> getBeans() { - return beans; + public List<AbstractCamelFactoryBean<?>> getBeansFactory() { + return beansFactory; } /** * Miscellaneous configurations */ + public void setBeansFactory(List<AbstractCamelFactoryBean<?>> beansFactory) { + this.beansFactory = beansFactory; + } + + @Override + public List<?> getBeans() { + return beans; + } + public void setBeans(List<?> beans) { this.beans = beans; } @@ -990,5 +994,4 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Spr public void setImplicitId(boolean flag) { implicitId = flag; } - } http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/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 68ae70d..12cc996 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 @@ -39,11 +39,6 @@ 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.remote.ConsulConfigurationDefinition; -import org.apache.camel.model.remote.DnsConfigurationDefinition; -import org.apache.camel.model.remote.EtcdConfigurationDefinition; -import org.apache.camel.model.remote.KubernetesConfigurationDefinition; -import org.apache.camel.model.remote.RibbonConfigurationDefinition; import org.apache.camel.spi.CamelContextNameStrategy; import org.apache.camel.spi.NamespaceAware; import org.apache.camel.spring.CamelBeanPostProcessor; @@ -154,11 +149,6 @@ public class CamelNamespaceHandler extends NamespaceHandlerSupport { addBeanDefinitionParser("streamCaching", CamelStreamCachingStrategyDefinition.class, false, false); addBeanDefinitionParser("propertyPlaceholder", CamelPropertyPlaceholderDefinition.class, false, false); addBeanDefinitionParser("hystrixConfiguration", HystrixConfigurationDefinition.class, false, false); - addBeanDefinitionParser("consulConfiguration", ConsulConfigurationDefinition.class, false, false); - addBeanDefinitionParser("dnsConfiguration", DnsConfigurationDefinition.class, false, false); - addBeanDefinitionParser("etcdConfiguration", EtcdConfigurationDefinition.class, false, false); - addBeanDefinitionParser("kubernetesConfiguration", KubernetesConfigurationDefinition.class, false, false); - addBeanDefinitionParser("ribbonConfiguration", RibbonConfigurationDefinition.class, false, false); // errorhandler could be the sub element of camelContext or defined outside camelContext BeanDefinitionParser errorHandlerParser = new ErrorHandlerDefinitionParser(); @@ -409,6 +399,8 @@ public class CamelNamespaceHandler extends NamespaceHandlerSupport { builder.addPropertyValue("camelJMXAgent", factoryBean.getCamelJMXAgent()); builder.addPropertyValue("camelStreamCachingStrategy", factoryBean.getCamelStreamCachingStrategy()); builder.addPropertyValue("threadPoolProfiles", factoryBean.getThreadPoolProfiles()); + builder.addPropertyValue("beansFactory", factoryBean.getBeansFactory()); + builder.addPropertyValue("beans", factoryBean.getBeans()); // add any depends-on addDependsOn(factoryBean, builder); } http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-spring/src/test/java/org/apache/camel/spring/cloud/ServiceCallConfigurationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/cloud/ServiceCallConfigurationTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/cloud/ServiceCallConfigurationTest.java new file mode 100644 index 0000000..fe3371e --- /dev/null +++ b/components/camel-spring/src/test/java/org/apache/camel/spring/cloud/ServiceCallConfigurationTest.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.spring.cloud; + +import org.apache.camel.model.cloud.ServiceCallConfigurationDefinition; +import org.apache.camel.model.cloud.StaticServiceCallServiceDiscoveryConfiguration; +import org.apache.camel.spring.SpringCamelContext; +import org.junit.Test; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class ServiceCallConfigurationTest { + @Test + public void testServiceDiscoveryConfiguration() { + SpringCamelContext context = createContext("org/apache/camel/spring/cloud/ServiceCallConfigurationTest.xml"); + + ServiceCallConfigurationDefinition conf1 = context.getServiceCallConfiguration("conf1"); + assertNotNull("No ServiceCallConfiguration (1)", conf1); + assertNotNull("No ServiceDiscoveryConfiguration (1)", conf1.getServiceDiscoveryConfiguration()); + + StaticServiceCallServiceDiscoveryConfiguration discovery1 = (StaticServiceCallServiceDiscoveryConfiguration)conf1.getServiceDiscoveryConfiguration(); + assertEquals(1, discovery1.getServers().size()); + assertEquals("localhost:9091", discovery1.getServers().get(0)); + + ServiceCallConfigurationDefinition conf2 = context.getServiceCallConfiguration("conf2"); + assertNotNull("No ServiceCallConfiguration (2)", conf2); + assertNotNull("No ServiceDiscoveryConfiguration (2)", conf2.getServiceDiscoveryConfiguration()); + + StaticServiceCallServiceDiscoveryConfiguration discovery2 = (StaticServiceCallServiceDiscoveryConfiguration)conf2.getServiceDiscoveryConfiguration(); + assertEquals(2, discovery2.getServers().size()); + assertEquals("localhost:9092", discovery2.getServers().get(0)); + assertEquals("localhost:9093,localhost:9094", discovery2.getServers().get(1)); + } + + protected SpringCamelContext createContext(String classpathConfigFile) { + ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(classpathConfigFile); + + SpringCamelContext camelContext = appContext.getBean(SpringCamelContext.class); + assertNotNull("No Camel Context in file: " + classpathConfigFile, camelContext); + + return camelContext; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-spring/src/test/resources/org/apache/camel/spring/cloud/ServiceCallConfigurationTest.xml ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/cloud/ServiceCallConfigurationTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/cloud/ServiceCallConfigurationTest.xml new file mode 100644 index 0000000..efc7711 --- /dev/null +++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/cloud/ServiceCallConfigurationTest.xml @@ -0,0 +1,51 @@ +<?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"> + + <camelContext xmlns="http://camel.apache.org/schema/spring"> + + <serviceCallConfiguration id="conf1"> + <staticServiceDiscovery> + <servers>localhost:9091</servers> + </staticServiceDiscovery> + </serviceCallConfiguration> + + <serviceCallConfiguration id="conf2"> + <staticServiceDiscovery> + <servers>localhost:9092</servers> + <servers>localhost:9093,localhost:9094</servers> + </staticServiceDiscovery> + </serviceCallConfiguration> + + <route id="test1"> + <from uri="direct:start1"/> + <serviceCall name="test" configurationRef="conf1"/> + </route> + <route id="test2"> + <from uri="direct:start2"/> + <serviceCall name="test" configurationRef="conf2"/> + </route> + </camelContext> + +</beans> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/cloud/ServiceCallConfigurationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/cloud/ServiceCallConfigurationTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/cloud/ServiceCallConfigurationTest.java new file mode 100644 index 0000000..a577f88 --- /dev/null +++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/cloud/ServiceCallConfigurationTest.java @@ -0,0 +1,50 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.test.blueprint.cloud; + +import org.apache.camel.model.cloud.ServiceCallConfigurationDefinition; +import org.apache.camel.model.cloud.StaticServiceCallServiceDiscoveryConfiguration; +import org.apache.camel.test.blueprint.CamelBlueprintTestSupport; +import org.junit.Test; + +public class ServiceCallConfigurationTest extends CamelBlueprintTestSupport { + @Override + protected String getBlueprintDescriptor() { + return "org/apache/camel/test/blueprint/cloud/ServiceCallConfigurationTest.xml"; + } + + @Test + public void testServiceDiscoveryConfiguration() { + ServiceCallConfigurationDefinition conf1 = context.getServiceCallConfiguration("conf1"); + assertNotNull("No ServiceCallConfiguration (1)", conf1); + assertNotNull("No ServiceDiscoveryConfiguration (1)", conf1.getServiceDiscoveryConfiguration()); + + StaticServiceCallServiceDiscoveryConfiguration discovery1 = (StaticServiceCallServiceDiscoveryConfiguration)conf1.getServiceDiscoveryConfiguration(); + assertEquals(1, discovery1.getServers().size()); + assertEquals("localhost:9091", discovery1.getServers().get(0)); + + ServiceCallConfigurationDefinition conf2 = context.getServiceCallConfiguration("conf2"); + assertNotNull("No ServiceCallConfiguration (2)", conf2); + assertNotNull("No ServiceDiscoveryConfiguration (2)", conf2.getServiceDiscoveryConfiguration()); + + StaticServiceCallServiceDiscoveryConfiguration discovery2 = (StaticServiceCallServiceDiscoveryConfiguration)conf2.getServiceDiscoveryConfiguration(); + assertEquals(2, discovery2.getServers().size()); + assertEquals("localhost:9092", discovery2.getServers().get(0)); + assertEquals("localhost:9093,localhost:9094", discovery2.getServers().get(1)); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/cloud/ServiceCallConfigurationTest.xml ---------------------------------------------------------------------- diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/cloud/ServiceCallConfigurationTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/cloud/ServiceCallConfigurationTest.xml new file mode 100644 index 0000000..27bdc6e --- /dev/null +++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/cloud/ServiceCallConfigurationTest.xml @@ -0,0 +1,49 @@ +<?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 + https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> + + <camelContext xmlns="http://camel.apache.org/schema/blueprint"> + + <serviceCallConfiguration id="conf1"> + <staticServiceDiscovery> + <servers>localhost:9091</servers> + </staticServiceDiscovery> + </serviceCallConfiguration> + + <serviceCallConfiguration id="conf2"> + <staticServiceDiscovery> + <servers>localhost:9092</servers> + <servers>localhost:9093,localhost:9094</servers> + </staticServiceDiscovery> + </serviceCallConfiguration> + + <route id="test1"> + <from uri="direct:start1"/> + <serviceCall name="test" configurationRef="conf1"/> + </route> + <route id="test2"> + <from uri="direct:start2"/> + <serviceCall name="test" configurationRef="conf2"/> + </route> + </camelContext> + +</blueprint> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/a811f400/components/pom.xml ---------------------------------------------------------------------- diff --git a/components/pom.xml b/components/pom.xml index 0ba98f0..9852969 100644 --- a/components/pom.xml +++ b/components/pom.xml @@ -58,6 +58,9 @@ <module>camel-cxf-transport</module> <module>camel-jms</module> + <!-- build it first so it can be used by other component to test i.e. ServiceCall EIP --> + <module>camel-ribbon</module> + <!-- regular modules in alphabetic order --> <module>camel-ahc</module> <module>camel-ahc-ws</module> @@ -213,7 +216,6 @@ <module>camel-quickfix</module> <module>camel-rabbitmq</module> <module>camel-restlet</module> - <module>camel-ribbon</module> <module>camel-rmi</module> <module>camel-routebox</module> <module>camel-rss</module>