【问题标题】:Accessing request parameters from Google Cloud Endpoints that have not been named从尚未命名的 Google Cloud Endpoints 访问请求参数
【发布时间】:2014-07-10 19:33:30
【问题描述】:

我正在使用 Google Cloud Endpoints 并且有一个 GET 方法。我正在使用的前端库添加了按以下约定命名的请求参数:

bSortable_{INT}

bSortable_0 bSortable_1 bSortable_2 bSortable_3 ...

这些参数的数量总是会根据使用的列数而变化。还有很多其他命名参数也遵循相同的约定。

由于这些参数是动态命名和提供的,因此为每个参数创建一个@Nullable @Named 参数是不可行的。我想我会做的是注入 HttpServletRequest 并从请求中获取参数,但看起来 Cloud Endpoints API 可能在到达我的方法之前已经将它们剥离了。

请求 URI:

 _ah/api/myapp/v1/list?bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=true

API方法:

@ApiMethod
public getList(HttpServletRequest request) {
  int len = request.getParameterMap().size(); // len == 0
}

我怀疑这可能是设计使然。没有创建任意数量的可能超过 50 标记的命名参数,有什么建议吗?

编辑:事实上,命名参数甚至都不能解决,我希望能够像地图一样访问这些参数...

map.get("bSortable_" + myInt)
request.getParameter("bSortable_" + myInt)

【问题讨论】:

    标签: google-app-engine rest servlets cloud endpoints


    【解决方案1】:

    我认为在这种情况下,使用 Cloud Endpoints 不可能。 在你的位置,我会使用一个(坏的)解决方法,比如构建一个带有分隔符的单个命名参数。例如:

    请求 URI:

    _ah/api/myapp/v1/list?filter=bSortable_0::true||bSortable_1::true||bSortable_2::true||bSortable_3::true
    

    方法:

    @ApiMethod
    public getList({@Named} filter) {
      String[] params = filter.split("||");
    }
    

    Google Cloud Endpoints 是一个非常特殊的 REST 框架...

    【讨论】:

    • 我想这就是我正在寻找的确认。解决方法的创新想法,我正在使用的库需要修改才能执行。所以,对于这个特定的场景,我将坚持使用一个普通的旧 servlet。感谢您的回复,很高兴接受您的回答。
    猜你喜欢
    • 1970-01-01
    • 2017-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多