云端点参数不应该被命名 [英] Cloud Endpoint parameter should not be named
问题描述
我想从JS应用程序发送一个 HashMap< String,String>
到我的Google App。我创建了 HashMapContainer
类,如下所示: Cloud Endpoints收集参数。
Endpoint方法定义如下:
public entity myMethod(
@Named('param1')String param1,
@Nullable @Named('param2')HashMapContainer param2){
// .. 。
}
当我运行API生成这个错误时:
com.google.api.server.spi.config.validation.ApiConfigInvalidException:
资源类型'class com.mason.server.entity方法'endpoint.myMethod'中的.HashMapContainer'
不应该被命名。
因此,我删除了 @Named
注释。 API已生成,但很明显,我没有收到JS应用程序发送的参数。我的JavaScript是这样的:
函数doTransaction(){
var req = gapi.client.myApi.endpoint。 myMethod({$ b $'param1':'FOO',
'param2':{$ b $'value1':'foofoo',
'value2':'barbar',
'value3':'foobar'
}
});
req.execute(function(data){
console.log(data);
});
$ / code>
如何获取 param2
如果我不允许使用 @Named
注释?
也许我的JavaScript错了?
Google Cloud Enpoints 文档说:
@Named:此注释表示在这里注入的
请求中的参数。使用@Named注释
的参数将注入整个请求对象。
基本上,据我了解,当您添加 @Named
注释时,参数将包含在请求URL的末尾:
http:// end_point_url?parameter1 = xxx& parameter2 = yyy
很明显,支持 为了在HTTP正文中发送一个参数,使用$ API客户端会自动发送 这在 此部分 的Google API客户端库JavaScript文档。 I want send a The Endpoint method is defined like this : When I run the API generation this error happens : Therefore, I remove the How I can get the Google Cloud Enpoints documentation says: @Named: This annotation indicates the name of the parameter in the
request that gets injected here. A parameter that is not annotated
with @Named is injected with the whole request object. Basically, as far as I understand, when you add Obviously the parameter types that support On the other hand, if you don't use In order to send a parameter within the HTTP body using the Google APIs Client Library for JavaScript, you just have to include that parameter into an object called The API client will automatically send This is explained in detail in this section of the Google APIs Client Library for JavaScript documentation. 这篇关于云端点参数不应该被命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! @Named
注释的参数类型只有少数(int,long,String,Boolean和它们的对应数组,我认为),因为你另一方面,如果你不使用 @Named $ c
resource
的对象中t,像这样:
var req = gapi.client.myApi.endpoint.myMethod({
'param1' :'FOO',
'资源':{
'param2':{$ b $'value1':'foofoo',
'value2':'barbar',
'value3':'foobar'
}
}
});
param1
in POST数据中的URL和 param2
...
HashMap<String, String>
from JS application to my Google App. I created a HashMapContainer
class such as in : Cloud Endpoints Collection Parameter.public Entity myMethod(
@Named('param1') String param1,
@Nullable @Named('param2') HashMapContainer param2) {
//...
}
com.google.api.server.spi.config.validation.ApiConfigInvalidException:
Resource type 'class com.mason.server.entity.HashMapContainer'
in method 'endpoint.myMethod' should not be named.
@Named
annotation. The API is generated but obviously, I do not receive the parameter send by the JS application. My JavaScript is like this :function doTransaction() {
var req = gapi.client.myApi.endpoint.myMethod({
'param1': 'FOO',
'param2': {
'value1':'foofoo',
'value2':'barbar',
'value3':'foobar'
}
});
req.execute(function(data) {
console.log(data);
});
}
param2
if I'm not allowed to use the @Named
annotation ?
Maybe my JavaScript is wrong?
@Named
annotation, the parameters will be included at the end of the request URL:http://end_point_url?parameter1=xxx¶meter2=yyy
@Named
annotation are only a few (int, long, String, Boolean and their correspondent arrays, I think), because you can't append a whole hashmap to the request URL!@Named
, the parameter will be included (injected) within the POST data.resource
inside the JSON-RPC request, like this:var req = gapi.client.myApi.endpoint.myMethod({
'param1': 'FOO',
'resource': {
'param2': {
'value1':'foofoo',
'value2':'barbar',
'value3':'foobar'
}
}
});
param1
in the URL and param2
in the POST data...