Skip to content

Consider adding request attribute support for webclient in webflux integration #3936

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

Closed
saxenaj opened this issue Nov 2, 2022 · 6 comments
Closed

Comments

@saxenaj
Copy link
Contributor

saxenaj commented Nov 2, 2022

Expected Behavior
It seems like webflux integration doesnt support for request attributes.

Current Behavior
Currently below code line up creating new DefaultRequestBodyUriSpec on every call
WebFluxRequestExecutingMessageHandler

Even if i pass custom webclient which has all the attributes added, above implementation ignores existing attributes in webclient.

Context
I am passing request attributes which is getting used in exchangefilter to influence the flow. This request attribute is of type String as Key and Value as a user defined object.

My expectation is to pass this information in request attributes so that it will eventually available in exchangefilter for further processing but i dont find a way to pass these request attribute in webflux integration.

There is a workaround to pass required information in headers but headers only support String key value pair. It become difficult to pass information in format of String as key and user defined object as value.

As a workaround,i end up creating my own requestexecutingmessagehandler by extending WebFluxRequestExecutingMessageHandler and adding required attributes.

@saxenaj saxenaj added status: waiting-for-triage The issue need to be evaluated and its future decided type: enhancement labels Nov 2, 2022
@artembilan
Copy link
Member

For more context: https://stackoverflow.com/questions/74215136/how-to-add-request-attribute-through-spring-webflux-integration-for-outbound-gat.

@saxenaj ,

the contribution is welcome!

I didn't look in details what is to deal with request attributes, but probably they can be resolved by SpEL expression against request message, since it really sounds like request-specific feature.

Thank you!

@artembilan artembilan added in: webflux and removed status: waiting-for-triage The issue need to be evaluated and its future decided labels Nov 2, 2022
@artembilan artembilan added this to the Backlog milestone Nov 2, 2022
@saxenaj
Copy link
Contributor Author

saxenaj commented Nov 3, 2022

Thanks @artembilan for prompt response. I will be happy to contribute.
I am planning to add a new attribute in webflux schema for outbound gateway which is similar to uri-variable-expression.

Here user can pass a map which contain key-value pair which needs to be set in request attribute in the outbound configuration xml.

In WebFluxRequestExecutingHandler , i will be evaluating using StandardEvaluationContext which is already present in application context and generates a map with key value pairs and eventually this map will be set as request attributes.
Let me know if it sounds reasonable.

@artembilan
Copy link
Member

Yep! Sounds good. With only one remark that this must not be a map of expression, but more like a single expression which has to be evaluate into a Map<String, Object>.
I mean, please, don't follow the logic we have in the AbstractHttpRequestExecutingMessageHandler for uriVariablesExpression.
It is more like what we have now in the GraphQlMessageHandler for the variablesExpression.

@saxenaj
Copy link
Contributor Author

saxenaj commented Nov 3, 2022

Ok!! I believe this is what you are referring to with VariablesExpression. In this example,i see that SupplierExpression is provided with null. In webflux outbound scenario, are we expecting user to provide the supplierExpression. Also can you pls give me an example of single expression(probably with String Key and custom object as Value) which will evaluate to Map<String, Object> using SupplierExpression. I was trying to find in Spring integration code and didnt find any.

@artembilan
Copy link
Member

No-no. don't jump too deep in details of that GraphQlMessageHandler: the new SupplierExpression<>(() -> null) is just a default "no value" expression.
Of course end-user is going to set anything else into the setAttributesExpression(Expression attributesExpression).
Any Expression impl is valid. Mostly we really talk about a SpEL, which is going to be supplied from the mentioned XML config.
Here you can find docs about SpEL and its map support: https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#expressions-inline-maps.

@saxenaj
Copy link
Contributor Author

saxenaj commented Nov 17, 2022

Hi @artembilan - I have went through the contribution guide and created a PR for this issue #3950.
Pls review it and let me know if there are any changes needed.

@artembilan artembilan modified the milestones: Backlog, 6.0.0 Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants