You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2023/10/18 08:38:22 UTC

[camel] branch main updated: CAMEL-20002: Make it easier to extend DefaultInjector

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.git


The following commit(s) were added to refs/heads/main by this push:
     new 821378eed35 CAMEL-20002: Make it easier to extend DefaultInjector
821378eed35 is described below

commit 821378eed3556090c55cc1b7ddae73310c82cb8d
Author: James Netherton <ja...@gmail.com>
AuthorDate: Wed Oct 18 08:18:53 2023 +0100

    CAMEL-20002: Make it easier to extend DefaultInjector
---
 .../apache/camel/impl/engine/DefaultInjector.java    | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultInjector.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultInjector.java
index 332dd05b64f..a8d9e67ecbc 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultInjector.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultInjector.java
@@ -34,8 +34,8 @@ import org.apache.camel.support.PluginHelper;
 public class DefaultInjector implements Injector {
 
     // use the reflection injector
-    private final CamelContext camelContext;
-    private final CamelBeanPostProcessor postProcessor;
+    protected final CamelContext camelContext;
+    protected final CamelBeanPostProcessor postProcessor;
 
     public DefaultInjector(CamelContext context) {
         this.camelContext = context;
@@ -78,12 +78,7 @@ public class DefaultInjector implements Injector {
         // inject camel context if needed
         CamelContextAware.trySetCamelContext(answer, camelContext);
         if (postProcessBean) {
-            try {
-                postProcessor.postProcessBeforeInitialization(answer, answer.getClass().getName());
-                postProcessor.postProcessAfterInitialization(answer, answer.getClass().getName());
-            } catch (Exception e) {
-                throw new RuntimeCamelException("Error during post processing of bean: " + answer, e);
-            }
+            applyBeanPostProcessing(answer);
         }
         return answer;
     }
@@ -92,4 +87,13 @@ public class DefaultInjector implements Injector {
     public boolean supportsAutoWiring() {
         return false;
     }
+
+    protected <T> void applyBeanPostProcessing(T bean) {
+        try {
+            postProcessor.postProcessBeforeInitialization(bean, bean.getClass().getName());
+            postProcessor.postProcessAfterInitialization(bean, bean.getClass().getName());
+        } catch (Exception e) {
+            throw new RuntimeCamelException("Error during post processing of bean: " + bean, e);
+        }
+    }
 }