Red Hat JBoss Fuse

Apache Camel Development Guide

Develop applications with Apache Camel

Red Hat

Version 6.1

Legal Notice

Trademark Disclaimer

The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, JBoss, MetaMatrix, Fedora, the Infinity Logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Apache, ServiceMix, Camel, CXF, and ActiveMQ are trademarks of Apache Software Foundation. Any other names contained herein may be trademarks of their respective owners.

Legal Notice

Third Party Acknowledgements

One or more products in the Red Hat JBoss Fuse release includes third party components covered by licenses that require that the following documentation notices be provided:
  • JLine (http://jline.sourceforge.net) jline:jline:jar:1.0
    License: BSD (LICENSE.txt) - Copyright (c) 2002-2006, Marc Prud'hommeaux
    All rights reserved.
    Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
    • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
    • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    • Neither the name of JLine nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  • Stax2 API (http://woodstox.codehaus.org/StAX2) org.codehaus.woodstox:stax2-api:jar:3.1.1
    Copyright (c) <YEAR>, <OWNER> All rights reserved.
    Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
    • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
    • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  • jibx-run - JiBX runtime (http://www.jibx.org/main-reactor/jibx-run) org.jibx:jibx-run:bundle:1.2.3
    License: BSD (http://jibx.sourceforge.net/jibx-license.html) Copyright (c) 2003-2010, Dennis M. Sosnoski.
    All rights reserved.
    Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
    • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
    • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    • Neither the name of JiBX nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  • JavaAssist (http://www.jboss.org/javassist) org.jboss.javassist:com.springsource.javassist:jar:3.9.0.GA:compile
  • HAPI-OSGI-Base Module (http://hl7api.sourceforge.net/hapi-osgi-base/) ca.uhn.hapi:hapi-osgi-base:bundle:1.2
    License: Mozilla Public License 1.1 (http://www.mozilla.org/MPL/MPL-1.1.txt)
27 Apr 2015

Abstract

Guide to developing routes with Apache Camel.
I. Implementing Enterprise Integration Patterns
1. Building Blocks for Route Definitions
1.1. Implementing a RouteBuilder Class
1.2. Basic Java DSL Syntax
1.3. Router Schema in a Spring XML File
1.4. Endpoints
1.5. Processors
2. Basic Principles of Route Building
2.1. Pipeline Processing
2.2. Multiple Inputs
2.3. Exception Handling
2.3.1. onException Clause
2.3.2. Error Handler
2.3.3. doTry, doCatch, and doFinally
2.3.4. Propagating SOAP Exceptions
2.4. Bean Integration
2.5. Creating Exchange Instances
2.6. Transforming Message Content
2.6.1. Simple Message Transformations
2.6.2. Marshalling and Unmarshalling
2.6.3. Endpoint Bindings
2.7. Property Placeholders
2.8. Aspect Oriented Programming
2.9. Threading Model
2.10. Controlling Start-Up and Shutdown of Routes
2.11. Scheduled Route Policy
2.11.1. Overview of Scheduled Route Policies
2.11.2. Simple Scheduled Route Policy
2.11.3. Cron Scheduled Route Policy
2.12. JMX Naming
2.13. Performance and Optimization
3. Introducing Enterprise Integration Patterns
3.1. Overview of the Patterns
4. Messaging Systems
4.1. Message
4.2. Message Channel
4.3. Message Endpoint
4.4. Pipes and Filters
4.5. Message Router
4.6. Message Translator
5. Messaging Channels
5.1. Point-to-Point Channel
5.2. Publish-Subscribe Channel
5.3. Dead Letter Channel
5.4. Guaranteed Delivery
5.5. Message Bus
6. Message Construction
6.1. Correlation Identifier
6.2. Event Message
6.3. Return Address
7. Message Routing
7.1. Content-Based Router
7.2. Message Filter
7.3. Recipient List
7.4. Splitter
7.5. Aggregator
7.6. Resequencer
7.7. Routing Slip
7.8. Throttler
7.9. Delayer
7.10. Load Balancer
7.11. Multicast
7.12. Composed Message Processor
7.13. Scatter-Gather
7.14. Loop
7.15. Sampling
7.16. Dynamic Router
8. Message Transformation
8.1. Content Enricher
8.2. Content Filter
8.3. Normalizer
8.4. Claim Check
8.5. Sort
8.6. Validate
9. Messaging Endpoints
9.1. Messaging Mapper
9.2. Event Driven Consumer
9.3. Polling Consumer
9.4. Competing Consumers
9.5. Message Dispatcher
9.6. Selective Consumer
9.7. Durable Subscriber
9.8. Idempotent Consumer
9.9. Transactional Client
9.10. Messaging Gateway
9.11. Service Activator
10. System Management
10.1. Detour
10.2. LogEIP
10.3. Wire Tap
A. Migrating from ServiceMix EIP
A.1. Migrating Endpoints
A.2. Common Elements
A.3. ServiceMix EIP Patterns
A.4. Content-based Router
A.5. Content Enricher
A.6. Message Filter
A.7. Pipeline
A.8. Resequencer
A.9. Static Recipient List
A.10. Static Routing Slip
A.11. Wire Tap
A.12. XPath Splitter
II. Routing Expression and Predicate Languages
11. Introduction
11.1. Overview of the Languages
11.2. How to Invoke an Expression Language
12. Constant
13. EL
14. The File Language
14.1. When to Use the File Language
14.2. File Variables
14.3. Examples
15. Groovy
16. Header
17. JavaScript
18. JoSQL
19. JXPath
20. MVEL
21. The Object-Graph Navigation Language(OGNL)
22. PHP
23. Property
24. Python
25. Ref
26. Ruby
27. The Simple Language
27.1. Java DSL
27.2. XML DSL
27.3. Invoking an External Script
27.4. Expressions
27.5. Predicates
27.6. Variable Reference
27.7. Operator Reference
28. SpEL
29. The XPath Language
29.1. Java DSL
29.2. XML DSL
29.3. XPath Injection
29.4. XPath Builder
29.5. Enabling Saxon
29.6. Expressions
29.7. Predicates
29.8. Using Variables and Functions
29.9. Variable Namespaces
29.10. Function Reference
30. XQuery
III. Web Services and Routing with Camel CXF
31. Demonstration Code for Camel/CXF
31.1. Downloading and Installing the Demonstrations
31.2. Running the Demonstrations
32. Java-First Service Implementation
32.1. Java-First Overview
32.2. Define SEI and Related Classes
32.3. Annotate SEI for JAX-WS
32.4. Instantiate the WS Endpoint
32.5. Java-to-WSDL Maven Plug-In
33. WSDL-First Service Implementation
33.1. WSDL-First Overview
33.2. CustomerService WSDL Contract
33.3. WSDL-to-Java Maven Plug-In
33.4. Instantiate the WS Endpoint
33.5. Deploy to an OSGi Container
34. Implementing a WS Client
34.1. WS Client Overview
34.2. WSDL-to-Java Maven Plug-In
34.3. Instantiate the WS Client Proxy
34.4. Invoke WS Operations
34.5. Deploy to an OSGi Container
35. Pojo-Based Route
35.1. Processing Messages in POJO Format
35.2. WSDL-to-Java Maven Plug-In
35.3. Instantiate the WS Endpoint
35.4. Sort Messages by Operation Name
35.5. Process Operation Parameters
35.6. Deploy to OSGi
36. Payload-Based Route
36.1. Processing Messages in PAYLOAD Format
36.2. Instantiate the WS Endpoint
36.3. Sort Messages by Operation Name
36.4. SOAP/HTTP-to-JMS Bridge Use Case
36.5. Generating Responses Using Templates
36.6. TypeConverter for CXFPayload
36.7. Deploy to OSGi
37. Provider-Based Route
37.1. Provider-Based JAX-WS Endpoint
37.2. Create a Provider<?> Implementation Class
37.3. Instantiate the WS Endpoint
37.4. Sort Messages by Operation Name
37.5. SOAP/HTTP-to-JMS Bridge Use Case
37.6. Generating Responses Using Templates
37.7. TypeConverter for SAXSource
37.8. Deploy to OSGi
38. Proxying a Web Service
38.1. Proxying with HTTP
38.2. Proxying with POJO Format
38.3. Proxying with PAYLOAD Format
38.4. Handling HTTP Headers
39. Filtering SOAP Message Headers
39.1. Basic Configuration
39.2. Header Filtering
39.3. Implementing a Custom Filter
39.4. Installing Filters
IV. Programming EIP Components
40. Understanding Message Formats
40.1. Exchanges
40.2. Messages
40.3. Built-In Type Converters
40.4. Built-In UUID Generators
41. Implementing a Processor
41.1. Processing Model
41.2. Implementing a Simple Processor
41.3. Accessing Message Content
41.4. The ExchangeHelper Class
42. Type Converters
42.1. Type Converter Architecture
42.2. Implementing Type Converter Using Annotations
42.3. Implementing a Type Converter Directly
43. Producer and Consumer Templates
43.1. Using the Producer Template
43.1.1. Introduction to the Producer Template
43.1.2. Synchronous Send
43.1.3. Synchronous Request with InOut Pattern
43.1.4. Asynchronous Send
43.1.5. Asynchronous Request with InOut Pattern
43.1.6. Asynchronous Send with Callback
43.2. Using the Consumer Template
44. Implementing a Component
44.1. Component Architecture
44.1.1. Factory Patterns for a Component
44.1.2. Using a Component in a Route
44.1.3. Consumer Patterns and Threading
44.1.4. Asynchronous Processing
44.2. How to Implement a Component
44.3. Auto-Discovery and Configuration
44.3.1. Setting Up Auto-Discovery
44.3.2. Configuring a Component
45. Component Interface
45.1. The Component Interface
45.2. Implementing the Component Interface
46. Endpoint Interface
46.1. The Endpoint Interface
46.2. Implementing the Endpoint Interface
47. Consumer Interface
47.1. The Consumer Interface
47.2. Implementing the Consumer Interface
48. Producer Interface
48.1. The Producer Interface
48.2. Implementing the Producer Interface
49. Exchange Interface
49.1. The Exchange Interface
50. Message Interface
50.1. The Message Interface
50.2. Implementing the Message Interface
Index