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:
我只是尝试向端点方法发送一个长字符串参数。其中一个参数是List
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... :/
我真的不能在一个参数中传递超过500个字符吗?那太糟糕了......:/
Is there a way to exceed this limit or pass this data some other way?
有没有办法超过这个限制或以其他方式传递这些数据?
NOTE:
注意:
This endpoint method colaborates with Android app!
这个端点方法与Android应用程序合作!
NOTE 2:
笔记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.
如果真的有端点参数的500个字符的限制,我在GAE的任何文档中找不到,只是想知道实体列表是如何通过的...其中一些肯定会超过500个字符后序列化为字符串。
2 个解决方案
#1
0
@Xylian, to bypass the limitation you can either break your String into multiple parameters or play with @ApiTransformer to bypass the limitation.
@Xylian,为了绕过限制,您可以将String分解为多个参数,或者使用@ApiTransformer来绕过限制。
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.
限制每个字符串中发送的字符数。您可以只发送数字(1,2,10 ......)来表示这些ID(或者它们是什么),而不是发送21个字符长的字符串,然后在服务器上有一个映射表来“转换”这些短ID长ID。
-
Batch several calls to the API to avoid running over the quota in only one call.
批量调用API,以避免仅在一次调用中运行配额。
#2
0
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!
由于Google App Engine开发者小组被googlers放弃并搬到这里,我官方将其作为一个错误发布。这是一个荒谬的限制,只会让严肃的开发人员烦恼,我只能绕过它。请在端点方法参数中删除500个字符的无证件限制!
To the solution then...
到那个解决方案......
I've decided to define a a new servlet that would handle this instead of endpoint method. Here it is:
我决定定义一个新的servlet来处理这个而不是端点方法。这里是:
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...
然后我用一些非常长的参数向这个servlet提出了请求......
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.
中提琴!刚刚传递给我的Google App Engine后端参数,长度为1664.我只是将它序列化为json,并返回一个json作为响应。不像端点方法那么舒服,但它有效。
#1
0
@Xylian, to bypass the limitation you can either break your String into multiple parameters or play with @ApiTransformer to bypass the limitation.
@Xylian,为了绕过限制,您可以将String分解为多个参数,或者使用@ApiTransformer来绕过限制。
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.
限制每个字符串中发送的字符数。您可以只发送数字(1,2,10 ......)来表示这些ID(或者它们是什么),而不是发送21个字符长的字符串,然后在服务器上有一个映射表来“转换”这些短ID长ID。
-
Batch several calls to the API to avoid running over the quota in only one call.
批量调用API,以避免仅在一次调用中运行配额。
#2
0
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!
由于Google App Engine开发者小组被googlers放弃并搬到这里,我官方将其作为一个错误发布。这是一个荒谬的限制,只会让严肃的开发人员烦恼,我只能绕过它。请在端点方法参数中删除500个字符的无证件限制!
To the solution then...
到那个解决方案......
I've decided to define a a new servlet that would handle this instead of endpoint method. Here it is:
我决定定义一个新的servlet来处理这个而不是端点方法。这里是:
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...
然后我用一些非常长的参数向这个servlet提出了请求......
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.
中提琴!刚刚传递给我的Google App Engine后端参数,长度为1664.我只是将它序列化为json,并返回一个json作为响应。不像端点方法那么舒服,但它有效。