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

Cannot build link using Spring-MVC and router functions dsl #1964

Open
NoxFr opened this issue Apr 26, 2023 · 1 comment
Open

Cannot build link using Spring-MVC and router functions dsl #1964

NoxFr opened this issue Apr 26, 2023 · 1 comment
Assignees
Labels

Comments

@NoxFr
Copy link

NoxFr commented Apr 26, 2023

Trying to add spring-hateoas in a Spring-Mvc / Kotlin / router functions DSL context.

Constructing link with :

fun Survey.toDto(): SurveyDto {
    return SurveyDto(
        id = id,
        description = description,
        questions = questions.map { it.toDto() },
        tags = tags.map { it.toDto() },
        state = state.name,
        createdAt = createdAt,
        updatedAt = updatedAt
    ).add(SurveyHandler::class) {
        linkTo { getSurvey(id.toString()) } withRel SELF
    }
}

With SurveryService

@Component
class SurveyHandler(private val surveyService: SurveyService) {
    private val logger = KotlinLogging.logger {}

    fun getSurvey(id: String): SurveyDto {
        logger.info { "Calling GET survey with id: $id" }
        return surveyService.findSurvey(UUID.fromString(id)).toDto()
    }

And Routing

@Configuration
class RoutesConfiguration(private val surveyHandler: SurveyHandler) {
    @Bean
    fun surveyRoutes() = router {
        "/v1/admin/survey".nest {
            GET("/{id}") {
                ok().body(surveyHandler.getSurvey(it.pathVariable("id")))
            }
        }
        onError<Exception>(::handleExceptions)
    }

}

Throws exception
java.lang.IllegalArgumentException: No mapping found for public com.liksi.questionr.server.survey.dto.SurveyDto com.liksi.questionr.server.survey.handler.SurveyHandler.getSurvey(java.lang.String)!

As seen here it seems to only handle @RequestMapping annotated method :
https://github.com/spring-projects/spring-hateoas/blob/main/src/main/java/org/springframework/hateoas/server/core/SpringAffordanceBuilder.java

Am i missing something ?

@odrotbohm
Copy link
Member

You don't. There's currently no support for that, as we rely on being able to find the mapping information by inspecting the methods of the class pointed to by the method used in linkTo. I'll have to take this back to the core Spring team for options how to fix that.

@odrotbohm odrotbohm self-assigned this May 3, 2023
@odrotbohm odrotbohm added type: enhancement in: core Core parts of the project kotlin labels May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants