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: 800792 $ 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 * Send the body to an endpoint returning any result output body. 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 endpoint the Endpoint to send to 553 * @param body the payload 554 * @param header the header name 555 * @param headerValue the header value 556 * @return the result (see class javadoc) 557 * @throws CamelExecutionException if the processing of the exchange failed 558 */ 559 Object requestBodyAndHeader(Endpoint endpoint, Object body, String header, Object headerValue); 560 561 /** 562 * Send the body to an endpoint returning any result output body. 563 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 564 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 565 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 566 * the caused exception wrapped. 567 * 568 * @param endpoint the Endpoint to send to 569 * @param body the payload 570 * @param header the header name 571 * @param headerValue the header value 572 * @param type the expected response type 573 * @return the result (see class javadoc) 574 * @throws CamelExecutionException if the processing of the exchange failed 575 */ 576 <T> T requestBodyAndHeader(Endpoint endpoint, Object body, String header, Object headerValue, Class<T> type); 577 578 /** 579 * Send the body to an endpoint returning any result output body. 580 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 581 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 582 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 583 * the caused exception wrapped. 584 * 585 * @param endpointUri the endpoint URI to send to 586 * @param body the payload 587 * @param header the header name 588 * @param headerValue the header value 589 * @return the result (see class javadoc) 590 * @throws CamelExecutionException if the processing of the exchange failed 591 */ 592 Object requestBodyAndHeader(String endpointUri, Object body, String header, Object headerValue); 593 594 /** 595 * Send the body to an endpoint returning any result output body. 596 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 597 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 598 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 599 * the caused exception wrapped. 600 * 601 * @param endpointUri the endpoint URI to send to 602 * @param body the payload 603 * @param header the header name 604 * @param headerValue the header value 605 * @param type the expected response type 606 * @return the result (see class javadoc) 607 * @throws CamelExecutionException if the processing of the exchange failed 608 */ 609 <T> T requestBodyAndHeader(String endpointUri, Object body, String header, Object headerValue, Class<T> type); 610 611 /** 612 * Sends the body to an endpoint with the specified headers and header values. 613 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 614 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 615 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 616 * the caused exception wrapped. 617 * 618 * @param endpointUri the endpoint URI to send to 619 * @param body the payload to send 620 * @param headers headers 621 * @return the result (see class javadoc) 622 * @throws CamelExecutionException if the processing of the exchange failed 623 */ 624 Object requestBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers); 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 * @param type the expected response type 637 * @return the result (see class javadoc) 638 * @throws CamelExecutionException if the processing of the exchange failed 639 */ 640 <T> T requestBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers, Class<T> type); 641 642 /** 643 * Sends the body to an endpoint with the specified headers and header values. 644 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 645 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 646 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 647 * the caused exception wrapped. 648 * 649 * @param endpoint the endpoint URI to send to 650 * @param body the payload to send 651 * @param headers headers 652 * @return the result (see class javadoc) 653 * @throws CamelExecutionException if the processing of the exchange failed 654 */ 655 Object requestBodyAndHeaders(Endpoint endpoint, Object body, Map<String, Object> headers); 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 * @param type the expected response type 668 * @return the result (see class javadoc) 669 * @throws CamelExecutionException if the processing of the exchange failed 670 */ 671 <T> T requestBodyAndHeaders(Endpoint endpoint, Object body, Map<String, Object> headers, Class<T> type); 672 673 674 // Asynchronous methods 675 // ----------------------------------------------------------------------- 676 677 /** 678 * Sets the executor service to use for async messaging. 679 * <p/> 680 * If none provided Camel will default use a {@link java.util.concurrent.ScheduledExecutorService} 681 * with a pool of 5 threads. 682 * 683 * @param executorService the executor service. 684 */ 685 void setExecutorService(ExecutorService executorService); 686 687 /** 688 * Sends an asynchronous exchange to the given endpoint. 689 * 690 * @param endpointUri the endpoint URI to send the exchange to 691 * @param exchange the exchange to send 692 * @return a handle to be used to get the response in the future 693 */ 694 Future<Exchange> asyncSend(String endpointUri, Exchange exchange); 695 696 /** 697 * Sends an asynchronous exchange to the given endpoint. 698 * 699 * @param endpointUri the endpoint URI to send the exchange to 700 * @param processor the transformer used to populate the new exchange 701 * @return a handle to be used to get the response in the future 702 */ 703 Future<Exchange> asyncSend(String endpointUri, Processor processor); 704 705 /** 706 * Sends an asynchronous body to the given endpoint. 707 * Uses an {@link ExchangePattern#InOnly} message exchange pattern. 708 * 709 * @param endpointUri the endpoint URI to send the exchange to 710 * @param body the body to send 711 * @return a handle to be used to get the response in the future 712 */ 713 Future<Object> asyncSendBody(String endpointUri, Object body); 714 715 /** 716 * Sends an asynchronous body to the given endpoint. 717 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 718 * 719 * @param endpointUri the endpoint URI to send the exchange to 720 * @param body the body to send 721 * @return a handle to be used to get the response in the future 722 */ 723 Future<Object> asyncRequestBody(String endpointUri, Object body); 724 725 /** 726 * Sends an asynchronous body to the given endpoint. 727 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 728 * 729 * @param endpointUri the endpoint URI to send the exchange to 730 * @param body the body to send 731 * @param header the header name 732 * @param headerValue the header value 733 * @return a handle to be used to get the response in the future 734 */ 735 Future<Object> asyncRequestBodyAndHeader(String endpointUri, Object body, String header, Object headerValue); 736 737 /** 738 * Sends an asynchronous body to the given endpoint. 739 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 740 * 741 * @param endpointUri the endpoint URI to send the exchange to 742 * @param body the body to send 743 * @param headers headers 744 * @return a handle to be used to get the response in the future 745 */ 746 Future<Object> asyncRequestBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers); 747 748 /** 749 * Sends an asynchronous body to the given endpoint. 750 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 751 * 752 * @param endpointUri the endpoint URI to send the exchange to 753 * @param body the body to send 754 * @param type the expected response type 755 * @return a handle to be used to get the response in the future 756 */ 757 <T> Future<T> asyncRequestBody(String endpointUri, Object body, Class<T> type); 758 759 /** 760 * Sends an asynchronous body to the given endpoint. 761 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 762 * 763 * @param endpointUri the endpoint URI to send the exchange to 764 * @param body the body to send 765 * @param header the header name 766 * @param headerValue the header value 767 * @param type the expected response type 768 * @return a handle to be used to get the response in the future 769 */ 770 <T> Future<T> asyncRequestBodyAndHeader(String endpointUri, Object body, String header, Object headerValue, Class<T> type); 771 772 /** 773 * Sends an asynchronous body to the given endpoint. 774 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 775 * 776 * @param endpointUri the endpoint URI to send the exchange to 777 * @param body the body to send 778 * @param headers headers 779 * @param type the expected response type 780 * @return a handle to be used to get the response in the future 781 */ 782 <T> Future<T> asyncRequestBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers, Class<T> type); 783 784 /** 785 * Sends an asynchronous exchange to the given endpoint. 786 * 787 * @param endpoint the endpoint to send the exchange to 788 * @param exchange the exchange to send 789 * @return a handle to be used to get the response in the future 790 */ 791 Future<Exchange> asyncSend(Endpoint endpoint, Exchange exchange); 792 793 /** 794 * Sends an asynchronous exchange to the given endpoint. 795 * 796 * @param endpoint the endpoint to send the exchange to 797 * @param processor the transformer used to populate the new exchange 798 * @return a handle to be used to get the response in the future 799 */ 800 Future<Exchange> asyncSend(Endpoint endpoint, Processor processor); 801 802 /** 803 * Sends an asynchronous body to the given endpoint. 804 * Uses an {@link ExchangePattern#InOnly} message exchange pattern. 805 * 806 * @param endpoint the endpoint to send the exchange to 807 * @param body the body to send 808 * @return a handle to be used to get the response in the future 809 */ 810 Future<Object> asyncSendBody(Endpoint endpoint, Object body); 811 812 /** 813 * Sends an asynchronous body to the given endpoint. 814 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 815 * 816 * @param endpoint the endpoint to send the exchange to 817 * @param body the body to send 818 * @return a handle to be used to get the response in the future 819 */ 820 Future<Object> asyncRequestBody(Endpoint endpoint, Object body); 821 822 /** 823 * Sends an asynchronous body to the given endpoint. 824 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 825 * 826 * @param endpoint the endpoint to send the exchange to 827 * @param body the body to send 828 * @param header the header name 829 * @param headerValue the header value 830 * @return a handle to be used to get the response in the future 831 */ 832 Future<Object> asyncRequestBodyAndHeader(Endpoint endpoint, Object body, String header, Object headerValue); 833 834 /** 835 * Sends an asynchronous body to the given endpoint. 836 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 837 * 838 * @param endpoint the endpoint to send the exchange to 839 * @param body the body to send 840 * @param headers headers 841 * @return a handle to be used to get the response in the future 842 */ 843 Future<Object> asyncRequestBodyAndHeaders(Endpoint endpoint, Object body, Map<String, Object> headers); 844 845 /** 846 * Sends an asynchronous body to the given endpoint. 847 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 848 * 849 * @param endpoint the endpoint to send the exchange to 850 * @param body the body to send 851 * @param type the expected response type 852 * @return a handle to be used to get the response in the future 853 */ 854 <T> Future<T> asyncRequestBody(Endpoint endpoint, Object body, Class<T> type); 855 856 /** 857 * Sends an asynchronous body to the given endpoint. 858 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 859 * 860 * @param endpoint the endpoint to send the exchange to 861 * @param body the body to send 862 * @param header the header name 863 * @param headerValue the header value 864 * @param type the expected response type 865 * @return a handle to be used to get the response in the future 866 */ 867 <T> Future<T> asyncRequestBodyAndHeader(Endpoint endpoint, Object body, String header, Object headerValue, Class<T> type); 868 869 /** 870 * Sends an asynchronous body to the given endpoint. 871 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 872 * 873 * @param endpoint the endpoint to send the exchange to 874 * @param body the body to send 875 * @param headers headers 876 * @param type the expected response type 877 * @return a handle to be used to get the response in the future 878 */ 879 <T> Future<T> asyncRequestBodyAndHeaders(Endpoint endpoint, Object body, Map<String, Object> headers, Class<T> type); 880 881 /** 882 * Gets the response body from the future handle, will wait until the response is ready. 883 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 884 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 885 * the caused exception wrapped. 886 * 887 * @param future the handle to get the response 888 * @param type the expected response type 889 * @return the result (see class javadoc) 890 * @throws CamelExecutionException if the processing of the exchange failed 891 */ 892 <T> T extractFutureBody(Future future, Class<T> type); 893 894 /** 895 * Gets the response body from the future handle, will wait at most the given time for the response to be ready. 896 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 897 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 898 * the caused exception wrapped. 899 * 900 * @param future the handle to get the response 901 * @param timeout the maximum time to wait 902 * @param unit the time unit of the timeout argument 903 * @param type the expected response type 904 * @return the result (see class javadoc) 905 * @throws java.util.concurrent.TimeoutException if the wait timed out 906 * @throws CamelExecutionException if the processing of the exchange failed 907 */ 908 <T> T extractFutureBody(Future future, long timeout, TimeUnit unit, Class<T> type) throws TimeoutException; 909 910 // Asynchronous methods with callback 911 // ----------------------------------------------------------------------- 912 913 /** 914 * Sends an asynchronous exchange to the given endpoint. 915 * 916 * @param endpointUri the endpoint URI to send the exchange to 917 * @param exchange the exchange to send 918 * @param onCompletion callback invoked when exchange has been completed 919 * @return a handle to be used to get the response in the future 920 */ 921 Future<Exchange> asyncCallback(String endpointUri, Exchange exchange, Synchronization onCompletion); 922 923 /** 924 * Sends an asynchronous exchange to the given endpoint. 925 * 926 * @param endpoint the endpoint to send the exchange to 927 * @param exchange the exchange to send 928 * @param onCompletion callback invoked when exchange has been completed 929 * @return a handle to be used to get the response in the future 930 */ 931 Future<Exchange> asyncCallback(Endpoint endpoint, Exchange exchange, Synchronization onCompletion); 932 933 /** 934 * Sends an asynchronous exchange to the given endpoint using a supplied processor. 935 * 936 * @param endpointUri the endpoint URI to send the exchange to 937 * @param processor the transformer used to populate the new exchange 938 * {@link Processor} to populate the exchange 939 * @param onCompletion callback invoked when exchange has been completed 940 * @return a handle to be used to get the response in the future 941 */ 942 Future<Exchange> asyncCallback(String endpointUri, Processor processor, Synchronization onCompletion); 943 944 /** 945 * Sends an asynchronous exchange to the given endpoint using a supplied processor. 946 * 947 * @param endpoint the endpoint to send the exchange to 948 * @param processor the transformer used to populate the new exchange 949 * {@link Processor} to populate the exchange 950 * @param onCompletion callback invoked when exchange has been completed 951 * @return a handle to be used to get the response in the future 952 */ 953 Future<Exchange> asyncCallback(Endpoint endpoint, Processor processor, Synchronization onCompletion); 954 955 /** 956 * Sends an asynchronous body to the given endpoint. 957 * Uses an {@link ExchangePattern#InOnly} message exchange pattern. 958 * 959 * @param endpointUri the endpoint URI to send the exchange to 960 * @param body the body to send 961 * @param onCompletion callback invoked when exchange has been completed 962 * @return a handle to be used to get the response in the future 963 */ 964 Future<Object> asyncCallbackSendBody(String endpointUri, Object body, Synchronization onCompletion); 965 966 /** 967 * Sends an asynchronous body to the given endpoint. 968 * Uses an {@link ExchangePattern#InOnly} message exchange pattern. 969 * 970 * @param endpoint the endpoint to send the exchange to 971 * @param body the body to send 972 * @param onCompletion callback invoked when exchange has been completed 973 * @return a handle to be used to get the response in the future 974 */ 975 Future<Object> asyncCallbackSendBody(Endpoint endpoint, Object body, Synchronization onCompletion); 976 977 /** 978 * Sends an asynchronous body to the given endpoint. 979 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 980 * 981 * @param endpointUri the endpoint URI to send the exchange to 982 * @param body the body to send 983 * @param onCompletion callback invoked when exchange has been completed 984 * @return a handle to be used to get the response in the future 985 */ 986 Future<Object> asyncCallbackRequestBody(String endpointUri, Object body, Synchronization onCompletion); 987 988 /** 989 * Sends an asynchronous body to the given endpoint. 990 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 991 * 992 * @param endpoint the endpoint to send the exchange to 993 * @param body the body to send 994 * @param onCompletion callback invoked when exchange has been completed 995 * @return a handle to be used to get the response in the future 996 */ 997 Future<Object> asyncCallbackRequestBody(Endpoint endpoint, Object body, Synchronization onCompletion); 998 999 }