[
https://issues.apache.org/jira/browse/CAMEL-12570?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16507878#comment-16507878
]
ASF GitHub Bot commented on CAMEL-12570:
----------------------------------------
grgrzybek closed pull request #2369: [CAMEL-12570] Upgrade to blueprint.core
1.10.0, blueprint.cm 1.3.0, a…
URL: https://github.com/apache/camel/pull/2369
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintPropertiesParser.java
b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintPropertiesParser.java
index ad9a5cafaa21..ac1ff46352e2 100644
---
a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintPropertiesParser.java
+++
b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintPropertiesParser.java
@@ -26,7 +26,9 @@
import org.apache.aries.blueprint.ExtendedBeanMetadata;
import org.apache.aries.blueprint.ext.AbstractPropertyPlaceholder;
+import org.apache.aries.blueprint.ext.AbstractPropertyPlaceholderExt;
import org.apache.aries.blueprint.ext.PropertyPlaceholder;
+import org.apache.aries.blueprint.ext.PropertyPlaceholderExt;
import org.apache.camel.component.properties.DefaultPropertiesParser;
import org.apache.camel.component.properties.PropertiesComponent;
import org.apache.camel.component.properties.PropertiesParser;
@@ -47,8 +49,9 @@
private final PropertiesComponent propertiesComponent;
private final BlueprintContainer container;
private final PropertiesParser delegate;
- private final Set<AbstractPropertyPlaceholder> placeholders = new
LinkedHashSet<>();
+ private final Set<PropertyPlaceholderWrapper> placeholders = new
LinkedHashSet<PropertyPlaceholderWrapper>();
private Method method;
+ private Method oldMethod;
public BlueprintPropertiesParser(PropertiesComponent propertiesComponent,
BlueprintContainer container, PropertiesParser delegate) {
super(propertiesComponent);
@@ -71,7 +74,8 @@ public BlueprintPropertiesParser(PropertiesComponent
propertiesComponent, Bluepr
ComponentMetadata meta = container.getComponentMetadata(id);
if (meta instanceof ExtendedBeanMetadata) {
Class<?> clazz = ((ExtendedBeanMetadata)
meta).getRuntimeClass();
- if (clazz != null &&
AbstractPropertyPlaceholder.class.isAssignableFrom(clazz)) {
+ if (clazz != null &&
(AbstractPropertyPlaceholder.class.isAssignableFrom(clazz)
+ ||
AbstractPropertyPlaceholderExt.class.isAssignableFrom(clazz))) {
ids.add(id);
}
}
@@ -88,15 +92,16 @@ public BlueprintPropertiesParser(PropertiesComponent
propertiesComponent, Bluepr
public void addPropertyPlaceholder(String id) {
Object component = container.getComponentInstance(id);
- if (component instanceof AbstractPropertyPlaceholder) {
- AbstractPropertyPlaceholder placeholder =
(AbstractPropertyPlaceholder) component;
- placeholders.add(placeholder);
+ // new API
+ if (component instanceof AbstractPropertyPlaceholderExt) {
+ AbstractPropertyPlaceholderExt placeholder =
(AbstractPropertyPlaceholderExt) component;
+ placeholders.add(new
AbstractPropertyPlaceholderExtWrapper(placeholder));
log.debug("Adding Blueprint PropertyPlaceholder: {}", id);
if (method == null) {
try {
- method =
AbstractPropertyPlaceholder.class.getDeclaredMethod("retrieveValue",
String.class);
+ method =
AbstractPropertyPlaceholderExt.class.getDeclaredMethod("retrieveValue",
String.class);
method.setAccessible(true);
} catch (NoSuchMethodException e) {
throw new IllegalStateException("Cannot add blueprint
property placeholder: " + id
@@ -104,6 +109,24 @@ public void addPropertyPlaceholder(String id) {
}
}
}
+
+ // old, deprecated API
+ if (component instanceof AbstractPropertyPlaceholder) {
+ AbstractPropertyPlaceholder placeholder =
(AbstractPropertyPlaceholder) component;
+ placeholders.add(new
AbstractPropertyPlaceholderWrapper(placeholder));
+
+ log.debug("Adding Blueprint PropertyPlaceholder: {}", id);
+
+ if (oldMethod == null) {
+ try {
+ oldMethod =
AbstractPropertyPlaceholder.class.getDeclaredMethod("retrieveValue",
String.class);
+ oldMethod.setAccessible(true);
+ } catch (NoSuchMethodException e) {
+ throw new IllegalStateException("Cannot add blueprint
property placeholder: " + id
+ + " as the method retrieveValue is not
accessible", e);
+ }
+ }
+ }
}
@Override
@@ -122,12 +145,15 @@ public String parseProperty(String key, String value,
Properties properties) {
// lookup key in blueprint and return its value
if (answer == null && key != null) {
- for (AbstractPropertyPlaceholder placeholder : placeholders) {
+ for (PropertyPlaceholderWrapper placeholder : placeholders) {
boolean isDefault = false;
if (placeholders.size() > 1) {
// okay we have multiple placeholders and we want to
return the answer that
// is not the default placeholder if there is multiple keys
- if (placeholder instanceof PropertyPlaceholder) {
+ if (placeholder instanceof PropertyPlaceholderExt) {
+ Map map = ((PropertyPlaceholderExt)
placeholder).getDefaultProperties();
+ isDefault = map != null && map.containsKey(key);
+ } else if (placeholder instanceof PropertyPlaceholder) {
Map map = ((PropertyPlaceholder)
placeholder).getDefaultProperties();
isDefault = map != null && map.containsKey(key);
}
@@ -135,7 +161,7 @@ public String parseProperty(String key, String value,
Properties properties) {
}
try {
- String candidate = (String)
ObjectHelper.invokeMethod(method, placeholder, key);
+ String candidate = placeholder.retrieveValue(key);
if (candidate != null) {
if (answer == null || !isDefault) {
@@ -164,4 +190,44 @@ public String parseProperty(String key, String value,
Properties properties) {
return answer;
}
+ private interface PropertyPlaceholderWrapper {
+
+ /**
+ * Retrieves the String value (or {@code null}) from underlying
placeholder
+ * @param key
+ * @return
+ */
+ String retrieveValue(String key);
+ }
+
+ private class AbstractPropertyPlaceholderExtWrapper implements
PropertyPlaceholderWrapper {
+
+ private AbstractPropertyPlaceholderExt delegate;
+
+ public
AbstractPropertyPlaceholderExtWrapper(AbstractPropertyPlaceholderExt delegate) {
+ this.delegate = delegate;
+ }
+
+ @Override
+ public String retrieveValue(String key) {
+ Object v = ObjectHelper.invokeMethod(method, delegate, key);
+ return v == null ? null : v.toString();
+ }
+ }
+
+ private class AbstractPropertyPlaceholderWrapper implements
PropertyPlaceholderWrapper {
+
+ private AbstractPropertyPlaceholder delegate;
+
+ public AbstractPropertyPlaceholderWrapper(AbstractPropertyPlaceholder
delegate) {
+ this.delegate = delegate;
+ }
+
+ @Override
+ public String retrieveValue(String key) {
+ Object v = ObjectHelper.invokeMethod(oldMethod, delegate, key);
+ return v == null ? null : v.toString();
+ }
+ }
+
}
diff --git a/components/camel-test-blueprint/pom.xml
b/components/camel-test-blueprint/pom.xml
index 8b351f3310ed..b33ac4d6b470 100644
--- a/components/camel-test-blueprint/pom.xml
+++ b/components/camel-test-blueprint/pom.xml
@@ -66,14 +66,9 @@
with felix-connect, and you may get a weird error if wrong order
-->
<dependency>
<groupId>org.apache.aries.proxy</groupId>
- <artifactId>org.apache.aries.proxy.api</artifactId>
+ <artifactId>org.apache.aries.proxy</artifactId>
<version>${aries-blueprint-proxy-version}</version>
</dependency>
- <dependency>
- <groupId>org.apache.aries.proxy</groupId>
- <artifactId>org.apache.aries.proxy.impl</artifactId>
- <version>${aries-blueprint-proxy-impl-version}</version>
- </dependency>
<dependency>
<groupId>org.apache.aries.blueprint</groupId>
<artifactId>org.apache.aries.blueprint.api</artifactId>
diff --git a/parent/pom.xml b/parent/pom.xml
index c8e26665ba2d..5b63fd2a5f4e 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -53,10 +53,10 @@
<apache-gora-version>0.8</apache-gora-version>
<apache-mime4j-version>0.7.2</apache-mime4j-version>
<aries-blueprint-api-version>1.0.1</aries-blueprint-api-version>
- <aries-blueprint-cm-version>1.0.6</aries-blueprint-cm-version>
- <aries-blueprint-core-version>1.4.4</aries-blueprint-core-version>
- <aries-blueprint-proxy-version>1.0.1</aries-blueprint-proxy-version>
-
<aries-blueprint-proxy-impl-version>1.0.6</aries-blueprint-proxy-impl-version>
+ <aries-blueprint-cm-version>1.3.0</aries-blueprint-cm-version>
+ <aries-blueprint-core-version>1.10.0</aries-blueprint-core-version>
+ <aries-blueprint-proxy-version>1.1.1</aries-blueprint-proxy-version>
+
<aries-blueprint-proxy-impl-version>1.1.1</aries-blueprint-proxy-impl-version>
<aries-spifly-version>1.0.8</aries-spifly-version>
<aries-util-version>1.1.3</aries-util-version>
<arquillian-container-se-managed-version>1.0.0.Final</arquillian-container-se-managed-version>
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Support fixed property placeholders from Aries blueprint
> --------------------------------------------------------
>
> Key: CAMEL-12570
> URL: https://issues.apache.org/jira/browse/CAMEL-12570
> Project: Camel
> Issue Type: Bug
> Components: camel-blueprint
> Affects Versions: 2.21.1
> Reporter: Grzegorz Grzybek
> Assignee: Grzegorz Grzybek
> Priority: Major
> Fix For: 2.21.2, 2.22.0
>
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)