-
Notifications
You must be signed in to change notification settings - Fork 38k
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
Introduce request attributes in RestClient #32027
Comments
RestClient
Regarding the For both of these reasons it would be nice to have a uniform way of passing attributes to the interceptors, instead of every interceptor having to re-invent the wheel. |
In the future, please do not list multiple feature requests in a single issue, but create separate issues instead. This makes it easier to track the state of each. AttributesWith regard to attributes, it is important to understand that they were introduced into The We can of course consider introducing support for attributes in TimeoutsI am not entirely sure what you mean with the lack of options to configure timeouts. For Are these configuration options sufficient, or is there something that is lacking? |
True enough, it's possible that some of us have become too preoccupied with keeping the APIs/usage of There are helper methods in the restClient
.get()
.uri("/rest/person")
.authorization(oauth2
.clientRegistrationId("my-client-registration")
.principal("johndoe"))
.retrieve()
// ... as opposed to the monstrosity we'd have to write with today's API: restClient
.get()
.uri("/rest/person")
.headers(headers -> headers
.setBearerAuth(oauth2
.clientRegistrationId("my-client-registration")
.principal("johndoe")
.build()))
.retrieve()
// ... Note the mention of "bearer" (which should be an implementation detail, not up to the caller) and an explicit call to some sort of terminating method ( |
Re-added feedback label as an answer from @evkaky is still forthcoming. |
Hi everyone. On @Bean
RestClient myRestClient(RestClient.Builder builder) {
builder
.baseUrl("...")
.requestInterceptor((request, body, execution) -> {
String someId = RequestContextHolder.getRequestAttributes().getAttribute("someId", 0).toString();
// I need this someId to make a request to a 3rd party API,
// that 3rd party API will return a `token`, which I will attach to the header of the initial request, like this
String token = getTokenFromAuthService(someId);
request.getHeaders().setBearerAuth(token);
})
.build();
} and then, somewhere on the call site (in my case "call site" is a message handler of some queue): @Autowired
@Qualifier("myRestClient")
RestClient myRestClient;
void onDataReceive(String someId) {
RequestContextHolder.getRequestAttributes().setAttribute("someId", someId, 0);
myRestClient
.get()
.retrieve()
// ...
} |
+1 for the request attributes, for my case, I want to transfer some data to the Regarding the question about |
It seems like |
RestClient
RestClient
Thanks for the feedback, everybody, I have scheduled this issue for 6.2. |
RestClient
Use of ThreadLocals via RequestContextHolder is simply bad design. There is extra burdon of cleaning up after. +1 from me for request attributes. |
@KrishnaST this is already done. Is there something missing? Please advise. |
@bclozel am I missing something here? How to pass attributes to interceptors? |
Hi there!
When spring boot 3.2 came out, I considered switching from
WebClient
toRestClient
as the first one needs all interceptors to be written in reactive style which makes them harder to support and understand.It turns out
RestClient
doesn't provide any alternates to 2 pretty important features which are present inWebClient
and which we heavily use.attribute(key, value)
method forRestClient
. That means it's not possible to pass a value from the call site into the interceptor code. Dozen of auth interceptors become impossible to implement withRestClient
. Here is how we use them withWebClient
:WebClient
there are lots of them. An exampleAre those things something which is planned to be implemented in spring boot 3.3+ ? Or there some fundamental issues with
RestClient
underlying implementation so noattribute()
and no timeouts?The text was updated successfully, but these errors were encountered: