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