You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2023/02/28 13:12:13 UTC
[camel] 05/05: CAMEL-19090: Remove deprecated apis in core
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 04b257c7b7c7a159529271c2b85692ba979f38e1
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Feb 28 13:58:56 2023 +0100
CAMEL-19090: Remove deprecated apis in core
---
.../main/java/org/apache/camel/spi/BeanIntrospection.java | 10 ++++++++++
.../apache/camel/impl/engine/DefaultBeanIntrospection.java | 9 +++++++++
.../java/org/apache/camel/converter/ConverterTest.java | 11 +++++++++--
.../org/apache/camel/model/ModelSanityCheckerTest.java | 14 ++++++++++----
4 files changed, 38 insertions(+), 6 deletions(-)
diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/BeanIntrospection.java b/core/camel-api/src/main/java/org/apache/camel/spi/BeanIntrospection.java
index c88e37b8ed1..ad01fc882b2 100644
--- a/core/camel-api/src/main/java/org/apache/camel/spi/BeanIntrospection.java
+++ b/core/camel-api/src/main/java/org/apache/camel/spi/BeanIntrospection.java
@@ -156,6 +156,16 @@ public interface BeanIntrospection extends StaticService, AfterPropertiesConfigu
*/
Method getPropertyGetter(Class<?> type, String propertyName, boolean ignoreCase) throws NoSuchMethodException;
+ /**
+ * Gets the setter method for the property.
+ *
+ * @param type the target class
+ * @param propertyName the property name
+ * @return the setter method
+ * @throws NoSuchMethodException is thrown if there are no setter method for the property
+ */
+ Method getPropertySetter(Class<?> type, String propertyName) throws NoSuchMethodException;
+
/**
* This method supports three modes to set a property:
*
diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultBeanIntrospection.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultBeanIntrospection.java
index 9081bd7b05c..0d605aaa0fb 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultBeanIntrospection.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultBeanIntrospection.java
@@ -183,6 +183,15 @@ public class DefaultBeanIntrospection extends ServiceSupport implements BeanIntr
return IntrospectionSupport.getPropertyGetter(type, propertyName, ignoreCase);
}
+ @Override
+ public Method getPropertySetter(Class<?> type, String propertyName) throws NoSuchMethodException {
+ invoked.incrementAndGet();
+ if (!preStartDone || logger.shouldLog()) {
+ log("getPropertySetter", type, propertyName);
+ }
+ return IntrospectionSupport.getPropertySetter(type, propertyName);
+ }
+
@Override
public boolean setProperty(
CamelContext context, TypeConverter typeConverter, Object target, String name, Object value, String refName,
diff --git a/core/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java b/core/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java
index 2ee4c710c85..67c02345979 100644
--- a/core/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java
@@ -34,8 +34,8 @@ import org.apache.camel.TypeConverter;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.converter.DefaultTypeConverter;
import org.apache.camel.impl.engine.DefaultPackageScanClassResolver;
+import org.apache.camel.spi.BeanIntrospection;
import org.apache.camel.support.DefaultExchange;
-import org.apache.camel.support.IntrospectionSupport;
import org.apache.camel.support.service.ServiceHelper;
import org.apache.camel.util.ReflectionInjector;
import org.junit.jupiter.api.BeforeEach;
@@ -189,9 +189,16 @@ public class ConverterTest extends TestSupport {
@Test
public void testPrimitiveIntPropertySetter() {
MyBean bean = new MyBean();
- assertDoesNotThrow(() -> IntrospectionSupport.setProperty(converter, bean, "foo", "4"),
+
+ CamelContext context = new DefaultCamelContext();
+ context.start();
+ BeanIntrospection bi = context.getCamelContextExtension().getBeanIntrospection();
+
+ assertDoesNotThrow(() -> bi.setProperty(context, converter, bean, "foo", "4", null, true, true, true),
"Setting an int property in a bean, should have succeeded without throwing exceptions");
assertEquals(4, bean.getFoo(), "The property bean.foo does not match the value that was previously set");
+
+ context.stop();
}
@Test
diff --git a/core/camel-core/src/test/java/org/apache/camel/model/ModelSanityCheckerTest.java b/core/camel-core/src/test/java/org/apache/camel/model/ModelSanityCheckerTest.java
index a2b4297ef6a..3dfc9607a1a 100644
--- a/core/camel-core/src/test/java/org/apache/camel/model/ModelSanityCheckerTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/model/ModelSanityCheckerTest.java
@@ -25,8 +25,10 @@ import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElementRef;
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.engine.DefaultPackageScanClassResolver;
-import org.apache.camel.support.IntrospectionSupport;
+import org.apache.camel.spi.BeanIntrospection;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -49,6 +51,10 @@ public class ModelSanityCheckerTest {
@Test
public void testSanity() throws Exception {
+ CamelContext context = new DefaultCamelContext();
+ context.start();
+ BeanIntrospection bi = context.getCamelContextExtension().getBeanIntrospection();
+
Set<Class<?>> classes = discoverJaxbClasses();
assertNotNull(classes);
assertTrue(classes.size() > 140, "There should be > 140 classes, was: " + classes.size());
@@ -84,8 +90,8 @@ public class ModelSanityCheckerTest {
// check getter/setter
if (attribute || element || elementRef) {
// check for getter/setter
- Method getter = IntrospectionSupport.getPropertyGetter(clazz, field.getName());
- Method setter = IntrospectionSupport.getPropertySetter(clazz, field.getName());
+ Method getter = bi.getPropertyGetter(clazz, field.getName(), false);
+ Method setter = bi.getPropertySetter(clazz, field.getName());
assertNotNull(getter, "Getter " + field.getName() + " on class " + clazz.getName() + " is missing");
assertNotNull(setter, "Setter " + field.getName() + " on class " + clazz.getName() + " is missing");
@@ -116,7 +122,7 @@ public class ModelSanityCheckerTest {
+ " should not have @XmlElementRef annotation");
}
}
-
+ context.stop();
}
}