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

Remove leftover RestClient attribute methods #31625

Closed
giovannitomasicchio opened this issue Nov 19, 2023 · 5 comments
Closed

Remove leftover RestClient attribute methods #31625

giovannitomasicchio opened this issue Nov 19, 2023 · 5 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: task A general task
Milestone

Comments

@giovannitomasicchio
Copy link

Affects: Spring Framework 6.1.0-RC2


The new RestClient allows you to set attributes but it seems that they are not saved in the ClientHttpRequest so you can't retrieve them in a ClientHttpRequestInterceptor.

So what are the RestClient attributes for?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 19, 2023
@poutsma poutsma self-assigned this Nov 20, 2023
@poutsma
Copy link
Contributor

poutsma commented Nov 21, 2023

So what are the RestClient attributes for?

A fair question. They are leftovers from an abandoned experiment that should never have made it into 6.1.0 GA. Therefore, the attribute(String, Object) and attributes(Consumer) methods will be removed in 6.1.1, as they are essentially no-ops and not hooked up to the related infrastructure (such as ClientHttpRequest and—as you correctly pointed out—ClientHttpRequestInterceptor).

@poutsma poutsma added in: web Issues in web modules (web, webmvc, webflux, websocket) type: task A general task and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 21, 2023
@poutsma poutsma added this to the 6.1.1 milestone Nov 21, 2023
@poutsma poutsma changed the title How to retrieve RestClient attributes in a ClientHttpRequestInterceptor? Remove leftover RestClient attribute methods Nov 21, 2023
@chrislhardin
Copy link

So I actually used the attributes but wasn't aware it was not working. What is the alternative to putting attributes onto the request in this? uriVariables is a HashMap that I was passing in. I don't see another way to add the request attributes other than calling url(u -> u.build(uriVariables)) but I think that is to build the actual url from its constituent components. I just want to pass the url in its entirety and then pass some variable onto it. I could expand them on the url String before I make the call I guess.

restClient.method(method).uri(url) .attributes(a -> Optional.ofNullable(uriVariables).ifPresent(v -> a.putAll(uriVariables))) .headers(httpHeaders -> httpHeaders.addAll(headers)).retrieve().toEntity(responseType);

@poutsma
Copy link
Contributor

poutsma commented Nov 27, 2023

So I actually used the attributes but wasn't aware it was not working. What is the alternative to putting attributes onto the request in this? uriVariables is a HashMap that I was passing in. I don't see another way to add the request attributes other than calling url(u -> u.build(uriVariables)) but I think that is to build the actual url from its constituent components. I just want to pass the url in its entirety and then pass some variable onto it. I could expand them on the url String before I make the call I guess.

In the WebClient, where the concept originated and is still in use, request attributes are used for propagating request-related data. This is necessary because in a reactive environment, you cannot rely on ThreadLocal. You can compare them to Servlet request attributes.

From your description, it looks like you are trying to build a URI with query parameters based on a map. You can do that by doing something like:

restClient.method(method)
  .uri(uriBuilder -> uriBuilder.queryParams(queryParams).build())
  .retrieve()
  ...

@chrislhardin
Copy link

yeah I saw that but I was missing the url part so I ended up with this. I haven't tested it yet.

restClient.method(method).uri(url, uriBuilder -> uriBuilder.queryParams(uriVariables).build()) .headers(httpHeaders -> httpHeaders.addAll(headers)).retrieve().toEntity(responseType);

@sbrannen sbrannen changed the title Remove leftover RestClient attribute methods Remove leftover RestClient attribute methods Jan 14, 2024
@KrishnaST

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: task A general task
Projects
None yet
Development

No branches or pull requests

5 participants