oscerd commented on code in PR #27781:
URL: https://github.com/apache/camel/pull/27781#discussion_r4268172768
##########
components/camel-telegram/src/main/java/org/apache/camel/component/telegram/service/TelegramServiceRestBotAPIAdapter.java:
##########
@@ -152,36 +154,52 @@ public UpdateResult getUpdates(Long offset, Integer
limit, Integer timeoutSecond
}
<T> T sendSyncRequest(final HttpRequest request, Class<T> resultType) {
+ final String description = describe(request.method(), request.uri());
try {
final HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
int code = response.statusCode();
if (code >= 200 && code < 300) {
final String responseBody = response.body();
if (LOG.isTraceEnabled()) {
- LOG.trace("Received body for {} {}: {}", request.method(),
request.uri(), responseBody);
+ LOG.trace("Received body for {}: {}", description,
responseBody);
}
return mapper.readValue(responseBody, resultType);
} else {
throw new TelegramException(
- "Could not " + request.method() + " " + request.uri()
+ ": " + response.statusCode() + " "
- + response.body(),
+ "Could not " + description + ": " +
response.statusCode() + " " + response.body(),
response.statusCode(), response.body());
}
} catch (JsonProcessingException e) {
- throw new RuntimeCamelException(
- "Could not parse the response from " + request.method() +
" " + request.uri(), e);
+ throw new RuntimeCamelException("Could not parse the response from
" + description, e);
} catch (IOException e) {
- throw new RuntimeCamelException("Could not request " +
request.method() + " " + request.uri(), e);
+ throw new RuntimeCamelException("Could not request " +
description, e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeCamelException(e);
}
}
+ /**
+ * Describes a request to the Bot API in logs and exception messages by
its HTTP method and the method of the Bot
+ * API, such as {@code GET getUpdates}. The request URI is not used, as it
contains the authorization token.
+ */
+ static String describe(String httpMethod, URI uri) {
+ String path = uri.getPath();
+ return httpMethod + " " + path.substring(path.lastIndexOf('/') + 1);
+ }
+
@Override
public boolean setWebhook(String url) {
- final String uri = baseUri + "/setWebhook?url=" + url;
+ return setWebhook(url, null);
+ }
+
+ @Override
+ public boolean setWebhook(String url, String secretToken) {
+ String uri = baseUri + "/setWebhook?url=" + url;
Review Comment:
Agreed that the asymmetry is worth noting. For this backport I'm keeping
`setWebhook` identical to #27716 as merged on `main`, where `url` is still sent
as before, unencoded. The value is built by Camel from the configured external
URL and a base64url path, so in practice it has no `&` or `?` of its own.
Encoding it would change the request sent to Telegram for every existing user,
so if we want it, it should go to `main` first as a small change of its own and
then be ported, rather than diverge here. The secret token is encoded because a
configured value is the one input on that line that a user types; values that
pass the `[A-Za-z0-9_-]` check are unchanged by the encoding.
_Claude Code on behalf of oscerd_
--
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]