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     */
017    package org.apache.camel;
018    
019    import java.util.Map;
020    import java.util.concurrent.ExecutorService;
021    import java.util.concurrent.Future;
022    import java.util.concurrent.TimeUnit;
023    import java.util.concurrent.TimeoutException;
024    
025    import org.apache.camel.spi.Synchronization;
026    
027    /**
028     * Template (named like Spring's TransactionTemplate & JmsTemplate
029     * et al) for working with Camel and sending {@link Message} instances in an
030     * {@link Exchange} to an {@link Endpoint}.
031     * <br/><br/>
032     * <p/><b>Important:</b> Read the javadoc of each method carefully to ensure the behavior of the method is understood.
033     * Some methods is for <tt>InOnly</tt>, others for <tt>InOut</tt> MEP. And some methods throws
034     * {@link org.apache.camel.CamelExecutionException} while others stores any thrown exception on the returned
035     * {@link Exchange}.
036     * <br/><br/>
037     * <p/>All the methods which sends a message may throw {@link FailedToCreateProducerException} in
038     * case the {@link Producer} could not be created. Or a {@link NoSuchEndpointException} if the endpoint could
039     * not be resolved. There may be other related exceptions being thrown which occurs <i>before</i> the {@link Producer}
040     * has started sending the message.
041     * <br/><br/>
042     * <p/>All the sendBody or requestBody methods will return the content according to this strategy:
043     * <ul>
044     *   <li>throws {@link org.apache.camel.CamelExecutionException} if processing failed <i>during</i> routing
045     *       with the caused exception wrapped</li>
046     *   <li>The <tt>fault.body</tt> if there is a fault message set and its not <tt>null</tt></li>
047     *   <li>Either <tt>IN</tt> or <tt>OUT</tt> body according to the message exchange pattern. If the pattern is
048     *   Out capable then the <tt>OUT</tt> body is returned, otherwise <tt>IN</tt>.
049     * </ul>
050     * <br/><br/>
051     * <p/><b>Important note on usage:</b> See this
052     * <a href="http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html">FAQ entry</a>
053     * before using.
054     *
055     * @version $Revision: 962915 $
056     */
057    public interface ProducerTemplate extends Service {
058    
059        // Configuration methods
060        // -----------------------------------------------------------------------
061    
062        /**
063         * Gets the maximum cache size used in the backing cache pools.
064         *
065         * @return the maximum cache size
066         */
067        int getMaximumCacheSize();
068    
069        /**
070         * Sets a custom maximum cache size to use in the backing cache pools.
071         *
072         * @param maximumCacheSize the custom maximum cache size
073         */
074        void setMaximumCacheSize(int maximumCacheSize);
075    
076        /**
077         * Gets an approximated size of the current cached resources in the backing cache pools.
078         *
079         * @return the size of current cached resources
080         */
081        int getCurrentCacheSize();
082    
083        // Synchronous methods
084        // -----------------------------------------------------------------------
085    
086        /**
087         * Sends the exchange to the default endpoint
088         * <br/><br/>
089         * <b>Notice:</b> that if the processing of the exchange failed with an Exception
090         * it is <b>not</b> thrown from this method, but you can access it from the returned exchange using
091         * {@link org.apache.camel.Exchange#getException()}.
092         *
093         * @param exchange the exchange to send
094         * @return the returned exchange
095         */
096        Exchange send(Exchange exchange);
097    
098        /**
099         * Sends an exchange to the default endpoint using a supplied processor
100         * <br/><br/>
101         * <b>Notice:</b> that if the processing of the exchange failed with an Exception
102         * it is <b>not</b> thrown from this method, but you can access it from the returned exchange using
103         * {@link org.apache.camel.Exchange#getException()}.
104         *
105         * @param processor the transformer used to populate the new exchange
106         * {@link Processor} to populate the exchange
107         * @return the returned exchange
108         */
109        Exchange send(Processor processor);
110    
111        /**
112         * Sends the body to the default endpoint
113         * <br/><br/>
114         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
115         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
116         * the caused exception wrapped.
117         *
118         * @param body the payload to send
119         * @throws CamelExecutionException if the processing of the exchange failed
120         */
121        void sendBody(Object body) throws CamelExecutionException;
122    
123        /**
124         * Sends the body to the default endpoint with a specified header and header value
125         * <br/><br/>
126         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
127         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
128         * the caused exception wrapped.
129         *
130         * @param body the payload to send
131         * @param header the header name
132         * @param headerValue the header value
133         * @throws CamelExecutionException if the processing of the exchange failed
134         */
135        void sendBodyAndHeader(Object body, String header, Object headerValue) throws CamelExecutionException;
136    
137        /**
138         * Sends the body to the default endpoint with a specified property and property value
139         * <br/><br/>
140         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
141         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
142         * the caused exception wrapped.
143         *
144         * @param body          the payload to send
145         * @param property      the property name
146         * @param propertyValue the property value
147         * @throws CamelExecutionException if the processing of the exchange failed
148         */
149        void sendBodyAndProperty(Object body, String property, Object propertyValue) throws CamelExecutionException;
150        
151        /**
152         * Sends the body to the default endpoint with the specified headers and header values
153         * <br/><br/>
154         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
155         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
156         * the caused exception wrapped.
157         *
158         * @param body the payload to send
159         * @param headers      the headers
160         * @throws CamelExecutionException if the processing of the exchange failed
161         */
162        void sendBodyAndHeaders(Object body, Map<String, Object> headers) throws CamelExecutionException;
163    
164        // Allow sending to arbitrary endpoints
165        // -----------------------------------------------------------------------
166    
167        /**
168         * Sends the exchange to the given endpoint
169         * <br/><br/>
170         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
171         * it is <b>not</b> thrown from this method, but you can access it from the returned exchange using
172         * {@link org.apache.camel.Exchange#getException()}.
173         *
174         * @param endpointUri the endpoint URI to send the exchange to
175         * @param exchange    the exchange to send
176         * @return the returned exchange
177         * @throws CamelExecutionException if the processing of the exchange failed
178         */
179        Exchange send(String endpointUri, Exchange exchange);
180    
181        /**
182         * Sends an exchange to an endpoint using a supplied processor
183         * <br/><br/>
184         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
185         * it is <b>not</b> thrown from this method, but you can access it from the returned exchange using
186         * {@link org.apache.camel.Exchange#getException()}.
187         *
188         * @param endpointUri the endpoint URI to send the exchange to
189         * @param processor   the transformer used to populate the new exchange
190         * {@link Processor} to populate the exchange
191         * @return the returned exchange
192         * @throws CamelExecutionException if the processing of the exchange failed
193         */
194        Exchange send(String endpointUri, Processor processor);
195    
196        /**
197         * Sends an exchange to an endpoint using a supplied processor
198         * <br/><br/>
199         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
200         * it is <b>not</b> thrown from this method, but you can access it from the returned exchange using
201         * {@link org.apache.camel.Exchange#getException()}.
202         *
203         * @param endpointUri the endpoint URI to send the exchange to
204         * @param pattern     the message {@link ExchangePattern} such as
205         *                    {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut}
206         * @param processor   the transformer used to populate the new exchange
207         * {@link Processor} to populate the exchange
208         * @return the returned exchange
209         */
210        Exchange send(String endpointUri, ExchangePattern pattern, Processor processor);
211    
212        /**
213         * Sends the exchange to the given endpoint
214         * <br/><br/>
215         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
216         * it is <b>not</b> thrown from this method, but you can access it from the returned exchange using
217         * {@link org.apache.camel.Exchange#getException()}.
218         *
219         * @param endpoint the endpoint to send the exchange to
220         * @param exchange the exchange to send
221         * @return the returned exchange
222         */
223        Exchange send(Endpoint endpoint, Exchange exchange);
224    
225        /**
226         * Sends an exchange to an endpoint using a supplied processor
227         * <br/><br/>
228         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
229         * it is <b>not</b> thrown from this method, but you can access it from the returned exchange using
230         * {@link org.apache.camel.Exchange#getException()}.
231         *
232         * @param endpoint  the endpoint to send the exchange to
233         * @param processor the transformer used to populate the new exchange
234         * {@link Processor} to populate the exchange
235         * @return the returned exchange
236         */
237        Exchange send(Endpoint endpoint, Processor processor);
238    
239        /**
240         * Sends an exchange to an endpoint using a supplied processor
241         * <br/><br/>
242         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
243         * it is <b>not</b> thrown from this method, but you can access it from the returned exchange using
244         * {@link org.apache.camel.Exchange#getException()}.
245         *
246         * @param endpoint  the endpoint to send the exchange to
247         * @param pattern   the message {@link ExchangePattern} such as
248         *                  {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut}
249         * @param processor the transformer used to populate the new exchange
250         * {@link Processor} to populate the exchange
251         * @return the returned exchange
252         */
253        Exchange send(Endpoint endpoint, ExchangePattern pattern, Processor processor);
254    
255        /**
256         * Send the body to an endpoint
257         * <br/><br/>
258         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
259         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
260         * the caused exception wrapped.
261         *
262         * @param endpoint   the endpoint to send the exchange to
263         * @param body       the payload
264         * @throws CamelExecutionException if the processing of the exchange failed
265         */
266        void sendBody(Endpoint endpoint, Object body) throws CamelExecutionException;
267    
268        /**
269         * Send the body to an endpoint
270         * <br/><br/>
271         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
272         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
273         * the caused exception wrapped.
274         *
275         * @param endpointUri   the endpoint URI to send the exchange to
276         * @param body          the payload
277         * @throws CamelExecutionException if the processing of the exchange failed
278         */
279        void sendBody(String endpointUri, Object body) throws CamelExecutionException;
280    
281        /**
282         * Send the body to an endpoint with the given {@link ExchangePattern}
283         * returning any result output body
284         * <br/><br/>
285         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
286         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
287         * the caused exception wrapped.
288         *
289         * @param endpoint      the endpoint to send the exchange to
290         * @param body          the payload
291         * @param pattern       the message {@link ExchangePattern} such as
292         *   {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut}
293         * @return the result if {@link ExchangePattern} is OUT capable, otherwise <tt>null</tt>
294         * @throws CamelExecutionException if the processing of the exchange failed
295         */
296        Object sendBody(Endpoint endpoint, ExchangePattern pattern, Object body) throws CamelExecutionException;
297    
298        /**
299         * Send the body to an endpoint returning any result output body
300         * <br/><br/>
301         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
302         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
303         * the caused exception wrapped.
304         *
305         * @param endpointUri   the endpoint URI to send the exchange to
306         * @param pattern       the message {@link ExchangePattern} such as
307         *   {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut}
308         * @param body          the payload
309         * @return the result if {@link ExchangePattern} is OUT capable, otherwise <tt>null</tt>
310         * @throws CamelExecutionException if the processing of the exchange failed
311         */
312        Object sendBody(String endpointUri, ExchangePattern pattern, Object body) throws CamelExecutionException;
313    
314        /**
315         * Sends the body to an endpoint with a specified header and header value
316         * <br/><br/>
317         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
318         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
319         * the caused exception wrapped.
320         *
321         * @param endpointUri the endpoint URI to send to
322         * @param body the payload to send
323         * @param header the header name
324         * @param headerValue the header value
325         * @throws CamelExecutionException if the processing of the exchange failed
326         */
327        void sendBodyAndHeader(String endpointUri, Object body, String header, Object headerValue) throws CamelExecutionException;
328    
329        /**
330         * Sends the body to an endpoint with a specified header and header value
331         * <br/><br/>
332         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
333         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
334         * the caused exception wrapped.
335         *
336         * @param endpoint the Endpoint to send to
337         * @param body the payload to send
338         * @param header the header name
339         * @param headerValue the header value
340         * @throws CamelExecutionException if the processing of the exchange failed
341         */
342        void sendBodyAndHeader(Endpoint endpoint, Object body, String header, Object headerValue) throws CamelExecutionException;
343    
344        /**
345         * Sends the body to an endpoint with a specified header and header value
346         * <br/><br/>
347         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
348         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
349         * the caused exception wrapped.
350         *
351         * @param endpoint the Endpoint to send to
352         * @param pattern the message {@link ExchangePattern} such as
353         *   {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut}
354         * @param body the payload to send
355         * @param header the header name
356         * @param headerValue the header value
357         * @return the result if {@link ExchangePattern} is OUT capable, otherwise <tt>null</tt>
358         * @throws CamelExecutionException if the processing of the exchange failed
359         */
360        Object sendBodyAndHeader(Endpoint endpoint, ExchangePattern pattern, Object body,
361                                 String header, Object headerValue) throws CamelExecutionException;
362    
363        /**
364         * Sends the body to an endpoint with a specified header and header value
365         * <br/><br/>
366         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
367         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
368         * the caused exception wrapped.
369         *
370         * @param endpoint the Endpoint URI to send to
371         * @param pattern the message {@link ExchangePattern} such as
372         *   {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut}
373         * @param body the payload to send
374         * @param header the header name
375         * @param headerValue the header value
376         * @return the result if {@link ExchangePattern} is OUT capable, otherwise <tt>null</tt>
377         * @throws CamelExecutionException if the processing of the exchange failed
378         */
379        Object sendBodyAndHeader(String endpoint, ExchangePattern pattern, Object body,
380                                 String header, Object headerValue) throws CamelExecutionException;
381    
382        /**
383         * Sends the body to an endpoint with a specified property and property value
384         * <br/><br/>
385         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
386         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
387         * the caused exception wrapped.
388         *
389         * @param endpointUri the endpoint URI to send to
390         * @param body the payload to send
391         * @param property the property name
392         * @param propertyValue the property value
393         * @throws CamelExecutionException if the processing of the exchange failed
394         */
395        void sendBodyAndProperty(String endpointUri, Object body, String property, Object propertyValue) throws CamelExecutionException;
396    
397        /**
398         * Sends the body to an endpoint with a specified property and property value
399         * <br/><br/>
400         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
401         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
402         * the caused exception wrapped.
403         *
404         * @param endpoint the Endpoint to send to
405         * @param body the payload to send
406         * @param property the property name
407         * @param propertyValue the property value
408         * @throws CamelExecutionException if the processing of the exchange failed
409         */
410        void sendBodyAndProperty(Endpoint endpoint, Object body, String property, Object propertyValue) throws CamelExecutionException;
411    
412        /**
413         * Sends the body to an endpoint with a specified property and property value
414         * <br/><br/>
415         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
416         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
417         * the caused exception wrapped.
418         *
419         * @param endpoint the Endpoint to send to
420         * @param pattern the message {@link ExchangePattern} such as
421         *   {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut}
422         * @param body the payload to send
423         * @param property the property name
424         * @param propertyValue the property value
425         * @return the result if {@link ExchangePattern} is OUT capable, otherwise <tt>null</tt>
426         * @throws CamelExecutionException if the processing of the exchange failed
427         */
428        Object sendBodyAndProperty(Endpoint endpoint, ExchangePattern pattern, Object body,
429                                   String property, Object propertyValue) throws CamelExecutionException;
430    
431        /**
432         * Sends the body to an endpoint with a specified property and property value
433         * <br/><br/>
434         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
435         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
436         * the caused exception wrapped.
437         *
438         * @param endpoint the Endpoint URI to send to
439         * @param pattern the message {@link ExchangePattern} such as
440         *   {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut}
441         * @param body the payload to send
442         * @param property the property name
443         * @param propertyValue the property value
444         * @return the result if {@link ExchangePattern} is OUT capable, otherwise <tt>null</tt>
445         * @throws CamelExecutionException if the processing of the exchange failed
446         */
447        Object sendBodyAndProperty(String endpoint, ExchangePattern pattern, Object body,
448                                   String property, Object propertyValue) throws CamelExecutionException;
449    
450        /**
451         * Sends the body to an endpoint with the specified headers and header values
452         * <br/><br/>
453         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
454         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
455         * the caused exception wrapped.
456         *
457         * @param endpointUri the endpoint URI to send to
458         * @param body the payload to send
459         * @param headers headers
460         * @throws CamelExecutionException if the processing of the exchange failed
461         */
462        void sendBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers) throws CamelExecutionException;
463    
464        /**
465         * Sends the body to an endpoint with the specified headers and header values
466         * <br/><br/>
467         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
468         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
469         * the caused exception wrapped.
470         *
471         * @param endpoint the endpoint URI to send to
472         * @param body the payload to send
473         * @param headers headers
474         * @throws CamelExecutionException if the processing of the exchange failed
475         */
476        void sendBodyAndHeaders(Endpoint endpoint, Object body, Map<String, Object> headers) throws CamelExecutionException;
477    
478        /**
479         * Sends the body to an endpoint with the specified headers and header values
480         * <br/><br/>
481         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
482         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
483         * the caused exception wrapped.
484         *
485         * @param endpointUri the endpoint URI to send to
486         * @param pattern the message {@link ExchangePattern} such as
487         *   {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut}
488         * @param body the payload to send
489         * @param headers headers
490         * @return the result if {@link ExchangePattern} is OUT capable, otherwise <tt>null</tt>
491         * @throws CamelExecutionException if the processing of the exchange failed
492         */
493        Object sendBodyAndHeaders(String endpointUri, ExchangePattern pattern, Object body,
494                                  Map<String, Object> headers) throws CamelExecutionException;
495    
496        /**
497         * Sends the body to an endpoint with the specified headers and header values
498         * <br/><br/>
499         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
500         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
501         * the caused exception wrapped.
502         *
503         * @param endpoint the endpoint URI to send to
504         * @param pattern the message {@link ExchangePattern} such as
505         *   {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut}
506         * @param body the payload to send
507         * @param headers headers
508         * @return the result if {@link ExchangePattern} is OUT capable, otherwise <tt>null</tt>
509         * @throws CamelExecutionException if the processing of the exchange failed
510         */
511        Object sendBodyAndHeaders(Endpoint endpoint, ExchangePattern pattern, Object body,
512                                  Map<String, Object> headers) throws CamelExecutionException;
513    
514    
515        // Methods using an InOut ExchangePattern
516        // -----------------------------------------------------------------------
517    
518        /**
519         * Sends an exchange to an endpoint using a supplied processor
520         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
521         * <br/><br/>
522         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
523         * it is <b>not</b> thrown from this method, but you can access it from the returned exchange using
524         * {@link org.apache.camel.Exchange#getException()}.
525         *
526         * @param endpoint  the Endpoint to send to
527         * @param processor the processor which will populate the exchange before sending
528         * @return the result (see class javadoc)
529         */
530        Exchange request(Endpoint endpoint, Processor processor);
531    
532        /**
533         * Sends an exchange to an endpoint using a supplied processor
534         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
535         * <br/><br/>
536         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
537         * it is <b>not</b> thrown from this method, but you can access it from the returned exchange using
538         * {@link org.apache.camel.Exchange#getException()}.
539         *
540         * @param endpointUri the endpoint URI to send to
541         * @param processor the processor which will populate the exchange before sending
542         * @return the result (see class javadoc)
543         */
544        Exchange request(String endpointUri, Processor processor);
545    
546        /**
547         * Sends the body to the default endpoint and returns the result content
548         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
549         * <br/><br/>
550         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
551         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
552         * the caused exception wrapped.
553         *
554         * @param body the payload to send
555         * @return the result (see class javadoc)
556         * @throws CamelExecutionException if the processing of the exchange failed
557         */
558        Object requestBody(Object body) throws CamelExecutionException;
559    
560        /**
561         * Sends the body to the default endpoint and returns the result content
562         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
563         * <br/><br/>
564         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
565         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
566         * the caused exception wrapped.
567         *
568         * @param body the payload to send
569         * @param type the expected response type
570         * @return the result (see class javadoc)
571         * @throws CamelExecutionException if the processing of the exchange failed
572         */
573        <T> T requestBody(Object body, Class<T> type) throws CamelExecutionException;
574    
575        /**
576         * Send the body to an endpoint returning any result output body.
577         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
578         * <br/><br/>
579         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
580         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
581         * the caused exception wrapped.
582         *
583         * @param endpoint the Endpoint to send to
584         * @param body     the payload
585         * @return the result (see class javadoc)
586         * @throws CamelExecutionException if the processing of the exchange failed
587         */
588        Object requestBody(Endpoint endpoint, Object body) throws CamelExecutionException;
589    
590        /**
591         * Send the body to an endpoint returning any result output body.
592         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
593         * <br/><br/>
594         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
595         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
596         * the caused exception wrapped.
597         *
598         * @param endpoint the Endpoint to send to
599         * @param body     the payload
600         * @param type     the expected response type
601         * @return the result (see class javadoc)
602         * @throws CamelExecutionException if the processing of the exchange failed
603         */
604        <T> T requestBody(Endpoint endpoint, Object body, Class<T> type) throws CamelExecutionException;
605    
606        /**
607         * Send the body to an endpoint returning any result output body.
608         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
609         * <br/><br/>
610         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
611         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
612         * the caused exception wrapped.
613         *
614         * @param endpointUri the endpoint URI to send to
615         * @param body        the payload
616         * @return the result (see class javadoc)
617         * @throws CamelExecutionException if the processing of the exchange failed
618         */
619        Object requestBody(String endpointUri, Object body) throws CamelExecutionException;
620    
621        /**
622         * Send the body to an endpoint returning any result output body.
623         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
624         * <br/><br/>
625         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
626         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
627         * the caused exception wrapped.
628         *
629         * @param endpointUri the endpoint URI to send to
630         * @param body        the payload
631         * @param type        the expected response type
632         * @return the result (see class javadoc)
633         * @throws CamelExecutionException if the processing of the exchange failed
634         */
635        <T> T requestBody(String endpointUri, Object body, Class<T> type) throws CamelExecutionException;
636    
637        /**
638         * Sends the body to the default endpoint and returns the result content
639         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
640         * <br/><br/>
641         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
642         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
643         * the caused exception wrapped.
644         *
645         * @param body        the payload
646         * @param header      the header name
647         * @param headerValue the header value
648         * @return the result (see class javadoc)
649         * @throws CamelExecutionException if the processing of the exchange failed
650         */
651        Object requestBodyAndHeader(Object body, String header, Object headerValue) throws CamelExecutionException;
652    
653        /**
654         * Send the body to an endpoint returning any result output body.
655         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
656         * <br/><br/>
657         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
658         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
659         * the caused exception wrapped.
660         *
661         * @param endpoint    the Endpoint to send to
662         * @param body        the payload
663         * @param header      the header name
664         * @param headerValue the header value
665         * @return the result (see class javadoc)
666         * @throws CamelExecutionException if the processing of the exchange failed
667         */
668        Object requestBodyAndHeader(Endpoint endpoint, Object body, String header, Object headerValue) throws CamelExecutionException;
669    
670        /**
671         * Send the body to an endpoint returning any result output body.
672         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
673         * <br/><br/>
674         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
675         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
676         * the caused exception wrapped.
677         *
678         * @param endpoint    the Endpoint to send to
679         * @param body        the payload
680         * @param header      the header name
681         * @param headerValue the header value
682         * @param type        the expected response type
683         * @return the result (see class javadoc)
684         * @throws CamelExecutionException if the processing of the exchange failed
685         */
686        <T> T requestBodyAndHeader(Endpoint endpoint, Object body, String header, Object headerValue, Class<T> type) throws CamelExecutionException;
687    
688        /**
689         * Send the body to an endpoint returning any result output body.
690         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
691         * <br/><br/>
692         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
693         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
694         * the caused exception wrapped.
695         *
696         * @param endpointUri the endpoint URI to send to
697         * @param body        the payload
698         * @param header      the header name
699         * @param headerValue the header value
700         * @return the result (see class javadoc)
701         * @throws CamelExecutionException if the processing of the exchange failed
702         */
703        Object requestBodyAndHeader(String endpointUri, Object body, String header, Object headerValue) throws CamelExecutionException;
704    
705        /**
706         * Send the body to an endpoint returning any result output body.
707         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
708         * <br/><br/>
709         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
710         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
711         * the caused exception wrapped.
712         *
713         * @param endpointUri the endpoint URI to send to
714         * @param body        the payload
715         * @param header      the header name
716         * @param headerValue the header value
717         * @param type        the expected response type
718         * @return the result (see class javadoc)
719         * @throws CamelExecutionException if the processing of the exchange failed
720         */
721        <T> T requestBodyAndHeader(String endpointUri, Object body, String header, Object headerValue, Class<T> type) throws CamelExecutionException;
722    
723        /**
724         * Sends the body to an endpoint with the specified headers and header values.
725         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
726         * <br/><br/>
727         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
728         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
729         * the caused exception wrapped.
730         *
731         * @param endpointUri the endpoint URI to send to
732         * @param body the payload to send
733         * @param headers headers
734         * @return the result (see class javadoc)
735         * @throws CamelExecutionException if the processing of the exchange failed
736         */
737        Object requestBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers) throws CamelExecutionException;
738    
739        /**
740         * Sends the body to an endpoint with the specified headers and header values.
741         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
742         * <br/><br/>
743         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
744         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
745         * the caused exception wrapped.
746         *
747         * @param endpointUri the endpoint URI to send to
748         * @param body the payload to send
749         * @param headers headers
750         * @param type the expected response type
751         * @return the result (see class javadoc)
752         * @throws CamelExecutionException if the processing of the exchange failed
753         */
754        <T> T requestBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers, Class<T> type) throws CamelExecutionException;
755    
756        /**
757         * Sends the body to an endpoint with the specified headers and header values.
758         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
759         * <br/><br/>
760         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
761         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
762         * the caused exception wrapped.
763         *
764         * @param endpoint the endpoint URI to send to
765         * @param body the payload to send
766         * @param headers headers
767         * @return the result (see class javadoc)
768         * @throws CamelExecutionException if the processing of the exchange failed
769         */
770        Object requestBodyAndHeaders(Endpoint endpoint, Object body, Map<String, Object> headers) throws CamelExecutionException;
771    
772        /**
773         * Sends the body to the default endpoint and returns the result content
774         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
775         * <br/><br/>
776         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
777         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
778         * the caused exception wrapped.
779         *
780         * @param body the payload to send
781         * @param headers headers
782         * @return the result (see class javadoc)
783         * @throws CamelExecutionException if the processing of the exchange failed
784         */
785        Object requestBodyAndHeaders(Object body, Map<String, Object> headers) throws CamelExecutionException;
786    
787        /**
788         * Sends the body to an endpoint with the specified headers and header values.
789         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
790         * <br/><br/>
791         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
792         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
793         * the caused exception wrapped.
794         *
795         * @param endpoint the endpoint URI to send to
796         * @param body the payload to send
797         * @param headers headers
798         * @param type the expected response type
799         * @return the result (see class javadoc)
800         * @throws CamelExecutionException if the processing of the exchange failed
801         */
802        <T> T requestBodyAndHeaders(Endpoint endpoint, Object body, Map<String, Object> headers, Class<T> type) throws CamelExecutionException;
803    
804    
805        // Asynchronous methods
806        // -----------------------------------------------------------------------
807    
808        /**
809         * Sets a custom executor service to use for async messaging.
810         *
811         * @param executorService  the executor service.
812         */
813        void setExecutorService(ExecutorService executorService);
814    
815        /**
816         * Sends an asynchronous exchange to the given endpoint.
817         *
818         * @param endpointUri the endpoint URI to send the exchange to
819         * @param exchange    the exchange to send
820         * @return a handle to be used to get the response in the future
821         */
822        Future<Exchange> asyncSend(String endpointUri, Exchange exchange);
823    
824        /**
825         * Sends an asynchronous exchange to the given endpoint.
826         *
827         * @param endpointUri the endpoint URI to send the exchange to
828         * @param processor   the transformer used to populate the new exchange
829         * @return a handle to be used to get the response in the future
830         */
831        Future<Exchange> asyncSend(String endpointUri, Processor processor);
832    
833        /**
834         * Sends an asynchronous body to the given endpoint.
835         * Uses an {@link ExchangePattern#InOnly} message exchange pattern.
836         *
837         * @param endpointUri the endpoint URI to send the exchange to
838         * @param body        the body to send
839         * @return a handle to be used to get the response in the future
840         */
841        Future<Object> asyncSendBody(String endpointUri, Object body);
842    
843        /**
844         * Sends an asynchronous body to the given endpoint.
845         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
846         *
847         * @param endpointUri the endpoint URI to send the exchange to
848         * @param body        the body to send
849         * @return a handle to be used to get the response in the future
850         */
851        Future<Object> asyncRequestBody(String endpointUri, Object body);
852    
853        /**
854         * Sends an asynchronous body to the given endpoint.
855         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
856         *
857         * @param endpointUri the endpoint URI to send the exchange to
858         * @param body        the body to send
859         * @param header      the header name
860         * @param headerValue the header value
861         * @return a handle to be used to get the response in the future
862         */
863        Future<Object> asyncRequestBodyAndHeader(String endpointUri, Object body, String header, Object headerValue);
864    
865        /**
866         * Sends an asynchronous body to the given endpoint.
867         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
868         *
869         * @param endpointUri the endpoint URI to send the exchange to
870         * @param body        the body to send
871         * @param headers     headers
872         * @return a handle to be used to get the response in the future
873         */
874        Future<Object> asyncRequestBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers);
875    
876        /**
877         * Sends an asynchronous body to the given endpoint.
878         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
879         *
880         * @param endpointUri the endpoint URI to send the exchange to
881         * @param body        the body to send
882         * @param type        the expected response type
883         * @return a handle to be used to get the response in the future
884         */
885        <T> Future<T> asyncRequestBody(String endpointUri, Object body, Class<T> type);
886    
887        /**
888         * Sends an asynchronous body to the given endpoint.
889         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
890         *
891         * @param endpointUri the endpoint URI to send the exchange to
892         * @param body        the body to send
893         * @param header      the header name
894         * @param headerValue the header value
895         * @param type        the expected response type
896         * @return a handle to be used to get the response in the future
897         */
898        <T> Future<T> asyncRequestBodyAndHeader(String endpointUri, Object body, String header, Object headerValue, Class<T> type);
899    
900        /**
901         * Sends an asynchronous body to the given endpoint.
902         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
903         *
904         * @param endpointUri the endpoint URI to send the exchange to
905         * @param body        the body to send
906         * @param headers     headers
907         * @param type        the expected response type
908         * @return a handle to be used to get the response in the future
909         */
910        <T> Future<T> asyncRequestBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers, Class<T> type);
911    
912        /**
913         * Sends an asynchronous exchange to the given endpoint.
914         *
915         * @param endpoint    the endpoint to send the exchange to
916         * @param exchange    the exchange to send
917         * @return a handle to be used to get the response in the future
918         */
919        Future<Exchange> asyncSend(Endpoint endpoint, Exchange exchange);
920    
921        /**
922         * Sends an asynchronous exchange to the given endpoint.
923         *
924         * @param endpoint    the endpoint to send the exchange to
925         * @param processor   the transformer used to populate the new exchange
926         * @return a handle to be used to get the response in the future
927         */
928        Future<Exchange> asyncSend(Endpoint endpoint, Processor processor);
929    
930        /**
931         * Sends an asynchronous body to the given endpoint.
932         * Uses an {@link ExchangePattern#InOnly} message exchange pattern.
933         *
934         * @param endpoint    the endpoint to send the exchange to
935         * @param body        the body to send
936         * @return a handle to be used to get the response in the future
937         */
938        Future<Object> asyncSendBody(Endpoint endpoint, Object body);
939    
940        /**
941         * Sends an asynchronous body to the given endpoint.
942         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
943         *
944         * @param endpoint    the endpoint to send the exchange to
945         * @param body        the body to send
946         * @return a handle to be used to get the response in the future
947         */
948        Future<Object> asyncRequestBody(Endpoint endpoint, Object body);
949    
950        /**
951         * Sends an asynchronous body to the given endpoint.
952         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
953         *
954         * @param endpoint the endpoint to send the exchange to
955         * @param body        the body to send
956         * @param header      the header name
957         * @param headerValue the header value
958         * @return a handle to be used to get the response in the future
959         */
960        Future<Object> asyncRequestBodyAndHeader(Endpoint endpoint, Object body, String header, Object headerValue);
961    
962        /**
963         * Sends an asynchronous body to the given endpoint.
964         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
965         *
966         * @param endpoint    the endpoint to send the exchange to
967         * @param body        the body to send
968         * @param headers     headers
969         * @return a handle to be used to get the response in the future
970         */
971        Future<Object> asyncRequestBodyAndHeaders(Endpoint endpoint, Object body, Map<String, Object> headers);
972    
973        /**
974         * Sends an asynchronous body to the given endpoint.
975         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
976         *
977         * @param endpoint    the endpoint to send the exchange to
978         * @param body        the body to send
979         * @param type        the expected response type
980         * @return a handle to be used to get the response in the future
981         */
982        <T> Future<T> asyncRequestBody(Endpoint endpoint, Object body, Class<T> type);
983    
984        /**
985         * Sends an asynchronous body to the given endpoint.
986         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
987         *
988         * @param endpoint    the endpoint to send the exchange to
989         * @param body        the body to send
990         * @param header      the header name
991         * @param headerValue the header value
992         * @param type        the expected response type
993         * @return a handle to be used to get the response in the future
994         */
995        <T> Future<T> asyncRequestBodyAndHeader(Endpoint endpoint, Object body, String header, Object headerValue, Class<T> type);
996    
997        /**
998         * Sends an asynchronous body to the given endpoint.
999         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
1000         *
1001         * @param endpoint    the endpoint to send the exchange to
1002         * @param body        the body to send
1003         * @param headers     headers
1004         * @param type        the expected response type
1005         * @return a handle to be used to get the response in the future
1006         */
1007        <T> Future<T> asyncRequestBodyAndHeaders(Endpoint endpoint, Object body, Map<String, Object> headers, Class<T> type);
1008    
1009        /**
1010         * Gets the response body from the future handle, will wait until the response is ready.
1011         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
1012         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
1013         * the caused exception wrapped.
1014         *
1015         * @param future      the handle to get the response
1016         * @param type        the expected response type
1017         * @return the result (see class javadoc)
1018         * @throws CamelExecutionException if the processing of the exchange failed
1019         */
1020        <T> T extractFutureBody(Future<Object> future, Class<T> type) throws CamelExecutionException;
1021    
1022        /**
1023         * Gets the response body from the future handle, will wait at most the given time for the response to be ready.
1024         * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
1025         * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
1026         * the caused exception wrapped.
1027         *
1028         * @param future      the handle to get the response
1029         * @param timeout     the maximum time to wait
1030         * @param unit        the time unit of the timeout argument
1031         * @param type        the expected response type
1032         * @return the result (see class javadoc)
1033         * @throws java.util.concurrent.TimeoutException if the wait timed out
1034         * @throws CamelExecutionException if the processing of the exchange failed
1035         */
1036        <T> T extractFutureBody(Future<Object> future, long timeout, TimeUnit unit, Class<T> type) throws TimeoutException, CamelExecutionException;
1037    
1038        // Asynchronous methods with callback
1039        // -----------------------------------------------------------------------
1040    
1041        /**
1042         * Sends an asynchronous exchange to the given endpoint.
1043         *
1044         * @param endpointUri   the endpoint URI to send the exchange to
1045         * @param exchange      the exchange to send
1046         * @param onCompletion  callback invoked when exchange has been completed
1047         * @return a handle to be used to get the response in the future
1048         */
1049        Future<Exchange> asyncCallback(String endpointUri, Exchange exchange, Synchronization onCompletion);
1050    
1051        /**
1052         * Sends an asynchronous exchange to the given endpoint.
1053         *
1054         * @param endpoint      the endpoint to send the exchange to
1055         * @param exchange      the exchange to send
1056         * @param onCompletion  callback invoked when exchange has been completed
1057         * @return a handle to be used to get the response in the future
1058         */
1059        Future<Exchange> asyncCallback(Endpoint endpoint, Exchange exchange, Synchronization onCompletion);
1060    
1061        /**
1062         * Sends an asynchronous exchange to the given endpoint using a supplied processor.
1063         *
1064         * @param endpointUri   the endpoint URI to send the exchange to
1065         * @param processor     the transformer used to populate the new exchange
1066         * {@link Processor} to populate the exchange
1067         * @param onCompletion  callback invoked when exchange has been completed
1068         * @return a handle to be used to get the response in the future
1069         */
1070        Future<Exchange> asyncCallback(String endpointUri, Processor processor, Synchronization onCompletion);
1071    
1072        /**
1073         * Sends an asynchronous exchange to the given endpoint using a supplied processor.
1074         *
1075         * @param endpoint      the endpoint to send the exchange to
1076         * @param processor     the transformer used to populate the new exchange
1077         * {@link Processor} to populate the exchange
1078         * @param onCompletion  callback invoked when exchange has been completed
1079         * @return a handle to be used to get the response in the future
1080         */
1081        Future<Exchange> asyncCallback(Endpoint endpoint, Processor processor, Synchronization onCompletion);
1082    
1083        /**
1084         * Sends an asynchronous body to the given endpoint.
1085         * Uses an {@link ExchangePattern#InOnly} message exchange pattern.
1086         *
1087         * @param endpointUri   the endpoint URI to send the exchange to
1088         * @param body          the body to send
1089         * @param onCompletion  callback invoked when exchange has been completed
1090         * @return a handle to be used to get the response in the future
1091         */
1092        Future<Object> asyncCallbackSendBody(String endpointUri, Object body, Synchronization onCompletion);
1093    
1094        /**
1095         * Sends an asynchronous body to the given endpoint.
1096         * Uses an {@link ExchangePattern#InOnly} message exchange pattern.
1097         *
1098         * @param endpoint      the endpoint to send the exchange to
1099         * @param body          the body to send
1100         * @param onCompletion  callback invoked when exchange has been completed
1101         * @return a handle to be used to get the response in the future
1102         */
1103        Future<Object> asyncCallbackSendBody(Endpoint endpoint, Object body, Synchronization onCompletion);
1104    
1105        /**
1106         * Sends an asynchronous body to the given endpoint.
1107         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
1108         *
1109         * @param endpointUri   the endpoint URI to send the exchange to
1110         * @param body          the body to send
1111         * @param onCompletion  callback invoked when exchange has been completed
1112         * @return a handle to be used to get the response in the future
1113         */
1114        Future<Object> asyncCallbackRequestBody(String endpointUri, Object body, Synchronization onCompletion);
1115    
1116        /**
1117         * Sends an asynchronous body to the given endpoint.
1118         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
1119         *
1120         * @param endpoint      the endpoint to send the exchange to
1121         * @param body          the body to send
1122         * @param onCompletion  callback invoked when exchange has been completed
1123         * @return a handle to be used to get the response in the future
1124         */
1125        Future<Object> asyncCallbackRequestBody(Endpoint endpoint, Object body, Synchronization onCompletion);
1126    
1127    }