CAMEL-10235: Add fluentTemplate to XML DSL
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/eb8fcf9a Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/eb8fcf9a Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/eb8fcf9a Branch: refs/heads/master Commit: eb8fcf9abce22241f950291d283f75f167b5dfd8 Parents: 2663959 Author: Claus Ibsen <davscl...@apache.org> Authored: Thu Aug 11 11:09:49 2016 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Thu Aug 11 11:09:49 2016 +0200 ---------------------------------------------------------------------- .../blueprint/CamelContextFactoryBean.java | 113 ++++++++++--------- .../CamelFluentProducerTemplateFactoryBean.java | 66 +++++++++++ .../org/apache/camel/blueprint/jaxb.index | 1 + .../org/apache/camel/spring/jaxb.index | 1 + 4 files changed, 125 insertions(+), 56 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/eb8fcf9a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java ---------------------------------------------------------------------- diff --git a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java index be8a6af..4961bee 100644 --- a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java +++ b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java @@ -86,109 +86,110 @@ import org.slf4j.LoggerFactory; public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<BlueprintCamelContext> { private static final Logger LOG = LoggerFactory.getLogger(CamelContextFactoryBean.class); - @XmlAttribute(name = "depends-on", required = false) + @XmlAttribute(name = "depends-on") private String dependsOn; - @XmlAttribute(required = false) + @XmlAttribute private String trace; - @XmlAttribute(required = false) + @XmlAttribute private String messageHistory; - @XmlAttribute(required = false) + @XmlAttribute private String logExhaustedMessageBody; - @XmlAttribute(required = false) + @XmlAttribute private String streamCache = "false"; - @XmlAttribute(required = false) + @XmlAttribute private String delayer; - @XmlAttribute(required = false) + @XmlAttribute private String handleFault; - @XmlAttribute(required = false) + @XmlAttribute private String errorHandlerRef; - @XmlAttribute(required = false) + @XmlAttribute private String autoStartup = "true"; - @XmlAttribute(required = false) + @XmlAttribute private String useMDCLogging; - @XmlAttribute(required = false) + @XmlAttribute private String useBreadcrumb; - @XmlAttribute(required = false) + @XmlAttribute private String allowUseOriginalMessage; - @XmlAttribute(required = false) + @XmlAttribute private String runtimeEndpointRegistryEnabled; - @XmlAttribute(required = false) + @XmlAttribute private String managementNamePattern; - @XmlAttribute(required = false) + @XmlAttribute private String threadNamePattern; - @XmlAttribute(required = false) + @XmlAttribute private Boolean useBlueprintPropertyResolver; - @XmlAttribute(required = false) + @XmlAttribute private ShutdownRoute shutdownRoute; - @XmlAttribute(required = false) + @XmlAttribute private ShutdownRunningTask shutdownRunningTask; - @XmlAttribute(required = false) + @XmlAttribute @Deprecated private Boolean lazyLoadTypeConverters; - @XmlAttribute(required = false) + @XmlAttribute private Boolean typeConverterStatisticsEnabled; - @XmlAttribute(required = false) + @XmlAttribute private TypeConverterExists typeConverterExists; - @XmlAttribute(required = false) + @XmlAttribute private LoggingLevel typeConverterExistsLoggingLevel; - @XmlElement(name = "properties", required = false) + @XmlElement(name = "properties") private PropertiesDefinition properties; - @XmlElement(name = "propertyPlaceholder", type = CamelPropertyPlaceholderDefinition.class, required = false) + @XmlElement(name = "propertyPlaceholder", type = CamelPropertyPlaceholderDefinition.class) private CamelPropertyPlaceholderDefinition camelPropertyPlaceholder; - @XmlElement(name = "package", required = false) + @XmlElement(name = "package") private String[] packages = {}; - @XmlElement(name = "packageScan", type = PackageScanDefinition.class, required = false) + @XmlElement(name = "packageScan", type = PackageScanDefinition.class) private PackageScanDefinition packageScan; - @XmlElement(name = "contextScan", type = ContextScanDefinition.class, required = false) + @XmlElement(name = "contextScan", type = ContextScanDefinition.class) private ContextScanDefinition contextScan; - @XmlElement(name = "jmxAgent", type = CamelJMXAgentDefinition.class, required = false) + @XmlElement(name = "jmxAgent", type = CamelJMXAgentDefinition.class) private CamelJMXAgentDefinition camelJMXAgent; - @XmlElement(name = "streamCaching", type = CamelStreamCachingStrategyDefinition.class, required = false) + @XmlElement(name = "streamCaching", type = CamelStreamCachingStrategyDefinition.class) private CamelStreamCachingStrategyDefinition camelStreamCachingStrategy; @XmlElements({ - @XmlElement(name = "hystrixConfiguration", type = HystrixConfigurationDefinition.class, required = false), - @XmlElement(name = "kubernetesConfiguration", type = KubernetesConfigurationDefinition.class, required = false), - @XmlElement(name = "ribbonConfiguration", type = RibbonConfigurationDefinition.class, required = false), - @XmlElement(name = "consulConfiguration", type = ConsulConfigurationDefinition.class, required = false), - @XmlElement(name = "dnsConfiguration", type = DnsConfigurationDefinition.class, required = false), - @XmlElement(name = "etcdConfiguration", type = EtcdConfigurationDefinition.class, required = false), - @XmlElement(name = "template", type = CamelProducerTemplateFactoryBean.class, required = false), - @XmlElement(name = "consumerTemplate", type = CamelConsumerTemplateFactoryBean.class, required = false), - @XmlElement(name = "proxy", type = CamelProxyFactoryBean.class, required = false), - @XmlElement(name = "export", type = CamelServiceExporterDefinition.class, required = false), - @XmlElement(name = "errorHandler", type = CamelErrorHandlerFactoryBean.class, required = false)}) + @XmlElement(name = "hystrixConfiguration", type = HystrixConfigurationDefinition.class), + @XmlElement(name = "kubernetesConfiguration", type = KubernetesConfigurationDefinition.class), + @XmlElement(name = "ribbonConfiguration", type = RibbonConfigurationDefinition.class), + @XmlElement(name = "consulConfiguration", type = ConsulConfigurationDefinition.class), + @XmlElement(name = "dnsConfiguration", type = DnsConfigurationDefinition.class), + @XmlElement(name = "etcdConfiguration", type = EtcdConfigurationDefinition.class), + @XmlElement(name = "template", type = CamelProducerTemplateFactoryBean.class), + @XmlElement(name = "fluentTemplate", type = CamelFluentProducerTemplateFactoryBean.class), + @XmlElement(name = "consumerTemplate", type = CamelConsumerTemplateFactoryBean.class), + @XmlElement(name = "proxy", type = CamelProxyFactoryBean.class), + @XmlElement(name = "export", type = CamelServiceExporterDefinition.class), + @XmlElement(name = "errorHandler", type = CamelErrorHandlerFactoryBean.class)}) private List<?> beans; - @XmlElement(name = "routeBuilder", required = false) + @XmlElement(name = "routeBuilder") private List<RouteBuilderDefinition> builderRefs = new ArrayList<RouteBuilderDefinition>(); - @XmlElement(name = "routeContextRef", required = false) + @XmlElement(name = "routeContextRef") private List<RouteContextRefDefinition> routeRefs = new ArrayList<RouteContextRefDefinition>(); - @XmlElement(name = "restContextRef", required = false) + @XmlElement(name = "restContextRef") private List<RestContextRefDefinition> restRefs = new ArrayList<RestContextRefDefinition>(); - @XmlElement(name = "threadPoolProfile", required = false) + @XmlElement(name = "threadPoolProfile") private List<ThreadPoolProfileDefinition> threadPoolProfiles; - @XmlElement(name = "threadPool", required = false) + @XmlElement(name = "threadPool") private List<CamelThreadPoolFactoryBean> threadPools; - @XmlElement(name = "endpoint", required = false) + @XmlElement(name = "endpoint") private List<CamelEndpointFactoryBean> endpoints; - @XmlElement(name = "dataFormats", required = false) + @XmlElement(name = "dataFormats") private DataFormatsDefinition dataFormats; - @XmlElement(name = "redeliveryPolicyProfile", required = false) + @XmlElement(name = "redeliveryPolicyProfile") private List<CamelRedeliveryPolicyFactoryBean> redeliveryPolicies; - @XmlElement(name = "onException", required = false) + @XmlElement(name = "onException") private List<OnExceptionDefinition> onExceptions = new ArrayList<OnExceptionDefinition>(); - @XmlElement(name = "onCompletion", required = false) + @XmlElement(name = "onCompletion") private List<OnCompletionDefinition> onCompletions = new ArrayList<OnCompletionDefinition>(); - @XmlElement(name = "intercept", required = false) + @XmlElement(name = "intercept") private List<InterceptDefinition> intercepts = new ArrayList<InterceptDefinition>(); - @XmlElement(name = "interceptFrom", required = false) + @XmlElement(name = "interceptFrom") private List<InterceptFromDefinition> interceptFroms = new ArrayList<InterceptFromDefinition>(); - @XmlElement(name = "interceptSendToEndpoint", required = false) + @XmlElement(name = "interceptSendToEndpoint") private List<InterceptSendToEndpointDefinition> interceptSendToEndpoints = new ArrayList<InterceptSendToEndpointDefinition>(); - @XmlElement(name = "restConfiguration", required = false) + @XmlElement(name = "restConfiguration") private RestConfigurationDefinition restConfiguration; - @XmlElement(name = "rest", required = false) + @XmlElement(name = "rest") private List<RestDefinition> rests = new ArrayList<RestDefinition>(); - @XmlElement(name = "route", required = false) + @XmlElement(name = "route") private List<RouteDefinition> routes = new ArrayList<RouteDefinition>(); @XmlTransient private BlueprintCamelContext context; http://git-wip-us.apache.org/repos/asf/camel/blob/eb8fcf9a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelFluentProducerTemplateFactoryBean.java ---------------------------------------------------------------------- diff --git a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelFluentProducerTemplateFactoryBean.java b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelFluentProducerTemplateFactoryBean.java new file mode 100644 index 0000000..9637a20 --- /dev/null +++ b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelFluentProducerTemplateFactoryBean.java @@ -0,0 +1,66 @@ +/** + * 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.blueprint; + +import java.util.Set; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; + +import org.apache.camel.CamelContext; +import org.apache.camel.core.xml.AbstractCamelFluentProducerTemplateFactoryBean; +import org.osgi.service.blueprint.container.BlueprintContainer; + +/** + * A factory for creating a new {@link org.apache.camel.FluentProducerTemplate} + * instance with a minimum of XML + * + * @version + */ +@XmlRootElement(name = "fluentTemplate") +@XmlAccessorType(XmlAccessType.FIELD) +public class CamelFluentProducerTemplateFactoryBean extends AbstractCamelFluentProducerTemplateFactoryBean { + + @XmlTransient + private BlueprintContainer blueprintContainer; + + public void setBlueprintContainer(BlueprintContainer blueprintContainer) { + this.blueprintContainer = blueprintContainer; + } + + @Override + protected CamelContext getCamelContextWithId(String camelContextId) { + if (blueprintContainer != null) { + return (CamelContext) blueprintContainer.getComponentInstance(camelContextId); + } + return null; + } + + @Override + protected CamelContext discoverDefaultCamelContext() { + if (blueprintContainer != null) { + Set<String> ids = BlueprintCamelContextLookupHelper.lookupBlueprintCamelContext(blueprintContainer); + if (ids.size() == 1) { + // there is only 1 id for a BlueprintCamelContext so fallback and use this + return getCamelContextWithId(ids.iterator().next()); + } + } + return null; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/eb8fcf9a/components/camel-blueprint/src/main/resources/org/apache/camel/blueprint/jaxb.index ---------------------------------------------------------------------- diff --git a/components/camel-blueprint/src/main/resources/org/apache/camel/blueprint/jaxb.index b/components/camel-blueprint/src/main/resources/org/apache/camel/blueprint/jaxb.index index 2c1b625..54021b3 100644 --- a/components/camel-blueprint/src/main/resources/org/apache/camel/blueprint/jaxb.index +++ b/components/camel-blueprint/src/main/resources/org/apache/camel/blueprint/jaxb.index @@ -18,6 +18,7 @@ CamelConsumerTemplateFactoryBean CamelContextFactoryBean CamelEndpointFactoryBean CamelErrorHandlerFactoryBean +CamelFluentProducerTemplateFactoryBean CamelProducerTemplateFactoryBean CamelThreadPoolFactoryBean CamelRedeliveryPolicyFactoryBean http://git-wip-us.apache.org/repos/asf/camel/blob/eb8fcf9a/components/camel-spring/src/main/resources/org/apache/camel/spring/jaxb.index ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/main/resources/org/apache/camel/spring/jaxb.index b/components/camel-spring/src/main/resources/org/apache/camel/spring/jaxb.index index 780a60e..feb4365 100644 --- a/components/camel-spring/src/main/resources/org/apache/camel/spring/jaxb.index +++ b/components/camel-spring/src/main/resources/org/apache/camel/spring/jaxb.index @@ -18,6 +18,7 @@ CamelBeanPostProcessor CamelConsumerTemplateFactoryBean CamelContextFactoryBean CamelEndpointFactoryBean +CamelFluentProducerTemplateFactoryBean CamelProducerTemplateFactoryBean CamelRedeliveryPolicyFactoryBean CamelRestContextFactoryBean