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 /** 026 * Template (named like Spring's TransactionTemplate & JmsTemplate 027 * et al) for working with Camel and sending {@link Message} instances in an 028 * {@link Exchange} to an {@link Endpoint}. 029 * <p/> 030 * <b>All</b> methods throws {@link RuntimeCamelException} if processing of 031 * the {@link Exchange} failed and an Exception occured. The <tt>getCause</tt> 032 * method on {@link RuntimeCamelException} returns the wrapper original caused 033 * exception. 034 * <p/> 035 * All the send<b>Body</b> methods will return the content according to this strategy 036 * <ul> 037 * <li>throws {@link RuntimeCamelException} as stated above</li> 038 * <li>The <tt>fault.body</tt> if there is a fault message set and its not <tt>null</tt></li> 039 * <li>Either <tt>IN</tt> or <tt>OUT</tt> body according to the message exchange pattern. If the pattern is 040 * Out capable then the <tt>OUT</tt> body is returned, otherwise <tt>IN</tt>. 041 * </ul> 042 * <p/> 043 * <b>Important note on usage:</b> See this 044 * <a href="http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html">FAQ entry</a> 045 * before using. 046 * 047 * @version $Revision: 773182 $ 048 */ 049 public interface ProducerTemplate extends Service { 050 051 // Synchronous methods 052 // ----------------------------------------------------------------------- 053 054 /** 055 * Sends the exchange to the default endpoint 056 * 057 * @param exchange the exchange to send 058 * @return the returned exchange 059 */ 060 Exchange send(Exchange exchange); 061 062 /** 063 * Sends an exchange to the default endpoint using a supplied processor 064 * 065 * @param processor the transformer used to populate the new exchange 066 * {@link Processor} to populate the exchange 067 * @return the returned exchange 068 */ 069 Exchange send(Processor processor); 070 071 /** 072 * Sends the body to the default endpoint 073 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 074 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 075 * the caused exception wrapped. 076 * 077 * @param body the payload to send 078 * @throws CamelExecutionException if the processing of the exchange failed 079 */ 080 void sendBody(Object body); 081 082 /** 083 * Sends the body to the default endpoint with a specified header and header 084 * value 085 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 086 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 087 * the caused exception wrapped. 088 * 089 * @param body the payload to send 090 * @param header the header name 091 * @param headerValue the header value 092 * @throws CamelExecutionException if the processing of the exchange failed 093 */ 094 void sendBodyAndHeader(Object body, String header, Object headerValue); 095 096 /** 097 * Sends the body to the default endpoint with a specified property and property 098 * value 099 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 100 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 101 * the caused exception wrapped. 102 * 103 * @param body the payload to send 104 * @param property the property name 105 * @param propertyValue the property value 106 * @throws CamelExecutionException if the processing of the exchange failed 107 */ 108 void sendBodyAndProperty(Object body, String property, Object propertyValue); 109 110 /** 111 * Sends the body to the default endpoint with the specified headers and 112 * header values 113 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 114 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 115 * the caused exception wrapped. 116 * 117 * @param body the payload to send 118 * @param headers the headers 119 * @throws CamelExecutionException if the processing of the exchange failed 120 */ 121 void sendBodyAndHeaders(Object body, Map<String, Object> headers); 122 123 // Allow sending to arbitrary endpoints 124 // ----------------------------------------------------------------------- 125 126 /** 127 * Sends the exchange to the given endpoint 128 * 129 * @param endpointUri the endpoint URI to send the exchange to 130 * @param exchange the exchange to send 131 * @return the returned exchange 132 */ 133 Exchange send(String endpointUri, Exchange exchange); 134 135 /** 136 * Sends an exchange to an endpoint using a supplied processor 137 * 138 * @param endpointUri the endpoint URI to send the exchange to 139 * @param processor the transformer used to populate the new exchange 140 * {@link Processor} to populate the exchange 141 * @return the returned exchange 142 */ 143 Exchange send(String endpointUri, Processor processor); 144 145 /** 146 * Sends an exchange to an endpoint using a supplied processor 147 * 148 * @param endpointUri the endpoint URI to send the exchange to 149 * @param pattern the message {@link ExchangePattern} such as 150 * {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut} 151 * @param processor the transformer used to populate the new exchange 152 * {@link Processor} to populate the exchange 153 * @return the returned exchange 154 */ 155 Exchange send(String endpointUri, ExchangePattern pattern, Processor processor); 156 157 /** 158 * Sends the exchange to the given endpoint 159 * 160 * @param endpoint the endpoint to send the exchange to 161 * @param exchange the exchange to send 162 * @return the returned exchange 163 */ 164 Exchange send(Endpoint endpoint, Exchange exchange); 165 166 /** 167 * Sends an exchange to an endpoint using a supplied processor 168 * 169 * @param endpoint the endpoint to send the exchange to 170 * @param processor the transformer used to populate the new exchange 171 * {@link Processor} to populate the exchange 172 * @return the returned exchange 173 */ 174 Exchange send(Endpoint endpoint, Processor processor); 175 176 /** 177 * Sends an exchange to an endpoint using a supplied processor 178 * 179 * @param endpoint the endpoint to send the exchange to 180 * @param pattern the message {@link ExchangePattern} such as 181 * {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut} 182 * @param processor the transformer used to populate the new exchange 183 * {@link Processor} to populate the exchange 184 * @return the returned exchange 185 */ 186 Exchange send(Endpoint endpoint, ExchangePattern pattern, Processor processor); 187 188 /** 189 * Send the body to an endpoint 190 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 191 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 192 * the caused exception wrapped. 193 * 194 * @param endpoint the endpoint to send the exchange to 195 * @param body the payload 196 * @throws CamelExecutionException if the processing of the exchange failed 197 */ 198 void sendBody(Endpoint endpoint, Object body); 199 200 /** 201 * Send the body to an endpoint 202 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 203 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 204 * the caused exception wrapped. 205 * 206 * @param endpointUri the endpoint URI to send the exchange to 207 * @param body the payload 208 * @throws CamelExecutionException if the processing of the exchange failed 209 */ 210 void sendBody(String endpointUri, Object body); 211 212 /** 213 * Send the body to an endpoint with the given {@link ExchangePattern} 214 * returning any result output body 215 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 216 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 217 * the caused exception wrapped. 218 * 219 * @param endpoint the endpoint to send the exchange to 220 * @param body the payload 221 * @param pattern the message {@link ExchangePattern} such as 222 * {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut} 223 * @return the result if {@link ExchangePattern} is OUT capable, otherwise <tt>null</tt> 224 * @throws CamelExecutionException if the processing of the exchange failed 225 */ 226 Object sendBody(Endpoint endpoint, ExchangePattern pattern, Object body); 227 228 /** 229 * Send the body to an endpoint returning any result output body 230 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 231 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 232 * the caused exception wrapped. 233 * 234 * @param endpointUri the endpoint URI to send the exchange to 235 * @param pattern the message {@link ExchangePattern} such as 236 * {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut} 237 * @param body the payload 238 * @return the result if {@link ExchangePattern} is OUT capable, otherwise <tt>null</tt> 239 * @throws CamelExecutionException if the processing of the exchange failed 240 */ 241 Object sendBody(String endpointUri, ExchangePattern pattern, Object body); 242 243 /** 244 * Sends the body to an endpoint with a specified header and header value 245 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 246 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 247 * the caused exception wrapped. 248 * 249 * @param endpointUri the endpoint URI to send to 250 * @param body the payload to send 251 * @param header the header name 252 * @param headerValue the header value 253 * @throws CamelExecutionException if the processing of the exchange failed 254 */ 255 void sendBodyAndHeader(String endpointUri, Object body, String header, Object headerValue); 256 257 /** 258 * Sends the body to an endpoint with a specified header and header value 259 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 260 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 261 * the caused exception wrapped. 262 * 263 * @param endpoint the Endpoint to send to 264 * @param body the payload to send 265 * @param header the header name 266 * @param headerValue the header value 267 * @throws CamelExecutionException if the processing of the exchange failed 268 */ 269 void sendBodyAndHeader(Endpoint endpoint, Object body, String header, Object headerValue); 270 271 /** 272 * Sends the body to an endpoint with a specified header and header value 273 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 274 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 275 * the caused exception wrapped. 276 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 277 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 278 * the caused exception wrapped. 279 * 280 * @param endpoint the Endpoint to send to 281 * @param pattern the message {@link ExchangePattern} such as 282 * {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut} 283 * @param body the payload to send 284 * @param header the header name 285 * @param headerValue the header value 286 * @return the result if {@link ExchangePattern} is OUT capable, otherwise <tt>null</tt> 287 * @throws CamelExecutionException if the processing of the exchange failed 288 */ 289 Object sendBodyAndHeader(Endpoint endpoint, ExchangePattern pattern, Object body, 290 String header, Object headerValue); 291 292 /** 293 * Sends the body to an endpoint with a specified header and header value 294 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 295 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 296 * the caused exception wrapped. 297 * 298 * @param endpoint the Endpoint URI to send to 299 * @param pattern the message {@link ExchangePattern} such as 300 * {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut} 301 * @param body the payload to send 302 * @param header the header name 303 * @param headerValue the header value 304 * @return the result if {@link ExchangePattern} is OUT capable, otherwise <tt>null</tt> 305 * @throws CamelExecutionException if the processing of the exchange failed 306 */ 307 Object sendBodyAndHeader(String endpoint, ExchangePattern pattern, Object body, 308 String header, Object headerValue); 309 310 /** 311 * Sends the body to an endpoint with a specified property and property value 312 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 313 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 314 * the caused exception wrapped. 315 * 316 * @param endpointUri the endpoint URI to send to 317 * @param body the payload to send 318 * @param property the property name 319 * @param propertyValue the property value 320 * @throws CamelExecutionException if the processing of the exchange failed 321 */ 322 void sendBodyAndProperty(String endpointUri, Object body, String property, Object propertyValue); 323 324 /** 325 * Sends the body to an endpoint with a specified property and property value 326 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 327 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 328 * the caused exception wrapped. 329 * 330 * @param endpoint the Endpoint to send to 331 * @param body the payload to send 332 * @param property the property name 333 * @param propertyValue the property value 334 * @throws CamelExecutionException if the processing of the exchange failed 335 */ 336 void sendBodyAndProperty(Endpoint endpoint, Object body, String property, Object propertyValue); 337 338 /** 339 * Sends the body to an endpoint with a specified property and property value 340 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 341 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 342 * the caused exception wrapped. 343 * 344 * @param endpoint the Endpoint to send to 345 * @param pattern the message {@link ExchangePattern} such as 346 * {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut} 347 * @param body the payload to send 348 * @param property the property name 349 * @param propertyValue the property value 350 * @return the result if {@link ExchangePattern} is OUT capable, otherwise <tt>null</tt> 351 * @throws CamelExecutionException if the processing of the exchange failed 352 */ 353 Object sendBodyAndProperty(Endpoint endpoint, ExchangePattern pattern, Object body, 354 String property, Object propertyValue); 355 356 /** 357 * Sends the body to an endpoint with a specified property and property value 358 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 359 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 360 * the caused exception wrapped. 361 * 362 * @param endpoint the Endpoint URI to send to 363 * @param pattern the message {@link ExchangePattern} such as 364 * {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut} 365 * @param body the payload to send 366 * @param property the property name 367 * @param propertyValue the property value 368 * @return the result if {@link ExchangePattern} is OUT capable, otherwise <tt>null</tt> 369 * @throws CamelExecutionException if the processing of the exchange failed 370 */ 371 Object sendBodyAndProperty(String endpoint, ExchangePattern pattern, Object body, 372 String property, Object propertyValue); 373 374 /** 375 * Sends the body to an endpoint with the specified headers and header values 376 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 377 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 378 * the caused exception wrapped. 379 * 380 * @param endpointUri the endpoint URI to send to 381 * @param body the payload to send 382 * @param headers headers 383 * @throws CamelExecutionException if the processing of the exchange failed 384 */ 385 void sendBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers); 386 387 /** 388 * Sends the body to an endpoint with the specified headers and header values 389 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 390 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 391 * the caused exception wrapped. 392 * 393 * @param endpoint the endpoint URI to send to 394 * @param body the payload to send 395 * @param headers headers 396 * @throws CamelExecutionException if the processing of the exchange failed 397 */ 398 void sendBodyAndHeaders(Endpoint endpoint, Object body, Map<String, Object> headers); 399 400 /** 401 * Sends the body to an endpoint with the specified headers and header values 402 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 403 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 404 * the caused exception wrapped. 405 * 406 * @param endpointUri the endpoint URI to send to 407 * @param pattern the message {@link ExchangePattern} such as 408 * {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut} 409 * @param body the payload to send 410 * @param headers headers 411 * @return the result if {@link ExchangePattern} is OUT capable, otherwise <tt>null</tt> 412 * @throws CamelExecutionException if the processing of the exchange failed 413 */ 414 Object sendBodyAndHeaders(String endpointUri, ExchangePattern pattern, Object body, 415 Map<String, Object> headers); 416 417 /** 418 * Sends the body to an endpoint with the specified headers and header values 419 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 420 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 421 * the caused exception wrapped. 422 * 423 * @param endpoint the endpoint URI to send to 424 * @param pattern the message {@link ExchangePattern} such as 425 * {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut} 426 * @param body the payload to send 427 * @param headers headers 428 * @return the result if {@link ExchangePattern} is OUT capable, otherwise <tt>null</tt> 429 * @throws CamelExecutionException if the processing of the exchange failed 430 */ 431 Object sendBodyAndHeaders(Endpoint endpoint, ExchangePattern pattern, Object body, 432 Map<String, Object> headers); 433 434 435 // Methods using an InOut ExchangePattern 436 // ----------------------------------------------------------------------- 437 438 /** 439 * Sends an exchange to an endpoint using a supplied processor 440 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 441 * 442 * @param endpoint the Endpoint to send to 443 * @param processor the processor which will populate the exchange before sending 444 * @return the result (see class javadoc) 445 */ 446 Exchange request(Endpoint endpoint, Processor processor); 447 448 /** 449 * Sends an exchange to an endpoint using a supplied processor 450 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 451 * 452 * @param endpointUri the endpoint URI to send to 453 * @param processor the processor which will populate the exchange before sending 454 * @return the result (see class javadoc) 455 */ 456 Exchange request(String endpointUri, Processor processor); 457 458 /** 459 * Sends the body to the default endpoint and returns the result content 460 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 461 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 462 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 463 * the caused exception wrapped. 464 * 465 * @param body the payload to send 466 * @return the result (see class javadoc) 467 * @throws CamelExecutionException if the processing of the exchange failed 468 */ 469 Object requestBody(Object body); 470 471 /** 472 * Sends the body to the default endpoint and returns the result content 473 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 474 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 475 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 476 * the caused exception wrapped. 477 * 478 * @param body the payload to send 479 * @param type the expected response type 480 * @return the result (see class javadoc) 481 * @throws CamelExecutionException if the processing of the exchange failed 482 */ 483 <T> T requestBody(Object body, Class<T> type); 484 485 /** 486 * Send the body to an endpoint returning any result output body. 487 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 488 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 489 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 490 * the caused exception wrapped. 491 * 492 * @param endpoint the Endpoint to send to 493 * @param body the payload 494 * @return the result (see class javadoc) 495 * @throws CamelExecutionException if the processing of the exchange failed 496 */ 497 Object requestBody(Endpoint endpoint, Object body); 498 499 /** 500 * Send the body to an endpoint returning any result output body. 501 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 502 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 503 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 504 * the caused exception wrapped. 505 * 506 * @param endpoint the Endpoint to send to 507 * @param body the payload 508 * @param type the expected response type 509 * @return the result (see class javadoc) 510 * @throws CamelExecutionException if the processing of the exchange failed 511 */ 512 <T> T requestBody(Endpoint endpoint, Object body, Class<T> type); 513 514 /** 515 * Send the body to an endpoint returning any result output body. 516 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 517 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 518 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 519 * the caused exception wrapped. 520 * 521 * @param endpointUri the endpoint URI to send to 522 * @param body the payload 523 * @return the result (see class javadoc) 524 * @throws CamelExecutionException if the processing of the exchange failed 525 */ 526 Object requestBody(String endpointUri, Object body); 527 528 /** 529 * Send the body to an endpoint returning any result output body. 530 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 531 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 532 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 533 * the caused exception wrapped. 534 * 535 * @param endpointUri the endpoint URI to send to 536 * @param body the payload 537 * @param type the expected response type 538 * @return the result (see class javadoc) 539 * @throws CamelExecutionException if the processing of the exchange failed 540 */ 541 <T> T requestBody(String endpointUri, Object body, Class<T> type); 542 543 /** 544 * Send the body to an endpoint returning any result output body. 545 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 546 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 547 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 548 * the caused exception wrapped. 549 * 550 * @param endpoint the Endpoint to send to 551 * @param body the payload 552 * @param header the header name 553 * @param headerValue the header value 554 * @return the result (see class javadoc) 555 * @throws CamelExecutionException if the processing of the exchange failed 556 */ 557 Object requestBodyAndHeader(Endpoint endpoint, Object body, String header, Object headerValue); 558 559 /** 560 * Send the body to an endpoint returning any result output body. 561 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 562 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 563 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 564 * the caused exception wrapped. 565 * 566 * @param endpoint the Endpoint to send to 567 * @param body the payload 568 * @param header the header name 569 * @param headerValue the header value 570 * @param type the expected response type 571 * @return the result (see class javadoc) 572 * @throws CamelExecutionException if the processing of the exchange failed 573 */ 574 <T> T requestBodyAndHeader(Endpoint endpoint, Object body, String header, Object headerValue, Class<T> type); 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 endpointUri the endpoint URI to send to 584 * @param body the payload 585 * @param header the header name 586 * @param headerValue the header value 587 * @return the result (see class javadoc) 588 * @throws CamelExecutionException if the processing of the exchange failed 589 */ 590 Object requestBodyAndHeader(String endpointUri, Object body, String header, Object headerValue); 591 592 /** 593 * Send the body to an endpoint returning any result output body. 594 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 595 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 596 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 597 * the caused exception wrapped. 598 * 599 * @param endpointUri the endpoint URI to send to 600 * @param body the payload 601 * @param header the header name 602 * @param headerValue the header value 603 * @param type the expected response type 604 * @return the result (see class javadoc) 605 * @throws CamelExecutionException if the processing of the exchange failed 606 */ 607 <T> T requestBodyAndHeader(String endpointUri, Object body, String header, Object headerValue, Class<T> type); 608 609 /** 610 * Sends the body to an endpoint with the specified headers and header values. 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 to send 618 * @param headers headers 619 * @return the result (see class javadoc) 620 * @throws CamelExecutionException if the processing of the exchange failed 621 */ 622 Object requestBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers); 623 624 /** 625 * Sends the body to an endpoint with the specified headers and header values. 626 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 627 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 628 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 629 * the caused exception wrapped. 630 * 631 * @param endpointUri the endpoint URI to send to 632 * @param body the payload to send 633 * @param headers headers 634 * @param type the expected response type 635 * @return the result (see class javadoc) 636 * @throws CamelExecutionException if the processing of the exchange failed 637 */ 638 <T> T requestBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers, Class<T> type); 639 640 /** 641 * Sends the body to an endpoint with the specified headers and header values. 642 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 643 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 644 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 645 * the caused exception wrapped. 646 * 647 * @param endpoint the endpoint URI to send to 648 * @param body the payload to send 649 * @param headers headers 650 * @return the result (see class javadoc) 651 * @throws CamelExecutionException if the processing of the exchange failed 652 */ 653 Object requestBodyAndHeaders(Endpoint endpoint, Object body, Map<String, Object> headers); 654 655 /** 656 * Sends the body to an endpoint with the specified headers and header values. 657 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 658 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 659 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 660 * the caused exception wrapped. 661 * 662 * @param endpoint the endpoint URI to send to 663 * @param body the payload to send 664 * @param headers headers 665 * @param type the expected response type 666 * @return the result (see class javadoc) 667 * @throws CamelExecutionException if the processing of the exchange failed 668 */ 669 <T> T requestBodyAndHeaders(Endpoint endpoint, Object body, Map<String, Object> headers, Class<T> type); 670 671 672 // Asynchronous methods 673 // ----------------------------------------------------------------------- 674 675 /** 676 * Sets the executor service to use for async messaging. 677 * <p/> 678 * If none provided Camel will default use a {@link java.util.concurrent.ScheduledExecutorService} 679 * with a pool of 5 threads. 680 * 681 * @param executorService the executor service. 682 */ 683 void setExecutorService(ExecutorService executorService); 684 685 /** 686 * Sends an asynchronous exchange to the given endpoint. 687 * 688 * @param endpointUri the endpoint URI to send the exchange to 689 * @param exchange the exchange to send 690 * @return a handle to be used to get the response in the future 691 */ 692 Future<Exchange> asyncSend(String endpointUri, Exchange exchange); 693 694 /** 695 * Sends an asynchronous exchange to the given endpoint. 696 * 697 * @param endpointUri the endpoint URI to send the exchange to 698 * @param processor the transformer used to populate the new exchange 699 * @return a handle to be used to get the response in the future 700 */ 701 Future<Exchange> asyncSend(String endpointUri, Processor processor); 702 703 /** 704 * Sends an asynchronous body to the given endpoint. 705 * Uses an {@link ExchangePattern#InOnly} message exchange pattern. 706 * 707 * @param endpointUri the endpoint URI to send the exchange to 708 * @param body the body to send 709 * @return a handle to be used to get the response in the future 710 */ 711 Future<Object> asyncSendBody(String endpointUri, Object body); 712 713 /** 714 * Sends an asynchronous body to the given endpoint. 715 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 716 * 717 * @param endpointUri the endpoint URI to send the exchange to 718 * @param body the body to send 719 * @return a handle to be used to get the response in the future 720 */ 721 Future<Object> asyncRequestBody(String endpointUri, Object body); 722 723 /** 724 * Sends an asynchronous body to the given endpoint. 725 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 726 * 727 * @param endpointUri the endpoint URI to send the exchange to 728 * @param body the body to send 729 * @param header the header name 730 * @param headerValue the header value 731 * @return a handle to be used to get the response in the future 732 */ 733 Future<Object> asyncRequestBodyAndHeader(String endpointUri, Object body, String header, Object headerValue); 734 735 /** 736 * Sends an asynchronous body to the given endpoint. 737 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 738 * 739 * @param endpointUri the endpoint URI to send the exchange to 740 * @param body the body to send 741 * @param headers headers 742 * @return a handle to be used to get the response in the future 743 */ 744 Future<Object> asyncRequestBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers); 745 746 /** 747 * Sends an asynchronous body to the given endpoint. 748 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 749 * 750 * @param endpointUri the endpoint URI to send the exchange to 751 * @param body the body to send 752 * @param type the expected response type 753 * @return a handle to be used to get the response in the future 754 */ 755 <T> Future<T> asyncRequestBody(String endpointUri, Object body, Class<T> type); 756 757 /** 758 * Sends an asynchronous body to the given endpoint. 759 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 760 * 761 * @param endpointUri the endpoint URI to send the exchange to 762 * @param body the body to send 763 * @param header the header name 764 * @param headerValue the header value 765 * @param type the expected response type 766 * @return a handle to be used to get the response in the future 767 */ 768 <T> Future<T> asyncRequestBodyAndHeader(String endpointUri, Object body, String header, Object headerValue, Class<T> type); 769 770 /** 771 * Sends an asynchronous body to the given endpoint. 772 * Uses an {@link ExchangePattern#InOut} message exchange pattern. 773 * 774 * @param endpointUri the endpoint URI to send the exchange to 775 * @param body the body to send 776 * @param headers headers 777 * @param type the expected response type 778 * @return a handle to be used to get the response in the future 779 */ 780 <T> Future<T> asyncRequestBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers, Class<T> type); 781 782 /** 783 * Gets the response body from the future handle, will wait until the response is ready. 784 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 785 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 786 * the caused exception wrapped. 787 * 788 * @param future the handle to get the response 789 * @param type the expected response type 790 * @return the result (see class javadoc) 791 * @throws CamelExecutionException if the processing of the exchange failed 792 */ 793 <T> T extractFutureBody(Future future, Class<T> type); 794 795 /** 796 * Gets the response body from the future handle, will wait at most the given time for the response to be ready. 797 * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception 798 * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with 799 * the caused exception wrapped. 800 * 801 * @param future the handle to get the response 802 * @param timeout the maximum time to wait 803 * @param unit the time unit of the timeout argument 804 * @param type the expected response type 805 * @return the result (see class javadoc) 806 * @throws java.util.concurrent.TimeoutException if the wait timed out 807 * @throws CamelExecutionException if the processing of the exchange failed 808 */ 809 <T> T extractFutureBody(Future future, long timeout, TimeUnit unit, Class<T> type) throws TimeoutException; 810 811 }