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

RequestPredicates fail with UnsupportedOperationException with a custom servlet path #33251

Closed
xgwcy opened this issue Jul 22, 2024 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@xgwcy
Copy link

xgwcy commented Jul 22, 2024

Define a RouterFunction:

@Bean
  RouterFunction<ServerResponse> nest() {
    return route()
            .path("/persons", builder -> builder
                .GET("/{id}", accept(MediaType.TEXT_HTML), request -> ServerResponse.ok().body("query person"))
            )
            .build();
  }

Configure the following servlet path in application.yml

spring:
  mvc:
    servlet:
      path: /api

Access the GET /api/persons/666 interface,The console throws the following error.

java.lang.UnsupportedOperationException: null
	at org.springframework.web.util.ServletRequestPathUtils$ServletRequestPath.modifyContextPath(ServletRequestPathUtils.java:221) ~[spring-web-5.3.31.jar:5.3.31]
	at org.springframework.web.servlet.function.RequestPredicates$SubPathServerRequestWrapper.requestPath(RequestPredicates.java:944) ~[spring-webmvc-5.3.31.jar:5.3.31]
	at org.springframework.web.servlet.function.RequestPredicates$SubPathServerRequestWrapper.<init>(RequestPredicates.java:933) ~[spring-webmvc-5.3.31.jar:5.3.31]
	at org.springframework.web.servlet.function.RequestPredicates$PathPatternPredicate.lambda$nest$0(RequestPredicates.java:519) ~[spring-webmvc-5.3.31.jar:5.3.31]
	at java.base/java.util.Optional.map(Optional.java:260) ~[na:na]
	at org.springframework.web.servlet.function.RequestPredicates$PathPatternPredicate.nest(RequestPredicates.java:519) ~[spring-webmvc-5.3.31.jar:5.3.31]
	at org.springframework.web.servlet.function.RouterFunctions$DefaultNestedRouterFunction.route(RouterFunctions.java:1027) ~[spring-webmvc-5.3.31.jar:5.3.31]
	at org.springframework.web.servlet.function.RouterFunctionBuilder$BuiltRouterFunction.route(RouterFunctionBuilder.java:392) ~[spring-webmvc-5.3.31.jar:5.3.31]
	at org.springframework.web.servlet.function.RouterFunctions$DifferentComposedRouterFunction.route(RouterFunctions.java:928) ~[spring-webmvc-5.3.31.jar:5.3.31]
	at org.springframework.web.servlet.function.support.RouterFunctionMapping.getHandlerInternal(RouterFunctionMapping.java:220) ~[spring-webmvc-5.3.31.jar:5.3.31]
	at org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandler(AbstractHandlerMapping.java:498) ~[spring-webmvc-5.3.31.jar:5.3.31]
	at org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1266) ~[spring-webmvc-5.3.31.jar:5.3.31]
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1048) ~[spring-webmvc-5.3.31.jar:5.3.31]
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:965) ~[spring-webmvc-5.3.31.jar:5.3.31]
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.31.jar:5.3.31]
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) ~[spring-webmvc-5.3.31.jar:5.3.31]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:529) ~[tomcat-embed-core-9.0.83.jar:4.0.FR]
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.3.31.jar:5.3.31]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:623) ~[tomcat-embed-core-9.0.83.jar:4.0.FR]

version: Spring5.x and Spring6.x

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 22, 2024
@snicoll snicoll added in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jul 22, 2024
@snicoll snicoll added this to the 6.1.x milestone Jul 22, 2024
@snicoll snicoll changed the title Is this a bug of Functional Endpoints? RequestPredicates does not work with a custom servlet path Jul 22, 2024
@snicoll snicoll changed the title RequestPredicates does not work with a custom servlet path RequestPredicates fail with UnsupportedOperationException with a custom servlet path Jul 22, 2024
@bclozel
Copy link
Member

bclozel commented Jul 22, 2024

@xgwcy we're looking into this issue. In the meantime, you can consider the following as a replacement: server.servlet.context-path=/api.

@snicoll snicoll self-assigned this Aug 7, 2024
snicoll added a commit to snicoll/spring-framework that referenced this issue Aug 7, 2024
This commit implements modifyContextPath in ServletRequestPath and
apply the same logic of concatenating the servlet path with the
context path.

Closes spring-projectsgh-33251
@snicoll snicoll closed this as completed in 76b2d13 Aug 7, 2024
@snicoll snicoll modified the milestones: 6.1.x, 6.1.12 Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants