Skip to content

DefaultServerRequest bug with pathVariables when using MockServerRequest and MockServerWebExchange #25087

Closed
@IbrayevRamil

Description

@IbrayevRamil

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.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions