This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch pn in repository https://gitbox.apache.org/repos/asf/camel.git
commit c599eb44d0343531b37d986911756733d3d2a2ce Author: Claus Ibsen <[email protected]> AuthorDate: Thu Jun 13 15:07:20 2024 +0200 Upgrade camel-pubnub to v9 client --- .../apache/camel/catalog/components/pubnub.json | 4 +- .../org/apache/camel/component/pubnub/pubnub.json | 4 +- .../component/pubnub/PubNubConfiguration.java | 3 +- .../camel/component/pubnub/PubNubConsumer.java | 10 +- .../camel/component/pubnub/PubNubEndpoint.java | 5 +- .../camel/component/pubnub/PubNubProducer.java | 135 +++++++++++++-------- .../component/pubnub/PubNubOperationsTest.java | 23 +--- .../camel/component/pubnub/PubNubTestBase.java | 13 +- .../ROOT/pages/camel-4x-upgrade-guide-4_7.adoc | 4 + .../dsl/PubnubComponentBuilderFactory.java | 10 +- .../endpoint/dsl/PubNubEndpointBuilderFactory.java | 10 +- .../apache/camel/kotlin/components/PubnubUriDsl.kt | 3 +- parent/pom.xml | 2 +- 13 files changed, 118 insertions(+), 108 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/pubnub.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/pubnub.json index 0b6de36a99a..26f327070b1 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/pubnub.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/pubnub.json @@ -28,7 +28,7 @@ "bridgeErrorHandler": { "index": 2, "kind": "property", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the like [...] "withPresence": { "index": 3, "kind": "property", "displayName": "With Presence", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.pubnub.PubNubConfiguration", "configurationField": "configuration", "description": "Also subscribe to related presence information" }, "lazyStartProducer": { "index": 4, "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail [...] - "operation": { "index": 5, "kind": "property", "displayName": "Operation", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "HERENOW", "WHERENOW", "GETSTATE", "SETSTATE", "GETHISTORY", "PUBLISH", "FIRE" ], "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.pubnub.PubNubConfiguration", "configurationField": "configuration", "description": "The operation to p [...] + "operation": { "index": 5, "kind": "property", "displayName": "Operation", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "HERENOW", "GETSTATE", "SETSTATE", "GETHISTORY", "PUBLISH", "FIRE" ], "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.pubnub.PubNubConfiguration", "configurationField": "configuration", "description": "The operation to perform. PUBL [...] "autowiredEnabled": { "index": 6, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching t [...] "authKey": { "index": 7, "kind": "property", "displayName": "Auth Key", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.pubnub.PubNubConfiguration", "configurationField": "configuration", "description": "If Access Manager is utilized, client will use this authKey in all restricted requests." }, "cipherKey": { "index": 8, "kind": "property", "displayName": "Cipher Key", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.pubnub.PubNubConfiguration", "configurationField": "configuration", "description": "If cipher is passed, all communications to\/from PubNub will be encrypted." }, @@ -50,7 +50,7 @@ "bridgeErrorHandler": { "index": 3, "kind": "parameter", "displayName": "Bridge Error Handler", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming [...] "exceptionHandler": { "index": 4, "kind": "parameter", "displayName": "Exception Handler", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.spi.ExceptionHandler", "optionalPrefix": "consumer.", "deprecated": false, "autowired": false, "secret": false, "description": "To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By def [...] "exchangePattern": { "index": 5, "kind": "parameter", "displayName": "Exchange Pattern", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut" ], "deprecated": false, "autowired": false, "secret": false, "description": "Sets the exchange pattern when the consumer creates an exchange." }, - "operation": { "index": 6, "kind": "parameter", "displayName": "Operation", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "HERENOW", "WHERENOW", "GETSTATE", "SETSTATE", "GETHISTORY", "PUBLISH", "FIRE" ], "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.pubnub.PubNubConfiguration", "configurationField": "configuration", "description": "The operation to [...] + "operation": { "index": 6, "kind": "parameter", "displayName": "Operation", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "HERENOW", "GETSTATE", "SETSTATE", "GETHISTORY", "PUBLISH", "FIRE" ], "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.pubnub.PubNubConfiguration", "configurationField": "configuration", "description": "The operation to perform. PUB [...] "lazyStartProducer": { "index": 7, "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a produc [...] "pubnub": { "index": 8, "kind": "parameter", "displayName": "Pubnub", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "com.pubnub.api.PubNub", "deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, "description": "Reference to a Pubnub client in the registry." }, "authKey": { "index": 9, "kind": "parameter", "displayName": "Auth Key", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.pubnub.PubNubConfiguration", "configurationField": "configuration", "description": "If Access Manager is utilized, client will use this authKey in all restricted requests." }, diff --git a/components/camel-pubnub/src/generated/resources/META-INF/org/apache/camel/component/pubnub/pubnub.json b/components/camel-pubnub/src/generated/resources/META-INF/org/apache/camel/component/pubnub/pubnub.json index 0b6de36a99a..26f327070b1 100644 --- a/components/camel-pubnub/src/generated/resources/META-INF/org/apache/camel/component/pubnub/pubnub.json +++ b/components/camel-pubnub/src/generated/resources/META-INF/org/apache/camel/component/pubnub/pubnub.json @@ -28,7 +28,7 @@ "bridgeErrorHandler": { "index": 2, "kind": "property", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the like [...] "withPresence": { "index": 3, "kind": "property", "displayName": "With Presence", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.pubnub.PubNubConfiguration", "configurationField": "configuration", "description": "Also subscribe to related presence information" }, "lazyStartProducer": { "index": 4, "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail [...] - "operation": { "index": 5, "kind": "property", "displayName": "Operation", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "HERENOW", "WHERENOW", "GETSTATE", "SETSTATE", "GETHISTORY", "PUBLISH", "FIRE" ], "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.pubnub.PubNubConfiguration", "configurationField": "configuration", "description": "The operation to p [...] + "operation": { "index": 5, "kind": "property", "displayName": "Operation", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "HERENOW", "GETSTATE", "SETSTATE", "GETHISTORY", "PUBLISH", "FIRE" ], "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.pubnub.PubNubConfiguration", "configurationField": "configuration", "description": "The operation to perform. PUBL [...] "autowiredEnabled": { "index": 6, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching t [...] "authKey": { "index": 7, "kind": "property", "displayName": "Auth Key", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.pubnub.PubNubConfiguration", "configurationField": "configuration", "description": "If Access Manager is utilized, client will use this authKey in all restricted requests." }, "cipherKey": { "index": 8, "kind": "property", "displayName": "Cipher Key", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.pubnub.PubNubConfiguration", "configurationField": "configuration", "description": "If cipher is passed, all communications to\/from PubNub will be encrypted." }, @@ -50,7 +50,7 @@ "bridgeErrorHandler": { "index": 3, "kind": "parameter", "displayName": "Bridge Error Handler", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming [...] "exceptionHandler": { "index": 4, "kind": "parameter", "displayName": "Exception Handler", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.spi.ExceptionHandler", "optionalPrefix": "consumer.", "deprecated": false, "autowired": false, "secret": false, "description": "To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By def [...] "exchangePattern": { "index": 5, "kind": "parameter", "displayName": "Exchange Pattern", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut" ], "deprecated": false, "autowired": false, "secret": false, "description": "Sets the exchange pattern when the consumer creates an exchange." }, - "operation": { "index": 6, "kind": "parameter", "displayName": "Operation", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "HERENOW", "WHERENOW", "GETSTATE", "SETSTATE", "GETHISTORY", "PUBLISH", "FIRE" ], "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.pubnub.PubNubConfiguration", "configurationField": "configuration", "description": "The operation to [...] + "operation": { "index": 6, "kind": "parameter", "displayName": "Operation", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "HERENOW", "GETSTATE", "SETSTATE", "GETHISTORY", "PUBLISH", "FIRE" ], "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.pubnub.PubNubConfiguration", "configurationField": "configuration", "description": "The operation to perform. PUB [...] "lazyStartProducer": { "index": 7, "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a produc [...] "pubnub": { "index": 8, "kind": "parameter", "displayName": "Pubnub", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "com.pubnub.api.PubNub", "deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, "description": "Reference to a Pubnub client in the registry." }, "authKey": { "index": 9, "kind": "parameter", "displayName": "Auth Key", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.pubnub.PubNubConfiguration", "configurationField": "configuration", "description": "If Access Manager is utilized, client will use this authKey in all restricted requests." }, diff --git a/components/camel-pubnub/src/main/java/org/apache/camel/component/pubnub/PubNubConfiguration.java b/components/camel-pubnub/src/main/java/org/apache/camel/component/pubnub/PubNubConfiguration.java index a5a34046801..8b0227abe27 100644 --- a/components/camel-pubnub/src/main/java/org/apache/camel/component/pubnub/PubNubConfiguration.java +++ b/components/camel-pubnub/src/main/java/org/apache/camel/component/pubnub/PubNubConfiguration.java @@ -43,7 +43,7 @@ public class PubNubConfiguration implements Cloneable { @UriParam @Metadata(required = true) private String uuid; - @UriParam(label = "producer", enums = "HERENOW,WHERENOW,GETSTATE,SETSTATE,GETHISTORY,PUBLISH,FIRE") + @UriParam(label = "producer", enums = "HERENOW,GETSTATE,SETSTATE,GETHISTORY,PUBLISH,FIRE") private String operation; @UriParam(label = "consumer", defaultValue = "false") private boolean withPresence; @@ -153,7 +153,6 @@ public class PubNubConfiguration implements Cloneable { * Event Handlers registered on the channel.</li> * <li>HERENOW: Obtain information about the current state of a channel including a list of unique user-ids * currently subscribed to the channel and the total occupancy count.</li> - * <li>WHERENOW: Obtain information about the current list of channels to which a uuid is subscribed to.</li> * <li>GETSTATE: Used to get key/value pairs specific to a subscriber uuid. State information is supplied as a JSON * object of key/value pairs</li> * <li>SETSTATE: Used to set key/value pairs specific to a subscriber uuid</li> diff --git a/components/camel-pubnub/src/main/java/org/apache/camel/component/pubnub/PubNubConsumer.java b/components/camel-pubnub/src/main/java/org/apache/camel/component/pubnub/PubNubConsumer.java index bbd17fe994c..54ef929f7c4 100644 --- a/components/camel-pubnub/src/main/java/org/apache/camel/component/pubnub/PubNubConsumer.java +++ b/components/camel-pubnub/src/main/java/org/apache/camel/component/pubnub/PubNubConsumer.java @@ -37,7 +37,7 @@ import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static com.pubnub.api.enums.PNStatusCategory.PNTimeoutCategory; +import static com.pubnub.api.enums.PNStatusCategory.PNConnectionError; import static com.pubnub.api.enums.PNStatusCategory.PNUnexpectedDisconnectCategory; import static org.apache.camel.component.pubnub.PubNubConstants.CHANNEL; import static org.apache.camel.component.pubnub.PubNubConstants.TIMETOKEN; @@ -100,7 +100,7 @@ public class PubNubConsumer extends DefaultConsumer { @Override public void status(PubNub pubnub, PNStatus status) { - if (status.getCategory() == PNUnexpectedDisconnectCategory || status.getCategory() == PNTimeoutCategory) { + if (status.getCategory() == PNUnexpectedDisconnectCategory || status.getCategory() == PNConnectionError) { LOG.trace("Got status: {}. Reconnecting to PubNub", status); pubnub.reconnect(); } else { @@ -116,10 +116,14 @@ public class PubNubConsumer extends DefaultConsumer { inmessage.setHeader(TIMETOKEN, message.getTimetoken()); inmessage.setHeader(CHANNEL, message.getChannel()); inmessage.setHeader(Exchange.MESSAGE_TIMESTAMP, message.getTimetoken()); + try { getProcessor().process(exchange); } catch (Exception e) { - getExceptionHandler().handleException("Error processing exchange", e); + exchange.setException(e); + } + if (exchange.getException() != null) { + getExceptionHandler().handleException("Error processing exchange", exchange.getException()); } } 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 feecd6aea92..54f6d113dde 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,7 +89,6 @@ public class PubNubEndpoint extends DefaultEndpoint { } private PubNub getInstance() throws PubNubException { - PubNub answer = null; PNConfiguration pnConfiguration = new PNConfiguration(new UserId(configuration.getUuid())); pnConfiguration.setPublishKey(configuration.getPublishKey()); pnConfiguration.setSubscribeKey(configuration.getSubscribeKey()); @@ -97,8 +96,6 @@ public class PubNubEndpoint extends DefaultEndpoint { pnConfiguration.setAuthKey(configuration.getAuthKey()); pnConfiguration.setCipherKey(configuration.getCipherKey()); pnConfiguration.setSecure(configuration.isSecure()); - - answer = new PubNub(pnConfiguration); - return answer; + return PubNub.create(pnConfiguration); } } diff --git a/components/camel-pubnub/src/main/java/org/apache/camel/component/pubnub/PubNubProducer.java b/components/camel-pubnub/src/main/java/org/apache/camel/component/pubnub/PubNubProducer.java index 853161ea257..448771cc486 100644 --- a/components/camel-pubnub/src/main/java/org/apache/camel/component/pubnub/PubNubProducer.java +++ b/components/camel-pubnub/src/main/java/org/apache/camel/component/pubnub/PubNubProducer.java @@ -16,17 +16,15 @@ */ package org.apache.camel.component.pubnub; -import java.util.Arrays; +import java.util.List; import com.pubnub.api.PubNubException; -import com.pubnub.api.models.consumer.PNErrorData; import com.pubnub.api.models.consumer.PNPublishResult; -import com.pubnub.api.models.consumer.PNStatus; import com.pubnub.api.models.consumer.history.PNHistoryResult; import com.pubnub.api.models.consumer.presence.PNGetStateResult; import com.pubnub.api.models.consumer.presence.PNHereNowResult; import com.pubnub.api.models.consumer.presence.PNSetStateResult; -import com.pubnub.api.models.consumer.presence.PNWhereNowResult; +import com.pubnub.api.v2.callbacks.Result; import org.apache.camel.AsyncCallback; import org.apache.camel.CamelException; import org.apache.camel.Exchange; @@ -85,10 +83,6 @@ public class PubNubProducer extends DefaultAsyncProducer { doSetState(exchange, callback); break; } - case WHERENOW: { - doWhereNow(exchange, callback); - break; - } default: throw new UnsupportedOperationException(operation.toString()); } @@ -103,7 +97,7 @@ public class PubNubProducer extends DefaultAsyncProducer { private void doPublish(Exchange exchange, AsyncCallback callback) { Object body = exchange.getIn().getBody(); if (ObjectHelper.isEmpty(body)) { - throw new RuntimeCamelException("Can not publish empty message"); + throw new RuntimeCamelException("Cannot publish empty message"); } LOG.debug("Sending message [{}] to channel [{}]", body, getChannel(exchange)); endpoint.getPubnub() @@ -111,11 +105,21 @@ public class PubNubProducer extends DefaultAsyncProducer { .message(body) .channel(getChannel(exchange)) .usePOST(true) - .async((PNPublishResult result, PNStatus status) -> { - if (!status.isError()) { - exchange.getIn().setHeader(PubNubConstants.TIMETOKEN, result.getTimetoken()); + .async((Result<PNPublishResult> result) -> { + LOG.debug("Got publish message [{}]", result); + if (result.isFailure()) { + PubNubException ex = result.exceptionOrNull(); + if (ex != null) { + exchange.setException(ex); + } + callback.done(false); + } else { + PNPublishResult r = result.getOrNull(); + if (r != null) { + exchange.getIn().setHeader(PubNubConstants.TIMETOKEN, r.getTimetoken()); + } + processMessage(exchange, callback, null); } - processMessage(exchange, callback, status, null); }); } @@ -130,11 +134,21 @@ public class PubNubProducer extends DefaultAsyncProducer { .fire() .message(body) .channel(getChannel(exchange)) - .async((PNPublishResult result, PNStatus status) -> { - if (!status.isError()) { - exchange.getIn().setHeader(PubNubConstants.TIMETOKEN, result.getTimetoken()); + .async((Result<PNPublishResult> result) -> { + LOG.debug("Got fire message [{}]", result); + if (result.isFailure()) { + PubNubException ex = result.exceptionOrNull(); + if (ex != null) { + exchange.setException(ex); + } + callback.done(false); + } else { + PNPublishResult r = result.getOrNull(); + if (r != null) { + exchange.getIn().setHeader(PubNubConstants.TIMETOKEN, r.getTimetoken()); + } + processMessage(exchange, callback, null); } - processMessage(exchange, callback, status, null); }); } @@ -142,9 +156,18 @@ public class PubNubProducer extends DefaultAsyncProducer { endpoint.getPubnub() .history() .channel(getChannel(exchange)) - .async((PNHistoryResult result, PNStatus status) -> { + .async((Result<PNHistoryResult> result) -> { LOG.debug("Got history message [{}]", result); - processMessage(exchange, callback, status, result.getMessages()); + if (result.isFailure()) { + PubNubException ex = result.exceptionOrNull(); + if (ex != null) { + exchange.setException(ex); + } + callback.done(false); + } else { + PNHistoryResult r = result.getOrNull(); + processMessage(exchange, callback, r != null ? r.getMessages() : null); + } }); } @@ -157,61 +180,70 @@ public class PubNubProducer extends DefaultAsyncProducer { LOG.debug("Sending setState [{}] to channel [{}]", body, getChannel(exchange)); endpoint.getPubnub() .setPresenceState() - .channels(Arrays.asList(getChannel(exchange))) + .channels(List.of(getChannel(exchange))) .state(body) .uuid(getUUID(exchange)) - .async((PNSetStateResult result, PNStatus status) -> { - LOG.debug("Got setState responsee [{}]", result); - processMessage(exchange, callback, status, result); + .async((Result<PNSetStateResult> result) -> { + LOG.debug("Got setState response [{}]", result); + if (result.isFailure()) { + PubNubException ex = result.exceptionOrNull(); + if (ex != null) { + exchange.setException(ex); + } + callback.done(false); + } else { + PNSetStateResult r = result.getOrNull(); + processMessage(exchange, callback, r); + } }); } private void doGetState(Exchange exchange, AsyncCallback callback) { endpoint.getPubnub() .getPresenceState() - .channels(Arrays.asList(getChannel(exchange))) + .channels(List.of(getChannel(exchange))) .uuid(getUUID(exchange)) - .async((PNGetStateResult result, PNStatus status) -> { - LOG.debug("Got state [{}]", result.getStateByUUID()); - processMessage(exchange, callback, status, result); + .async((Result<PNGetStateResult> result) -> { + LOG.debug("Got state [{}]", result); + if (result.isFailure()) { + PubNubException ex = result.exceptionOrNull(); + if (ex != null) { + exchange.setException(ex); + } + callback.done(false); + } else { + PNGetStateResult r = result.getOrNull(); + processMessage(exchange, callback, r); + } }); } private void doHereNow(Exchange exchange, AsyncCallback callback) { endpoint.getPubnub() .hereNow() - .channels(Arrays.asList(getChannel(exchange))) + .channels(List.of(getChannel(exchange))) .includeState(true) .includeUUIDs(true) - .async((PNHereNowResult result, PNStatus status) -> { + .async((Result<PNHereNowResult> result) -> { LOG.debug("Got herNow message [{}]", result); - processMessage(exchange, callback, status, result); - }); - } - - private void doWhereNow(Exchange exchange, AsyncCallback callback) { - endpoint.getPubnub() - .whereNow() - .uuid(getUUID(exchange)) - .async((PNWhereNowResult result, PNStatus status) -> { - LOG.debug("Got whereNow message [{}]", result.getChannels()); - processMessage(exchange, callback, status, result.getChannels()); + if (result.isFailure()) { + PubNubException ex = result.exceptionOrNull(); + if (ex != null) { + exchange.setException(ex); + } + callback.done(false); + } else { + PNHereNowResult r = result.getOrNull(); + processMessage(exchange, callback, r); + } }); } - private void processMessage(Exchange exchange, AsyncCallback callback, PNStatus status, Object body) { - if (status.isError()) { - PNErrorData errorData = status.getErrorData(); - exchange.setException(errorData.getThrowable()); - if (errorData != null && errorData.getThrowable() instanceof PubNubException) { - PubNubException pubNubException = (PubNubException) errorData.getThrowable(); - throw new RuntimeCamelException(pubNubException.getPubnubError().getMessage(), errorData.getThrowable()); - } - throw new RuntimeCamelException(status.getErrorData().getThrowable()); + private void processMessage(Exchange exchange, AsyncCallback callback, Object body) { + if (body != null) { + ExchangeHelper.setInOutBodyPatternAware(exchange, body); } - ExchangeHelper.setInOutBodyPatternAware(exchange, body); - // signal exchange completion callback.done(false); } @@ -236,7 +268,6 @@ public class PubNubProducer extends DefaultAsyncProducer { private enum Operation { HERENOW, - WHERENOW, GETSTATE, SETSTATE, GETHISTORY, diff --git a/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/PubNubOperationsTest.java b/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/PubNubOperationsTest.java index ab2ea048fcf..5fbaa134672 100644 --- a/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/PubNubOperationsTest.java +++ b/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/PubNubOperationsTest.java @@ -21,6 +21,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; import com.pubnub.api.models.consumer.history.PNHistoryItemResult; import com.pubnub.api.models.consumer.presence.PNGetStateResult; import com.pubnub.api.models.consumer.presence.PNHereNowResult; @@ -38,22 +40,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; public class PubNubOperationsTest extends PubNubTestBase { - @Test - public void testWhereNow() { - stubFor(get(urlPathEqualTo("/v2/presence/sub-key/mySubscribeKey/uuid/myUUID")) - .willReturn(aResponse().withBody( - "{\"status\": 200, \"message\": \"OK\", \"payload\": {\"channels\": [\"channel-a\",\"channel-b\"]}, \"service\": \"Presence\"}"))); - - Map<String, Object> headers = new HashMap<>(); - headers.put(PubNubConstants.OPERATION, "WHERENOW"); - headers.put(PubNubConstants.UUID, "myUUID"); - @SuppressWarnings("unchecked") - List<String> response = template.requestBodyAndHeaders("direct:publish", null, headers, List.class); - assertNotNull(response); - assertListSize(response, 2); - assertEquals("channel-a", response.get(0)); - } - @Test public void testHereNow() { stubFor(get(urlPathEqualTo("/v2/presence/sub_key/mySubscribeKey/channel/myChannel")).willReturn(aResponse() @@ -94,8 +80,11 @@ public class PubNubOperationsTest extends PubNubTestBase { testArray.add(1234); testArray.add(4321); + ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); + String json = ow.writeValueAsString(testArray); + stubFor(get(urlPathEqualTo("/v2/history/sub-key/mySubscribeKey/channel/myChannel")) - .willReturn(aResponse().withBody(getPubnub().getMapper().toJson(testArray)))); + .willReturn(aResponse().withBody(json))); Map<String, Object> headers = new HashMap<>(); headers.put(PubNubConstants.OPERATION, "GETHISTORY"); diff --git a/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/PubNubTestBase.java b/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/PubNubTestBase.java index b47e03252f9..f100cf141b6 100644 --- a/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/PubNubTestBase.java +++ b/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/PubNubTestBase.java @@ -23,6 +23,7 @@ import com.pubnub.api.PubNub; import com.pubnub.api.PubNubException; import com.pubnub.api.UserId; import com.pubnub.api.enums.PNLogVerbosity; +import com.pubnub.internal.PubNubImpl; import org.apache.camel.BindToRegistry; import org.apache.camel.test.AvailablePortFinder; import org.apache.camel.test.junit5.CamelTestSupport; @@ -69,7 +70,7 @@ public class PubNubTestBase extends CamelTestSupport { pnConfiguration.setPublishKey("myPublishKey"); pnConfiguration.setLogVerbosity(PNLogVerbosity.NONE); pnConfiguration.setHeartbeatNotificationOptions(NONE); - class MockedTimePubNub extends PubNub { + class MockedTimePubNub extends PubNubImpl { MockedTimePubNub(PNConfiguration initialConfig) { super(initialConfig); @@ -85,16 +86,6 @@ public class PubNubTestBase extends CamelTestSupport { return "suchJava"; } - @Override - public String getInstanceId() { - return "PubNubInstanceId"; - } - - @Override - public String getRequestId() { - return "PubNubRequestId"; - } - } return new MockedTimePubNub(pnConfiguration); diff --git a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_7.adoc b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_7.adoc index 371b86760ec..6db2b4b26de 100644 --- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_7.adoc +++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_7.adoc @@ -144,6 +144,10 @@ As part of CAMEL-20785, we have started to rework the `CamelTestSupport` class. previous versions, as we are laying down the foundations for greater cleanups in the future. However, several methods have been marked as deprecated. Users of this class are advised to look at the deprecation notices and adjust the code accordingly. +=== camel-pubnub + +Upgraded PubNub client from v6 to v9 and the `wherenow` operation is removed due to no longer present in the client. + === camel-as2 The `camel-as2` component has been updated so that the client can compress a MIME body before signing or compress a MIME body before signing and encrypting as described in diff --git a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/PubnubComponentBuilderFactory.java b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/PubnubComponentBuilderFactory.java index cf5d9a5402c..fb950d8d3b7 100644 --- a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/PubnubComponentBuilderFactory.java +++ b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/PubnubComponentBuilderFactory.java @@ -161,12 +161,10 @@ public interface PubnubComponentBuilderFactory { * Event Handlers registered on the channel. HERENOW: Obtain information * about the current state of a channel including a list of unique * user-ids currently subscribed to the channel and the total occupancy - * count. WHERENOW: Obtain information about the current list of - * channels to which a uuid is subscribed to. GETSTATE: Used to get - * key/value pairs specific to a subscriber uuid. State information is - * supplied as a JSON object of key/value pairs SETSTATE: Used to set - * key/value pairs specific to a subscriber uuid GETHISTORY: Fetches - * historical messages of a channel. + * count. GETSTATE: Used to get key/value pairs specific to a subscriber + * uuid. State information is supplied as a JSON object of key/value + * pairs SETSTATE: Used to set key/value pairs specific to a subscriber + * uuid GETHISTORY: Fetches historical messages of a channel. * * The option is a: <code>java.lang.String</code> type. * diff --git a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/PubNubEndpointBuilderFactory.java b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/PubNubEndpointBuilderFactory.java index 22e4fe4470f..b003e0a9c8c 100644 --- a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/PubNubEndpointBuilderFactory.java +++ b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/PubNubEndpointBuilderFactory.java @@ -386,12 +386,10 @@ public interface PubNubEndpointBuilderFactory { * Event Handlers registered on the channel. HERENOW: Obtain information * about the current state of a channel including a list of unique * user-ids currently subscribed to the channel and the total occupancy - * count. WHERENOW: Obtain information about the current list of - * channels to which a uuid is subscribed to. GETSTATE: Used to get - * key/value pairs specific to a subscriber uuid. State information is - * supplied as a JSON object of key/value pairs SETSTATE: Used to set - * key/value pairs specific to a subscriber uuid GETHISTORY: Fetches - * historical messages of a channel. + * count. GETSTATE: Used to get key/value pairs specific to a subscriber + * uuid. State information is supplied as a JSON object of key/value + * pairs SETSTATE: Used to set key/value pairs specific to a subscriber + * uuid GETHISTORY: Fetches historical messages of a channel. * * The option is a: <code>java.lang.String</code> type. * diff --git a/dsl/camel-kotlin-api/src/generated/kotlin/org/apache/camel/kotlin/components/PubnubUriDsl.kt b/dsl/camel-kotlin-api/src/generated/kotlin/org/apache/camel/kotlin/components/PubnubUriDsl.kt index 9475c6be402..c80f6371754 100644 --- a/dsl/camel-kotlin-api/src/generated/kotlin/org/apache/camel/kotlin/components/PubnubUriDsl.kt +++ b/dsl/camel-kotlin-api/src/generated/kotlin/org/apache/camel/kotlin/components/PubnubUriDsl.kt @@ -122,8 +122,7 @@ public class PubnubUriDsl( * FIRE: allows the client to send a message to BLOCKS Event Handlers. These messages will go * directly to any Event Handlers registered on the channel. HERENOW: Obtain information about the * current state of a channel including a list of unique user-ids currently subscribed to the channel - * and the total occupancy count. WHERENOW: Obtain information about the current list of channels to - * which a uuid is subscribed to. GETSTATE: Used to get key/value pairs specific to a subscriber + * and the total occupancy count. GETSTATE: Used to get key/value pairs specific to a subscriber * uuid. State information is supplied as a JSON object of key/value pairs SETSTATE: Used to set * key/value pairs specific to a subscriber uuid GETHISTORY: Fetches historical messages of a * channel. diff --git a/parent/pom.xml b/parent/pom.xml index 4095c537bcb..3f528ad64b2 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -408,7 +408,7 @@ <protonpack-version>1.8</protonpack-version> <protostream-version>5.0.5.Final</protostream-version> <prowide-version>SRU2023-10.1.6</prowide-version> - <pubnub-version>6.4.5</pubnub-version> + <pubnub-version>9.2.0</pubnub-version> <pulsar-version>3.3.0</pulsar-version> <qdrant-client-version>1.9.1</qdrant-client-version> <qpid-broker-version>9.2.0</qpid-broker-version>
