25 Aralık 2020 Cuma

Camel Exception Kavramı

Giriş
Exception Route içinde yakalanır Açıklaması şöyle
The clause can either be included inside a specific route definition in order to handle exceptions thrown in said route as shown in the example, or on top of all route definitions in order to catch exceptions that could be thrown anywhere in the router.

It’s important to mention the clause handled(), which determines what to do when an exception is thrown. In this case, since we want to stop the execution and handle the exception, we used handled(true). If we used handled(false), the exception would be rethrown and it could either be caught in a different onException clause or crash the application. The default value is false, which means if we don’t include the clause, the exception will continue to crash the application.
Örnek
Şöyle yaparız. Burada exception bir route içinde yakalanıyor. handled(true) yapılıyor.
from("direct:say-hi")
  .onException(MissingParameterException.class)
    .handled(true)
    .setBody(constant("Expected a query param 'name' that could not be found."))
  .end()
  .choice()
    .when(isNull(header(NAME_TAG)))
      .throwException(new MissingParameterException())
    .otherwise()
      .setProperty(NAME_TAG, header(NAME_TAG))
  .end()
  .setBody(simple(String.format("Hello, ${property.%s}!", NAME_TAG)))
;

Hiç yorum yok:

Yorum Gönder