Skip to content

URL supports placeholders and can be dynamically replaced with msg ex… - #535

Open
zhengchangqing wants to merge 1 commit into
apache:masterfrom
zhengchangqing:master
Open

URL supports placeholders and can be dynamically replaced with msg ex…#535
zhengchangqing wants to merge 1 commit into
apache:masterfrom
zhengchangqing:master

Conversation

@zhengchangqing

@zhengchangqing zhengchangqing commented May 21, 2024

Copy link
Copy Markdown

What is the purpose of the change

[ISSUES #534 ]

Brief changelog

Modify HttpSinkTask supports placeholders and can be dynamically replaced with msg extendsions

Verifying 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.

  • Make sure there is a Github issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test(over 80% coverage) to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in test module.
  • Run mvn -B clean apache-rat:check findbugs:findbugs checkstyle:checkstyle to make sure basic checks pass. Run mvn clean install -DskipITs to make sure unit-test pass. Run mvn clean test-compile failsafe:integration-test to make sure integration-test pass.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@RockteMQ-AI

Copy link
Copy Markdown

Issue Evaluation

Category: enhancement | Status: Evaluated

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
Scope: connector URL configuration, message extension resolution
Compatibility: additive change, backward compatible with static URLs


Automated evaluation by github-manager-bot

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 like http://api.example.com/{id}/data will never match because matches() tries to match the full string against the pattern. This should be PATTERN.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 RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:155matches() should be find() — 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
*/

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants