davsclaus opened a new pull request, #29002: URL: https://github.com/apache/camel/pull/29002
Fixes [CAMEL-26173](https://issues.apache.org/jira/browse/CAMEL-26173). ### 1. `atBlock`, `fromBlock` and `toBlock` are documented with default `latest` but were null - **Wrong:** the three fields of `Web3jConfiguration` have `defaultValue = "latest"` but were not initialized. `Web3jHelper.toDefaultBlockParameter(null)` returns null, and web3j calls `getValue()` on it when it builds the request. So `ETH_GET_BALANCE`, `ETH_GET_BLOCK_BY_NUMBER` (and every other operation that takes a block: `ETH_GET_STORAGE_AT`, `ETH_GET_TRANSACTION_COUNT`, `ETH_GET_CODE`, `ETH_CALL`, ...) failed with a `NullPointerException` unless `atBlock` or `CamelWeb3jAtBlock` was set. `REPLAY_BLOCKS_OBSERVABLE` and `REPLAY_TRANSACTIONS_OBSERVABLE` without `fromBlock`/`toBlock` failed the same way (web3j asks the node for the block number of a non-numeric block parameter). - **Changed:** the three fields are initialized to `"latest"`. For the log filters (`ETH_LOG_OBSERVABLE`, `ETH_NEW_FILTER`, `ETH_GET_LOGS`) the filter now sends `"latest"` instead of leaving the field out, which nodes treat the same. A log consumer from `latest` is still subscribed again after an error. - **Tests:** `Web3jProducerTest.ethGetBalanceAtTheLatestBlockByDefaultTest`, `ethGetBlockByNumberAtTheLatestBlockByDefaultTest`, `Web3jConsumerTest.replayOfBlocksFromAndToTheLatestBlockByDefault`, `logFilterFromAndToTheLatestBlockByDefault`. ### 2. `ETH_GET_TRANSACTION_RECEIPT` put an `Optional` in the body - **Wrong:** the body was `response.getTransactionReceipt()`, an `Optional<TransactionReceipt>`, while the `ETH_GET_TRANSACTION_BY_*` operations unwrap it to the `Transaction` or null. - **Changed:** the body is the `TransactionReceipt`, or null when the node has none. The `@BodyTypes` entry and its description are updated (now `pojo`/`null` with `TransactionReceipt`). - **Tests:** `Web3jProducerTest.ethGetTransactionReceiptTest` (now asserts the receipt itself) and `ethGetTransactionReceiptNotFoundTest`. ### 3. The default operation `transaction` is not an operation - **Wrong:** a consumer without `operation` failed at start with only `Unsupported operation transaction`. A producer without the option and without the header failed with `Unsupported value transaction configured on the endpoint`, though the user never set `transaction`. - **Changed:** the consumer checks the operation at start and fails with `Unsupported operation transaction for the web3j consumer: set the operation option to one of ETH_LOG_OBSERVABLE, ...`. The producer fails the exchange with `No operation for the web3j producer: set the operation option or the CamelWeb3jOperation header`. The `operation` option description now says what the producer and the consumer need. The default value itself is unchanged. - **Small related fix on the same line:** the consumer's `switch` was case-sensitive, so `operation=block_observable` failed while the producer accepts lower-case operations. The consumer now upper-cases the operation. - **Tests:** `Web3jConsumerTest.consumerWithoutOperationFailsToStart`, `operationInLowerCase`, `Web3jProducerTest.producerWithoutOperationTest`. ### 4. Stopping a consumer reports an `UndeliverableException` when `eth_uninstallFilter` fails: NOT changed (open question) web3j registers `Filter::cancel` as the `Cancellable` of the `Flowable`. When `eth_uninstallFilter` fails, `Filter.cancel()` throws a `FilterException`. RxJava 2's `CancellableDisposable.dispose()` catches it and passes it to `RxJavaPlugins.onError`. With no global handler set, that prints the `UndeliverableException` and calls the thread's uncaught exception handler. `Disposable.dispose()` itself does not throw, so `Web3jConsumer.doStop` cannot catch it. The only hook is the JVM-wide `RxJavaPlugins.setErrorHandler`. Setting it from a component would change the behaviour of every RxJava 2 user in the JVM (and it fails if the plugins are locked down). So I left this out. The options are in the JIRA comment. My recommendation is not to install a global handler from Camel, and to ask web3j to log instead of throw in `Filter.cancel()`. The filter expires on the node anyway. ### Notes - All new tests failed before the fix (9 failures across `Web3jConsumerTest` and `Web3jProducerTest`) and pass after. Module: 146 tests, 0 failures (67 integration tests skipped as before). - Upgrade guide: a new `camel-web3j` section in `camel-4x-upgrade-guide-4_24.adoc` (the receipt body change, the block defaults, and the operation messages). - Regenerated: `web3j.json` (component and catalog), `Web3jEndpointBuilderFactory`, `Web3jComponentBuilderFactory`. _Claude Code on behalf of Claus Ibsen (davsclaus)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
