-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve ambiguous handler mapping in SeedController
Override the `@PostMapping` path pattern in `SeedController` to exclude `.xml` and `.json` suffixes, addressing a stricter behavior in Spring Boot compared to regular Spring. This resolves a potential `IllegalStateException` caused by ambiguous handler methods. - Updated `doPost` endpoint path to use regex excluding `.xml` and `.json`. - Prevents conflicts between JSON and XML payload handlers (`seedOrTruncateWithJsonPayload` and `seedOrTruncateWithXmlPayload`). - Fixes mapping collision issues observed when calling endpoints like `/rest/seed/workspace:layer.xml` under Spring Boot. This change ensures compatibility with Spring Boot's stricter handler mapping rules while maintaining functionality consistent with the base `SeedController` logic.
- Loading branch information
Showing
3 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/gwc/services/src/main/java/org/geoserver/cloud/gwc/config/services/SeedController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* (c) 2024 Open Source Geospatial Foundation - all rights reserved This code is licensed under the | ||
* GPL 2.0 license, available at the root application directory. | ||
*/ | ||
package org.geoserver.cloud.gwc.config.services; | ||
|
||
import java.io.InputStream; | ||
import java.util.Map; | ||
import javax.servlet.http.HttpServletRequest; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@Component | ||
@RestController | ||
@RequestMapping(path = "${gwc.context.suffix:}/rest") | ||
public class SeedController extends org.geowebcache.rest.controller.SeedController { | ||
|
||
/** | ||
* | ||
* {@inheritDoc} | ||
* <p> | ||
* Override for the {@code path} pattern to exclude {@code .xml} and | ||
* {@code .json} suffixes to avoid an exception like the following with | ||
* {@link #seedOrTruncateWithJsonPayload} and | ||
* {@link #seedOrTruncateWithXmlPayload}: | ||
* <pre> | ||
* <code> | ||
* java.lang.IllegalStateException: Ambiguous handler methods mapped for '.../rest/seed/workspace:layer.xml': { | ||
* public org.springframework.http.ResponseEntity org.geoserver.cloud.gwc.config.services.SeedController.seedOrTruncateWithXmlPayload(...), | ||
* public org.springframework.http.ResponseEntity org.geoserver.cloud.gwc.config.services.SeedController.doPost(...) | ||
* } | ||
* </code> | ||
* </pre> | ||
*/ | ||
@Override | ||
@PostMapping("/seed/{layer:^(?!.*\\.(?:xml|json)$).+}") | ||
public ResponseEntity<?> doPost( | ||
HttpServletRequest request, | ||
InputStream inputStream, | ||
@PathVariable String layer, | ||
@RequestParam Map<String, String> params) { | ||
|
||
return super.doPost(request, inputStream, layer, params); | ||
} | ||
} |