-
Notifications
You must be signed in to change notification settings - Fork 1.1k
GH 3936 : Request attribute for webclient in webflux integration has been added #3950
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,6 +201,12 @@ public void setPublisherElementTypeExpression(Expression publisherElementTypeExp | |
this.publisherElementTypeExpression = publisherElementTypeExpression; | ||
} | ||
|
||
/** | ||
* Configure expression to evaluate request attribute which will be added to webclient request attribute. | ||
* @param attributeVariablesExpression the expression to evaluate request attribute. | ||
* @since 6.0 | ||
* @see WebFluxRequestExecutingMessageHandler#evaluateAttributeVariables(Message) | ||
*/ | ||
public void setAttributeVariablesExpression(Expression attributeVariablesExpression) { | ||
artembilan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Assert.notNull(attributeVariablesExpression, "'attributeVariablesExpression' must not be null"); | ||
this.attributeVariablesExpression = attributeVariablesExpression; | ||
|
@@ -249,9 +255,11 @@ private WebClient.RequestBodySpec createRequestBodySpec(Object uri, HttpMethod h | |
|
||
requestSpec = requestSpec.headers(headers -> headers.putAll(httpRequest.getHeaders())); | ||
|
||
if(attributeVariablesExpression != null) { | ||
if (this.attributeVariablesExpression != null) { | ||
Map<String, Object> attributeMap = evaluateAttributeVariables(requestMessage); | ||
requestSpec = requestSpec.attributes(map -> map.putAll(attributeMap)); | ||
if (attributeMap != null && !attributeMap.isEmpty()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
requestSpec = requestSpec.attributes(map -> map.putAll(attributeMap)); | ||
} | ||
} | ||
|
||
BodyInserter<?, ? super ClientHttpRequest> inserter = buildBodyInserterForRequest(requestMessage, httpRequest); | ||
|
@@ -393,7 +401,8 @@ private Object createReplyFromResponse(Mono<ResponseEntity<Flux<Object>>> respon | |
.map(this::getReply); | ||
} | ||
|
||
private Map<String,Object> evaluateAttributeVariables(Message<?> requestMessage){ | ||
@SuppressWarnings("unchecked") | ||
private Map<String, Object> evaluateAttributeVariables(Message<?> requestMessage) { | ||
return this.attributeVariablesExpression.getValue(this.evaluationContext, requestMessage, Map.class); | ||
artembilan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
artembilan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -323,4 +323,5 @@ See <<./http.adoc#http-header-mapping,HTTP Header Mappings>> for more possible o | |
[[webflux-request-attribute]] | ||
=== WebFlux Request Attribute | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
Starting with Version 6, Webflux outbound request can have request attribute which can be specified in `attribute-variables-expression` attribute. This attribute will take an `expression` that should be evaluated in `Map`. | ||
Starting with version 6.0, Webflux outbound request `WebFluxRequestExecutingMessageHandler` can have request attribute which can be specified in `setAttributeVariablesExpression()`. | ||
This will take an `expression` that should be evaluated in `Map`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still would like to see a general sentence for reasoning behind these attributes. My point is that you need to convince me somehow in using this new feature from the doc. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about this? Starting with version 6.0, Webflux outbound request There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good! |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -188,9 +188,10 @@ The `ChannelSecurityInterceptor` and its annotation `@SecuredChannel` and XML `< | |
See <<./security.adoc#security,Security Support>> for more information. | ||
|
||
[[x6.0-webflux]] | ||
|
||
=== Webflux request attribute support | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blank line here between name and section body. |
||
Webclient Request attribute support has been added for outbound request.See <<./webflux.adoc#webflux-request-attribute,WebFlux Request Attribute>> for more information. | ||
|
||
Webclient Request attribute support has been added for outbound request. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
See <<./webflux.adoc#webflux-request-attribute,WebFlux Request Attribute>> for more information. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are pointing here to
private
method which is out of end-user interest.I'd say
@see WebClient.RequestBodySpec#attributes