Search code examples
google-app-enginerestservletscloudendpoints

Accessing request parameters from Google Cloud Endpoints that have not been named


I'm working with Google Cloud Endpoints and have a GET method. The front-end library I'm working with adds request parameters that are named in the following convention:

bSortable_{INT}

bSortable_0 bSortable_1 bSortable_2 bSortable_3 ...

The number of these parameters will always vary depending on how many columns are being used. There are a lot of other named parameters too that follow the same convention.

Since these parameters are named and provided somewhat dynamically, it's not feasible to create a @Nullable @Named parameter for each. What I thought I would do is inject the HttpServletRequest and get the parameter from the request but it looks like the Cloud Endpoints API may have stripped these out before it reaches my method.

Request URI:

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

Api Method:

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

I suspect this may be by design. Short of creating an arbitrary number of named parameters that may breach the 50 mark, any suggestions?

EDIT: In fact, named parameters are not even a work around, I'll want to be able to access these parameters like a map...

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

Solution

  • I think in that case it's not possible with Cloud Endpoints. In your place, I would use a (bad) workaround, like building a single named parameter, with a separator. For example :

    Request URI:

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

    Method:

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

    Google Cloud Endpoints is a really special REST frameworks...