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.git
The following commit(s) were added to refs/heads/main by this push:
new d4102516d2bc CAMEL-25281: camel-pubnub - an endpoint without
publishKey, secretKey or authKey must start (#27310)
d4102516d2bc is described below
commit d4102516d2bcc375825b371659c9ef54a575d562
Author: allthingssecurity <[email protected]>
AuthorDate: Sat Oct 3 12:19:05 2026 +0530
CAMEL-25281: camel-pubnub - an endpoint without publishKey, secretKey or
authKey must start (#27310)
When no PubNub client is given, `PubNubEndpoint` builds one from the
endpoint options and passes `publishKey`, `secretKey` and `authKey` to the
builder of the PubNub client (code from the upgrade to the PubNub 10 client,
Camel 4.9). That builder rejects `null` (checked with the SDK 13.4.4 in use),
so an endpoint that does not set all three keys failed to start with `Parameter
specified as non-null is null: method
com.pubnub.internal.java.v2.PNConfigurationImpl$Builder.publishKey`. So [...]
This change sets only the keys that are configured; the builder's defaults
apply to the others.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../camel/component/pubnub/PubNubEndpoint.java | 20 +++++++++-----
.../component/pubnub/PubNubConfigurationTest.java | 31 ++++++++++++++++++++++
2 files changed, 45 insertions(+), 6 deletions(-)
diff --git
a/components/camel-pubnub/src/main/java/org/apache/camel/component/pubnub/PubNubEndpoint.java
b/components/camel-pubnub/src/main/java/org/apache/camel/component/pubnub/PubNubEndpoint.java
index b837a11281f6..f157394a3b0c 100644
---
a/components/camel-pubnub/src/main/java/org/apache/camel/component/pubnub/PubNubEndpoint.java
+++
b/components/camel-pubnub/src/main/java/org/apache/camel/component/pubnub/PubNubEndpoint.java
@@ -89,11 +89,19 @@ public class PubNubEndpoint extends DefaultEndpoint {
}
private PubNub getInstance() throws PubNubException {
- PNConfiguration config = PNConfiguration.builder(new
UserId(configuration.getUuid()), configuration.getSubscribeKey())
- .publishKey(configuration.getPublishKey())
- .secretKey(configuration.getSecretKey())
- .authKey(configuration.getAuthKey())
- .secure(configuration.isSecure()).build();
- return PubNub.create(config);
+ PNConfiguration.Builder builder
+ = PNConfiguration.builder(new UserId(configuration.getUuid()),
configuration.getSubscribeKey())
+ .secure(configuration.isSecure());
+ // the builder does not accept null for the keys that are not
configured, its defaults apply then
+ if (configuration.getPublishKey() != null) {
+ builder.publishKey(configuration.getPublishKey());
+ }
+ if (configuration.getSecretKey() != null) {
+ builder.secretKey(configuration.getSecretKey());
+ }
+ if (configuration.getAuthKey() != null) {
+ builder.authKey(configuration.getAuthKey());
+ }
+ return PubNub.create(builder.build());
}
}
diff --git
a/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/PubNubConfigurationTest.java
b/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/PubNubConfigurationTest.java
index 2d26fd0fb13d..a0007138f339 100644
---
a/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/PubNubConfigurationTest.java
+++
b/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/PubNubConfigurationTest.java
@@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -60,4 +61,34 @@ public class PubNubConfigurationTest extends
CamelTestSupport {
assertFalse(endpoint.getConfiguration().isSecure());
}
+ @Test
+ public void startEndpointWithoutOptionalKeys() {
+ // the endpoint creates its own client, without publish, secret and
auth keys
+ PubNubEndpoint endpoint =
context.getEndpoint("pubnub:xxx?subscribeKey=mysubkey&uuid=myuuid",
PubNubEndpoint.class);
+
+ assertNotNull(endpoint.getPubnub());
+ assertEquals("mysubkey",
endpoint.getPubnub().getConfiguration().getSubscribeKey());
+ assertEquals("myuuid",
endpoint.getPubnub().getConfiguration().getUserId().getValue());
+ }
+
+ @Test
+ public void startEndpointWithPublishKey() {
+ PubNubEndpoint endpoint =
context.getEndpoint("pubnub:xxx?subscribeKey=mysubkey&publishKey=mypubkey&uuid=myuuid",
+ PubNubEndpoint.class);
+
+ assertNotNull(endpoint.getPubnub());
+ assertEquals("mypubkey",
endpoint.getPubnub().getConfiguration().getPublishKey());
+ }
+
+ @Test
+ public void startEndpointWithAllKeys() {
+ PubNubEndpoint endpoint = context.getEndpoint(
+
"pubnub:xxx?subscribeKey=mysubkey&publishKey=mypubkey&secretKey=secrets&authKey=authKey&uuid=myuuid",
+ PubNubEndpoint.class);
+
+ assertNotNull(endpoint.getPubnub());
+ assertEquals("mypubkey",
endpoint.getPubnub().getConfiguration().getPublishKey());
+ assertEquals("secrets",
endpoint.getPubnub().getConfiguration().getSecretKey());
+ }
+
}