This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new a459036eb2 Add an explanation of how to handle
ContextNotActiveException to CDI documentation
a459036eb2 is described below
commit a459036eb2a3b2f2a664ae435cccfde5255a68c8
Author: James Netherton <[email protected]>
AuthorDate: Mon Nov 18 10:15:06 2024 +0000
Add an explanation of how to handle ContextNotActiveException to CDI
documentation
Fixes #6792
---
docs/modules/ROOT/pages/user-guide/cdi.adoc | 35 +++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/docs/modules/ROOT/pages/user-guide/cdi.adoc
b/docs/modules/ROOT/pages/user-guide/cdi.adoc
index 9c826519a5..f2eed848b3 100644
--- a/docs/modules/ROOT/pages/user-guide/cdi.adoc
+++ b/docs/modules/ROOT/pages/user-guide/cdi.adoc
@@ -301,3 +301,38 @@ for you.
Note that Camel Quarkus will implicitly add `@jakarta.inject.Singleton` and
`jakarta.inject.Named("foo1234")` to the bean class, where `1234` is a hash
code obtained from the fully qualified class name.
If your bean has some CDI scope (such as `@ApplicationScoped`) or
`@Named("someName")` set already,
those will be honored in the auto-created route.
+
+== CDI Contexts & `ContextNotActiveException`
+
+When using CDI beans in `bean` endpoints, in the `.bean` or `.process` EIPs,
there is the potential for bean method invocations to throw
`ContextNotActiveException`.
+
+Typically, this can happen when invoking `list` & `query` operations on a
Hibernate Panache entity within your bean or processor methods. To ensure such
beans have access to the request scope, you can annotate methods with
`@ActivateRequestContext`.
+
+For example in a bean.
+
+[source,java]
+----
+@Singleton
+public class GreetingsBean {
+ @ActivateRequestContext
+ public String greet() {
+ Greeting greeting = Greeting.findById(1);
+ return greeting.getMessage();
+ }
+}
+----
+
+In `Processor` bean, annotate the `process` method with
`@ActivateRequestContext`.
+
+[source,java]
+----
+@Singleton
+public class GreetingsProcessor implements Processor {
+ @Override
+ @ActivateRequestContext
+ public void process(Exchange exchange) {
+ Greeting greeting = Greeting.findById(1);
+ exchange.getMessage().setBody(greeting.getMessage());
+ }
+}
+----