Skip to content

Kotlin DSL (RouterFunctionDsl) doesn't support RenderingResponse in router function [SPR-17244] #21777

@spring-projects-issues

Description

@spring-projects-issues

Maksim Kostromin opened SPR-17244 and commented

With java, to render template engine views i can use RouterFunction<?> in routes bean:

@SpringBootApplication
public class Application {
  @Bean RouterFunction routes(final ApplicationHandlers handlers) {
    return //...skipped
        .andOther(route(GET("/").and(accept(TEXT_HTML)), handlers::index))
        ;
  }
// main skipped..

so with that, I can use both, ServerResponse:

Mono<ServerResponse> index(final ServerRequest request) {
  return ok().contentType(TEXT_HTML)
             .render("index", singletonMap("message", "Hello, World!"))
      ;
}

and RenderingResponse:

Mono<RenderingResponse> index(final ServerRequest request) {
  return create("index").modelAttribute("message", "Hello, World!")
                        .build()
      ;
}

but unfortunately I can't do similar with Kotlin DSL:

@SpringBootApplication
class App {
  @Bean fun routes() = router {
    resources("/**", ClassPathResource("/static"))
    ("/").nest {
      GET("/") {
        create("index")
            .modelAttribute("message", "hey")
            .build()
      }
    }
  }
}

see screenshot-1.png in attachment:

!screenshot-1.png|thumbnail!

Only Mono<ServerResponse> handler like so:

    ok().contentType(TEXT_HTML)
        .render("index", mapOf("message" to "hey"))

will works correctly... RenderingResponse extends ServerResponse, but unfortunately Mono<RenderingResponse> doesn't extend Mono<ServerResponse>

at the moment I can force it only with unchecked cast

see screenshot-2.png from attachment:

!screenshot-2.png|thumbnail!

GET("/") {
  val res = create("index")
      .modelAttribute("message", "hey")
      .build()
  res as Mono<ServerResponse>
}

I think it's bug

here some described source code repo: https://github.com/daggerok/spring-boot-oauth2/blob/master/src/main/java/daggerok/App.kt#L32


Regards,
Maksim Kostromin


Affects: 5.1 RC2

Reference URL: spring-projects/spring-boot#14300

Attachments:

Referenced from: commits f8a0e3d

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions