This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-karaf.git
The following commit(s) were added to refs/heads/main by this push: new ab3441ae CAMEL-9627: camel-cxf splitup ab3441ae is described below commit ab3441aefb81b44ffe6e292e08c70f84e118432f Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Thu Jun 30 14:46:51 2022 +0200 CAMEL-9627: camel-cxf splitup --- components/camel-cxf-blueprint/pom.xml | 5 ++-- .../jaxrs/blueprint/CxfRsBlueprintEndpoint.java | 31 ++++++++++++++++++++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/components/camel-cxf-blueprint/pom.xml b/components/camel-cxf-blueprint/pom.xml index e3e4c2b7..4261a9b8 100644 --- a/components/camel-cxf-blueprint/pom.xml +++ b/components/camel-cxf-blueprint/pom.xml @@ -41,14 +41,13 @@ <dependencies> - <!-- TODO: avoid spring where we only depend on some spring reflection helper --> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-cxf-spring-soap</artifactId> + <artifactId>camel-cxf-soap</artifactId> </dependency> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-cxf-spring-rest</artifactId> + <artifactId>camel-cxf-rest</artifactId> </dependency> <!-- OSGi, Blueprint --> diff --git a/components/camel-cxf-blueprint/src/main/java/org/apache/camel/component/cxf/jaxrs/blueprint/CxfRsBlueprintEndpoint.java b/components/camel-cxf-blueprint/src/main/java/org/apache/camel/component/cxf/jaxrs/blueprint/CxfRsBlueprintEndpoint.java index 2fd2446f..856481bc 100644 --- a/components/camel-cxf-blueprint/src/main/java/org/apache/camel/component/cxf/jaxrs/blueprint/CxfRsBlueprintEndpoint.java +++ b/components/camel-cxf-blueprint/src/main/java/org/apache/camel/component/cxf/jaxrs/blueprint/CxfRsBlueprintEndpoint.java @@ -16,18 +16,21 @@ */ package org.apache.camel.component.cxf.jaxrs.blueprint; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; + import org.apache.camel.Component; import org.apache.camel.blueprint.BlueprintCamelContext; import org.apache.camel.component.cxf.blueprint.BlueprintSupport; import org.apache.camel.component.cxf.blueprint.RsClientBlueprintBean; import org.apache.camel.component.cxf.blueprint.RsServerBlueprintBean; import org.apache.camel.component.cxf.jaxrs.CxfRsEndpoint; +import org.apache.camel.util.ReflectionHelper; import org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean; import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; import org.osgi.framework.BundleContext; import org.osgi.service.blueprint.container.BlueprintContainer; -import org.springframework.util.ReflectionUtils; public class CxfRsBlueprintEndpoint extends CxfRsEndpoint { private AbstractJAXRSFactoryBean bean; @@ -94,10 +97,34 @@ public class CxfRsBlueprintEndpoint extends CxfRsEndpoint { RsClientBlueprintBean cfb = new RsClientBlueprintBean(); if (bean instanceof RsClientBlueprintBean) { - ReflectionUtils.shallowCopyFieldState(bean, cfb); + shallowCopyFieldState(bean, cfb); } return cfb; } + private static void shallowCopyFieldState(final Object src, final Object dest) { + if (!src.getClass().isAssignableFrom(dest.getClass())) { + throw new IllegalArgumentException("Destination class [" + dest.getClass().getName() + "] must be same or subclass as source class [" + src.getClass().getName() + "]"); + } else { + ReflectionHelper.doWithFields(src.getClass(), (field) -> { + if (isCopyableField(field)) { + makeAccessible(field); + Object srcValue = field.get(src); + field.set(dest, srcValue); + } + }); + } + } + + private static void makeAccessible(Field field) { + if ((!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers()) || Modifier.isFinal(field.getModifiers())) && !field.isAccessible()) { + field.setAccessible(true); + } + } + + private static boolean isCopyableField(Field field) { + return !Modifier.isStatic(field.getModifiers()) && !Modifier.isFinal(field.getModifiers()); + } + }