【问题标题】:Broadleaf APIs not working阔叶 API 不工作
【发布时间】:2018-01-20 23:07:34
【问题描述】:

我正在尝试使用 Broadleaf API 在消费者应用程序上创建购物车、添加商品和结帐。 克隆 Demo 应用程序并根据链接修改配置: https://www.broadleafcommerce.com/docs/core/current/broadleaf-concepts/rest/rest-tutorials

问题: 1. 新建购物车-> 发布:http://localhost:8080/api/v1/cart 异常:HttpRequestMethodNotSupportedException:不支持请求方法“POST” 使用 GET 请求:有效

  1. 添加产品 ID: 发布:http://localhost:8080/api/v1/cart/1?categoryId=1&customerId=100 异常:HttpRequestMethodNotSupportedException:不支持请求方法“POST” GET 请求有效,但未添加产品。

3.向订单添加付款 发布:http://localhost:8080/api/v1/cart/checkout/payment?customerId=100 如上述 URL 中所述,在正文中添加了 OrderPaymentWrapper 例外: messageKey": "queryParameterNotPresent", “消息”:“com.broadleafcommerce.rest.api.exception.BroadleafWebServicesException.queryParameterNotPresent”

或者,参考 https://demo.broadleafcommerce.org/api/v2/swagger-ui.html#/ 以根据 swagger 文档调用 API。 同样的问题,无法创建订单流。

我尝试通过在 localhost https://github.com/BroadleafCommerce/DemoSite 上运行进行调试 同样的问题。

请指教。

【问题讨论】:

  • 您使用的是哪个版本的 Broadleaf? 5.2 API(我们最新的)侦听端口 8082 和 8445,但如果您使用的是 8080,那么您似乎没有使用最新版本。正确答案取决于您使用的版本。
  • 感谢@phillipuniverse。是的,我已经克隆了最新的 Broadleaf spring boot 应用程序并运行了 API 模块。引用 localhost:8082/api/v1/swagger-ui.html (与我上面提到的相同问题,例如创建购物车说不支持 POST 请求)。无法使用 API 创建订单。如果我遗漏了什么,请提出建议。

标签: broadleaf-commerce


【解决方案1】:

这看起来像是我们的@FrameworkController 注释的一个突出问题。我在 https://github.com/BroadleafCommerce/Issues/issues/3 在 Broadleaf 中打开了一个问题,提供了有关它当前失败原因的更多信息。

解决方法是修改API项目中的CustomCartEndpoint,你必须在createNewCartForCustomer()方法中添加。 CustomCartEndpoint 的最终实现应该是这样的:

@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);
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多