Cannot have an @RequestMapping and @FrameworkMapping mapped to the same endpoint with different HTTP methods
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
Comienza rastreando DispatcherServlet a través de RequestMappingInfoHandlerMapping y FrameworkMappingHandlerMapping, usando el ejemplo de CartEndpoint y CustomCartEndpoint como reproducción. Identifica dónde la asignación GET impide la resolución posterior y, a continuación, verifica que las asignaciones GET y POST equivalentes puedan resolverse con ambas anotaciones sin el workaround descrito.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
The body of this issue was copied over from BroadleafCommerce/Issues#3.
Initially reported at https://stackoverflow.com/questions/45652009/broadleaf-apis-not-working
The example where this fails is CartEndpoint. We have an extension of the Broadleaf CartEndpoint called CustomCartEndpoint in DemoSite. The problem is that we overwrote the exact same URL that exists in the API module. So we essentially have this situation:
@FrameworkMapping(value = "/cart", method = RequestMethod.POST)
public OrderWrapper createNewCartForCustomer(HttpServletRequest request) {
...
}
@RequestMapping(value = "/cart", method = RequestMethod.GET)
public OrderWrapper findCartForCustomer(HttpServletRequest request) {
...
}
The problem is when the DispatcherServlet goes looking for a HandlerMapping to resolve the current request, it first consults the default RequestMappingInfoHandlerMapping (which is where all of the @RequestMapping endpoints go). The RequestMappingInfoHandlerMapping essentially only looks for something that matches the URL string and results in a partial mapping for the findCartForCustomer() method (which is a GET). Thus, it throws a 405 method not allowed rather than continue to send the request downstream to be handled by FrameworkMappingHandlerMapping, which is where all of the @FrameworkMapping methods are.
The workaround is to in CustomCartEndpoint in DemoSite extend the createNewCartForCustomer() method, put @RequestMapping on it and just call super. Thus, the final CustomCartEndpoint will look like:
@RestController
@RequestMapping(value = "/cart",
produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
public class CustomCartEndpoint extends CartEndpoint {
@Override
@RequestMapping(value = "", method = RequestMethod.GET)
public OrderWrapper findCartForCustomer(HttpServletRequest request) {
try {
return super.findCartForCustomer(request);
} catch (Exception e) {
// if we failed to find the cart, create a new one
return createNewCartForCustomer(request);
}
}
@Override
@RequestMapping(value = "", method = RequestMethod.POST)
public OrderWrapper createNewCartForCustomer(HttpServletRequest request) {
return super.createNewCartForCustomer(request);
}
}
- Lenguaje dominante
- Java
- Estrellas
- 2
- Forks
- 2
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de BroadleafCommerce/spring-frameworkmapping
-
Add support for Spring WebFlux Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
Todos los issues de BroadleafCommerce/spring-frameworkmapping
Issues similares
-
executions.Query — startDate and timeRange filters are sent with inverted comparison operators Abiertoarea/plugin
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
kestra-io/plugin-kestra#190 ·
-
litertlm-android AAR ships no consumer ProGuard rules → "mid == null" SIGABRT in minified apps Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
google-ai-edge/LiteRT-LM#3739 ·
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
Add canonical URLs and a sitemap Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
integra-team-red/meet-map#249 ·
-
[Studio][Bug] Cancelled create-user dialog keeps the password and admin switch for the next attempt Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
apache/rocketmq-dashboard#5064 ·