This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch bean in repository https://gitbox.apache.org/repos/asf/camel.git
commit e7cc6e1b3266be002e9b55c2063ba20e91a67282 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Thu Apr 25 09:58:40 2019 +0200 CAMEL-13449: camel3 - Move bean component out of camel-core --- MIGRATION.md | 3 + .../camel-bean}/src/main/docs/bean-component.adoc | 0 .../camel-bean}/src/main/docs/class-component.adoc | 0 .../apache/camel/component/bean/MethodInfo.java | 33 +++--- .../apache/camel/component/bean/ParameterInfo.java | 3 + .../java/org/apache/camel/language/bean}/Bean.java | 2 +- .../apache/camel/language/bean/BeanExpression.java | 0 .../apache/camel/language/bean/BeanLanguage.java | 0 .../bean/RuntimeBeanExpressionException.java | 0 .../org/apache/camel/language/bean/package.html | 0 .../camel/spi/AnnotationBasedProcessorFactory.java | 7 +- .../DefaultAnnotationBasedProcessorFactory.java | 7 +- .../camel/impl/SubscribeMethodProcessor.java | 2 + .../org/apache/camel/processor/RoutingSlip.java | 19 +-- .../file/FileConsumerMoveExpressionTest.java | 1 - .../language/BeanAnnotationParameterTest.java | 1 + .../language/BeanAnnotationParameterTwoTest.java | 1 + .../springboot/BeanComponentAutoConfiguration.java | 128 +++++++++++++++++++++ .../springboot/BeanComponentConfiguration.java | 68 +++++++++++ .../ClassComponentAutoConfiguration.java | 128 +++++++++++++++++++++ .../springboot/ClassComponentConfiguration.java | 68 +++++++++++ .../springboot/BeanLanguageAutoConfiguration.java | 117 +++++++++++++++++++ .../bean/springboot/BeanLanguageConfiguration.java | 52 +++++++++ .../src/main/resources/META-INF/spring.factories | 23 ++++ 24 files changed, 630 insertions(+), 33 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index 533d903..2b3dd26 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -33,6 +33,7 @@ You may find how to do that in the examples. We have also modularized many of the core components and moved them out of `camel-core` to individual components: +- camel-bean - camel-browse - camel-controlbus - camel-dataformat @@ -220,6 +221,8 @@ The annotation `org.apache.camel.language.XPath` has been moved to `org.apache.c The exception `org.apache.camel.builder.xml.InvalidXPathExpression` has been renamed to `org.apache.camel.language.xpath.InvalidXPathException` and in the `camel-xpath` JAR. +The annotation `org.apache.camel.language.Bean` has been moved to `org.apache.camel.language.bean.Bean` and in the `camel-bean` JAR. + #### camel-test If you are using camel-test and override the `createRegistry` method, for example to register beans from the `JndiRegisty` class, then this is no longer necessary, and instead diff --git a/core/camel-core/src/main/docs/bean-component.adoc b/components/camel-bean/src/main/docs/bean-component.adoc similarity index 100% rename from core/camel-core/src/main/docs/bean-component.adoc rename to components/camel-bean/src/main/docs/bean-component.adoc diff --git a/core/camel-core/src/main/docs/class-component.adoc b/components/camel-bean/src/main/docs/class-component.adoc similarity index 100% rename from core/camel-core/src/main/docs/class-component.adoc rename to components/camel-bean/src/main/docs/class-component.adoc diff --git a/components/camel-bean/src/main/java/org/apache/camel/component/bean/MethodInfo.java b/components/camel-bean/src/main/java/org/apache/camel/component/bean/MethodInfo.java index 317acdf..8a7a443 100644 --- a/components/camel-bean/src/main/java/org/apache/camel/component/bean/MethodInfo.java +++ b/components/camel-bean/src/main/java/org/apache/camel/component/bean/MethodInfo.java @@ -32,6 +32,7 @@ import java.util.concurrent.Callable; import java.util.concurrent.CompletionStage; import org.apache.camel.AsyncCallback; +import org.apache.camel.AsyncProcessor; import org.apache.camel.CamelContext; import org.apache.camel.Exchange; import org.apache.camel.ExchangePattern; @@ -43,10 +44,6 @@ import org.apache.camel.Pattern; import org.apache.camel.RuntimeCamelException; import org.apache.camel.RuntimeExchangeException; import org.apache.camel.StreamCache; -// TODO: avoid these imports -import org.apache.camel.processor.DynamicRouter; -import org.apache.camel.processor.RecipientList; -import org.apache.camel.processor.RoutingSlip; import org.apache.camel.support.DefaultMessage; import org.apache.camel.support.ExchangeHelper; import org.apache.camel.support.ExpressionAdapter; @@ -75,9 +72,9 @@ public class MethodInfo { private final boolean hasHandlerAnnotation; private Expression parametersExpression; private ExchangePattern pattern = ExchangePattern.InOut; - private RecipientList recipientList; - private RoutingSlip routingSlip; - private DynamicRouter dynamicRouter; + private AsyncProcessor recipientList; + private AsyncProcessor routingSlip; + private AsyncProcessor dynamicRouter; /** * Adapter to invoke the method which has been annotated with the @DynamicRouter @@ -127,7 +124,7 @@ public class MethodInfo { org.apache.camel.RoutingSlip routingSlipAnnotation = (org.apache.camel.RoutingSlip)collectedMethodAnnotation.get(org.apache.camel.RoutingSlip.class); if (routingSlipAnnotation != null && matchContext(routingSlipAnnotation.context())) { - routingSlip = (RoutingSlip) camelContext.getAnnotationBasedProcessorFactory().createRoutingSlip(camelContext, routingSlipAnnotation); + routingSlip = camelContext.getAnnotationBasedProcessorFactory().createRoutingSlip(camelContext, routingSlipAnnotation); // add created routingSlip as a service so we have its lifecycle managed try { camelContext.addService(routingSlip); @@ -140,7 +137,7 @@ public class MethodInfo { (org.apache.camel.DynamicRouter)collectedMethodAnnotation.get(org.apache.camel.DynamicRouter.class); if (dynamicRouterAnnotation != null && matchContext(dynamicRouterAnnotation.context())) { - dynamicRouter = (DynamicRouter) camelContext.getAnnotationBasedProcessorFactory().createDynamicRouter(camelContext, dynamicRouterAnnotation); + dynamicRouter = camelContext.getAnnotationBasedProcessorFactory().createDynamicRouter(camelContext, dynamicRouterAnnotation); // add created dynamicRouter as a service so we have its lifecycle managed try { camelContext.addService(dynamicRouter); @@ -153,7 +150,7 @@ public class MethodInfo { (org.apache.camel.RecipientList)collectedMethodAnnotation.get(org.apache.camel.RecipientList.class); if (recipientListAnnotation != null && matchContext(recipientListAnnotation.context())) { - recipientList = (RecipientList) camelContext.getAnnotationBasedProcessorFactory().createRecipientList(camelContext, recipientListAnnotation); + recipientList = camelContext.getAnnotationBasedProcessorFactory().createRecipientList(camelContext, recipientListAnnotation); // add created recipientList as a service so we have its lifecycle managed try { camelContext.addService(recipientList); @@ -242,12 +239,14 @@ public class MethodInfo { private boolean doProceed(AsyncCallback callback) throws Exception { // dynamic router should be invoked beforehand if (dynamicRouter != null) { - if (!dynamicRouter.isStarted()) { + if (!ServiceHelper.isStarted(dynamicRouter)) { ServiceHelper.startService(dynamicRouter); } + // TODO: Maybe use a new constant than EVALUATE_EXPRESSION_RESULT // use a expression which invokes the method to be used by dynamic router Expression expression = new DynamicRouterExpression(pojo); - return dynamicRouter.doRoutingSlip(exchange, expression, callback); + exchange.setProperty(Exchange.EVALUATE_EXPRESSION_RESULT, expression); + return dynamicRouter.process(exchange, callback); } // invoke pojo @@ -270,16 +269,18 @@ public class MethodInfo { if (recipientList != null) { // ensure its started - if (!recipientList.isStarted()) { + if (!ServiceHelper.isStarted(recipientList)) { ServiceHelper.startService(recipientList); } - return recipientList.sendToRecipientList(exchange, result, callback); + exchange.setProperty(Exchange.EVALUATE_EXPRESSION_RESULT, result); + return recipientList.process(exchange, callback); } if (routingSlip != null) { - if (!routingSlip.isStarted()) { + if (!ServiceHelper.isStarted(routingSlip)) { ServiceHelper.startService(routingSlip); } - return routingSlip.doRoutingSlip(exchange, result, callback); + exchange.setProperty(Exchange.EVALUATE_EXPRESSION_RESULT, result); + return routingSlip.process(exchange, callback); } //If it's Java 8 async result diff --git a/components/camel-bean/src/main/java/org/apache/camel/component/bean/ParameterInfo.java b/components/camel-bean/src/main/java/org/apache/camel/component/bean/ParameterInfo.java index 6adb2da..b747271 100644 --- a/components/camel-bean/src/main/java/org/apache/camel/component/bean/ParameterInfo.java +++ b/components/camel-bean/src/main/java/org/apache/camel/component/bean/ParameterInfo.java @@ -25,6 +25,9 @@ import org.apache.camel.Expression; * Parameter information to be used for method invocation. */ public class ParameterInfo { + + // TODO: Move to camel-support + private final int index; private final Class<?> type; private final Annotation[] annotations; diff --git a/core/camel-core/src/main/java/org/apache/camel/language/Bean.java b/components/camel-bean/src/main/java/org/apache/camel/language/bean/Bean.java similarity index 97% rename from core/camel-core/src/main/java/org/apache/camel/language/Bean.java rename to components/camel-bean/src/main/java/org/apache/camel/language/bean/Bean.java index e82fbae..7d494d1 100644 --- a/core/camel-core/src/main/java/org/apache/camel/language/Bean.java +++ b/components/camel-bean/src/main/java/org/apache/camel/language/bean/Bean.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.language; +package org.apache.camel.language.bean; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; diff --git a/core/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java b/components/camel-bean/src/main/java/org/apache/camel/language/bean/BeanExpression.java similarity index 100% rename from core/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java rename to components/camel-bean/src/main/java/org/apache/camel/language/bean/BeanExpression.java diff --git a/core/camel-core/src/main/java/org/apache/camel/language/bean/BeanLanguage.java b/components/camel-bean/src/main/java/org/apache/camel/language/bean/BeanLanguage.java similarity index 100% rename from core/camel-core/src/main/java/org/apache/camel/language/bean/BeanLanguage.java rename to components/camel-bean/src/main/java/org/apache/camel/language/bean/BeanLanguage.java diff --git a/core/camel-core/src/main/java/org/apache/camel/language/bean/RuntimeBeanExpressionException.java b/components/camel-bean/src/main/java/org/apache/camel/language/bean/RuntimeBeanExpressionException.java similarity index 100% rename from core/camel-core/src/main/java/org/apache/camel/language/bean/RuntimeBeanExpressionException.java rename to components/camel-bean/src/main/java/org/apache/camel/language/bean/RuntimeBeanExpressionException.java diff --git a/core/camel-core/src/main/java/org/apache/camel/language/bean/package.html b/components/camel-bean/src/main/java/org/apache/camel/language/bean/package.html similarity index 100% rename from core/camel-core/src/main/java/org/apache/camel/language/bean/package.html rename to components/camel-bean/src/main/java/org/apache/camel/language/bean/package.html diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/AnnotationBasedProcessorFactory.java b/core/camel-api/src/main/java/org/apache/camel/spi/AnnotationBasedProcessorFactory.java index 856d7a0..c720652 100644 --- a/core/camel-api/src/main/java/org/apache/camel/spi/AnnotationBasedProcessorFactory.java +++ b/core/camel-api/src/main/java/org/apache/camel/spi/AnnotationBasedProcessorFactory.java @@ -16,6 +16,7 @@ */ package org.apache.camel.spi; +import org.apache.camel.AsyncProcessor; import org.apache.camel.CamelContext; import org.apache.camel.DynamicRouter; import org.apache.camel.Processor; @@ -30,16 +31,16 @@ public interface AnnotationBasedProcessorFactory { /** * Creates dynamic router processor from the configured annotation. */ - Processor createDynamicRouter(CamelContext camelContext, DynamicRouter annotation); + AsyncProcessor createDynamicRouter(CamelContext camelContext, DynamicRouter annotation); /** * Creates recipient list processor from the configured annotation. */ - Processor createRecipientList(CamelContext camelContext, RecipientList annotation); + AsyncProcessor createRecipientList(CamelContext camelContext, RecipientList annotation); /** * Creates routing slip processor from the configured annotation. */ - Processor createRoutingSlip(CamelContext camelContext, RoutingSlip annotation); + AsyncProcessor createRoutingSlip(CamelContext camelContext, RoutingSlip annotation); } diff --git a/core/camel-core/src/main/java/org/apache/camel/impl/DefaultAnnotationBasedProcessorFactory.java b/core/camel-core/src/main/java/org/apache/camel/impl/DefaultAnnotationBasedProcessorFactory.java index 512da98..21945ff 100644 --- a/core/camel-core/src/main/java/org/apache/camel/impl/DefaultAnnotationBasedProcessorFactory.java +++ b/core/camel-core/src/main/java/org/apache/camel/impl/DefaultAnnotationBasedProcessorFactory.java @@ -19,6 +19,7 @@ package org.apache.camel.impl; import java.util.concurrent.ExecutorService; import org.apache.camel.AggregationStrategy; +import org.apache.camel.AsyncProcessor; import org.apache.camel.CamelContext; import org.apache.camel.DynamicRouter; import org.apache.camel.Processor; @@ -31,7 +32,7 @@ import org.apache.camel.util.ObjectHelper; public final class DefaultAnnotationBasedProcessorFactory implements AnnotationBasedProcessorFactory { @Override - public Processor createDynamicRouter(CamelContext camelContext, DynamicRouter annotation) { + public AsyncProcessor createDynamicRouter(CamelContext camelContext, DynamicRouter annotation) { org.apache.camel.processor.DynamicRouter dynamicRouter = new org.apache.camel.processor.DynamicRouter(camelContext); dynamicRouter.setDelimiter(annotation.delimiter()); dynamicRouter.setIgnoreInvalidEndpoints(annotation.ignoreInvalidEndpoints()); @@ -40,7 +41,7 @@ public final class DefaultAnnotationBasedProcessorFactory implements AnnotationB } @Override - public Processor createRecipientList(CamelContext camelContext, RecipientList annotation) { + public AsyncProcessor createRecipientList(CamelContext camelContext, RecipientList annotation) { org.apache.camel.processor.RecipientList recipientList = new org.apache.camel.processor.RecipientList(camelContext, annotation.delimiter()); recipientList.setStopOnException(annotation.stopOnException()); recipientList.setStopOnAggregateException(annotation.stopOnAggregateException()); @@ -76,7 +77,7 @@ public final class DefaultAnnotationBasedProcessorFactory implements AnnotationB } @Override - public Processor createRoutingSlip(CamelContext camelContext, RoutingSlip annotation) { + public AsyncProcessor createRoutingSlip(CamelContext camelContext, RoutingSlip annotation) { org.apache.camel.processor.RoutingSlip routingSlip = new org.apache.camel.processor.RoutingSlip(camelContext); routingSlip.setDelimiter(annotation.delimiter()); routingSlip.setIgnoreInvalidEndpoints(annotation.ignoreInvalidEndpoints()); diff --git a/core/camel-core/src/main/java/org/apache/camel/impl/SubscribeMethodProcessor.java b/core/camel-core/src/main/java/org/apache/camel/impl/SubscribeMethodProcessor.java index 00b98eb..a9cf35e 100644 --- a/core/camel-core/src/main/java/org/apache/camel/impl/SubscribeMethodProcessor.java +++ b/core/camel-core/src/main/java/org/apache/camel/impl/SubscribeMethodProcessor.java @@ -43,6 +43,8 @@ import org.apache.camel.util.ObjectHelper; */ public final class SubscribeMethodProcessor extends AsyncProcessorSupport implements Navigate<Processor> { + // TODO: requires camel-bean + private final Endpoint endpoint; private final Map<AsyncProcessor, Predicate> methods = new LinkedHashMap<>(); diff --git a/core/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java b/core/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java index 7e1c343..c786656 100644 --- a/core/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java +++ b/core/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java @@ -63,7 +63,6 @@ public class RoutingSlip extends AsyncProcessorSupport implements Traceable, IdA protected String uriDelimiter; protected final CamelContext camelContext; protected AsyncProcessor errorHandler; - protected SendDynamicProcessor sendDynamicProcessor; /** * The iterator to be used for retrieving the next routing slip(s) to be used. @@ -163,15 +162,17 @@ public class RoutingSlip extends AsyncProcessorSupport implements Traceable, IdA return true; } - return doRoutingSlipWithExpression(exchange, this.expression, callback); - } - - public boolean doRoutingSlip(Exchange exchange, Object routingSlip, AsyncCallback callback) { - if (routingSlip instanceof Expression) { - return doRoutingSlipWithExpression(exchange, (Expression) routingSlip, callback); - } else { - return doRoutingSlipWithExpression(exchange, ExpressionBuilder.constantExpression(routingSlip), callback); + Expression exp = expression; + Object slip = exchange.removeProperty(Exchange.EVALUATE_EXPRESSION_RESULT); + if (slip != null) { + if (slip instanceof Expression) { + exp = (Expression) slip; + } else { + exp = ExpressionBuilder.constantExpression(slip); + } } + + return doRoutingSlipWithExpression(exchange, exp, callback); } /** diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerMoveExpressionTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerMoveExpressionTest.java index 5fed08e..90fe358 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerMoveExpressionTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerMoveExpressionTest.java @@ -23,7 +23,6 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.impl.JndiRegistry; import org.apache.camel.language.bean.BeanExpression; -import org.apache.camel.language.bean.BeanLanguage; import org.junit.Before; import org.junit.Test; diff --git a/core/camel-core/src/test/java/org/apache/camel/language/BeanAnnotationParameterTest.java b/core/camel-core/src/test/java/org/apache/camel/language/BeanAnnotationParameterTest.java index 4e3183b..3226011 100644 --- a/core/camel-core/src/test/java/org/apache/camel/language/BeanAnnotationParameterTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/language/BeanAnnotationParameterTest.java @@ -20,6 +20,7 @@ import org.apache.camel.ContextTestSupport; import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.JndiRegistry; +import org.apache.camel.language.bean.Bean; import org.junit.Test; /** diff --git a/core/camel-core/src/test/java/org/apache/camel/language/BeanAnnotationParameterTwoTest.java b/core/camel-core/src/test/java/org/apache/camel/language/BeanAnnotationParameterTwoTest.java index 4d21b76..089e3aa 100644 --- a/core/camel-core/src/test/java/org/apache/camel/language/BeanAnnotationParameterTwoTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/language/BeanAnnotationParameterTwoTest.java @@ -20,6 +20,7 @@ import org.apache.camel.ContextTestSupport; import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.JndiRegistry; +import org.apache.camel.language.bean.Bean; import org.junit.Test; /** diff --git a/platforms/spring-boot/components-starter/camel-bean-starter/src/main/java/org/apache/camel/component/bean/springboot/BeanComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-bean-starter/src/main/java/org/apache/camel/component/bean/springboot/BeanComponentAutoConfiguration.java new file mode 100644 index 0000000..e078424 --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-bean-starter/src/main/java/org/apache/camel/component/bean/springboot/BeanComponentAutoConfiguration.java @@ -0,0 +1,128 @@ +/* + * 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.bean.springboot; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.annotation.Generated; +import org.apache.camel.CamelContext; +import org.apache.camel.component.bean.BeanComponent; +import org.apache.camel.spi.ComponentCustomizer; +import org.apache.camel.spi.HasId; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.apache.camel.spring.boot.ComponentConfigurationProperties; +import org.apache.camel.spring.boot.util.CamelPropertiesHelper; +import org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans; +import org.apache.camel.spring.boot.util.GroupCondition; +import org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator; +import org.apache.camel.support.IntrospectionSupport; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; + +/** + * Generated by camel-package-maven-plugin - do not edit this file! + */ +@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") +@Configuration +@Conditional({ConditionalOnCamelContextAndAutoConfigurationBeans.class, + BeanComponentAutoConfiguration.GroupConditions.class}) +@AutoConfigureAfter(CamelAutoConfiguration.class) +@EnableConfigurationProperties({ComponentConfigurationProperties.class, + BeanComponentConfiguration.class}) +public class BeanComponentAutoConfiguration { + + private static final Logger LOGGER = LoggerFactory + .getLogger(BeanComponentAutoConfiguration.class); + @Autowired + private ApplicationContext applicationContext; + @Autowired + private CamelContext camelContext; + @Autowired + private BeanComponentConfiguration configuration; + @Autowired(required = false) + private List<ComponentCustomizer<BeanComponent>> customizers; + + static class GroupConditions extends GroupCondition { + public GroupConditions() { + super("camel.component", "camel.component.bean"); + } + } + + @Lazy + @Bean(name = "bean-component") + @ConditionalOnMissingBean(BeanComponent.class) + public BeanComponent configureBeanComponent() throws Exception { + BeanComponent component = new BeanComponent(); + component.setCamelContext(camelContext); + Map<String, Object> parameters = new HashMap<>(); + IntrospectionSupport.getProperties(configuration, parameters, null, + false); + for (Map.Entry<String, Object> entry : parameters.entrySet()) { + Object value = entry.getValue(); + Class<?> paramClass = value.getClass(); + if (paramClass.getName().endsWith("NestedConfiguration")) { + Class nestedClass = null; + try { + nestedClass = (Class) paramClass.getDeclaredField( + "CAMEL_NESTED_CLASS").get(null); + HashMap<String, Object> nestedParameters = new HashMap<>(); + IntrospectionSupport.getProperties(value, nestedParameters, + null, false); + Object nestedProperty = nestedClass.newInstance(); + CamelPropertiesHelper.setCamelProperties(camelContext, + nestedProperty, nestedParameters, false); + entry.setValue(nestedProperty); + } catch (NoSuchFieldException e) { + } + } + } + CamelPropertiesHelper.setCamelProperties(camelContext, component, + parameters, false); + if (ObjectHelper.isNotEmpty(customizers)) { + for (ComponentCustomizer<BeanComponent> customizer : customizers) { + boolean useCustomizer = (customizer instanceof HasId) + ? HierarchicalPropertiesEvaluator.evaluate( + applicationContext.getEnvironment(), + "camel.component.customizer", + "camel.component.bean.customizer", + ((HasId) customizer).getId()) + : HierarchicalPropertiesEvaluator.evaluate( + applicationContext.getEnvironment(), + "camel.component.customizer", + "camel.component.bean.customizer"); + if (useCustomizer) { + LOGGER.debug("Configure component {}, with customizer {}", + component, customizer); + customizer.customize(component); + } + } + } + return component; + } +} \ No newline at end of file diff --git a/platforms/spring-boot/components-starter/camel-bean-starter/src/main/java/org/apache/camel/component/bean/springboot/BeanComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-bean-starter/src/main/java/org/apache/camel/component/bean/springboot/BeanComponentConfiguration.java new file mode 100644 index 0000000..3d802bc --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-bean-starter/src/main/java/org/apache/camel/component/bean/springboot/BeanComponentConfiguration.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.bean.springboot; + +import javax.annotation.Generated; +import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * The bean component is for invoking Java beans from Camel. + * + * Generated by camel-package-maven-plugin - do not edit this file! + */ +@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") +@ConfigurationProperties(prefix = "camel.component.bean") +public class BeanComponentConfiguration + extends + ComponentConfigurationPropertiesCommon { + + /** + * Whether to enable auto configuration of the bean component. This is + * enabled by default. + */ + private Boolean enabled; + /** + * If enabled, Camel will cache the result of the first Registry look-up. + * Cache can be enabled if the bean in the Registry is defined as a + * singleton scope. + */ + private Boolean cache; + /** + * Whether the component should resolve property placeholders on itself when + * starting. Only properties which are of String type can use property + * placeholders. + */ + private Boolean resolvePropertyPlaceholders = true; + + public Boolean getCache() { + return cache; + } + + public void setCache(Boolean cache) { + this.cache = cache; + } + + public Boolean getResolvePropertyPlaceholders() { + return resolvePropertyPlaceholders; + } + + public void setResolvePropertyPlaceholders( + Boolean resolvePropertyPlaceholders) { + this.resolvePropertyPlaceholders = resolvePropertyPlaceholders; + } +} \ No newline at end of file diff --git a/platforms/spring-boot/components-starter/camel-bean-starter/src/main/java/org/apache/camel/component/beanclass/springboot/ClassComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-bean-starter/src/main/java/org/apache/camel/component/beanclass/springboot/ClassComponentAutoConfiguration.java new file mode 100644 index 0000000..aeb6a59 --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-bean-starter/src/main/java/org/apache/camel/component/beanclass/springboot/ClassComponentAutoConfiguration.java @@ -0,0 +1,128 @@ +/* + * 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.beanclass.springboot; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.annotation.Generated; +import org.apache.camel.CamelContext; +import org.apache.camel.component.beanclass.ClassComponent; +import org.apache.camel.spi.ComponentCustomizer; +import org.apache.camel.spi.HasId; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.apache.camel.spring.boot.ComponentConfigurationProperties; +import org.apache.camel.spring.boot.util.CamelPropertiesHelper; +import org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans; +import org.apache.camel.spring.boot.util.GroupCondition; +import org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator; +import org.apache.camel.support.IntrospectionSupport; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; + +/** + * Generated by camel-package-maven-plugin - do not edit this file! + */ +@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") +@Configuration +@Conditional({ConditionalOnCamelContextAndAutoConfigurationBeans.class, + ClassComponentAutoConfiguration.GroupConditions.class}) +@AutoConfigureAfter(CamelAutoConfiguration.class) +@EnableConfigurationProperties({ComponentConfigurationProperties.class, + ClassComponentConfiguration.class}) +public class ClassComponentAutoConfiguration { + + private static final Logger LOGGER = LoggerFactory + .getLogger(ClassComponentAutoConfiguration.class); + @Autowired + private ApplicationContext applicationContext; + @Autowired + private CamelContext camelContext; + @Autowired + private ClassComponentConfiguration configuration; + @Autowired(required = false) + private List<ComponentCustomizer<ClassComponent>> customizers; + + static class GroupConditions extends GroupCondition { + public GroupConditions() { + super("camel.component", "camel.component.class"); + } + } + + @Lazy + @Bean(name = "class-component") + @ConditionalOnMissingBean(ClassComponent.class) + public ClassComponent configureClassComponent() throws Exception { + ClassComponent component = new ClassComponent(); + component.setCamelContext(camelContext); + Map<String, Object> parameters = new HashMap<>(); + IntrospectionSupport.getProperties(configuration, parameters, null, + false); + for (Map.Entry<String, Object> entry : parameters.entrySet()) { + Object value = entry.getValue(); + Class<?> paramClass = value.getClass(); + if (paramClass.getName().endsWith("NestedConfiguration")) { + Class nestedClass = null; + try { + nestedClass = (Class) paramClass.getDeclaredField( + "CAMEL_NESTED_CLASS").get(null); + HashMap<String, Object> nestedParameters = new HashMap<>(); + IntrospectionSupport.getProperties(value, nestedParameters, + null, false); + Object nestedProperty = nestedClass.newInstance(); + CamelPropertiesHelper.setCamelProperties(camelContext, + nestedProperty, nestedParameters, false); + entry.setValue(nestedProperty); + } catch (NoSuchFieldException e) { + } + } + } + CamelPropertiesHelper.setCamelProperties(camelContext, component, + parameters, false); + if (ObjectHelper.isNotEmpty(customizers)) { + for (ComponentCustomizer<ClassComponent> customizer : customizers) { + boolean useCustomizer = (customizer instanceof HasId) + ? HierarchicalPropertiesEvaluator.evaluate( + applicationContext.getEnvironment(), + "camel.component.customizer", + "camel.component.class.customizer", + ((HasId) customizer).getId()) + : HierarchicalPropertiesEvaluator.evaluate( + applicationContext.getEnvironment(), + "camel.component.customizer", + "camel.component.class.customizer"); + if (useCustomizer) { + LOGGER.debug("Configure component {}, with customizer {}", + component, customizer); + customizer.customize(component); + } + } + } + return component; + } +} \ No newline at end of file diff --git a/platforms/spring-boot/components-starter/camel-bean-starter/src/main/java/org/apache/camel/component/beanclass/springboot/ClassComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-bean-starter/src/main/java/org/apache/camel/component/beanclass/springboot/ClassComponentConfiguration.java new file mode 100644 index 0000000..cb083c8 --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-bean-starter/src/main/java/org/apache/camel/component/beanclass/springboot/ClassComponentConfiguration.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.beanclass.springboot; + +import javax.annotation.Generated; +import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * The Class Component is for invoking Java Classes (Java beans) from Camel. + * + * Generated by camel-package-maven-plugin - do not edit this file! + */ +@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") +@ConfigurationProperties(prefix = "camel.component.class") +public class ClassComponentConfiguration + extends + ComponentConfigurationPropertiesCommon { + + /** + * Whether to enable auto configuration of the class component. This is + * enabled by default. + */ + private Boolean enabled; + /** + * If enabled, Camel will cache the result of the first Registry look-up. + * Cache can be enabled if the bean in the Registry is defined as a + * singleton scope. + */ + private Boolean cache; + /** + * Whether the component should resolve property placeholders on itself when + * starting. Only properties which are of String type can use property + * placeholders. + */ + private Boolean resolvePropertyPlaceholders = true; + + public Boolean getCache() { + return cache; + } + + public void setCache(Boolean cache) { + this.cache = cache; + } + + public Boolean getResolvePropertyPlaceholders() { + return resolvePropertyPlaceholders; + } + + public void setResolvePropertyPlaceholders( + Boolean resolvePropertyPlaceholders) { + this.resolvePropertyPlaceholders = resolvePropertyPlaceholders; + } +} \ No newline at end of file diff --git a/platforms/spring-boot/components-starter/camel-bean-starter/src/main/java/org/apache/camel/language/bean/springboot/BeanLanguageAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-bean-starter/src/main/java/org/apache/camel/language/bean/springboot/BeanLanguageAutoConfiguration.java new file mode 100644 index 0000000..c3b0db8 --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-bean-starter/src/main/java/org/apache/camel/language/bean/springboot/BeanLanguageAutoConfiguration.java @@ -0,0 +1,117 @@ +/* + * 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.language.bean.springboot; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.annotation.Generated; +import org.apache.camel.CamelContext; +import org.apache.camel.CamelContextAware; +import org.apache.camel.language.bean.BeanLanguage; +import org.apache.camel.spi.HasId; +import org.apache.camel.spi.LanguageCustomizer; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.apache.camel.spring.boot.LanguageConfigurationProperties; +import org.apache.camel.spring.boot.util.CamelPropertiesHelper; +import org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans; +import org.apache.camel.spring.boot.util.GroupCondition; +import org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator; +import org.apache.camel.support.IntrospectionSupport; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Scope; + +/** + * Generated by camel-package-maven-plugin - do not edit this file! + */ +@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") +@Configuration +@Conditional({ConditionalOnCamelContextAndAutoConfigurationBeans.class, + BeanLanguageAutoConfiguration.GroupConditions.class}) +@AutoConfigureAfter(CamelAutoConfiguration.class) +@EnableConfigurationProperties({LanguageConfigurationProperties.class, + BeanLanguageConfiguration.class}) +public class BeanLanguageAutoConfiguration { + + private static final Logger LOGGER = LoggerFactory + .getLogger(BeanLanguageAutoConfiguration.class); + @Autowired + private ApplicationContext applicationContext; + @Autowired + private CamelContext camelContext; + @Autowired + private BeanLanguageConfiguration configuration; + @Autowired(required = false) + private List<LanguageCustomizer<BeanLanguage>> customizers; + + static class GroupConditions extends GroupCondition { + public GroupConditions() { + super("camel.component", "camel.component.bean"); + } + } + + @Bean(name = "bean-language") + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + @ConditionalOnMissingBean(BeanLanguage.class) + public BeanLanguage configureBeanLanguage() throws Exception { + BeanLanguage language = new BeanLanguage(); + if (CamelContextAware.class.isAssignableFrom(BeanLanguage.class)) { + CamelContextAware contextAware = CamelContextAware.class + .cast(language); + if (contextAware != null) { + contextAware.setCamelContext(camelContext); + } + } + Map<String, Object> parameters = new HashMap<>(); + IntrospectionSupport.getProperties(configuration, parameters, null, + false); + CamelPropertiesHelper.setCamelProperties(camelContext, language, + parameters, false); + if (ObjectHelper.isNotEmpty(customizers)) { + for (LanguageCustomizer<BeanLanguage> customizer : customizers) { + boolean useCustomizer = (customizer instanceof HasId) + ? HierarchicalPropertiesEvaluator.evaluate( + applicationContext.getEnvironment(), + "camel.language.customizer", + "camel.language.bean.customizer", + ((HasId) customizer).getId()) + : HierarchicalPropertiesEvaluator.evaluate( + applicationContext.getEnvironment(), + "camel.language.customizer", + "camel.language.bean.customizer"); + if (useCustomizer) { + LOGGER.debug("Configure language {}, with customizer {}", + language, customizer); + customizer.customize(language); + } + } + } + return language; + } +} \ No newline at end of file diff --git a/platforms/spring-boot/components-starter/camel-bean-starter/src/main/java/org/apache/camel/language/bean/springboot/BeanLanguageConfiguration.java b/platforms/spring-boot/components-starter/camel-bean-starter/src/main/java/org/apache/camel/language/bean/springboot/BeanLanguageConfiguration.java new file mode 100644 index 0000000..8e28050 --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-bean-starter/src/main/java/org/apache/camel/language/bean/springboot/BeanLanguageConfiguration.java @@ -0,0 +1,52 @@ +/* + * 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.language.bean.springboot; + +import javax.annotation.Generated; +import org.apache.camel.spring.boot.LanguageConfigurationPropertiesCommon; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * To use a Java bean (aka method call) in Camel expressions or predicates. + * + * Generated by camel-package-maven-plugin - do not edit this file! + */ +@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") +@ConfigurationProperties(prefix = "camel.language.bean") +public class BeanLanguageConfiguration + extends + LanguageConfigurationPropertiesCommon { + + /** + * Whether to enable auto configuration of the bean language. This is + * enabled by default. + */ + private Boolean enabled; + /** + * Whether to trim the value to remove leading and trailing whitespaces and + * line breaks + */ + private Boolean trim = true; + + public Boolean getTrim() { + return trim; + } + + public void setTrim(Boolean trim) { + this.trim = trim; + } +} \ No newline at end of file diff --git a/platforms/spring-boot/components-starter/camel-bean-starter/src/main/resources/META-INF/spring.factories b/platforms/spring-boot/components-starter/camel-bean-starter/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..36b4c94 --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-bean-starter/src/main/resources/META-INF/spring.factories @@ -0,0 +1,23 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +org.apache.camel.component.beanclass.springboot.ClassComponentAutoConfiguration,\ +org.apache.camel.component.bean.springboot.BeanComponentAutoConfiguration,\ +org.apache.camel.language.bean.springboot.BeanLanguageAutoConfiguration + +