This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch faq3 in repository https://gitbox.apache.org/repos/asf/camel.git
commit 1a6a9d561878ba5267a7bfe52acd42428fd367df Author: Claus Ibsen <[email protected]> AuthorDate: Sat Mar 7 16:42:41 2026 +0100 CAMEL-16861: Cleanup docs --- .../docs/modules/eips/pages/removeHeaders-eip.adoc | 14 +++ docs/user-manual/modules/ROOT/pages/component.adoc | 15 +++ docs/user-manual/modules/ROOT/pages/endpoint.adoc | 21 ++++ .../modules/ROOT/pages/exception-clause.adoc | 45 ++++++++ docs/user-manual/modules/faq/nav.adoc | 7 -- ...tion-orgapachecamelnosuchendpointexception.adoc | 24 ---- .../exception-orgxmlsaxsaxparseexception.adoc | 25 ----- ...-avoid-sending-some-or-all-message-headers.adoc | 121 --------------------- docs/user-manual/modules/faq/pages/index.adoc | 12 -- ...se-when-or-otherwise-in-a-java-camel-route.adoc | 87 --------------- ...-file-consumer-use-the-camel-error-handler.adoc | 48 -------- ...ge-with-error-handler-not-work-as-expected.adoc | 15 --- ...-the-exception-null-when-i-use-onexception.adoc | 36 ------ 13 files changed, 95 insertions(+), 375 deletions(-) diff --git a/core/camel-core-engine/src/main/docs/modules/eips/pages/removeHeaders-eip.adoc b/core/camel-core-engine/src/main/docs/modules/eips/pages/removeHeaders-eip.adoc index 97598fe8b564..2bdd4abac88a 100644 --- a/core/camel-core-engine/src/main/docs/modules/eips/pages/removeHeaders-eip.adoc +++ b/core/camel-core-engine/src/main/docs/modules/eips/pages/removeHeaders-eip.adoc @@ -109,6 +109,20 @@ YAML:: ---- ==== +== Leaking Camel headers when sending to an endpoint + +When I send a message to a Camel endpoint such as the +xref:components::mail-component.adoc[Mail] component, then the mail include some message +headers I do not want. How can I avoid this? + +This is a gotcha more people encounter. However, it's very easy to solve. +To remove all headers (see above) use a `*` expression: + +Most components will automatically remove all Camel specific headers (the header key starts with `Camel`) using +the `DefaultHeaderFilterStrategy` which automatic removes these headers. However if you use a component that does +not do this, such as a custom component, or a Camel component which has not been improved to do that, then you can +remove all these Camel specific headers using `Camel*` with the `removeHeaders` EIP as shown previously on this page. + == See Also Camel provides the following EIPs for removing headers or exchange properties: diff --git a/docs/user-manual/modules/ROOT/pages/component.adoc b/docs/user-manual/modules/ROOT/pages/component.adoc index 81f2f7dc1f54..34c74f28c7f3 100644 --- a/docs/user-manual/modules/ROOT/pages/component.adoc +++ b/docs/user-manual/modules/ROOT/pages/component.adoc @@ -139,6 +139,21 @@ Component-DSL is a builder API that allows using type-safe construction of Camel This is an advanced topic and described in more detail in the xref:writing-components.adoc[Writing Components Guide]. +=== Using HeaderFilterStrategy with components + +Some components supports configuring a custom header filter strategy. + +This allows you to implement the +`org.apache.camel.spi.HeaderFilterStrategy` interface, where one can +filter unwanted headers from the communication while not removing them from the +`Exchange`. + +Camel core offers a default filter strategy implementation, the +`DefaultHeaderFilterStrategy`, to which one can provide a regular expression +pattern or a set of header names to be filtered out. + + + == See Also - List of all Camel xref:components::index.adoc[Components] diff --git a/docs/user-manual/modules/ROOT/pages/endpoint.adoc b/docs/user-manual/modules/ROOT/pages/endpoint.adoc index 08d0283f20b9..489cbfeb03eb 100644 --- a/docs/user-manual/modules/ROOT/pages/endpoint.adoc +++ b/docs/user-manual/modules/ROOT/pages/endpoint.adoc @@ -177,6 +177,27 @@ So if you write the following XML it should work... </route> ---- +If you do not escape the & sign, then you can `org.xml.sax.SAXParseException` or other kind of XML parsing errors. + +In the URIs used for specifying Camel endpoints, the `&` is used to +separate the parameters. However, `&` also is a reserved character in XML. + +Because of this, you have to replace all `&` in your URIs by `+&+` when +using the XML DSL to configure Camel routes. + +An example: this snippet of code in Java DSL: + +[source,java] +---- +from("timer://myTimer?fixedRate=true&delay=0&period=2000") +---- + +... matches this example in the XML syntax where `&` has been replaced with `+&+` + +[source,xml] +---- +<from uri="timer://myTimer?fixedRate=true&delay=0&period=2000"/> +---- === Configuring parameter values using raw values, such as passwords diff --git a/docs/user-manual/modules/ROOT/pages/exception-clause.adoc b/docs/user-manual/modules/ROOT/pages/exception-clause.adoc index fc08a72fc348..cf2737cac53f 100644 --- a/docs/user-manual/modules/ROOT/pages/exception-clause.adoc +++ b/docs/user-manual/modules/ROOT/pages/exception-clause.adoc @@ -725,6 +725,51 @@ And the same example in YAML DSL uri: mock:result ---- +== Why is the exception null when I use onException ? + +If you use `onException` to handle exceptions, and want to get the caused +`Exception` from a `Processor` in Java code, such as shown below: + +[source,java] +---- +.onException(Exception.class) + .handled(true) + .process(new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + Exception cause = exchange.getException(); + // why cause exception is null ??? + } + }) +.end() +---- + +Then beware the caused exception is no longer available from `exchange.getException()`, because +the message is processed by the `onException` block. + +Instead, you can access the caused exception from exchange property on the +exchange with the key `Exchange.EXCEPTION_CAUGHT`, as follows: + +[source,java] +---- +Exception cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class); +---- + +The correct code to use in the example is there: + +[source,java] +---- +.onException(Exception.class).handled(true) + .process(new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + Exception cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class); + // we now have the caused exception + } + }) +.end() +---- + == Handling and Sending a Fixed Response Back to the Client In the route above we handled the exception but routed it to a different diff --git a/docs/user-manual/modules/faq/nav.adoc b/docs/user-manual/modules/faq/nav.adoc index fdee46d44771..ce01dab121e3 100644 --- a/docs/user-manual/modules/faq/nav.adoc +++ b/docs/user-manual/modules/faq/nav.adoc @@ -7,14 +7,7 @@ ** xref:what-is-camel.adoc[What is Camel?] ** xref:ROOT:languages.adoc[What languages are supported?] ** xref:why-the-name-camel.adoc[Why the name Camel?] -** xref:how-to-avoid-sending-some-or-all-message-headers.adoc[How to avoid sending some or all message headers?] ** xref:how-to-remove-the-http-protocol-headers-in-the-camel-message.adoc[How to remove the http protocol headers in the camel message?] ** xref:how-to-use-a-dynamic-uri-in-to.adoc[How to use a dynamic URI in to()?] ** xref:using-getin-or-getout-methods-on-exchange.adoc[Using getIn or getOut methods on Exchange] -** xref:why-can-i-not-use-when-or-otherwise-in-a-java-camel-route.adoc[Why can I not use when or otherwise in a Java Camel route?] -** xref:why-does-my-file-consumer-not-pick-up-the-file-and-how-do-i-let-the-file-consumer-use-the-camel-error-handler.adoc[Why does my file consumer not pick up the file, and how do I let the file consumer use the Camel error handler?] -** xref:why-does-useoriginalmessage-with-error-handler-not-work-as-expected.adoc[Why does useOriginalMessage with error handler not work as expected?] ** xref:why-is-my-message-body-empty.adoc[Why is my message body empty?] -** xref:why-is-the-exception-null-when-i-use-onexception.adoc[Why is the exception null when I use onException?] -** xref:exception-orgapachecamelnosuchendpointexception.adoc[Exception - org.apache.camel.NoSuchEndpointException] -** xref:exception-orgxmlsaxsaxparseexception.adoc[Exception - org.xml.sax.SAXParseException] diff --git a/docs/user-manual/modules/faq/pages/exception-orgapachecamelnosuchendpointexception.adoc b/docs/user-manual/modules/faq/pages/exception-orgapachecamelnosuchendpointexception.adoc deleted file mode 100644 index 487f046884eb..000000000000 --- a/docs/user-manual/modules/faq/pages/exception-orgapachecamelnosuchendpointexception.adoc +++ /dev/null @@ -1,24 +0,0 @@ -= Exception: `org.apache.camel.NoSuchEndpointException` - -The usual cause for this exception is a missing component JAR on the -classpath. The exception detail message will tell you what the missing -component is. You can solve the issue by adding the required JAR files -to the classpath. - -== Example: - -If you try to use the definition below without having `camel-jetty.jar` on -the classpath, you'll run into this exception: ----- -org.apache.camel.NoSuchEndpointException: No endpoint could be found for: jetty:http://localhost:8080/bus ----- - -For example in a route such as XML: - -[source,xml] ----- -<route> - <from uri="jetty:http://localhost:8080/bus" /> - <to uri="file://C:/tmp/something.xml" /> -</route> ----- diff --git a/docs/user-manual/modules/faq/pages/exception-orgxmlsaxsaxparseexception.adoc b/docs/user-manual/modules/faq/pages/exception-orgxmlsaxsaxparseexception.adoc deleted file mode 100644 index b67733a8ab71..000000000000 --- a/docs/user-manual/modules/faq/pages/exception-orgxmlsaxsaxparseexception.adoc +++ /dev/null @@ -1,25 +0,0 @@ -= Exception: `org.xml.sax.SAXParseException` - ----- -The reference to entity "..." must end with the ';' delimiter. ----- - -In the URIs used for specifying Camel endpoints, the `&` is used to -separate the parameters. However, `&` also is a reserved character in XML. - -Because of this, you have to replace all & in your URIs by `+&+` when -using the XML DSL to configure Camel routes. - -An example: this snippet of code in the xref:ROOT:dsl.adoc[DSL]... - -[source,java] ----- -from("timer://myTimer?fixedRate=true&delay=0&period=2000") ----- - -... matches this example in the XML syntax where `&` has been replaced with `+&+` - -[source,xml] ----- -<from uri="timer://myTimer?fixedRate=true&delay=0&period=2000"/> ----- diff --git a/docs/user-manual/modules/faq/pages/how-to-avoid-sending-some-or-all-message-headers.adoc b/docs/user-manual/modules/faq/pages/how-to-avoid-sending-some-or-all-message-headers.adoc deleted file mode 100644 index 6091e4d1235a..000000000000 --- a/docs/user-manual/modules/faq/pages/how-to-avoid-sending-some-or-all-message-headers.adoc +++ /dev/null @@ -1,121 +0,0 @@ -= How to avoid sending some or all message headers? - -When I send a message to a Camel endpoint such as the -xref:components::mail-component.adoc[Mail] component, then the mail include some message -headers I do not want. How can I avoid this? - -[[Howtoavoidsendingsomeorallmessageheaders-UseremoveHeadersintheroute]] -== Use removeHeaders in the route - -This is a gotcha more people encounter. However it's very easy to solve. -To remove all headers use a wildcard expression: - -[source,java] ----- -from(...).removeHeaders("*").to("smtp://....") ----- - -Similarly to remove all headers except some of your own (`myheader1` and -`myheader2`) use a wildcard with a vararg: - -[source,java] ----- -from(...).removeHeaders("*", "myheader1", "myheader2").to("smtp://....") ----- - -To do (a similar thing) in XML DSL you simply do: - -[source,xml] ----- -<route> - <from uri="..."/> - <removeHeaders pattern="*" excludePattern="header1|header2"/> - <to uri="smtp://..."/> -</route> ----- - -At present, the `excludePattern` only supports one header name (which -can be include wild cards or regular expressions). We tackle this -limitation with -https://issues.apache.org/jira/browse/CAMEL-6445[CAMEL-6445]. - -Again to remove only Camel headers but no other transport headers: - -[source,java] ----- -from(...).removeHeaders("Camel*").to("smtp://....") ----- - -To do this in XML DSL you simply do: - -[source,xml] ----- -<route> - <from uri="..."/> - <removeHeaders pattern="Camel*"/> - <to uri="smtp://..."/> -</route> ----- - -There is also a removeHeader in the DSL to remove a single header. But -it does not support patterns, so you can only remove a single header by -its name. - -[[Howtoavoidsendingsomeorallmessageheaders-UseHeaderFilterStrategy]] -== Use HeaderFilterStrategy - -An alternative is that some of the Camel -xref:ROOT:component.adoc[Components] supports configuring a custom header -filter strategy. -This allows you to implement the -`org.apache.camel.spi.HeaderFilterStrategy` interface, where one can -filter unwanted headers from the communication while not removing them from the -Exchange. Though it's often easier to use the `removeHeaders` in the Camel route -as shown above. - -Camel core offers a default filter strategy implementation, the -DefaultHeaderFilterStrategy class, to which one can provide a regular expression -pattern or a set of header names to be filtered out. - -[source,xml] ----- -<bean class="org.apache.camel.impl.DefaultHeaderFilterStrategy" id="myFilter"> - <property name="outFilter"> - <set> - <value>unwantedHeaderName</value> - </set> - </property> -</bean> -... -<setHeader name="allowedHeaderName"><constant>some metadata</constant></setHeader> -<setHeader name="unwantedHeaderName"><constant>some private data</constant></setHeader> -<to id="publish" uri="activemq:queue:destinationName?headerFilterStrategy=#myFilter"/> -<log message="${header.unwantedHeaderName}"/> ----- - -The destination queue would receive a JMS message with the allowedHeaderName as -JMS property. If the queue messages are consumed by a Camel route, then the -exchange will have the allowedHeaderName as a header. The log would print "some -private data" since the header has only been filtered out from the producer -endpoint, but not removed from the Exchange. - -[[Howtoavoidsendingsomeorallmessageheaders-SelectingTheAcceptedHeaders]] -== Selecting the accepted headers - -The more steps a route has, more headers tend to be present in the exchange. -When the number of headers is large, undetermined, or one can't know in advance -which headers must be filtered out, it is desirable not to deliver by default -the headers to the destination endpoint. - -In this case, one can filter out everything and selectively send only certain -headers to the destination endpoint. The DefaultHeaderFilterStrategy behavior -can be reversed so only certain headers are accepted through the filterOnMatch -property. - -[source,xml] ----- -<bean class="org.apache.camel.impl.DefaultHeaderFilterStrategy" id="myFilter"> - <property name="filterOnMatch" value="false" /> - ... -</bean> ----- diff --git a/docs/user-manual/modules/faq/pages/index.adoc b/docs/user-manual/modules/faq/pages/index.adoc index 75b98df03332..a90c274e152c 100644 --- a/docs/user-manual/modules/faq/pages/index.adoc +++ b/docs/user-manual/modules/faq/pages/index.adoc @@ -27,20 +27,8 @@ General questions about Camel Questions on using Apache Camel -* xref:how-to-avoid-sending-some-or-all-message-headers.adoc[How to avoid sending some or all message headers?] * xref:how-to-remove-the-http-protocol-headers-in-the-camel-message.adoc[How to remove the http protocol headers in the camel message?] * xref:how-to-use-a-dynamic-uri-in-to.adoc[How to use a dynamic URI in to()?] * xref:using-getin-or-getout-methods-on-exchange.adoc[Using getIn or getOut methods on Exchange] -* xref:why-can-i-not-use-when-or-otherwise-in-a-java-camel-route.adoc[Why can I not use when or otherwise in a Java Camel route?] -* xref:why-does-my-file-consumer-not-pick-up-the-file-and-how-do-i-let-the-file-consumer-use-the-camel-error-handler.adoc[Why does my file consumer not pick up the file, and how do I let the file consumer use the Camel error handler?] -* xref:why-does-useoriginalmessage-with-error-handler-not-work-as-expected.adoc[Why does useOriginalMessage with error handler not work as expected?] * xref:why-is-my-message-body-empty.adoc[Why is my message body empty?] -* xref:why-is-the-exception-null-when-i-use-onexception.adoc[Why is the exception null when I use onException?] -[[FAQ-CommonProblems]] -== Common Problems - -Common Problems that people have when riding the Camel - -* xref:exception-orgapachecamelnosuchendpointexception.adoc[Exception - org.apache.camel.NoSuchEndpointException] -* xref:exception-orgxmlsaxsaxparseexception.adoc[Exception - org.xml.sax.SAXParseException] diff --git a/docs/user-manual/modules/faq/pages/why-can-i-not-use-when-or-otherwise-in-a-java-camel-route.adoc b/docs/user-manual/modules/faq/pages/why-can-i-not-use-when-or-otherwise-in-a-java-camel-route.adoc deleted file mode 100644 index 73d74e734f08..000000000000 --- a/docs/user-manual/modules/faq/pages/why-can-i-not-use-when-or-otherwise-in-a-java-camel-route.adoc +++ /dev/null @@ -1,87 +0,0 @@ -= Why can I not use when/otherwise in a Java Camel route? - -When using the xref:components:eips:choice-eip.adoc[Content Based Router] in -the Java DSL you may have a situation where the compiler will not accept -the following `when()` or `otherwise()` statement. - -[TIP] -==== -**Quick tip** - -Use `.endChoice()` to return "back" to the -xref:components:eips:choice-eip.adoc[Content Based Router]. -==== - -For example as shown in the route below where we use the -xref:components:eips:loadBalance-eip.adoc[Load Balancer] inside the -xref:components:eips:choice-eip.adoc[Content Based Router] in the first when: - -*Code will not compile* - -[source,java] ----- -from("direct:start") - .choice() - .when(body().contains("Camel")) - .loadBalance().roundRobin().to("mock:foo").to("mock:bar") - .otherwise() - .to("mock:result"); ----- - -Well the first issue is that the xref:components:eips:loadBalance-eip.adoc[Load Balancer] -uses the additional routing to know what to use in the load balancing. -In this example that would be the: - -[source,java] ----- -.to("mock:foo").to("mock:bar") ----- - -To indicate when the balancing stops, you should use `.end()` to denote -the end. So the route is updates as follows: - -*Code will still not compile* - -[source,java] ----- -from("direct:start") - .choice() - .when(body().contains("Camel")) - .loadBalance().roundRobin().to("mock:foo").to("mock:bar").end() - .otherwise() - .to("mock:result"); ----- - -But the code will still not compile. The reason is we have stretched how -far we can take the good old Java language in terms of -xref:ROOT:dsl.adoc[DSL]. In a more modern language such as -Scala or Groovy you would be able -to let it be stack based, so the `.end()` will pop the last type of the -stack, and you would return back to the scope of the -xref:components:eips:choice-eip.adoc[Content Based Router]. However that's not -easily doable in Java. So we need to help Java a bit, which you do by -using `.endChoice()`, which tells Camel to "pop the stack" and return -back to the scope of the xref:components:eips:choice-eip.adoc[Content Based -Router]. - -*Code compiles* - -[source,java] ----- -from("direct:start") - .choice() - .when(body().contains("Camel")) - .loadBalance().roundRobin().to("mock:foo").to("mock:bar").endChoice() - .otherwise() - .to("mock:result"); ----- - -You only need to use `.endChoice()` when using certain -xref:components:eips:enterprise-integration-patterns.adoc[EIP]s which often have additional -methods to configure or as part of the -xref:components:eips:enterprise-integration-patterns.adoc[EIP] itself. For example the -xref:components:eips:split-eip.adoc[Splitter] EIP has a sub-route which denotes the -routing of each split message. You would also have to use -`.endChoice()` to indicate the end of the sub-route and to return back -to the xref:components:eips:choice-eip.adoc[Content Based Router]. - diff --git a/docs/user-manual/modules/faq/pages/why-does-my-file-consumer-not-pick-up-the-file-and-how-do-i-let-the-file-consumer-use-the-camel-error-handler.adoc b/docs/user-manual/modules/faq/pages/why-does-my-file-consumer-not-pick-up-the-file-and-how-do-i-let-the-file-consumer-use-the-camel-error-handler.adoc deleted file mode 100644 index c7f59334521c..000000000000 --- a/docs/user-manual/modules/faq/pages/why-does-my-file-consumer-not-pick-up-the-file-and-how-do-i-let-the-file-consumer-use-the-camel-error-handler.adoc +++ /dev/null @@ -1,48 +0,0 @@ -= Why does my file consumer not pick up the file, and how do I let the file consumer use the Camel error handler? - -There could be several reasons why the xref:components::file-component.adoc[File] consumer is -not picking up files. For example it may not run at all, or it cannot -acquire a read lock on the file. -xref:index.adoc#FAQ-LoggingQuestions[Check the logs] for any exceptions or other -informative messages. You can - -[[WhydoesmyfileconsumernotpickupthefileandhowdoIletthefileconsumerusetheCamelerrorhandler-HowtouseCamelsroutingerrorhandlerswiththefileconsumer]] -== How to use Camel's routing error handlers with the file consumer - -Well, this is really a -http://en.wikipedia.org/wiki/Chicken_or_the_egg["chicken or the egg"] -question. The Camel xref:ROOT:error-handler.adoc[error handler] -(e.g., in the routes) only applies when a message is being routed by the -routing engine. -Before this happens, a consumer must successfully receive a message, -create a Camel xref:ROOT:exchange.adoc[Exchange], populate the -xref:ROOT:exchange.adoc[Exchange] with message details (e.g., body and -headers), and then pass the xref:ROOT:exchange.adoc[Exchange] to the routing -engine. Only at this point can the routing error handler deal with -exceptions occurring. Before this point, any error handling is really -xref:ROOT:component.adoc[component]-specific. - -[NOTE] -==== -**Bridge with error handler** - -From Camel 2.10 onwards the file and ftp consumers can now bridge to the -Camel routing engine's error handler. See more details at the -`bridgeErrorHandler` option on the xref:components::file-component.adoc[File] -documentation. -==== - -If the component consumer extends the -https://github.com/apache/camel/blob/main/camel-core/src/main/java/org/apache/camel/impl/DefaultConsumer.java[`DefaultConsumer`] -from Camel, then it offers an -https://github.com/apache/camel/blob/main/camel-core/src/main/java/org/apache/camel/spi/ExceptionHandler.java[`org.apache.camel.spi.ExceptionHandler`] -hook for end users to plug-in a custom strategy. The default -implementation from Camel is -https://github.com/apache/camel/blob/main/camel-core/src/main/java/org/apache/camel/impl/LoggingExceptionHandler.java[`LoggingExceptionHandler`] -that will log the exception at `ERROR`/`WARN` level, and then ignore the -exception. - -See the xref:components::file-component.adoc[File] page in the bottom for an example how to -use a custom `ExceptionHandler` that sends a new message to the Camel -routing engine, which then allows the routing engine to trigger its own -error handling to deal with the exception. diff --git a/docs/user-manual/modules/faq/pages/why-does-useoriginalmessage-with-error-handler-not-work-as-expected.adoc b/docs/user-manual/modules/faq/pages/why-does-useoriginalmessage-with-error-handler-not-work-as-expected.adoc deleted file mode 100644 index aee6cc4232ca..000000000000 --- a/docs/user-manual/modules/faq/pages/why-does-useoriginalmessage-with-error-handler-not-work-as-expected.adoc +++ /dev/null @@ -1,15 +0,0 @@ -= Why does useOriginalMessage with error handler not work as expected? - -If you use the xref:ROOT:exception-clause.adoc[useOriginalMessage] option -from the Camel xref:ROOT:exception-clause.adoc[Error Handler] then it matters -if you use this with xref:components:eips:enterprise-integration-patterns.adoc[EIP]s such as: - -* xref:components:eips:recipientList-eip.adoc[Recipient List] -* xref:components:eips:split-eip.adoc[Splitter] -* xref:components:eips:multicast-eip.adoc[Multicast] - -Then the option `shareUnitOfWork` on these xref:components:eips:enterprise-integration-patterns.adoc[EIP]s -influence the message in use by the `useOriginalMessage` option. - -See more details at xref:components:eips:split-eip.adoc[Splitter] and further below with -the examples explaining this in more detail. diff --git a/docs/user-manual/modules/faq/pages/why-is-the-exception-null-when-i-use-onexception.adoc b/docs/user-manual/modules/faq/pages/why-is-the-exception-null-when-i-use-onexception.adoc deleted file mode 100644 index c15df27bc653..000000000000 --- a/docs/user-manual/modules/faq/pages/why-is-the-exception-null-when-i-use-onexception.adoc +++ /dev/null @@ -1,36 +0,0 @@ -= Why is the exception null when I use onException? - -If you use `onException` to handle exceptions, such as shown below: - -[source,java] ----- -.onException(Exception.class).handled(true) - .process(new Processor() { - @Override - public void process(Exchange exchange) throws Exception { - Exception cause = exchange.getException(); - // why cause exception is null ??? - } - }) -.end() ----- - -Then make notice the caused -exception is no longer available from `exchange.getException()`, because -the message is in the onException block. - -Instead you can access the caused exception from a property on the -exchange with the key `Exchange.EXCEPTION_CAUGHT`, as shown below: - -[source,java] ----- -.onException(Exception.class).handled(true) - .process(new Processor() { - @Override - public void process(Exchange exchange) throws Exception { - Exception cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class); - // we now have the caused exception - } - }) -.end() -----
