You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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 })
publicclassCustomCartEndpointextendsCartEndpoint {
@Override@RequestMapping(value = "", method = RequestMethod.GET)
publicOrderWrapperfindCartForCustomer(HttpServletRequestrequest) {
try {
returnsuper.findCartForCustomer(request);
} catch (Exceptione) {
// if we failed to find the cart, create a new onereturncreateNewCartForCustomer(request);
}
}
@Override@RequestMapping(value = "", method = RequestMethod.POST)
publicOrderWrappercreateNewCartForCustomer(HttpServletRequestrequest) {
returnsuper.createNewCartForCustomer(request);
}
}
The text was updated successfully, but these errors were encountered:
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 BroadleafCartEndpoint
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:The problem is when the
DispatcherServlet
goes looking for aHandlerMapping
to resolve the current request, it first consults the defaultRequestMappingInfoHandlerMapping
(which is where all of the@RequestMapping
endpoints go). TheRequestMappingInfoHandlerMapping
essentially only looks for something that matches the URL string and results in a partial mapping for thefindCartForCustomer()
method (which is aGET
). Thus, it throws a 405 method not allowed rather than continue to send the request downstream to be handled byFrameworkMappingHandlerMapping
, which is where all of the@FrameworkMapping
methods are.The workaround is to in
CustomCartEndpoint
in DemoSite extend thecreateNewCartForCustomer()
method, put@RequestMapping
on it and just call super. Thus, the finalCustomCartEndpoint
will look like:The text was updated successfully, but these errors were encountered: