001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.spring; 018 019import java.util.ArrayList; 020import java.util.List; 021import java.util.Map; 022 023import javax.xml.bind.annotation.XmlAccessType; 024import javax.xml.bind.annotation.XmlAccessorType; 025import javax.xml.bind.annotation.XmlAttribute; 026import javax.xml.bind.annotation.XmlElement; 027import javax.xml.bind.annotation.XmlElements; 028import javax.xml.bind.annotation.XmlRootElement; 029import javax.xml.bind.annotation.XmlTransient; 030 031import org.apache.camel.CamelContext; 032import org.apache.camel.LoggingLevel; 033import org.apache.camel.RoutesBuilder; 034import org.apache.camel.ShutdownRoute; 035import org.apache.camel.ShutdownRunningTask; 036import org.apache.camel.TypeConverterExists; 037import org.apache.camel.builder.RouteBuilder; 038import org.apache.camel.component.properties.PropertiesComponent; 039import org.apache.camel.component.properties.PropertiesLocation; 040import org.apache.camel.core.xml.AbstractCamelContextFactoryBean; 041import org.apache.camel.core.xml.AbstractCamelFactoryBean; 042import org.apache.camel.core.xml.CamelJMXAgentDefinition; 043import org.apache.camel.core.xml.CamelPropertyPlaceholderDefinition; 044import org.apache.camel.core.xml.CamelProxyFactoryDefinition; 045import org.apache.camel.core.xml.CamelServiceExporterDefinition; 046import org.apache.camel.core.xml.CamelStreamCachingStrategyDefinition; 047import org.apache.camel.model.ContextScanDefinition; 048import org.apache.camel.model.GlobalOptionsDefinition; 049import org.apache.camel.model.HystrixConfigurationDefinition; 050import org.apache.camel.model.InterceptDefinition; 051import org.apache.camel.model.InterceptFromDefinition; 052import org.apache.camel.model.InterceptSendToEndpointDefinition; 053import org.apache.camel.model.OnCompletionDefinition; 054import org.apache.camel.model.OnExceptionDefinition; 055import org.apache.camel.model.PackageScanDefinition; 056import org.apache.camel.model.PropertiesDefinition; 057import org.apache.camel.model.RestContextRefDefinition; 058import org.apache.camel.model.RouteBuilderDefinition; 059import org.apache.camel.model.RouteContextRefDefinition; 060import org.apache.camel.model.RouteDefinition; 061import org.apache.camel.model.ThreadPoolProfileDefinition; 062import org.apache.camel.model.cloud.ServiceCallConfigurationDefinition; 063import org.apache.camel.model.dataformat.DataFormatsDefinition; 064import org.apache.camel.model.rest.RestConfigurationDefinition; 065import org.apache.camel.model.rest.RestDefinition; 066import org.apache.camel.model.transformer.TransformersDefinition; 067import org.apache.camel.model.validator.ValidatorsDefinition; 068import org.apache.camel.spi.Metadata; 069import org.apache.camel.spi.PackageScanFilter; 070import org.apache.camel.spi.Registry; 071import org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer; 072import org.apache.camel.spring.spi.XmlCamelContextConfigurer; 073import org.apache.camel.util.CamelContextHelper; 074import org.apache.camel.util.ObjectHelper; 075import org.apache.camel.util.StopWatch; 076import org.slf4j.Logger; 077import org.slf4j.LoggerFactory; 078import org.springframework.beans.factory.DisposableBean; 079import org.springframework.beans.factory.FactoryBean; 080import org.springframework.beans.factory.InitializingBean; 081import org.springframework.beans.factory.config.BeanPostProcessor; 082import org.springframework.context.ApplicationContext; 083import org.springframework.context.ApplicationContextAware; 084import org.springframework.context.ApplicationListener; 085import org.springframework.context.Lifecycle; 086import org.springframework.context.Phased; 087import org.springframework.context.event.ContextRefreshedEvent; 088import org.springframework.core.Ordered; 089 090import static org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException; 091 092/** 093 * CamelContext using XML configuration. 094 */ 095@Metadata(label = "spring,configuration") 096@XmlRootElement(name = "camelContext") 097@XmlAccessorType(XmlAccessType.FIELD) 098public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<SpringCamelContext> 099 implements FactoryBean<SpringCamelContext>, InitializingBean, DisposableBean, ApplicationContextAware, Lifecycle, 100 Phased, ApplicationListener<ContextRefreshedEvent>, Ordered { 101 102 private static final Logger LOG = LoggerFactory.getLogger(CamelContextFactoryBean.class); 103 104 @XmlAttribute(name = "depends-on") 105 private String dependsOn; 106 @XmlAttribute 107 private String trace; 108 @XmlAttribute @Metadata(defaultValue = "true") 109 private String messageHistory; 110 @XmlAttribute @Metadata(defaultValue = "false") 111 private String logMask; 112 @XmlAttribute 113 private String logExhaustedMessageBody; 114 @XmlAttribute 115 private String streamCache; 116 @XmlAttribute 117 private String delayer; 118 @XmlAttribute 119 private String handleFault; 120 @XmlAttribute 121 private String errorHandlerRef; 122 @XmlAttribute @Metadata(defaultValue = "true") 123 private String autoStartup; 124 @XmlAttribute @Metadata(defaultValue = "true") 125 private String shutdownEager; 126 @XmlAttribute @Metadata(defaultValue = "false") 127 @Deprecated 128 private String registerEndpointIdsFromRoute; 129 @XmlAttribute 130 private String useMDCLogging; 131 @XmlAttribute 132 private String useDataType; 133 @XmlAttribute @Metadata(defaultValue = "true") 134 private String useBreadcrumb; 135 @XmlAttribute 136 private String allowUseOriginalMessage; 137 @XmlAttribute 138 private String runtimeEndpointRegistryEnabled; 139 @XmlAttribute @Metadata(defaultValue = "#name#") 140 private String managementNamePattern; 141 @XmlAttribute @Metadata(defaultValue = "Camel (#camelId#) thread ##counter# - #name#") 142 private String threadNamePattern; 143 @XmlAttribute @Metadata(defaultValue = "Default") 144 private ShutdownRoute shutdownRoute; 145 @XmlAttribute @Metadata(defaultValue = "CompleteCurrentTaskOnly") 146 private ShutdownRunningTask shutdownRunningTask; 147 @XmlAttribute 148 @Deprecated @Metadata(defaultValue = "false") 149 private Boolean lazyLoadTypeConverters; 150 @XmlAttribute @Metadata(defaultValue = "true") 151 private Boolean loadTypeConverters; 152 @XmlAttribute 153 private Boolean typeConverterStatisticsEnabled; 154 @XmlAttribute @Metadata(defaultValue = "Override") 155 private TypeConverterExists typeConverterExists; 156 @XmlAttribute @Metadata(defaultValue = "WARN") 157 private LoggingLevel typeConverterExistsLoggingLevel; 158 @Deprecated 159 @XmlElement(name = "properties") 160 private PropertiesDefinition properties; 161 @XmlElement(name = "globalOptions") 162 private GlobalOptionsDefinition globalOptions; 163 @XmlElement(name = "propertyPlaceholder", type = CamelPropertyPlaceholderDefinition.class) 164 private CamelPropertyPlaceholderDefinition camelPropertyPlaceholder; 165 @XmlElement(name = "package") 166 private String[] packages = {}; 167 @XmlElement(name = "packageScan", type = PackageScanDefinition.class) 168 private PackageScanDefinition packageScan; 169 @XmlElement(name = "contextScan", type = ContextScanDefinition.class) 170 private ContextScanDefinition contextScan; 171 @XmlElement(name = "streamCaching", type = CamelStreamCachingStrategyDefinition.class) 172 private CamelStreamCachingStrategyDefinition camelStreamCachingStrategy; 173 @XmlElement(name = "jmxAgent", type = CamelJMXAgentDefinition.class) 174 private CamelJMXAgentDefinition camelJMXAgent; 175 @XmlElements({ 176 @XmlElement(name = "template", type = CamelProducerTemplateFactoryBean.class), 177 @XmlElement(name = "fluentTemplate", type = CamelFluentProducerTemplateFactoryBean.class), 178 @XmlElement(name = "consumerTemplate", type = CamelConsumerTemplateFactoryBean.class)}) 179 private List<AbstractCamelFactoryBean<?>> beansFactory; 180 @XmlElements({ 181 @XmlElement(name = "proxy", type = CamelProxyFactoryDefinition.class), 182 @XmlElement(name = "export", type = CamelServiceExporterDefinition.class), 183 @XmlElement(name = "errorHandler", type = ErrorHandlerDefinition.class) }) 184 private List<?> beans; 185 @XmlElement(name = "defaultServiceCallConfiguration") 186 private ServiceCallConfigurationDefinition defaultServiceCallConfiguration; 187 @XmlElement(name = "serviceCallConfiguration", type = ServiceCallConfigurationDefinition.class) 188 private List<ServiceCallConfigurationDefinition> serviceCallConfigurations; 189 @XmlElement(name = "defaultHystrixConfiguration") 190 private HystrixConfigurationDefinition defaultHystrixConfiguration; 191 @XmlElement(name = "hystrixConfiguration", type = HystrixConfigurationDefinition.class) 192 private List<HystrixConfigurationDefinition> hystrixConfigurations; 193 @XmlElement(name = "routeBuilder") 194 private List<RouteBuilderDefinition> builderRefs = new ArrayList<>(); 195 @XmlElement(name = "routeContextRef") 196 private List<RouteContextRefDefinition> routeRefs = new ArrayList<>(); 197 @XmlElement(name = "restContextRef") 198 private List<RestContextRefDefinition> restRefs = new ArrayList<>(); 199 @XmlElement(name = "threadPoolProfile") 200 private List<ThreadPoolProfileDefinition> threadPoolProfiles; 201 @XmlElement(name = "threadPool") 202 private List<CamelThreadPoolFactoryBean> threadPools; 203 @XmlElement(name = "endpoint") 204 private List<CamelEndpointFactoryBean> endpoints; 205 @XmlElement(name = "dataFormats") 206 private DataFormatsDefinition dataFormats; 207 @XmlElement(name = "transformers") 208 private TransformersDefinition transformers; 209 @XmlElement(name = "validators") 210 private ValidatorsDefinition validators; 211 @XmlElement(name = "redeliveryPolicyProfile") 212 private List<CamelRedeliveryPolicyFactoryBean> redeliveryPolicies; 213 @XmlElement(name = "onException") 214 private List<OnExceptionDefinition> onExceptions = new ArrayList<>(); 215 @XmlElement(name = "onCompletion") 216 private List<OnCompletionDefinition> onCompletions = new ArrayList<>(); 217 @XmlElement(name = "intercept") 218 private List<InterceptDefinition> intercepts = new ArrayList<>(); 219 @XmlElement(name = "interceptFrom") 220 private List<InterceptFromDefinition> interceptFroms = new ArrayList<>(); 221 @XmlElement(name = "interceptSendToEndpoint") 222 private List<InterceptSendToEndpointDefinition> interceptSendToEndpoints = new ArrayList<>(); 223 @XmlElement(name = "restConfiguration") 224 private RestConfigurationDefinition restConfiguration; 225 @XmlElement(name = "rest") 226 private List<RestDefinition> rests = new ArrayList<>(); 227 @XmlElement(name = "route") 228 private List<RouteDefinition> routes = new ArrayList<>(); 229 @XmlTransient 230 private SpringCamelContext context; 231 @XmlTransient 232 private ClassLoader contextClassLoaderOnStart; 233 @XmlTransient 234 private ApplicationContext applicationContext; 235 @XmlTransient 236 private BeanPostProcessor beanPostProcessor; 237 @XmlTransient 238 private boolean implicitId; 239 240 @Override 241 public Class<SpringCamelContext> getObjectType() { 242 return SpringCamelContext.class; 243 } 244 245 protected <S> S getBeanForType(Class<S> clazz) { 246 S bean = null; 247 String[] names = getApplicationContext().getBeanNamesForType(clazz, true, true); 248 if (names.length == 1) { 249 bean = getApplicationContext().getBean(names[0], clazz); 250 } 251 if (bean == null) { 252 ApplicationContext parentContext = getApplicationContext().getParent(); 253 if (parentContext != null) { 254 names = parentContext.getBeanNamesForType(clazz, true, true); 255 if (names.length == 1) { 256 bean = parentContext.getBean(names[0], clazz); 257 } 258 } 259 } 260 return bean; 261 } 262 263 @Override 264 protected void findRouteBuildersByPackageScan(String[] packages, PackageScanFilter filter, List<RoutesBuilder> builders) throws Exception { 265 // add filter to class resolver which then will filter 266 getContext().getPackageScanClassResolver().addFilter(filter); 267 268 PackageScanRouteBuilderFinder finder = new PackageScanRouteBuilderFinder(getContext(), packages, getContextClassLoaderOnStart(), 269 getBeanPostProcessor(), getContext().getPackageScanClassResolver()); 270 finder.appendBuilders(builders); 271 272 // and remove the filter 273 getContext().getPackageScanClassResolver().removeFilter(filter); 274 } 275 276 @Override 277 protected void findRouteBuildersByContextScan(PackageScanFilter filter, boolean includeNonSingletons, List<RoutesBuilder> builders) throws Exception { 278 ContextScanRouteBuilderFinder finder = new ContextScanRouteBuilderFinder(getContext(), filter, includeNonSingletons); 279 finder.appendBuilders(builders); 280 } 281 282 protected void initBeanPostProcessor(SpringCamelContext context) { 283 if (beanPostProcessor != null) { 284 if (beanPostProcessor instanceof ApplicationContextAware) { 285 ((ApplicationContextAware) beanPostProcessor).setApplicationContext(applicationContext); 286 } 287 if (beanPostProcessor instanceof CamelBeanPostProcessor) { 288 ((CamelBeanPostProcessor) beanPostProcessor).setCamelContext(getContext()); 289 } 290 } 291 } 292 293 protected void postProcessBeforeInit(RouteBuilder builder) { 294 if (beanPostProcessor != null) { 295 // Inject the annotated resource 296 beanPostProcessor.postProcessBeforeInitialization(builder, builder.toString()); 297 } 298 } 299 300 @Override 301 public void afterPropertiesSet() throws Exception { 302 StopWatch watch = new StopWatch(); 303 304 super.afterPropertiesSet(); 305 306 Boolean shutdownEager = CamelContextHelper.parseBoolean(getContext(), getShutdownEager()); 307 if (shutdownEager != null) { 308 LOG.debug("Using shutdownEager: {}", shutdownEager); 309 getContext().setShutdownEager(shutdownEager); 310 } 311 312 LOG.debug("afterPropertiesSet() took {} millis", watch.stop()); 313 } 314 315 protected void initCustomRegistry(SpringCamelContext context) { 316 Registry registry = getBeanForType(Registry.class); 317 if (registry != null) { 318 LOG.info("Using custom Registry: {}", registry); 319 context.setRegistry(registry); 320 } 321 } 322 323 @Override 324 protected void initPropertyPlaceholder() throws Exception { 325 super.initPropertyPlaceholder(); 326 327 Map<String, BridgePropertyPlaceholderConfigurer> beans = applicationContext.getBeansOfType(BridgePropertyPlaceholderConfigurer.class); 328 if (beans.size() == 1) { 329 // setup properties component that uses this beans 330 BridgePropertyPlaceholderConfigurer configurer = beans.values().iterator().next(); 331 String id = beans.keySet().iterator().next(); 332 LOG.info("Bridging Camel and Spring property placeholder configurer with id: {}", id); 333 334 // get properties component 335 PropertiesComponent pc = (PropertiesComponent) getContext().getComponent("properties", false); 336 if (pc == null) { 337 // do not auto create the component as spring autowrire by constructor causes a side effect when using bridge 338 pc = new PropertiesComponent(); 339 getContext().addComponent("properties", pc); 340 } 341 // use the spring system properties mode which has a different value than Camel may have 342 pc.setSystemPropertiesMode(configurer.getSystemPropertiesMode()); 343 // replace existing resolver with us 344 configurer.setResolver(pc.getPropertiesResolver()); 345 configurer.setParser(pc.getPropertiesParser()); 346 // use the bridge to handle the resolve and parsing 347 pc.setPropertiesResolver(configurer); 348 pc.setPropertiesParser(configurer); 349 350 // and update locations to have our as ref first 351 List<PropertiesLocation> locations = new ArrayList<>(pc.getLocations()); 352 locations.add(0, new PropertiesLocation("ref", id)); 353 354 pc.setLocations(locations); 355 } else if (beans.size() > 1) { 356 LOG.warn("Cannot bridge Camel and Spring property placeholders, as exact only 1 bean of type BridgePropertyPlaceholderConfigurer" 357 + " must be defined, was {} beans defined.", beans.size()); 358 } 359 } 360 361 @Override 362 public void start() { 363 try { 364 setupRoutes(); 365 } catch (Exception e) { 366 throw wrapRuntimeCamelException(e); 367 } 368 369 // when the routes are setup we need to start the Camel context 370 context.start(); 371 } 372 373 @Override 374 public void stop() { 375 if (context != null) { 376 context.stop(); 377 } 378 } 379 380 @Override 381 public boolean isRunning() { 382 return context != null && context.isRunning(); 383 } 384 385 @Override 386 public int getPhase() { 387 // the factory starts the context from 388 // onApplicationEvent(ContextRefreshedEvent) so the phase we're 389 // in only influences when the context is to be stopped, and 390 // we want the CamelContext to be first in line to get stopped 391 // if we wanted the phase to be considered while starting, we 392 // would need to implement SmartLifecycle (see 393 // DefaultLifecycleProcessor::startBeans) 394 // we use LOWEST_PRECEDENCE here as this is taken into account 395 // only when stopping and then in reversed order 396 return LOWEST_PRECEDENCE - 1; 397 } 398 399 @Override 400 public int getOrder() { 401 // CamelContextFactoryBean implements Ordered so that it's the 402 // second to last in ApplicationListener to receive events, 403 // SpringCamelContext should be the last one, this is important 404 // for startup as we want all resources to be ready and all 405 // routes added to the context (see setupRoutes() and 406 // org.apache.camel.spring.boot.RoutesCollector) 407 return LOWEST_PRECEDENCE - 1; 408 } 409 410 @Override 411 public void onApplicationEvent(final ContextRefreshedEvent event) { 412 // start the CamelContext when the Spring ApplicationContext is 413 // done initializing, as the last step in ApplicationContext 414 // being started/refreshed, there could be a race condition with 415 // other ApplicationListeners that react to 416 // ContextRefreshedEvent but this is the best that we can do 417 start(); 418 } 419 420 // Properties 421 // ------------------------------------------------------------------------- 422 423 public ApplicationContext getApplicationContext() { 424 if (applicationContext == null) { 425 throw new IllegalArgumentException("No applicationContext has been injected!"); 426 } 427 return applicationContext; 428 } 429 430 @Override 431 public void setApplicationContext(ApplicationContext applicationContext) { 432 this.applicationContext = applicationContext; 433 } 434 435 public void setBeanPostProcessor(BeanPostProcessor postProcessor) { 436 this.beanPostProcessor = postProcessor; 437 } 438 439 public BeanPostProcessor getBeanPostProcessor() { 440 return beanPostProcessor; 441 } 442 443 // Implementation methods 444 // ------------------------------------------------------------------------- 445 446 /** 447 * Create the context 448 */ 449 protected SpringCamelContext createContext() { 450 SpringCamelContext ctx = newCamelContext(); 451 ctx.setName(getId()); 452 453 return ctx; 454 } 455 456 /** 457 * Apply additional configuration to the context 458 */ 459 protected void configure(SpringCamelContext ctx) { 460 try { 461 // allow any custom configuration, such as when running in camel-spring-boot 462 if (applicationContext.containsBean("xmlCamelContextConfigurer")) { 463 XmlCamelContextConfigurer configurer = applicationContext.getBean("xmlCamelContextConfigurer", XmlCamelContextConfigurer.class); 464 if (configurer != null) { 465 configurer.configure(applicationContext, ctx); 466 } 467 } 468 } catch (Exception e) { 469 // error during configuration 470 throw ObjectHelper.wrapRuntimeCamelException(e); 471 } 472 } 473 474 protected SpringCamelContext newCamelContext() { 475 return new SpringCamelContext(getApplicationContext()); 476 } 477 478 public SpringCamelContext getContext(boolean create) { 479 if (context == null && create) { 480 context = createContext(); 481 configure(context); 482 } 483 return context; 484 } 485 486 public void setContext(SpringCamelContext context) { 487 this.context = context; 488 } 489 490 public List<RouteDefinition> getRoutes() { 491 return routes; 492 } 493 494 /** 495 * Contains the Camel routes 496 */ 497 public void setRoutes(List<RouteDefinition> routes) { 498 this.routes = routes; 499 } 500 501 public List<RestDefinition> getRests() { 502 return rests; 503 } 504 505 /** 506 * Contains the rest services defined using the rest-dsl 507 */ 508 public void setRests(List<RestDefinition> rests) { 509 this.rests = rests; 510 } 511 512 public RestConfigurationDefinition getRestConfiguration() { 513 return restConfiguration; 514 } 515 516 /** 517 * Configuration for rest-dsl 518 */ 519 public void setRestConfiguration(RestConfigurationDefinition restConfiguration) { 520 this.restConfiguration = restConfiguration; 521 } 522 523 public List<CamelEndpointFactoryBean> getEndpoints() { 524 return endpoints; 525 } 526 527 /** 528 * Configuration of endpoints 529 */ 530 public void setEndpoints(List<CamelEndpointFactoryBean> endpoints) { 531 this.endpoints = endpoints; 532 } 533 534 public List<CamelRedeliveryPolicyFactoryBean> getRedeliveryPolicies() { 535 return redeliveryPolicies; 536 } 537 538 public List<InterceptDefinition> getIntercepts() { 539 return intercepts; 540 } 541 542 /** 543 * Configuration of interceptors. 544 */ 545 public void setIntercepts(List<InterceptDefinition> intercepts) { 546 this.intercepts = intercepts; 547 } 548 549 public List<InterceptFromDefinition> getInterceptFroms() { 550 return interceptFroms; 551 } 552 553 /** 554 * Configuration of interceptors that triggers from the beginning of routes. 555 */ 556 public void setInterceptFroms(List<InterceptFromDefinition> interceptFroms) { 557 this.interceptFroms = interceptFroms; 558 } 559 560 public List<InterceptSendToEndpointDefinition> getInterceptSendToEndpoints() { 561 return interceptSendToEndpoints; 562 } 563 564 /** 565 * Configuration of interceptors that triggers sending messages to endpoints. 566 */ 567 public void setInterceptSendToEndpoints(List<InterceptSendToEndpointDefinition> interceptSendToEndpoints) { 568 this.interceptSendToEndpoints = interceptSendToEndpoints; 569 } 570 571 @Deprecated 572 public PropertiesDefinition getProperties() { 573 return properties; 574 } 575 576 @Override 577 public GlobalOptionsDefinition getGlobalOptions() { 578 return globalOptions; 579 } 580 581 /** 582 * Configuration of CamelContext properties such as limit of debug logging 583 * and other general options. 584 * 585 * @deprecated Use {@link GlobalOptionsDefinition} instead. 586 */ 587 @Deprecated 588 public void setProperties(PropertiesDefinition properties) { 589 this.properties = properties; 590 } 591 592 /** 593 * Configuration of CamelContext properties such as limit of debug logging 594 * and other general options. 595 */ 596 public void setGlobalOptions(GlobalOptionsDefinition globalOptions) { 597 this.globalOptions = globalOptions; 598 } 599 600 public String[] getPackages() { 601 return packages; 602 } 603 604 /** 605 * Sets the package names to be recursively searched for Java classes which 606 * extend {@link org.apache.camel.builder.RouteBuilder} to be auto-wired up to the 607 * {@link CamelContext} as a route. Note that classes are excluded if 608 * they are specifically configured in the spring.xml 609 * <p/> 610 * A more advanced configuration can be done using {@link #setPackageScan(org.apache.camel.model.PackageScanDefinition)} 611 * 612 * @param packages the package names which are recursively searched 613 * @see #setPackageScan(org.apache.camel.model.PackageScanDefinition) 614 */ 615 public void setPackages(String[] packages) { 616 this.packages = packages; 617 } 618 619 public PackageScanDefinition getPackageScan() { 620 return packageScan; 621 } 622 623 /** 624 * Sets the package scanning information. Package scanning allows for the 625 * automatic discovery of certain camel classes at runtime for inclusion 626 * e.g. {@link org.apache.camel.builder.RouteBuilder} implementations 627 * 628 * @param packageScan the package scan 629 */ 630 public void setPackageScan(PackageScanDefinition packageScan) { 631 this.packageScan = packageScan; 632 } 633 634 public ContextScanDefinition getContextScan() { 635 return contextScan; 636 } 637 638 /** 639 * Sets the context scanning (eg Spring's ApplicationContext) information. 640 * Context scanning allows for the automatic discovery of Camel routes runtime for inclusion 641 * e.g. {@link org.apache.camel.builder.RouteBuilder} implementations 642 * 643 * @param contextScan the context scan 644 */ 645 public void setContextScan(ContextScanDefinition contextScan) { 646 this.contextScan = contextScan; 647 } 648 649 public CamelPropertyPlaceholderDefinition getCamelPropertyPlaceholder() { 650 return camelPropertyPlaceholder; 651 } 652 653 /** 654 * Configuration of property placeholder 655 */ 656 public void setCamelPropertyPlaceholder(CamelPropertyPlaceholderDefinition camelPropertyPlaceholder) { 657 this.camelPropertyPlaceholder = camelPropertyPlaceholder; 658 } 659 660 public CamelStreamCachingStrategyDefinition getCamelStreamCachingStrategy() { 661 return camelStreamCachingStrategy; 662 } 663 664 /** 665 * Configuration of stream caching. 666 */ 667 public void setCamelStreamCachingStrategy(CamelStreamCachingStrategyDefinition camelStreamCachingStrategy) { 668 this.camelStreamCachingStrategy = camelStreamCachingStrategy; 669 } 670 671 /** 672 * Configuration of JMX. 673 */ 674 public void setCamelJMXAgent(CamelJMXAgentDefinition agent) { 675 camelJMXAgent = agent; 676 } 677 678 public String getTrace() { 679 return trace; 680 } 681 682 /** 683 * Sets whether tracing is enabled or not. 684 */ 685 public void setTrace(String trace) { 686 this.trace = trace; 687 } 688 689 public String getMessageHistory() { 690 return messageHistory; 691 } 692 693 /** 694 * Sets whether message history is enabled or not. 695 */ 696 public void setMessageHistory(String messageHistory) { 697 this.messageHistory = messageHistory; 698 } 699 700 public String getLogMask() { 701 return logMask; 702 } 703 704 /** 705 * Sets whether security mask for Logging is enabled or not. 706 */ 707 public void setLogMask(String logMask) { 708 this.logMask = logMask; 709 } 710 711 public String getLogExhaustedMessageBody() { 712 return logExhaustedMessageBody; 713 } 714 715 /** 716 * Sets whether to log exhausted message body with message history. 717 */ 718 public void setLogExhaustedMessageBody(String logExhaustedMessageBody) { 719 this.logExhaustedMessageBody = logExhaustedMessageBody; 720 } 721 722 public String getStreamCache() { 723 return streamCache; 724 } 725 726 /** 727 * Sets whether stream caching is enabled or not. 728 */ 729 public void setStreamCache(String streamCache) { 730 this.streamCache = streamCache; 731 } 732 733 public String getDelayer() { 734 return delayer; 735 } 736 737 /** 738 * Sets a delay value in millis that a message is delayed at every step it takes in the route path, 739 * slowing the process down to better observe what is occurring 740 */ 741 public void setDelayer(String delayer) { 742 this.delayer = delayer; 743 } 744 745 public String getHandleFault() { 746 return handleFault; 747 } 748 749 /** 750 * Sets whether fault handling is enabled or not (default is disabled). 751 */ 752 public void setHandleFault(String handleFault) { 753 this.handleFault = handleFault; 754 } 755 756 public String getAutoStartup() { 757 return autoStartup; 758 } 759 760 /** 761 * Sets whether the object should automatically start when Camel starts. 762 * <p/> 763 * <b>Important:</b> Currently only routes can be disabled, as {@link CamelContext}s are always started. 764 * <br/> 765 * <b>Note:</b> When setting auto startup <tt>false</tt> on {@link CamelContext} then that takes precedence 766 * and <i>no</i> routes is started. You would need to start {@link CamelContext} explicit using 767 * the {@link org.apache.camel.CamelContext#start()} method, to start the context, and then 768 * you would need to start the routes manually using {@link CamelContext#startRoute(String)}. 769 */ 770 public void setAutoStartup(String autoStartup) { 771 this.autoStartup = autoStartup; 772 } 773 774 public String getShutdownEager() { 775 return shutdownEager; 776 } 777 778 /** 779 * Whether to shutdown CamelContext eager when Spring is shutting down. 780 * This ensure a cleaner shutdown of Camel, as dependent bean's are not shutdown at this moment. 781 * The bean's will then be shutdown after camelContext. 782 */ 783 public void setShutdownEager(String shutdownEager) { 784 this.shutdownEager = shutdownEager; 785 } 786 787 public String getRegisterEndpointIdsFromRoute() { 788 return registerEndpointIdsFromRoute; 789 } 790 791 /** 792 * Sets whether to register endpoints that has id attribute assigned in the Spring registry. 793 * <p/> 794 * This mode is by default false, but can be turned on for backwards compatibility. 795 */ 796 public void setRegisterEndpointIdsFromRoute(String registerEndpointIdsFromRoute) { 797 this.registerEndpointIdsFromRoute = registerEndpointIdsFromRoute; 798 } 799 800 public String getUseMDCLogging() { 801 return useMDCLogging; 802 } 803 804 /** 805 * Set whether <a href="http://www.slf4j.org/api/org/slf4j/MDC.html">MDC</a> is enabled. 806 */ 807 public void setUseMDCLogging(String useMDCLogging) { 808 this.useMDCLogging = useMDCLogging; 809 } 810 811 public String getUseDataType() { 812 return useDataType; 813 } 814 815 /** 816 * Whether to enable using data type on Camel messages. 817 * <p/> 818 * Data type are automatic turned on if: 819 * <ul> 820 * <li>one ore more routes has been explicit configured with input and output types</li> 821 * <li>when using rest-dsl with binding turned on</li> 822 * </ul> 823 * Otherwise data type is default off. 824 */ 825 public void setUseDataType(String useDataType) { 826 this.useDataType = useDataType; 827 } 828 829 public String getUseBreadcrumb() { 830 return useBreadcrumb; 831 } 832 833 /** 834 * Set whether breadcrumb is enabled. 835 */ 836 public void setUseBreadcrumb(String useBreadcrumb) { 837 this.useBreadcrumb = useBreadcrumb; 838 } 839 840 public String getAllowUseOriginalMessage() { 841 return allowUseOriginalMessage; 842 } 843 844 /** 845 * Sets whether to allow access to the original message from Camel's error handler, 846 * or from {@link org.apache.camel.spi.UnitOfWork#getOriginalInMessage()}. 847 * <p/> 848 * Turning this off can optimize performance, as defensive copy of the original message is not needed. 849 */ 850 public void setAllowUseOriginalMessage(String allowUseOriginalMessage) { 851 this.allowUseOriginalMessage = allowUseOriginalMessage; 852 } 853 854 public String getRuntimeEndpointRegistryEnabled() { 855 return runtimeEndpointRegistryEnabled; 856 } 857 858 /** 859 * Sets whether {@link org.apache.camel.spi.RuntimeEndpointRegistry} is enabled. 860 */ 861 public void setRuntimeEndpointRegistryEnabled(String runtimeEndpointRegistryEnabled) { 862 this.runtimeEndpointRegistryEnabled = runtimeEndpointRegistryEnabled; 863 } 864 865 public String getManagementNamePattern() { 866 return managementNamePattern; 867 } 868 869 /** 870 * The naming pattern for creating the CamelContext management name. 871 */ 872 public void setManagementNamePattern(String managementNamePattern) { 873 this.managementNamePattern = managementNamePattern; 874 } 875 876 public String getThreadNamePattern() { 877 return threadNamePattern; 878 } 879 880 /** 881 * Sets the thread name pattern used for creating the full thread name. 882 * <p/> 883 * The default pattern is: <tt>Camel (#camelId#) thread ##counter# - #name#</tt> 884 * <p/> 885 * Where <tt>#camelId#</tt> is the name of the {@link org.apache.camel.CamelContext} 886 * <br/>and <tt>#counter#</tt> is a unique incrementing counter. 887 * <br/>and <tt>#name#</tt> is the regular thread name. 888 * <br/>You can also use <tt>#longName#</tt> is the long thread name which can includes endpoint parameters etc. 889 */ 890 public void setThreadNamePattern(String threadNamePattern) { 891 this.threadNamePattern = threadNamePattern; 892 } 893 894 @Deprecated 895 public Boolean getLazyLoadTypeConverters() { 896 return lazyLoadTypeConverters; 897 } 898 899 /** 900 * Sets whether type converters should be loaded lazy 901 */ 902 @Deprecated 903 public void setLazyLoadTypeConverters(Boolean lazyLoadTypeConverters) { 904 this.lazyLoadTypeConverters = lazyLoadTypeConverters; 905 } 906 907 @Override 908 public Boolean getLoadTypeConverters() { 909 return loadTypeConverters; 910 } 911 912 /** 913 * Sets whether to load custom type converters by scanning classpath. 914 * This can be turned off if you are only using Camel components 915 * that does not provide type converters which is needed at runtime. 916 * In such situations setting this option to false, can speedup starting 917 * Camel. 918 * 919 * @param loadTypeConverters whether to load custom type converters. 920 */ 921 public void setLoadTypeConverters(Boolean loadTypeConverters) { 922 this.loadTypeConverters = loadTypeConverters; 923 } 924 925 public Boolean getTypeConverterStatisticsEnabled() { 926 return typeConverterStatisticsEnabled; 927 } 928 929 /** 930 * Sets whether or not type converter statistics is enabled. 931 * <p/> 932 * By default the type converter utilization statistics is disabled. 933 * <b>Notice:</b> If enabled then there is a slight performance impact under very heavy load. 934 * <p/> 935 * You can enable/disable the statistics at runtime using the 936 * {@link org.apache.camel.spi.TypeConverterRegistry#getStatistics()#setTypeConverterStatisticsEnabled(Boolean)} method, 937 * or from JMX on the {@link org.apache.camel.api.management.mbean.ManagedTypeConverterRegistryMBean} mbean. 938 */ 939 public void setTypeConverterStatisticsEnabled(Boolean typeConverterStatisticsEnabled) { 940 this.typeConverterStatisticsEnabled = typeConverterStatisticsEnabled; 941 } 942 943 public TypeConverterExists getTypeConverterExists() { 944 return typeConverterExists; 945 } 946 947 /** 948 * What should happen when attempting to add a duplicate type converter. 949 * <p/> 950 * The default behavior is to override the existing. 951 */ 952 public void setTypeConverterExists(TypeConverterExists typeConverterExists) { 953 this.typeConverterExists = typeConverterExists; 954 } 955 956 public LoggingLevel getTypeConverterExistsLoggingLevel() { 957 return typeConverterExistsLoggingLevel; 958 } 959 960 /** 961 * The logging level to use when logging that a type converter already exists when attempting to add a duplicate type converter. 962 * <p/> 963 * The default logging level is <tt>WARN</tt> 964 */ 965 public void setTypeConverterExistsLoggingLevel(LoggingLevel typeConverterExistsLoggingLevel) { 966 this.typeConverterExistsLoggingLevel = typeConverterExistsLoggingLevel; 967 } 968 969 public CamelJMXAgentDefinition getCamelJMXAgent() { 970 return camelJMXAgent; 971 } 972 973 public List<RouteBuilderDefinition> getBuilderRefs() { 974 return builderRefs; 975 } 976 977 /** 978 * Refers to Java {@link RouteBuilder} instances to include as routes in this CamelContext. 979 */ 980 public void setBuilderRefs(List<RouteBuilderDefinition> builderRefs) { 981 this.builderRefs = builderRefs; 982 } 983 984 public List<RouteContextRefDefinition> getRouteRefs() { 985 return routeRefs; 986 } 987 988 /** 989 * Refers to XML routes to include as routes in this CamelContext. 990 */ 991 public void setRouteRefs(List<RouteContextRefDefinition> routeRefs) { 992 this.routeRefs = routeRefs; 993 } 994 995 public List<RestContextRefDefinition> getRestRefs() { 996 return restRefs; 997 } 998 999 /** 1000 * Refers to XML rest-dsl to include as REST services in this CamelContext. 1001 */ 1002 public void setRestRefs(List<RestContextRefDefinition> restRefs) { 1003 this.restRefs = restRefs; 1004 } 1005 1006 public String getErrorHandlerRef() { 1007 return errorHandlerRef; 1008 } 1009 1010 /** 1011 * Sets the name of the error handler object used to default the error handling strategy 1012 */ 1013 public void setErrorHandlerRef(String errorHandlerRef) { 1014 this.errorHandlerRef = errorHandlerRef; 1015 } 1016 1017 /** 1018 * Configuration of data formats. 1019 */ 1020 public void setDataFormats(DataFormatsDefinition dataFormats) { 1021 this.dataFormats = dataFormats; 1022 } 1023 1024 public DataFormatsDefinition getDataFormats() { 1025 return dataFormats; 1026 } 1027 1028 /** 1029 * Configuration of transformers. 1030 */ 1031 public void setTransformers(TransformersDefinition transformers) { 1032 this.transformers = transformers; 1033 } 1034 1035 public TransformersDefinition getTransformers() { 1036 return transformers; 1037 } 1038 1039 /** 1040 * Configuration of validators. 1041 */ 1042 public void setValidators(ValidatorsDefinition validators) { 1043 this.validators = validators; 1044 } 1045 1046 public ValidatorsDefinition getValidators() { 1047 return validators; 1048 } 1049 1050 /** 1051 * Configuration of redelivery settings. 1052 */ 1053 public void setRedeliveryPolicies(List<CamelRedeliveryPolicyFactoryBean> redeliveryPolicies) { 1054 this.redeliveryPolicies = redeliveryPolicies; 1055 } 1056 1057 @Override 1058 public List<AbstractCamelFactoryBean<?>> getBeansFactory() { 1059 return beansFactory; 1060 } 1061 1062 /** 1063 * Miscellaneous configurations 1064 */ 1065 public void setBeansFactory(List<AbstractCamelFactoryBean<?>> beansFactory) { 1066 this.beansFactory = beansFactory; 1067 } 1068 1069 @Override 1070 public List<?> getBeans() { 1071 return beans; 1072 } 1073 1074 /** 1075 * Miscellaneous configurations 1076 */ 1077 public void setBeans(List<?> beans) { 1078 this.beans = beans; 1079 } 1080 1081 @Override 1082 public ServiceCallConfigurationDefinition getDefaultServiceCallConfiguration() { 1083 return defaultServiceCallConfiguration; 1084 } 1085 1086 /** 1087 * ServiceCall EIP default configuration 1088 */ 1089 public void setDefaultServiceCallConfiguration(ServiceCallConfigurationDefinition defaultServiceCallConfiguration) { 1090 this.defaultServiceCallConfiguration = defaultServiceCallConfiguration; 1091 } 1092 1093 @Override 1094 public List<ServiceCallConfigurationDefinition> getServiceCallConfigurations() { 1095 return serviceCallConfigurations; 1096 } 1097 1098 /** 1099 * ServiceCall EIP configurations 1100 */ 1101 public void setServiceCallConfigurations(List<ServiceCallConfigurationDefinition> serviceCallConfigurations) { 1102 this.serviceCallConfigurations = serviceCallConfigurations; 1103 } 1104 1105 @Override 1106 public List<HystrixConfigurationDefinition> getHystrixConfigurations() { 1107 return hystrixConfigurations; 1108 } 1109 1110 @Override 1111 public HystrixConfigurationDefinition getDefaultHystrixConfiguration() { 1112 return defaultHystrixConfiguration; 1113 } 1114 1115 /** 1116 * Hystrix EIP default configuration 1117 */ 1118 public void setDefaultHystrixConfiguration(HystrixConfigurationDefinition defaultHystrixConfiguration) { 1119 this.defaultHystrixConfiguration = defaultHystrixConfiguration; 1120 } 1121 1122 /** 1123 * Hystrix EIP configurations 1124 */ 1125 public void setHystrixConfigurations(List<HystrixConfigurationDefinition> hystrixConfigurations) { 1126 this.hystrixConfigurations = hystrixConfigurations; 1127 } 1128 1129 /** 1130 * Configuration of error handlers that triggers on exceptions thrown. 1131 */ 1132 public void setOnExceptions(List<OnExceptionDefinition> onExceptions) { 1133 this.onExceptions = onExceptions; 1134 } 1135 1136 public List<OnExceptionDefinition> getOnExceptions() { 1137 return onExceptions; 1138 } 1139 1140 public List<OnCompletionDefinition> getOnCompletions() { 1141 return onCompletions; 1142 } 1143 1144 /** 1145 * Configuration of sub routes to run at the completion of routing. 1146 */ 1147 public void setOnCompletions(List<OnCompletionDefinition> onCompletions) { 1148 this.onCompletions = onCompletions; 1149 } 1150 1151 public ShutdownRoute getShutdownRoute() { 1152 return shutdownRoute; 1153 } 1154 1155 /** 1156 * Sets the ShutdownRoute option for routes. 1157 */ 1158 public void setShutdownRoute(ShutdownRoute shutdownRoute) { 1159 this.shutdownRoute = shutdownRoute; 1160 } 1161 1162 public ShutdownRunningTask getShutdownRunningTask() { 1163 return shutdownRunningTask; 1164 } 1165 1166 /** 1167 * Sets the ShutdownRunningTask option to use when shutting down a route. 1168 */ 1169 public void setShutdownRunningTask(ShutdownRunningTask shutdownRunningTask) { 1170 this.shutdownRunningTask = shutdownRunningTask; 1171 } 1172 1173 public List<ThreadPoolProfileDefinition> getThreadPoolProfiles() { 1174 return threadPoolProfiles; 1175 } 1176 1177 /** 1178 * Configuration of thread pool profiles. 1179 */ 1180 public void setThreadPoolProfiles(List<ThreadPoolProfileDefinition> threadPoolProfiles) { 1181 this.threadPoolProfiles = threadPoolProfiles; 1182 } 1183 1184 public List<CamelThreadPoolFactoryBean> getThreadPools() { 1185 return threadPools; 1186 } 1187 1188 /** 1189 * Configuration of thread pool 1190 */ 1191 public void setThreadPools(List<CamelThreadPoolFactoryBean> threadPools) { 1192 this.threadPools = threadPools; 1193 } 1194 1195 public String getDependsOn() { 1196 return dependsOn; 1197 } 1198 1199 /** 1200 * List of other bean id's this CamelContext depends up. Multiple bean id's can be separated by comma. 1201 */ 1202 public void setDependsOn(String dependsOn) { 1203 this.dependsOn = dependsOn; 1204 } 1205 1206 public boolean isImplicitId() { 1207 return implicitId; 1208 } 1209 1210 public void setImplicitId(boolean flag) { 1211 implicitId = flag; 1212 } 1213}