Handling Errors in a Route
The Akula Server, which is based on Apache Camel, supports using Camel's
<onException> tag in route configuration files. You use the
<onException> block in your route configuration to define how the server handles exceptions at the route configuration level. By using the
<onException> block, you can specify additional modules or commands to execute when the route encounters an exception. You can also configure the in-route exception handler to return an error to the client or not, and whether or not to continue processing the route after the exception handler finishes.
This section describes the following topics:
Using the <onException> block
To add an
<onException> block to your route configuration, insert it after the
<from> tag inside a single route.
The following example shows a simple
In this case, the Akula Server attempts to process the modules in the route twice. If it still encounters an AKException or a subclass of AKException, the Akula Server logs an ERROR message to the log, stops processing the route at the exception point, and returns an error to the client.
The following table describes the child tags you can use in an
Specifies the class name of the exception that this block handles. You can set this to a generic exception type (such as java.lang.Exception), or a more specific exception type (such as java.io.IOException).
If you specify a generic type that is a parent class of the specific exception that is thrown, then this
Determines if the Akula Server returns an error or an OK message to the client.
The value of the
|Sets the maximum number of retries that the Akula Server attempts to make on the original module. If the maximum number is reached, then the Akula Server proceeds with processing the rest of the |
Specifies an additional module or command to execute when the route encounters an exception. For example, you can instruct the Akula Server to log a message or to execute a different module. You can include any number of
Determines if the route should "swallow" the exception (as if
The value of the
The following example sets the
<continued> child tag to
true. This instructs the Akula Server to return an OK message to the client, and to continue processing the route after the
<onException> block is done:
Handling in-route exceptions
When a route encounters an exception, the Akula Server adds the following exchange properties to the exchange object:
CamelFailureEndpoint– The module in the route that triggered the exception. This includes the prefix and the directive of the module. For example, "myModule://MyCustomModule".
CamelExceptionCaught– The fully qualified class name of the exception that was thrown. For example, "com.verivo.akula.api.core.exception.AKException".
In a custom module, you can use the
getProperties() methods of the AKExchange object to access the values of these exchange properties. You can specify a custom module that handles exceptions based on these properties in your
For more information about using custom modules, see Writing a Custom Module.