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