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

Redirection issues for spring-webflux [SPR-16704] #21245

Closed
spring-projects-issues opened this issue Apr 10, 2018 · 6 comments
Closed

Redirection issues for spring-webflux [SPR-16704] #21245

spring-projects-issues opened this issue Apr 10, 2018 · 6 comments
Assignees
Labels
in: web status: invalid

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Apr 10, 2018

cafebaby opened SPR-16704 and commented

According to the redirection test described in the official website "WebFlux Reference Documentation", I found that the redirection is not the same as described in the spring MVC format.
For example: "redirect:/some/resource", the access will be reported abnormally when running.

The exception information is as follows:

java.lang.IllegalStateException: Could not resolve view with name 'redirect:/complete'.
	at org.springframework.web.reactive.result.view.ViewResolutionResultHandler.lambda$resolveViews$3(ViewResolutionResultHandler.java:277) ~[spring-webflux-5.0.4.RELEASE.jar:5.0.4.RELEASE]
	at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:107) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.FluxOnAssembly$OnAssemblySubscriber.onNext(FluxOnAssembly.java:450) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1069) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.MonoCollectList$MonoBufferAllSubscriber.onComplete(MonoCollectList.java:117) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.FluxOnAssembly$OnAssemblySubscriber.onComplete(FluxOnAssembly.java:460) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.drain(FluxConcatMap.java:349) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.onComplete(FluxConcatMap.java:265) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.FluxOnAssembly$OnAssemblySubscriber.onComplete(FluxOnAssembly.java:460) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.Operators.complete(Operators.java:125) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:111) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:61) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.FluxOnAssembly.subscribe(FluxOnAssembly.java:252) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.FluxConcatMap.subscribe(FluxConcatMap.java:121) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.FluxOnAssembly.subscribe(FluxOnAssembly.java:252) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.MonoCollectList.subscribe(MonoCollectList.java:59) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.MonoOnAssembly.subscribe(MonoOnAssembly.java:76) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.MonoMapFuseable.subscribe(MonoMapFuseable.java:59) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.MonoOnAssembly.subscribe(MonoOnAssembly.java:76) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.MonoFlatMap.subscribe(MonoFlatMap.java:60) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.MonoOnAssembly.subscribe(MonoOnAssembly.java:76) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:150) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.FluxOnAssembly$OnAssemblySubscriber.onNext(FluxOnAssembly.java:450) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubscriber.onNext(FluxSwitchIfEmpty.java:67) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.FluxOnAssembly$OnAssemblySubscriber.onNext(FluxOnAssembly.java:450) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.Operators$ScalarSubscription.request(Operators.java:1626) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.FluxOnAssembly$OnAssemblySubscriber.request(FluxOnAssembly.java:532) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.set(Operators.java:1440) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.onSubscribe(Operators.java:1314) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.FluxOnAssembly$OnAssemblySubscriber.onSubscribe(FluxOnAssembly.java:516) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.MonoJust.subscribe(MonoJust.java:54) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.MonoCallableOnAssembly.subscribe(MonoCallableOnAssembly.java:82) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.MonoSwitchIfEmpty.subscribe(MonoSwitchIfEmpty.java:44) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.MonoOnAssembly.subscribe(MonoOnAssembly.java:76) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.MonoFlatMap.subscribe(MonoFlatMap.java:60) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.MonoOnAssembly.subscribe(MonoOnAssembly.java:76) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.MonoOnErrorResume.subscribe(MonoOnErrorResume.java:44) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.MonoOnAssembly.subscribe(MonoOnAssembly.java:76) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:150) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.FluxOnAssembly$OnAssemblySubscriber.onNext(FluxOnAssembly.java:450) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]
	at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1069) ~[reactor-core-3.1.5.RELEASE.jar:3.1.5.RELEASE]

The meaning of the error message is to use the return value as the String type to match the corresponding view instead of selecting the redirect.

By looking at the source code ViewResolutionResultHandler class. Finding the method in the handleResultResult

else if (CharSequence.class.isAssignableFrom(clazz) && !hasModelAnnotation(parameter)) {
	viewsMono = resolveViews(returnValue.toString(), locale);
}
else if (Rendering.class.isAssignableFrom(clazz)) {
	Rendering render = (Rendering) returnValue;
	HttpStatus status = render.status();
	if (status != null) {
		exchange.getResponse().setStatusCode(status);
	}
	exchange.getResponse().getHeaders().putAll(render.headers());
	model.addAllAttributes(render.modelAttributes());
	Object view = render.view();
	if (view == null) {
		view = getDefaultViewName(exchange);
	}

Discovered string is forwarded as view name.

I don't know if I understand right, but at the moment I feel my opinion is right.


Affects: 5.0.4

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 10, 2018

Sébastien Deleuze commented

Could you please share a repro project that demonstrates the issue?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 10, 2018

cafebaby commented

The first time I used this platform, I didn't know how to upload the project. But I'm sure that I modified some of the logic of the ViewResolutionResultHandler class. Now it is OK, but the source code is still not

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 10, 2018

Sébastien Deleuze commented

Redirect is expected to work correctly with WebFlux, so I would need a repro project to understand the issue you face. You can attach a zip file (using the More button) containing the project, put it on a GitHub repository or send a PR on https://github.com/spring-projects/spring-framework-issues.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 10, 2018

cafebaby commented

my project url:https://github.com/zhouzhou19950825/springwebflux/

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 10, 2018

Rossen Stoyanchev commented

The code for detecting "redirect:" is in UrlBasedViewResolver (same as in Spring MVC BTW). Perhaps you don't have any view resolver configured? So the view name simply remains unresolved.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 11, 2018

Sébastien Deleuze commented

Indeed, just adding for example spring-boot-starter-mustache dependency makes the redirect working in the repro project.

@spring-projects-issues spring-projects-issues added type: bug status: invalid in: web labels Jan 11, 2019
@spring-projects-issues spring-projects-issues removed the type: bug label Jan 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web status: invalid
Projects
None yet
Development

No branches or pull requests

2 participants