This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch cloud2 in repository https://gitbox.apache.org/repos/asf/camel.git
commit 463c929e525b28c83ec6b9cc1c85a7abb5c76957 Author: Claus Ibsen <[email protected]> AuthorDate: Fri Apr 5 16:52:51 2019 +0200 CAMEL-13380: camel-core - Move cloud out into camel-cloud component. Woprk in progress --- core/camel-cloud/pom.xml | 17 ++++++++++++ .../impl/cloud/ServiceCallProcessorFactory.java | 30 ++++++++++++---------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/core/camel-cloud/pom.xml b/core/camel-cloud/pom.xml index 28f48e5..0c88956 100644 --- a/core/camel-cloud/pom.xml +++ b/core/camel-cloud/pom.xml @@ -41,6 +41,18 @@ <dependency> <groupId>org.apache.camel</groupId> + <artifactId>spi-annotations</artifactId> + <optional>true</optional> + </dependency> + + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>meta-annotations</artifactId> + <optional>true</optional> + </dependency> + + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-core</artifactId> </dependency> @@ -62,6 +74,11 @@ </exclusion> </exclusions> </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> <!-- logging --> <dependency> diff --git a/core/camel-cloud/src/main/java/org/apache/camel/impl/cloud/ServiceCallProcessorFactory.java b/core/camel-cloud/src/main/java/org/apache/camel/impl/cloud/ServiceCallProcessorFactory.java index eb0904a..3626ef8 100644 --- a/core/camel-cloud/src/main/java/org/apache/camel/impl/cloud/ServiceCallProcessorFactory.java +++ b/core/camel-cloud/src/main/java/org/apache/camel/impl/cloud/ServiceCallProcessorFactory.java @@ -55,13 +55,17 @@ public class ServiceCallProcessorFactory extends TypedProcessorFactory<ServiceCa // Processor Factory // ***************************** + private volatile ServiceCallDefinition definition; + @Override public Processor doCreateProcessor(RouteContext routeContext, ServiceCallDefinition definition) throws Exception { + this.definition = definition; + final CamelContext camelContext = routeContext.getCamelContext(); - final ServiceDiscovery serviceDiscovery = retrieveServiceDiscovery(camelContext, definition); - final ServiceFilter serviceFilter = retrieveServiceFilter(camelContext, definition); - final ServiceChooser serviceChooser = retrieveServiceChooser(camelContext, definition); - final ServiceLoadBalancer loadBalancer = retrieveLoadBalancer(camelContext, definition); + final ServiceDiscovery serviceDiscovery = retrieveServiceDiscovery(camelContext); + final ServiceFilter serviceFilter = retrieveServiceFilter(camelContext); + final ServiceChooser serviceChooser = retrieveServiceChooser(camelContext); + final ServiceLoadBalancer loadBalancer = retrieveLoadBalancer(camelContext); CamelContextAware.trySetCamelContext(serviceDiscovery, camelContext); CamelContextAware.trySetCamelContext(serviceFilter, camelContext); @@ -82,7 +86,7 @@ public class ServiceCallProcessorFactory extends TypedProcessorFactory<ServiceCa // The component configured on EIP takes precedence vs configured on configuration. String endpointScheme = definition.getComponent(); if (endpointScheme == null) { - ServiceCallConfigurationDefinition conf = retrieveConfig(camelContext, definition); + ServiceCallConfigurationDefinition conf = retrieveConfig(camelContext); if (conf != null) { endpointScheme = conf.getComponent(); } @@ -98,7 +102,7 @@ public class ServiceCallProcessorFactory extends TypedProcessorFactory<ServiceCa // The uri configured on EIP takes precedence vs configured on configuration. String endpointUri = definition.getUri(); if (endpointUri == null) { - ServiceCallConfigurationDefinition conf = retrieveConfig(camelContext, definition); + ServiceCallConfigurationDefinition conf = retrieveConfig(camelContext); if (conf != null) { endpointUri = conf.getUri(); } @@ -123,7 +127,7 @@ public class ServiceCallProcessorFactory extends TypedProcessorFactory<ServiceCa endpointUri, definition.getPattern(), loadBalancer, - retrieveExpression(camelContext, endpointScheme, definition)); + retrieveExpression(camelContext, endpointScheme)); } // ***************************** @@ -152,7 +156,7 @@ public class ServiceCallProcessorFactory extends TypedProcessorFactory<ServiceCa return config; } - private ServiceCallConfigurationDefinition retrieveConfig(CamelContext camelContext, ServiceCallDefinition definition) { + private ServiceCallConfigurationDefinition retrieveConfig(CamelContext camelContext) { ServiceCallConfigurationDefinition config = null; if (definition.getConfigurationRef() != null) { // lookup in registry firstNotNull @@ -190,7 +194,7 @@ public class ServiceCallProcessorFactory extends TypedProcessorFactory<ServiceCa return answer; } - private ServiceDiscovery retrieveServiceDiscovery(CamelContext camelContext, ServiceCallDefinition definition) throws Exception { + private ServiceDiscovery retrieveServiceDiscovery(CamelContext camelContext) throws Exception { return Suppliers.firstNotNull( () -> (definition.getServiceDiscoveryConfiguration() != null) ? definition.getServiceDiscoveryConfiguration().newInstance(camelContext) : null, // Local configuration @@ -246,7 +250,7 @@ public class ServiceCallProcessorFactory extends TypedProcessorFactory<ServiceCa return answer; } - private ServiceFilter retrieveServiceFilter(CamelContext camelContext, ServiceCallDefinition definition) throws Exception { + private ServiceFilter retrieveServiceFilter(CamelContext camelContext) throws Exception { return Suppliers.firstNotNull( () -> (definition.getServiceFilterConfiguration() != null) ? definition.getServiceFilterConfiguration().newInstance(camelContext) : null, // Local configuration @@ -296,7 +300,7 @@ public class ServiceCallProcessorFactory extends TypedProcessorFactory<ServiceCa return answer; } - private ServiceChooser retrieveServiceChooser(CamelContext camelContext, ServiceCallDefinition definition) throws Exception { + private ServiceChooser retrieveServiceChooser(CamelContext camelContext) throws Exception { return Suppliers.firstNotNull( // Local configuration () -> retrieve(ServiceChooser.class, camelContext, definition::getServiceChooser, definition::getServiceChooserRef), @@ -338,7 +342,7 @@ public class ServiceCallProcessorFactory extends TypedProcessorFactory<ServiceCa return answer; } - private ServiceLoadBalancer retrieveLoadBalancer(CamelContext camelContext, ServiceCallDefinition definition) throws Exception { + private ServiceLoadBalancer retrieveLoadBalancer(CamelContext camelContext) throws Exception { return Suppliers.firstNotNull( () -> (definition.getLoadBalancerConfiguration() != null) ? definition.getLoadBalancerConfiguration().newInstance(camelContext) : null, // Local configuration @@ -381,7 +385,7 @@ public class ServiceCallProcessorFactory extends TypedProcessorFactory<ServiceCa return answer; } - private Expression retrieveExpression(CamelContext camelContext, String component, ServiceCallDefinition definition) throws Exception { + private Expression retrieveExpression(CamelContext camelContext, String component) throws Exception { Optional<Expression> expression = Suppliers.firstNotNull( () -> (definition.getExpressionConfiguration() != null) ? definition.getExpressionConfiguration().newInstance(camelContext) : null, // Local configuration
