Cannot have an @RequestMapping and @FrameworkMapping mapped to the same endpoint with different HTTP methods
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
調査の方向性
まず、CartEndpoint と CustomCartEndpoint の例を再現ケースとして使用し、DispatcherServlet を RequestMappingInfoHandlerMapping と FrameworkMappingHandlerMapping を通じて追跡します。GET マッピングによって下流の解決が妨げられる箇所を特定し、その後、説明されている workaround なしで、同等の GET および POST マッピングを両方のアノテーションにまたがって解決できることを検証します。
索引モデルが issue の本文から書いたものです。
説明
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);
}
}
- 主要言語
- Java
- スター
- 2
- フォーク
- 2
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
BroadleafCommerce/spring-frameworkmapping のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
BroadleafCommerce/spring-frameworkmapping の issue をすべて見る
似ている issue
-
area/plugin
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
kestra-io/plugin-kestra#190 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
google-ai-edge/LiteRT-LM#3739 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
integra-team-red/meet-map#249 ·
-
[Studio][Bug] Cancelled create-user dialog keeps the password and admin switch for the next attempt オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
apache/rocketmq-dashboard#5064 ·