davsclaus opened a new pull request, #29001:
URL: https://github.com/apache/camel/pull/29001

   Fixes [CAMEL-26171](https://issues.apache.org/jira/browse/CAMEL-26171).
   
   ### 1. The option `currency=BTC` fails with no type converter
   
   The generated configurer converts the value to 
`org.knowm.xchange.currency.Currency`, and there was no converter from String, 
so `xchange:binance?service=metadata&method=currencyMetaData&currency=BTC` 
failed. The `setCurrency(String)` overload is never called.
   
   Changed: a new `XChangeConverters` type converter, String to `Currency` and 
String to `CurrencyPair`. The option keeps its `Currency` type, so the Java 
endpoint DSL `currency(Currency)` method is unchanged.
   
   ### 2. A String currency or currency pair in the header or body is not 
converted
   
   `XChangeMarketDataProducer` and `XChangeMetaDataProducer` read the 
`CurrencyPair` / `Currency` header and the body as `CurrencyPair` / `Currency`. 
Text such as `BTC/USDT` or `USDT` gave null, so the call failed with "Null 
currency pair" or "Null currency".
   
   Changed: the same converters fix this. They only look up currencies XChange 
already knows (`Currency.getInstanceNoCreate`): the predefined ones and those 
of the loaded exchanges. Unknown text fails with `Unknown currency: X`. `new 
CurrencyPair(String)` and `Currency.getInstance(String)` would register every 
new code in a JVM-wide static map of XChange, which should not grow with text 
that comes with messages. The pair is split like `new CurrencyPair(String)` 
does (`-` or `/`); text with no separator fails with `Could not parse currency 
pair from: ...`.
   
   ### 3. `currencyPairMetaData` with no pair reports "Null currency"
   
   Changed to "Null currency pair" in `XChangeEndpoint.getCurrencyPairMetaData`.
   
   ### 4. A method of another service silently does nothing
   
   Each producer only handles the methods of its own service, so 
`service=marketdata&method=currencies` left the body unchanged. The same 
happened with no `method`.
   
   Changed: `XChangeMethod` now knows its service, and 
`XChangeComponent.createEndpoint` fails when `service` or `method` is missing 
or the method belongs to another service. The check runs before the exchange is 
created, so no remote call is made for a wrong endpoint.
   
   ### Tests
   
   New `XChangeCurrencyConversionTest` runs the producers against a fake 
exchange (dynamic proxies of `Exchange` and `MarketDataService`), so no network 
is used: option `currency=BTC`, text currency in header and body, unknown 
currency, text pair in header (ticker) and body (currencyPairMetaData), pair 
text without separator, no pair, method of another service, no method. All 10 
fail on main and pass with the fix. The other tests of the module are 
`@Disabled` (CAMEL-19751, they hit the live Binance API).
   
   ### Docs and generated files
   
   - `xchange-component.adoc`: new "Services and methods" and "Currency and 
currency pair" sections; copied to the catalog.
   - `@BodyTypes`: the producer input no longer says text is not converted; the 
output no longer lists `unchanged` (a method of another service now fails). 
Regenerated `xchange.json` and copied it to the catalog. No yaml-dsl-validator 
test refers to xchange.
   - New generated `XChangeConvertersLoader` and its `TypeConverterLoader` 
service file.
   - Upgrade guide 4.24: an endpoint with no method or a method of another 
service now fails; header and body text is converted.
   
   ### Not changed
   
   - The `currencyPair` option still uses `new CurrencyPair(String)`, as 
before; it comes from the route, not from a message.
   - `XChangeConfiguration.setCurrency(String)` is kept (public API), though 
the configurer does not use it.
   - An option `currency=XYZ` for a coin that is not predefined in XChange 
fails with `Unknown currency` when the endpoint is the first one of its 
exchange, because the exchange (and its currencies) is loaded after the options 
are set. Before, every value failed.
   
   _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]

Reply via email to