URL supports placeholders and can be dynamically replaced with msg ex… - #535
URL supports placeholders and can be dynamically replaced with msg ex…#535zhengchangqing wants to merge 1 commit into
Conversation
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Review: Approved ✅
PR: #535 — URL supports placeholders and can be dynamically replaced with msg extensions
Type: Enhancement (1 file, +33/-1)
Assessment
Adds placeholder support to HTTP sink task URL, enabling dynamic replacement from message extensions. Useful for routing based on message metadata.
Verdict
✅ Clean enhancement with practical use case.
🤖 Automated review by oss-sentinel-ai
|
Issue Evaluation Category: Feature request to support URL placeholders that can be dynamically replaced with message extension values. This would enable more flexible routing in connectors. Feasibility: feasible Automated evaluation by github-manager-bot |
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Summary
URL placeholder support for HttpSinkTask — allows dynamic URL construction using message extension values via {key} placeholders.
Findings
- [Critical]
formatUrl()line 68:PATTERN.matcher(url).matches()requires the entire string to match the regex\{(\w+)\}, not just contain a placeholder. A URL likehttp://api.example.com/{id}/datawill never match becausematches()tries to match the full string against the pattern. This should bePATTERN.matcher(url).find()instead. As written, the placeholder replacement will never execute for any real URL.
Suggestions
// Change from:
if (PATTERN.matcher(url).matches()) {
// To:
if (PATTERN.matcher(url).find()) {Automated review by github-manager-bot
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Summary
Review of PR #535: URL supports placeholders and can be dynamically replaced with msg ex…
Findings: 3 issue(s) identified (1 critical).
CLA: unknown
Please address the inline comments above.
Automated review by github-manager-bot
| @@ -140,6 +146,32 @@ public void put(List<ConnectRecord> records) throws ConnectException { | |||
| } | |||
| } | |||
|
|
|||
There was a problem hiding this comment.
formatUrl uses PATTERN.matcher(url).matches(), which requires the entire URL to match the placeholder pattern \\{(\\w+)\\}. A real URL such as http://host/api/{id} will not match, so the method almost always returns the original URL unchanged and placeholder replacement is effectively broken. Use find() to detect placeholders within the URL instead.
| * @return the formatted url | ||
| */ | ||
| private String formatUrl(String url, KeyValue extensions) { | ||
| if (!PATTERN.matcher(url).matches()) { |
There was a problem hiding this comment.
Extension values are inserted into the URL via raw string replacement without URL encoding. Values containing reserved characters (/, ?, &, =, #, spaces, etc.) can produce malformed URLs or alter request semantics. Encode values before substitution, e.g. with URLEncoder.encode(value, StandardCharsets.UTF_8).
| @@ -140,6 +146,32 @@ public void put(List<ConnectRecord> records) throws ConnectException { | |||
| } | |||
There was a problem hiding this comment.
The new formatUrl placeholder replacement logic has no test coverage in the diff. Add unit tests covering: successful replacement, missing extension key handling, null/empty extensions, special characters in values, and URLs with multiple placeholders.
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Summary
Re-review of PR #535 after new commits. The critical regex bug identified in the previous review remains unfixed.
The formatUrl() method uses PATTERN.matcher(url).matches() which will never match a real URL containing placeholders (e.g., http://api.example.com/{id}/data). This makes the entire placeholder feature non-functional.
Findings
- [Critical]
HttpSinkTask.java:155—matches()should befind()— placeholder replacement is currently dead code
Suggestions
// Change from:
if (!PATTERN.matcher(url).matches()) {
// To:
if (!PATTERN.matcher(url).find()) {Automated review by github-manager-bot
| * @param url the source url str | ||
| * @param extensions ConnectRecord Extension Values | ||
| * @return the formatted url | ||
| */ |
There was a problem hiding this comment.
[Critical] PATTERN.matcher(url).matches() requires the entire string to match the regex \{(\w+)\}. A real URL like http://api.example.com/{id}/data will never match because matches() anchors at both ends. This means the placeholder replacement will silently never execute for any practical URL.
Fix: Change to PATTERN.matcher(url).find() which checks if the pattern exists anywhere in the string.
What is the purpose of the change
[ISSUES #534 ]
Brief changelog
Modify
HttpSinkTasksupports placeholders and can be dynamically replaced with msg extendsionsVerifying this change
Follow this checklist to help us incorporate your contribution quickly and easily. Notice,
it would be helpful if you could finish the following 5 checklist(the last one is not necessary)before request the community to review your PR.[ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.mvn -B clean apache-rat:check findbugs:findbugs checkstyle:checkstyleto make sure basic checks pass. Runmvn clean install -DskipITsto make sure unit-test pass. Runmvn clean test-compile failsafe:integration-testto make sure integration-test pass.