Hisoka-X commented on code in PR #9184:
URL: https://github.com/apache/seatunnel/pull/9184#discussion_r2065659820
##########
seatunnel-connectors-v2/connector-http/connector-http-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/http/source/HttpSourceReader.java:
##########
@@ -170,41 +171,145 @@ private void updateRequestParam(PageInfo pageInfo) {
}
return;
}
-
+ Long pageValue = pageInfo.getPageIndex();
+ String pageField = pageInfo.getPageField();
+
+ // Process headers
+ if (MapUtils.isNotEmpty(this.httpParameter.getHeaders())) {
+ processPageMap(
+ this.httpParameter.getHeaders(),
+ pageField,
+ pageValue.toString(),
+ usePlaceholderReplacement);
+
+ processPageMap(
+ this.httpParameter.getHeaders(),
+ pageInfo.getPageCursorFieldName(),
+ pageInfo.getCursor(),
+ usePlaceholderReplacement);
+ }
// if not set keepPageParamAsHttpParam, but page field is in params,
then set page index as
- // params
if (MapUtils.isNotEmpty(this.httpParameter.getParams())) {
- // set page index as params
- if
(this.httpParameter.getParams().containsKey(pageInfo.getPageField())) {
- this.httpParameter
- .getParams()
- .put(pageInfo.getPageField(),
pageInfo.getPageIndex().toString());
- }
-
- // set page cursor as params
- if
(this.httpParameter.getParams().containsKey(pageInfo.getPageCursorFieldName())
- && pageInfo.getCursor() != null) {
- this.httpParameter
- .getParams()
- .put(pageInfo.getPageCursorFieldName(),
pageInfo.getCursor());
- }
+ processPageMap(
+ this.httpParameter.getParams(),
+ pageField,
+ pageValue.toString(),
+ usePlaceholderReplacement);
+ processPageMap(
+ this.httpParameter.getParams(),
+ pageInfo.getPageCursorFieldName(),
+ pageInfo.getCursor(),
+ usePlaceholderReplacement);
}
// 2. param in body
if (MapUtils.isNotEmpty(this.httpParameter.getBody())) {
+ processBodyPageMap(
+ this.httpParameter.getBody(), pageField, pageValue,
usePlaceholderReplacement);
+ processBodyPageMap(
+ this.httpParameter.getBody(),
+ pageInfo.getPageCursorFieldName(),
+ pageInfo.getCursor(),
+ usePlaceholderReplacement);
+ }
+ }
+
+ /**
+ * Replace placeholder in a string value
+ *
+ * @param value The string value that may contain a placeholder
+ * @param pageField The page field name
+ * @param pageValue The page value to replace the placeholder with
+ * @return The string with placeholder replaced, or null if no placeholder
found
+ */
+ private String replacePlaceholder(String value, String pageField, Object
pageValue) {
+ if (value == null || pageField == null || !value.contains("${" +
pageField + "}")) {
+ return null;
+ }
+
+ String placeholder = "${" + pageField + "}";
+ int placeholderIndex = value.indexOf(placeholder);
+ if (placeholderIndex >= 0) {
+ String prefix = value.substring(0, placeholderIndex);
+ String suffix = value.substring(placeholderIndex +
placeholder.length());
+ return prefix + pageValue + suffix;
+ }
+ return null;
Review Comment:
@CosmosNi
--
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]