gnodet-bot commented on code in PR #27781:
URL: https://github.com/apache/camel/pull/27781#discussion_r4258498352
##########
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:
💡 **Nit:** The `url` parameter is concatenated raw into the query string
here, while `secretToken` on the very next line is encoded with
`URLEncoder.encode()`. This is a pre-existing pattern (the old single-arg
`setWebhook` did the same) and safe in practice because the URL is a
well-formed HTTPS URL set by Camel itself — not user-supplied input. But the
asymmetry is worth noting: if a future caller ever passes a URL with query
parameters or special characters, it would break silently. Consider applying
`URLEncoder.encode(url, StandardCharsets.UTF_8)` for consistency and defensive
correctness.
--
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]