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