Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor preparePutOrPost in HttpJdkSolrClient #2454

Merged
merged 2 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ Other Changes
* SOLR-16505: Use Jetty HTTP2 for index replication and other "recovery" operations
(Sanjay Dutt, David Smiley)

* GITHUB#2454: Refactor preparePutOrPost method in HttpJdkSolrClient (Andy Webb)

================== 9.6.0 ==================
New Features
---------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,17 @@ private PreparedRequest preparePutOrPost(

InputStream is = streams.iterator().next().getStream();
bodyPublisher = HttpRequest.BodyPublishers.ofInputStream(() -> is);
} else if (queryParams != null && urlParamNames != null) {
ModifiableSolrParams requestParams = queryParams;
queryParams = calculateQueryParams(urlParamNames, requestParams);
queryParams.add(calculateQueryParams(solrRequest.getQueryParams(), requestParams));
// note the toQueryString() method adds a leading question mark which needs to be removed here
bodyPublisher =
HttpRequest.BodyPublishers.ofString(requestParams.toQueryString().substring(1));
} else {
bodyPublisher = HttpRequest.BodyPublishers.noBody();
// move any params specified in urlParamNames or solrRequest from queryParams into urlParams
ModifiableSolrParams urlParams = calculateQueryParams(urlParamNames, queryParams);
urlParams.add(calculateQueryParams(solrRequest.getQueryParams(), queryParams));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm unclear when this would kick in - it can't trigger if urlParamNames is null.

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed urlParamNames is never null (see HttpSolrClientBase constructor line 107ff), so the null check is spurious. Should you comment-out line 306, you will see testQueryString fail in the case where there are query parameters but nothing was set for urlParamNames (using the withTheseParamNamesInTheUrl option).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

queryParams can't be null either, can it? I've made this the else block - I added an UnsupportedOperationException in the original noBody() one and saw it was never triggered by tests. Does this change look good to you?

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, you are right, it does not seem urlParams or queryParams can ever be null. So you're correct, the "noBody" case never gets touched. I guess I had thought there would be a case where we would could post with an empty body but clearly this cannot happen.


// put the remaining params in the request body
// note the toQueryString() method adds a leading question mark which needs to be removed here
bodyPublisher = HttpRequest.BodyPublishers.ofString(queryParams.toQueryString().substring(1));

// replace queryParams with the selected set
queryParams = urlParams;
}

decorateRequest(reqb, solrRequest);
Expand Down
Loading