This is an automated email from the ASF dual-hosted git repository.

zhfeng 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 ce04a45aac5 CAMEL-21163: unwrap the synthetic ClientProxy beans 
(#15421)
ce04a45aac5 is described below

commit ce04a45aac5c8364622bc8eb928501e0aaa06281
Author: Zheng Feng <[email protected]>
AuthorDate: Wed Sep 4 16:41:35 2024 +0800

    CAMEL-21163: unwrap the synthetic ClientProxy beans (#15421)
---
 .../apache/camel/component/jms/JmsEndpoint.java    |  8 +++++
 .../camel/component/sql/DefaultSqlEndpoint.java    |  8 +++++
 .../component/sql/stored/SqlStoredEndpoint.java    |  8 +++++
 .../java/org/apache/camel/util/UnwrapHelper.java   | 36 ++++++++++++++++++++++
 4 files changed, 60 insertions(+)

diff --git 
a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
 
b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
index be80215543b..40318d38bbf 100644
--- 
a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
+++ 
b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
@@ -51,6 +51,7 @@ import org.apache.camel.support.PluginHelper;
 import org.apache.camel.support.SynchronousDelegateProducer;
 import org.apache.camel.util.StringHelper;
 import org.apache.camel.util.UnsafeUriCharactersEncoder;
+import org.apache.camel.util.UnwrapHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.core.task.TaskExecutor;
@@ -148,6 +149,13 @@ public class JmsEndpoint extends DefaultEndpoint
             // we need to use reflection to find the URL to the brokers, so do 
this once on startup
             BeanIntrospection bi = 
PluginHelper.getBeanIntrospection(getCamelContext());
             ConnectionFactory cf = getConnectionFactory();
+            // unwrap if cf is from a synthetic ClientProxy bean
+            if (cf != null && cf.getClass().getName().endsWith("ClientProxy")) 
{
+                ConnectionFactory actual = UnwrapHelper.unwrapClientProxy(cf);
+                if (actual != null) {
+                    cf = actual;
+                }
+            }
             serviceUrl = 
JmsServiceLocationHelper.getBrokerURLFromConnectionFactory(bi, cf);
             serviceProtocol = getComponent().getDefaultName();
 
diff --git 
a/components/camel-sql/src/main/java/org/apache/camel/component/sql/DefaultSqlEndpoint.java
 
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/DefaultSqlEndpoint.java
index 7ba81bc6c12..473d1ed24ee 100644
--- 
a/components/camel-sql/src/main/java/org/apache/camel/component/sql/DefaultSqlEndpoint.java
+++ 
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/DefaultSqlEndpoint.java
@@ -34,6 +34,7 @@ import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.support.DefaultPollingEndpoint;
 import org.apache.camel.support.PluginHelper;
+import org.apache.camel.util.UnwrapHelper;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.jdbc.core.RowMapper;
 import org.springframework.jdbc.core.RowMapperResultSetExtractor;
@@ -557,6 +558,13 @@ public abstract class DefaultSqlEndpoint extends 
DefaultPollingEndpoint implemen
             // we need to use reflection to find the URL to the database, so 
do this once on startup
             BeanIntrospection bi = 
PluginHelper.getBeanIntrospection(getCamelContext());
             DataSource ds = getDataSource();
+            // unwrap if ds is from a synthetic ClientProxy bean
+            if (ds != null && ds.getClass().getName().endsWith("ClientProxy")) 
{
+                DataSource actual = UnwrapHelper.unwrapClientProxy(ds);
+                if (actual != null) {
+                    ds = actual;
+                }
+            }
             serviceUrl = SqlServiceLocationHelper.getJDBCURLFromDataSource(bi, 
ds);
 
             serviceMetadata = new HashMap<>();
diff --git 
a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredEndpoint.java
 
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredEndpoint.java
index da9dd136310..a70dc660d54 100644
--- 
a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredEndpoint.java
+++ 
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredEndpoint.java
@@ -35,6 +35,7 @@ import org.apache.camel.spi.UriPath;
 import org.apache.camel.support.DefaultEndpoint;
 import org.apache.camel.support.PluginHelper;
 import org.apache.camel.util.UnsafeUriCharactersEncoder;
+import org.apache.camel.util.UnwrapHelper;
 import org.springframework.jdbc.core.JdbcTemplate;
 
 /**
@@ -126,6 +127,13 @@ public class SqlStoredEndpoint extends DefaultEndpoint {
             // we need to use reflection to find the URL to the database, so 
do this once on startup
             BeanIntrospection bi = 
PluginHelper.getBeanIntrospection(getCamelContext());
             DataSource ds = getDataSource();
+            // unwrap if ds is from a synthetic ClientProxy bean
+            if (ds != null && ds.getClass().getName().endsWith("ClientProxy")) 
{
+                DataSource actual = UnwrapHelper.unwrapClientProxy(ds);
+                if (actual != null) {
+                    ds = actual;
+                }
+            }
             serviceUrl = SqlServiceLocationHelper.getJDBCURLFromDataSource(bi, 
ds);
 
             serviceMetadata = new HashMap<>();
diff --git 
a/core/camel-util/src/main/java/org/apache/camel/util/UnwrapHelper.java 
b/core/camel-util/src/main/java/org/apache/camel/util/UnwrapHelper.java
new file mode 100644
index 00000000000..846890efdf2
--- /dev/null
+++ b/core/camel-util/src/main/java/org/apache/camel/util/UnwrapHelper.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.util;
+
+import java.lang.reflect.Method;
+
+/**
+ * Helper for unwrapping from the proxy objects
+ */
+public final class UnwrapHelper {
+
+    public static <T> T unwrapClientProxy(T obj) {
+        try {
+            Method method = 
ReflectionHelper.findMethod(Class.forName("io.quarkus.arc.ClientProxy"), 
"unwrap", Object.class);
+            if (method != null) {
+                return (T) method.invoke(null, obj);
+            }
+        } catch (Exception e) {
+        }
+        return null;
+    }
+}

Reply via email to