Uh oh!
There was an error while loading. Please reload this page.
[Java][Spring] do webflux controllers the right way - #571
Conversation
jmini
commented
Jul 18, 2018
Java Technical Committee: cc @macjohnny |
cbornet
commented
Jul 18, 2018
It’s better to return a ResponseEntity to give the possibility for the implementer to set the Http status code and headers |
ilya1st
commented
Jul 18, 2018
@cbornet that is wrong way cause with ResponseEntity you have to set http status code only once, before data is fetched and computed(before you know them). And cannot change them to status you need. But you can set them with WebExchange e.g.
After you fetch your data. And this is more flexible way than using ResponseEntity and exception handlers |
@ilya1st it might be helpful for reviewing to optimize the PR. could you please
|
cbornet
commented
Jul 18, 2018
@ilya1st I'm not saying that the current implementation is OK but that we should keep the ResponseEntity. So return |
Actually the ServerWebExchange is already passed (we use it for the examples). Which is a good thing since it's the layer that gives the most flexibility (you can force the payload with untyped/raw data, etc...) |
ilya1st
commented
Jul 18, 2018
@macjohnny I've reset branch to commit with mustache fixes. |
wing328
commented
Jul 31, 2018
I've updated the Petstore samples via e5f222d. Let's see how it goes. |
cbornet
commented
Jul 31, 2018
@wing328 Note that there are still changes required on this PR |
wing328
commented
Jul 31, 2018
@cbornet thanks for the heads-up. I'm just trying to resolve the Shippable CI error. Let me update the samples one more time to see how it goes. |
ilya1st
commented
Jul 31, 2018
@cbornet We had to write our generator based on this generator class for our internal projects for webflux. There are some issues with wrong work of delegate methods and classes for example. There are to much issues to make PRs for them. For webflux case code looks slack-baked. May be better idea for springboot webflux case write separate generator from scratch? For now templates are too overloaded with cases to prevent erros there. |
IsaacDeLaRosa
commented
Aug 27, 2018
@cbornet Is support for |
cbornet
commented
Aug 27, 2018
@IsaacDeLaRosa see #913 . As for the gradle part, have you tried the gradle plugin ? |
cbornet
commented
Aug 31, 2018
Workaround with the current templates : if you need to set the status code or the headers reactively, you can do so by setting them on the @OverridepublicResponseEntity<Mono<Void>> deletePet(LongpetId, StringapiKey, ServerWebExchangeexchange) {
Mono<Void> result = Mono.empty()
.doOnSuccess(it -> exchange.getResponse().setStatusCode(HttpStatus.FORBIDDEN))
.doOnSuccess(it -> exchange.getResponse().getHeaders().add("foo", "bar"))
.then();
returnResponseEntity.status(HttpStatus.OK).body(result);
} |
jrobison153
commented
Oct 23, 2018
Chiming in here in agreement with the OP. We've been looking at the generated Spring Web Reactive interfaces and the response type wrappings seem superfluous, this is using version
From all of our testing this behaves identically to Is there a reason for this or can it be simplified to |
cbornet
commented
Oct 23, 2018
The same about ResponseEntity could be said for the non-reactive generation. I agree that it could be an option not to wrap into ResponseEntity. |
jrobison153
commented
Oct 24, 2018
Thanks for the quick response @cbornet, is this something you would be willing to take a PR for? If so would you want it conditional on option or just outright make the generator always create Flux and Mono response types? |
cbornet
commented
Oct 24, 2018
It shall be conditional with an option at least for backward compat. We can discuss on what should be the default. I don't know when I can find enough time for this... |
I'm closing this PR as the webflux gen has been fixed in another one. |
jrobison153
commented
Oct 24, 2018
will do, cheers |
Hello, there is a problem with mustache templates for spring-boot-webflux reactive case.
ResponseEntity<Mono|Flux> is wrong way for this case.
Right way is to use @RestController annotation and return directly Flux or Mono objects from controllers.
Here is patchset to make generator do it right.