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

DefaultServerRequest bug with pathVariables when using MockServerRequest and MockServerWebExchange #25087

Closed
IbrayevRamil opened this issue May 15, 2020 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket)
Milestone

Comments

@IbrayevRamil
Copy link

IbrayevRamil commented May 15, 2020

Affects: 5.2.5

Description
In 5.2.5 version MockServerRequest has been deprecated in favor of ServerRequest.create(ServerWebExchange, List)} combined with MockServerWebExchange.

Implementation of pathVariables() method in DefaultServerRequest looks like:

@Override
public Map<String, String> pathVariables() {
	return this.exchange.getAttributeOrDefault(
		RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, Collections.emptyMap());
}

And the problem is that URI_TEMPLATE_VARIABLES_ATTRIBUTE attribute is not set during creation of MockServerWebExchange.

So, it's impossible to get pathVariables from DefaultServerRequest implementation of ServerRequest when it's created from MockServerRequest and MockServerWebExchange.

Example of how I'm using MockServerRequest in tests (Spock).

final mockServerHttpRequest = MockServerHttpRequest
                .post('/foo/{bar}/{bar1}', 'var1', 'var2')
                .contentType(MediaType.APPLICATION_JSON)
                .body('{}')
final mockServerWebExchange = MockServerWebExchange.from(mockServerHttpRequest)
final mockServerRequest = ServerRequest.create(mockServerWebExchange, HandlerStrategies.withDefaults().messageReaders())

And then this mockServerRequest is passed into handler function as an argument.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 15, 2020
@IbrayevRamil IbrayevRamil changed the title DefaultServerRequest bug with pathVariables DefaultServerRequest bug with pathVariables when using MockServerRequest and MockServerWebExchange May 16, 2020
@poutsma poutsma self-assigned this Jun 8, 2020
@poutsma poutsma added in: web Issues in web modules (web, webmvc, webflux, websocket) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jun 8, 2020
@poutsma poutsma added this to the 5.2.7 milestone Jun 8, 2020
@poutsma
Copy link
Contributor

poutsma commented Jun 8, 2020

I do not see an easy way to resolve this, so I am undoing the deprecation.

@poutsma poutsma closed this as completed in 0ccf5e1 Jun 8, 2020
FelixFly pushed a commit to FelixFly/spring-framework that referenced this issue Aug 16, 2020
Setting path variables (and making sure they are available in a
HandlerFunction) is more convenient with MockServerRequest than
having to set attributes in MockServerWebExchange.

This commit removes MockServerRequest's deprecation.

Closes spring-projectsgh-25087
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)
Projects
None yet
Development

No branches or pull requests

3 participants