问题
I just tried to send a long String param to the endpoint method. One of the params is List<String>
, that contains a large number of values, which look like this:
105969550886996847196,109334384788152421649,109172191656045871108,... and more
The method itself is very simple:
@ApiMethod(name = "getFullObjects")
public MyObject getFullObjects(List<String> ids) {
//body not relevant
}
It throws this:
Error Code: 400
Reason: badRequest
Message: java.lang.IllegalArgumentException: The string property ids has a value that is too long. It cannot exceed 500 characters.
Do I really can't pass more than 500 characters in one param? That would be awful... :/
Is there a way to exceed this limit or pass this data some other way?
NOTE:
This endpoint method colaborates with Android app!
NOTE 2:
If there realy, really is the limitation of 500 characters for endpoint param, wchich I can't find in any documentation for GAE, just wondering how there are list of Entities passable... some of them would sure take more than 500 chars after serialization to string.
回答1:
@Xylian, to bypass the limitation you can either break your String into multiple parameters or play with @ApiTransformer to bypass the limitation.
Other options you have:
Limit the number of characters you are sending in each one of the String. Instead of sending Strings 21 characters-long, you can send only numbers (1, 2, 10...) to represent these IDs (or whatever they are), then have a mapping table on the server to "convert" these short IDs to the long ID.
Batch several calls to the API to avoid running over the quota in only one call.
回答2:
I think I found the best solution possible.
But first...
Since Google App Engine developers group was abandoned by googlers and moved here I officialy post it as a bug. This is a ridicolous limitation, that only annoys serious developers and I just had to bypass it. Please remove undocumented limiation of 500 chars in endpoint method param!
To the solution then...
I've decided to define a a new servlet that would handle this instead of endpoint method. Here it is:
public class LongParamTestServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String paramsString = req.getParameter("params");
resp.getWriter().write("string length: " + paramsString.length());
}
}
Then I made a request to this servlet with some very long param...
And now the response...
string length: 1664
Viola! Just passed to my Google App Engine backend param of length 1664. I'll just serialize it as a json, and return a json in response too. Not as comfortable as an endpoint method but it works.
来源:https://stackoverflow.com/questions/23942383/the-string-property-has-a-value-that-is-too-long-it-cannot-exceed-500-character