Skip to content

Commit

Permalink
Resource Adapter: consider {} as an empty configuration to be overrid…
Browse files Browse the repository at this point in the history
…den with default values
  • Loading branch information
Enrico Olivelli committed Aug 13, 2021
1 parent ea6d849 commit e59d6d0
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pulsar-jms-integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<artifactId>pulsar-jms-integration-tests</artifactId>
<packaging>jar</packaging>
<name>Pulsar JMS Integration Tests</name>
<properties />
<properties/>
<dependencies>
<dependency>
<groupId>com.datastax.oss</groupId>
Expand Down
2 changes: 1 addition & 1 deletion resource-adapter-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<artifactId>pulsar-jms-resource-adapter-tests</artifactId>
<packaging>jar</packaging>
<name>Pulsar JMS Resource Adapter Tests for Jakarta EE Containers</name>
<properties />
<properties/>
<dependencies>
<dependency>
<groupId>org.apache.tomee</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ public String toString() {
}

public String getMergedConfiguration(String configuration) {
if (this.configuration == null || this.configuration.trim().isEmpty()) {
if (this.configuration == null
|| this.configuration.trim().isEmpty()
|| this.configuration.replace(" ", "").equals("{}")) { // empty "{}"
return configuration;
} else {
return this.configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ public void setResourceAdapter(ResourceAdapter resourceAdapter) throws ResourceE
}

String getMergedConfiguration() {
if (this.configuration == null || this.configuration.trim().isEmpty()) {
if (this.configuration == null
|| this.configuration.trim().isEmpty()
|| this.configuration.replace(" ", "").equals("{}")) { // empty "{}") {
return resourceAdapter.getConfiguration();
} else {
return configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,14 @@ public void endpointActivation(
MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec)
throws ResourceException {
try {
log.info("Activate endpoint {} {}", activationSpec, messageEndpointFactory);
PulsarActivationSpec pulsarActivationSpec = (PulsarActivationSpec) activationSpec;
PulsarConnectionFactory connectionFactory =
getPulsarConnectionFactory(pulsarActivationSpec.getMergedConfiguration(configuration));
String mergedConfiguration = pulsarActivationSpec.getMergedConfiguration(configuration);
log.info(
"Activate endpoint {} {} configuration {}",
activationSpec,
messageEndpointFactory,
mergedConfiguration);
PulsarConnectionFactory connectionFactory = getPulsarConnectionFactory(mergedConfiguration);
PulsarMessageEndpoint endpoint =
buildMessageEndpoint(messageEndpointFactory, pulsarActivationSpec, connectionFactory);
endpoints.add(endpoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,13 @@ public void testMergeConfiguration() throws Exception {
spec.setConfiguration(null);
assertEquals("bar", spec.getMergedConfiguration("bar"));
assertEquals(null, spec.getConfiguration());

spec.setConfiguration("{}");
assertEquals("bar", spec.getMergedConfiguration("bar"));
assertEquals("{}", spec.getConfiguration());

spec.setConfiguration("{ }");
assertEquals("bar", spec.getMergedConfiguration("bar"));
assertEquals("{ }", spec.getConfiguration());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ public void testMergeConfiguration() throws Exception {
assertEquals("bar", spec.getMergedConfiguration());
assertEquals(null, spec.getConfiguration());

spec.setConfiguration("{}");
assertEquals("bar", spec.getMergedConfiguration());
assertEquals("{}", spec.getConfiguration());

spec.setConfiguration("{ }");
assertEquals("bar", spec.getMergedConfiguration());
assertEquals("{ }", spec.getConfiguration());

PrintWriter useless = new PrintWriter(new StringWriter());
spec.setLogWriter(useless);
assertSame(useless, spec.getLogWriter());
Expand Down

0 comments on commit e59d6d0

Please sign in to comment.