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.model; 018 019import java.util.ArrayList; 020import java.util.Arrays; 021import java.util.List; 022import java.util.concurrent.atomic.AtomicBoolean; 023import java.util.function.Supplier; 024 025import javax.xml.bind.annotation.XmlAccessType; 026import javax.xml.bind.annotation.XmlAccessorType; 027import javax.xml.bind.annotation.XmlAttribute; 028import javax.xml.bind.annotation.XmlElement; 029import javax.xml.bind.annotation.XmlElementRef; 030import javax.xml.bind.annotation.XmlRootElement; 031import javax.xml.bind.annotation.XmlTransient; 032import javax.xml.bind.annotation.XmlType; 033 034import org.apache.camel.Endpoint; 035import org.apache.camel.ErrorHandlerFactory; 036import org.apache.camel.NamedRoute; 037import org.apache.camel.ShutdownRoute; 038import org.apache.camel.ShutdownRunningTask; 039import org.apache.camel.builder.EndpointConsumerBuilder; 040import org.apache.camel.builder.ErrorHandlerBuilderRef; 041import org.apache.camel.model.rest.RestBindingDefinition; 042import org.apache.camel.model.rest.RestDefinition; 043import org.apache.camel.reifier.errorhandler.ErrorHandlerReifier; 044import org.apache.camel.spi.AsEndpointUri; 045import org.apache.camel.spi.Metadata; 046import org.apache.camel.spi.RoutePolicy; 047 048/** 049 * A Camel route 050 */ 051@Metadata(label = "configuration") 052@XmlRootElement(name = "route") 053@XmlType(propOrder = {"input", "inputType", "outputType", "outputs", "routeProperties"}) 054@XmlAccessorType(XmlAccessType.PROPERTY) 055// must use XmlAccessType.PROPERTY as there is some custom logic needed to be executed in the setter methods 056public class RouteDefinition extends ProcessorDefinition<RouteDefinition> implements OutputNode, NamedRoute { 057 private final AtomicBoolean prepared = new AtomicBoolean(false); 058 private FromDefinition input; 059 private List<ProcessorDefinition<?>> outputs = new ArrayList<>(); 060 private String group; 061 private String streamCache; 062 private String trace; 063 private String messageHistory; 064 private String logMask; 065 private String delayer; 066 private String autoStartup; 067 private Integer startupOrder; 068 private List<RoutePolicy> routePolicies; 069 private String routePolicyRef; 070 private ShutdownRoute shutdownRoute; 071 private ShutdownRunningTask shutdownRunningTask; 072 private String errorHandlerRef; 073 private ErrorHandlerFactory errorHandlerFactory; 074 // keep state whether the error handler is context scoped or not 075 // (will by default be context scoped of no explicit error handler 076 // configured) 077 private boolean contextScopedErrorHandler = true; 078 private Boolean rest; 079 private RestDefinition restDefinition; 080 private RestBindingDefinition restBindingDefinition; 081 private InputTypeDefinition inputType; 082 private OutputTypeDefinition outputType; 083 private List<PropertyDefinition> routeProperties; 084 085 public RouteDefinition() { 086 } 087 088 public RouteDefinition(@AsEndpointUri String uri) { 089 from(uri); 090 } 091 092 public RouteDefinition(Endpoint endpoint) { 093 from(endpoint); 094 } 095 096 /** 097 * This route is created from the REST DSL. 098 */ 099 public void fromRest(@AsEndpointUri String uri) { 100 from(uri); 101 rest = true; 102 } 103 104 /** 105 * Check if the route has been prepared 106 * 107 * @return wether the route has been prepared or not 108 * @see RouteDefinitionHelper#prepareRoute(ModelCamelContext, 109 * RouteDefinition) 110 */ 111 public boolean isPrepared() { 112 return prepared.get(); 113 } 114 115 /** 116 * Marks the route definition as prepared. 117 * <p/> 118 * This is needed if routes have been created by components such as 119 * <tt>camel-spring</tt> or <tt>camel-blueprint</tt>. Usually they share 120 * logic in the <tt>camel-core-xml</tt> module which prepares the routes. 121 */ 122 public void markPrepared() { 123 prepared.set(true); 124 } 125 126 /** 127 * Marks the route definition as un-prepared. 128 * <p/> 129 * This is needed if routes have been created by components such as 130 * <tt>camel-scala</tt>. To unset the prepare so the routes can be prepared 131 * at a later stage when scala has build the routes completely. 132 */ 133 public void markUnprepared() { 134 prepared.set(false); 135 } 136 137 @Override 138 public String toString() { 139 if (getId() != null) { 140 return "Route(" + getId() + ")[" + (input != null ? input : "") + " -> " + outputs + "]"; 141 } else { 142 return "Route[" + input + " -> " + outputs + "]"; 143 } 144 } 145 146 @Override 147 public String getShortName() { 148 return "route"; 149 } 150 151 @Override 152 public String getLabel() { 153 return "Route[" + input.getLabel() + "]"; 154 } 155 156 @Override 157 public String getRouteId() { 158 return getId(); 159 } 160 161 @Override 162 public String getEndpointUrl() { 163 return input != null ? input.getEndpointUri() : null; 164 } 165 166 // Fluent API 167 // ----------------------------------------------------------------------- 168 169 /** 170 * Creates an input to the route 171 * 172 * @param uri the from uri 173 * @return the builder 174 */ 175 public RouteDefinition from(@AsEndpointUri String uri) { 176 setInput(new FromDefinition(uri)); 177 return this; 178 } 179 180 /** 181 * Creates an input to the route 182 * 183 * @param endpoint the from endpoint 184 * @return the builder 185 */ 186 public RouteDefinition from(Endpoint endpoint) { 187 setInput(new FromDefinition(endpoint)); 188 return this; 189 } 190 191 /** 192 * Creates an input to the route 193 * 194 * @param endpoint the from endpoint 195 * @return the builder 196 */ 197 public RouteDefinition from(EndpointConsumerBuilder endpoint) { 198 setInput(new FromDefinition(endpoint)); 199 return this; 200 } 201 202 /** 203 * Set the group name for this route 204 * 205 * @param name the group name 206 * @return the builder 207 */ 208 public RouteDefinition group(String name) { 209 setGroup(name); 210 return this; 211 } 212 213 /** 214 * Set the route group for this route 215 * 216 * @param group the route group 217 * @return the builder 218 */ 219 @Override 220 public RouteDefinition routeGroup(String group) { 221 setGroup(group); 222 return this; 223 } 224 225 /** 226 * Set the route id for this route 227 * 228 * @param id the route id 229 * @return the builder 230 */ 231 @Override 232 public RouteDefinition routeId(String id) { 233 if (hasCustomIdAssigned()) { 234 throw new IllegalArgumentException("You can only set routeId one time per route."); 235 } 236 setId(id); 237 return this; 238 } 239 240 /** 241 * Set the route description for this route 242 * 243 * @param description the route description 244 * @return the builder 245 */ 246 @Override 247 public RouteDefinition routeDescription(String description) { 248 DescriptionDefinition desc = new DescriptionDefinition(); 249 desc.setText(description); 250 setDescription(desc); 251 return this; 252 } 253 254 /** 255 * Disable stream caching for this route. 256 * 257 * @return the builder 258 */ 259 public RouteDefinition noStreamCaching() { 260 setStreamCache("false"); 261 return this; 262 } 263 264 /** 265 * Enable stream caching for this route. 266 * 267 * @return the builder 268 */ 269 public RouteDefinition streamCaching() { 270 setStreamCache("true"); 271 return this; 272 } 273 274 /** 275 * Enable stream caching for this route. 276 * 277 * @param streamCache whether to use stream caching (true or false), the 278 * value can be a property placeholder 279 * @return the builder 280 */ 281 public RouteDefinition streamCaching(String streamCache) { 282 setStreamCache(streamCache); 283 return this; 284 } 285 286 /** 287 * Disable tracing for this route. 288 * 289 * @return the builder 290 */ 291 public RouteDefinition noTracing() { 292 setTrace("false"); 293 return this; 294 } 295 296 /** 297 * Enable tracing for this route. 298 * 299 * @return the builder 300 */ 301 public RouteDefinition tracing() { 302 setTrace("true"); 303 return this; 304 } 305 306 /** 307 * Enable tracing for this route. 308 * 309 * @param tracing whether to use tracing (true or false), the value can be a 310 * property placeholder 311 * @return the builder 312 */ 313 public RouteDefinition tracing(String tracing) { 314 setTrace(tracing); 315 return this; 316 } 317 318 /** 319 * Enable message history for this route. 320 * 321 * @return the builder 322 */ 323 public RouteDefinition messageHistory() { 324 setMessageHistory("true"); 325 return this; 326 } 327 328 /** 329 * Enable message history for this route. 330 * 331 * @param messageHistory whether to use message history (true or false), the 332 * value can be a property placeholder 333 * @return the builder 334 */ 335 public RouteDefinition messageHistory(String messageHistory) { 336 setMessageHistory(messageHistory); 337 return this; 338 } 339 340 /** 341 * Enable security mask for Logging on this route. 342 * 343 * @return the builder 344 */ 345 public RouteDefinition logMask() { 346 setLogMask("true"); 347 return this; 348 } 349 350 /** 351 * Sets whether security mask for logging is enabled on this route. 352 * 353 * @param logMask whether to enable security mask for Logging (true or 354 * false), the value can be a property placeholder 355 * @return the builder 356 */ 357 public RouteDefinition logMask(String logMask) { 358 setLogMask(logMask); 359 return this; 360 } 361 362 /** 363 * Disable message history for this route. 364 * 365 * @return the builder 366 */ 367 public RouteDefinition noMessageHistory() { 368 setMessageHistory("false"); 369 return this; 370 } 371 372 /** 373 * Disable delayer for this route. 374 * 375 * @return the builder 376 */ 377 public RouteDefinition noDelayer() { 378 setDelayer("0"); 379 return this; 380 } 381 382 /** 383 * Enable delayer for this route. 384 * 385 * @param delay delay in millis 386 * @return the builder 387 */ 388 public RouteDefinition delayer(long delay) { 389 setDelayer("" + delay); 390 return this; 391 } 392 393 /** 394 * Installs the given 395 * <a href="http://camel.apache.org/error-handler.html">error handler</a> 396 * builder. 397 * 398 * @param errorHandlerBuilder the error handler to be used by default for 399 * all child routes 400 * @return the current builder with the error handler configured 401 */ 402 public RouteDefinition errorHandler(ErrorHandlerFactory errorHandlerBuilder) { 403 setErrorHandlerFactory(errorHandlerBuilder); 404 // we are now using a route scoped error handler 405 contextScopedErrorHandler = false; 406 return this; 407 } 408 409 /** 410 * Disables this route from being auto started when Camel starts. 411 * 412 * @return the builder 413 */ 414 public RouteDefinition noAutoStartup() { 415 setAutoStartup("false"); 416 return this; 417 } 418 419 /** 420 * Sets the auto startup property on this route. 421 * 422 * @param autoStartup whether to auto startup (true or false), the value can 423 * be a property placeholder 424 * @return the builder 425 */ 426 public RouteDefinition autoStartup(String autoStartup) { 427 setAutoStartup(autoStartup); 428 return this; 429 } 430 431 /** 432 * Sets the auto startup property on this route. 433 * 434 * @param autoStartup - boolean indicator 435 * @return the builder 436 */ 437 public RouteDefinition autoStartup(boolean autoStartup) { 438 setAutoStartup(Boolean.toString(autoStartup)); 439 return this; 440 } 441 442 /** 443 * Configures the startup order for this route 444 * <p/> 445 * Camel will reorder routes and star them ordered by 0..N where 0 is the 446 * lowest number and N the highest number. Camel will stop routes in reverse 447 * order when its stopping. 448 * 449 * @param order the order represented as a number 450 * @return the builder 451 */ 452 @Override 453 public RouteDefinition startupOrder(int order) { 454 setStartupOrder(order); 455 return this; 456 } 457 458 /** 459 * Configures route policies for this route 460 * 461 * @param policies the route policies 462 * @return the builder 463 */ 464 public RouteDefinition routePolicy(RoutePolicy... policies) { 465 if (routePolicies == null) { 466 routePolicies = new ArrayList<>(); 467 } 468 routePolicies.addAll(Arrays.asList(policies)); 469 return this; 470 } 471 472 /** 473 * Configures route policy for this route 474 * 475 * @param policy route policy 476 * @return the builder 477 */ 478 public RouteDefinition routePolicy(Supplier<RoutePolicy> policy) { 479 return routePolicy(policy.get()); 480 } 481 482 /** 483 * Configures a route policy for this route 484 * 485 * @param routePolicyRef reference to a {@link RoutePolicy} to lookup and 486 * use. You can specify multiple references by separating using 487 * comma. 488 * @return the builder 489 */ 490 public RouteDefinition routePolicyRef(String routePolicyRef) { 491 setRoutePolicyRef(routePolicyRef); 492 return this; 493 } 494 495 /** 496 * Configures a shutdown route option. 497 * 498 * @param shutdownRoute the option to use when shutting down this route 499 * @return the builder 500 */ 501 public RouteDefinition shutdownRoute(ShutdownRoute shutdownRoute) { 502 setShutdownRoute(shutdownRoute); 503 return this; 504 } 505 506 /** 507 * Configures a shutdown running task option. 508 * 509 * @param shutdownRunningTask the option to use when shutting down and how 510 * to act upon running tasks. 511 * @return the builder 512 */ 513 public RouteDefinition shutdownRunningTask(ShutdownRunningTask shutdownRunningTask) { 514 setShutdownRunningTask(shutdownRunningTask); 515 return this; 516 } 517 518 /** 519 * Declare the expected data type of the input message. If the actual 520 * message type is different at runtime, camel look for a required 521 * {@link org.apache.camel.spi.Transformer} and apply if exists. The type 522 * name consists of two parts, 'scheme' and 'name' connected with ':'. For 523 * Java type 'name' is a fully qualified class name. For example 524 * {@code java:java.lang.String}, {@code json:ABCOrder}. 525 * 526 * @see org.apache.camel.spi.Transformer 527 * @param urn input type URN 528 * @return the builder 529 */ 530 public RouteDefinition inputType(String urn) { 531 inputType = new InputTypeDefinition(); 532 inputType.setUrn(urn); 533 inputType.setValidate(false); 534 return this; 535 } 536 537 /** 538 * Declare the expected data type of the input message with content 539 * validation enabled. If the actual message type is different at runtime, 540 * camel look for a required {@link org.apache.camel.spi.Transformer} and 541 * apply if exists, and then applies {@link org.apache.camel.spi.Validator} 542 * as well. The type name consists of two parts, 'scheme' and 'name' 543 * connected with ':'. For Java type 'name' is a fully qualified class name. 544 * For example {@code java:java.lang.String}, {@code json:ABCOrder}. 545 * 546 * @see org.apache.camel.spi.Transformer 547 * @see org.apache.camel.spi.Validator 548 * @param urn input type URN 549 * @return the builder 550 */ 551 public RouteDefinition inputTypeWithValidate(String urn) { 552 inputType = new InputTypeDefinition(); 553 inputType.setUrn(urn); 554 inputType.setValidate(true); 555 return this; 556 } 557 558 /** 559 * Declare the expected data type of the input message by Java class. If the 560 * actual message type is different at runtime, camel look for a required 561 * {@link org.apache.camel.spi.Transformer} and apply if exists. 562 * 563 * @see org.apache.camel.spi.Transformer 564 * @param clazz Class object of the input type 565 * @return the builder 566 */ 567 public RouteDefinition inputType(Class clazz) { 568 inputType = new InputTypeDefinition(); 569 inputType.setJavaClass(clazz); 570 inputType.setValidate(false); 571 return this; 572 } 573 574 /** 575 * Declare the expected data type of the input message by Java class with 576 * content validation enabled. If the actual message type is different at 577 * runtime, camel look for a required 578 * {@link org.apache.camel.spi.Transformer} and apply if exists, and then 579 * applies {@link org.apache.camel.spi.Validator} as well. 580 * 581 * @see org.apache.camel.spi.Transformer 582 * @see org.apache.camel.spi.Validator 583 * @param clazz Class object of the input type 584 * @return the builder 585 */ 586 public RouteDefinition inputTypeWithValidate(Class clazz) { 587 inputType = new InputTypeDefinition(); 588 inputType.setJavaClass(clazz); 589 inputType.setValidate(true); 590 return this; 591 } 592 593 /** 594 * Declare the expected data type of the output message. If the actual 595 * message type is different at runtime, camel look for a required 596 * {@link org.apache.camel.spi.Transformer} and apply if exists. The type 597 * name consists of two parts, 'scheme' and 'name' connected with ':'. For 598 * Java type 'name' is a fully qualified class name. For example 599 * {@code java:java.lang.String}, {@code json:ABCOrder}. 600 * 601 * @see org.apache.camel.spi.Transformer 602 * @param urn output type URN 603 * @return the builder 604 */ 605 public RouteDefinition outputType(String urn) { 606 outputType = new OutputTypeDefinition(); 607 outputType.setUrn(urn); 608 outputType.setValidate(false); 609 return this; 610 } 611 612 /** 613 * Declare the expected data type of the output message with content 614 * validation enabled. If the actual message type is different at runtime, 615 * Camel look for a required {@link org.apache.camel.spi.Transformer} and 616 * apply if exists, and then applies {@link org.apache.camel.spi.Validator} 617 * as well. The type name consists of two parts, 'scheme' and 'name' 618 * connected with ':'. For Java type 'name' is a fully qualified class name. 619 * For example {@code java:java.lang.String}, {@code json:ABCOrder}. 620 * 621 * @see org.apache.camel.spi.Transformer 622 * @see org.apache.camel.spi.Validator 623 * @param urn output type URN 624 * @return the builder 625 */ 626 public RouteDefinition outputTypeWithValidate(String urn) { 627 outputType = new OutputTypeDefinition(); 628 outputType.setUrn(urn); 629 outputType.setValidate(true); 630 return this; 631 } 632 633 /** 634 * Declare the expected data type of the output message by Java class. If 635 * the actual message type is different at runtime, camel look for a 636 * required {@link org.apache.camel.spi.Transformer} and apply if exists. 637 * 638 * @see org.apache.camel.spi.Transformer 639 * @param clazz Class object of the output type 640 * @return the builder 641 */ 642 public RouteDefinition outputType(Class clazz) { 643 outputType = new OutputTypeDefinition(); 644 outputType.setJavaClass(clazz); 645 outputType.setValidate(false); 646 return this; 647 } 648 649 /** 650 * Declare the expected data type of the ouput message by Java class with 651 * content validation enabled. If the actual message type is different at 652 * runtime, camel look for a required 653 * {@link org.apache.camel.spi.Transformer} and apply if exists, and then 654 * applies {@link org.apache.camel.spi.Validator} as well. 655 * 656 * @see org.apache.camel.spi.Transformer 657 * @see org.apache.camel.spi.Validator 658 * @param clazz Class object of the output type 659 * @return the builder 660 */ 661 public RouteDefinition outputTypeWithValidate(Class clazz) { 662 outputType = new OutputTypeDefinition(); 663 outputType.setJavaClass(clazz); 664 outputType.setValidate(true); 665 return this; 666 } 667 668 /** 669 * Adds a custom property on the route. 670 */ 671 public RouteDefinition routeProperty(String key, String value) { 672 if (routeProperties == null) { 673 routeProperties = new ArrayList<>(); 674 } 675 676 PropertyDefinition prop = new PropertyDefinition(); 677 prop.setKey(key); 678 prop.setValue(value); 679 680 routeProperties.add(prop); 681 682 return this; 683 } 684 685 // Properties 686 // ----------------------------------------------------------------------- 687 688 public FromDefinition getInput() { 689 return input; 690 } 691 692 /** 693 * Input to the route. 694 */ 695 @XmlElementRef(required = false) 696 public void setInput(FromDefinition input) { 697 // required = false: in rest-dsl you can embed an in-lined route which 698 // does not have a <from> as its implied to be the rest endpoint 699 this.input = input; 700 } 701 702 @Override 703 public List<ProcessorDefinition<?>> getOutputs() { 704 return outputs; 705 } 706 707 /** 708 * Outputs are processors that determines how messages are processed by this 709 * route. 710 */ 711 @XmlElementRef 712 public void setOutputs(List<ProcessorDefinition<?>> outputs) { 713 this.outputs = outputs; 714 715 if (outputs != null) { 716 for (ProcessorDefinition<?> output : outputs) { 717 configureChild(output); 718 } 719 } 720 } 721 722 /** 723 * The group that this route belongs to; could be the name of the 724 * RouteBuilder class or be explicitly configured in the XML. 725 * <p/> 726 * May be null. 727 */ 728 public String getGroup() { 729 return group; 730 } 731 732 /** 733 * The group that this route belongs to; could be the name of the 734 * RouteBuilder class or be explicitly configured in the XML. 735 * <p/> 736 * May be null. 737 */ 738 @XmlAttribute 739 public void setGroup(String group) { 740 this.group = group; 741 } 742 743 /** 744 * Whether stream caching is enabled on this route. 745 */ 746 public String getStreamCache() { 747 return streamCache; 748 } 749 750 /** 751 * Whether stream caching is enabled on this route. 752 */ 753 @XmlAttribute 754 public void setStreamCache(String streamCache) { 755 this.streamCache = streamCache; 756 } 757 758 /** 759 * Whether tracing is enabled on this route. 760 */ 761 public String getTrace() { 762 return trace; 763 } 764 765 /** 766 * Whether tracing is enabled on this route. 767 */ 768 @XmlAttribute 769 public void setTrace(String trace) { 770 this.trace = trace; 771 } 772 773 /** 774 * Whether message history is enabled on this route. 775 */ 776 public String getMessageHistory() { 777 return messageHistory; 778 } 779 780 /** 781 * Whether message history is enabled on this route. 782 */ 783 @XmlAttribute 784 @Metadata(defaultValue = "true") 785 public void setMessageHistory(String messageHistory) { 786 this.messageHistory = messageHistory; 787 } 788 789 /** 790 * Whether security mask for Logging is enabled on this route. 791 */ 792 public String getLogMask() { 793 return logMask; 794 } 795 796 /** 797 * Whether security mask for Logging is enabled on this route. 798 */ 799 @XmlAttribute 800 public void setLogMask(String logMask) { 801 this.logMask = logMask; 802 } 803 804 /** 805 * Whether to slow down processing messages by a given delay in msec. 806 */ 807 public String getDelayer() { 808 return delayer; 809 } 810 811 /** 812 * Whether to slow down processing messages by a given delay in msec. 813 */ 814 @XmlAttribute 815 public void setDelayer(String delayer) { 816 this.delayer = delayer; 817 } 818 819 /** 820 * Whether to auto start this route 821 */ 822 public String getAutoStartup() { 823 return autoStartup; 824 } 825 826 /** 827 * Whether to auto start this route 828 */ 829 @XmlAttribute 830 @Metadata(defaultValue = "true") 831 public void setAutoStartup(String autoStartup) { 832 this.autoStartup = autoStartup; 833 } 834 835 /** 836 * To configure the ordering of the routes being started 837 */ 838 public Integer getStartupOrder() { 839 return startupOrder; 840 } 841 842 /** 843 * To configure the ordering of the routes being started 844 */ 845 @XmlAttribute 846 public void setStartupOrder(Integer startupOrder) { 847 this.startupOrder = startupOrder; 848 } 849 850 /** 851 * Sets the bean ref name of the error handler builder to use on this route 852 */ 853 @XmlAttribute 854 public void setErrorHandlerRef(String errorHandlerRef) { 855 this.errorHandlerRef = errorHandlerRef; 856 // we use an specific error handler ref (from Spring DSL) then wrap that 857 // with a error handler build ref so Camel knows its not just the 858 // default one 859 setErrorHandlerFactory(new ErrorHandlerBuilderRef(errorHandlerRef)); 860 } 861 862 /** 863 * Sets the bean ref name of the error handler builder to use on this route 864 */ 865 public String getErrorHandlerRef() { 866 return errorHandlerRef; 867 } 868 869 /** 870 * Sets the error handler if one is not already set 871 */ 872 public void setErrorHandlerFactoryIfNull(ErrorHandlerFactory errorHandlerFactory) { 873 if (this.errorHandlerFactory == null) { 874 setErrorHandlerFactory(errorHandlerFactory); 875 } 876 } 877 878 /** 879 * Reference to custom {@link org.apache.camel.spi.RoutePolicy} to use by 880 * the route. Multiple policies can be configured by separating values using 881 * comma. 882 */ 883 @XmlAttribute 884 public void setRoutePolicyRef(String routePolicyRef) { 885 this.routePolicyRef = routePolicyRef; 886 } 887 888 /** 889 * Reference to custom {@link org.apache.camel.spi.RoutePolicy} to use by 890 * the route. Multiple policies can be configured by separating values using 891 * comma. 892 */ 893 public String getRoutePolicyRef() { 894 return routePolicyRef; 895 } 896 897 public List<RoutePolicy> getRoutePolicies() { 898 return routePolicies; 899 } 900 901 @XmlTransient 902 public void setRoutePolicies(List<RoutePolicy> routePolicies) { 903 this.routePolicies = routePolicies; 904 } 905 906 public ShutdownRoute getShutdownRoute() { 907 return shutdownRoute; 908 } 909 910 /** 911 * To control how to shutdown the route. 912 */ 913 @XmlAttribute 914 @Metadata(defaultValue = "Default") 915 public void setShutdownRoute(ShutdownRoute shutdownRoute) { 916 this.shutdownRoute = shutdownRoute; 917 } 918 919 /** 920 * To control how to shutdown the route. 921 */ 922 public ShutdownRunningTask getShutdownRunningTask() { 923 return shutdownRunningTask; 924 } 925 926 /** 927 * To control how to shutdown the route. 928 */ 929 @XmlAttribute 930 @Metadata(defaultValue = "CompleteCurrentTaskOnly") 931 public void setShutdownRunningTask(ShutdownRunningTask shutdownRunningTask) { 932 this.shutdownRunningTask = shutdownRunningTask; 933 } 934 935 private ErrorHandlerFactory createErrorHandlerBuilder() { 936 if (errorHandlerRef != null) { 937 return new ErrorHandlerBuilderRef(errorHandlerRef); 938 } 939 940 // return a reference to the default error handler 941 return new ErrorHandlerBuilderRef(ErrorHandlerReifier.DEFAULT_ERROR_HANDLER_BUILDER); 942 } 943 944 @XmlTransient 945 public ErrorHandlerFactory getErrorHandlerFactory() { 946 if (errorHandlerFactory == null) { 947 errorHandlerFactory = createErrorHandlerBuilder(); 948 } 949 return errorHandlerFactory; 950 } 951 952 /** 953 * Sets the error handler to use with processors created by this builder 954 */ 955 public void setErrorHandlerFactory(ErrorHandlerFactory errorHandlerFactory) { 956 this.errorHandlerFactory = errorHandlerFactory; 957 } 958 959 @XmlAttribute 960 public Boolean isRest() { 961 return rest; 962 } 963 964 public RestDefinition getRestDefinition() { 965 return restDefinition; 966 } 967 968 @XmlTransient 969 public void setRestDefinition(RestDefinition restDefinition) { 970 this.restDefinition = restDefinition; 971 } 972 973 public RestBindingDefinition getRestBindingDefinition() { 974 return restBindingDefinition; 975 } 976 977 @XmlTransient 978 public void setRestBindingDefinition(RestBindingDefinition restBindingDefinition) { 979 this.restBindingDefinition = restBindingDefinition; 980 } 981 982 public boolean isContextScopedErrorHandler() { 983 return contextScopedErrorHandler; 984 } 985 986 @XmlElementRef(required = false) 987 public void setInputType(InputTypeDefinition inputType) { 988 this.inputType = inputType; 989 } 990 991 public InputTypeDefinition getInputType() { 992 return this.inputType; 993 } 994 995 @XmlElementRef(required = false) 996 public void setOutputType(OutputTypeDefinition outputType) { 997 this.outputType = outputType; 998 } 999 1000 public OutputTypeDefinition getOutputType() { 1001 return this.outputType; 1002 } 1003 1004 public List<PropertyDefinition> getRouteProperties() { 1005 return routeProperties; 1006 } 1007 1008 /** 1009 * To set metadata as properties on the route. 1010 */ 1011 @XmlElement(name = "routeProperty") 1012 @Metadata(label = "advanced") 1013 public void setRouteProperties(List<PropertyDefinition> routeProperties) { 1014 this.routeProperties = routeProperties; 1015 } 1016 1017 // **************************** 1018 // Static helpers 1019 // **************************** 1020 1021 public static RouteDefinition fromUri(String uri) { 1022 return new RouteDefinition().from(uri); 1023 } 1024 1025 public static RouteDefinition fromEndpoint(Endpoint endpoint) { 1026 return new RouteDefinition().from(endpoint); 1027 } 1028 1029}