GWT 查询仅第二次失败
您好,
我在 GWT 中有一个可视化功能,它需要相同面板的两个实例 - 两个查询。现在,假设一个 url 是 A,另一个 url 是 B。在这里,我面临一个问题,如果首先调用 A,那么 A 和 B 都可以工作。如果首先调用 B,则只有 B 有效,A - 超时。如果我两次调用 A,则只有第一次 A 有效,第二次超时。如果我调用B两次,它两次都会顺利运行。
即使错误出现在超时时,它实际上并没有超时 - 在 FF 状态栏中,它显示直到 - 从 A 传输数据,然后就卡住了。这甚至不会出现在第一次查询中。
A 和 B 之间的唯一区别是 B 返回速度非常快,而 A 返回速度相对较慢。
示例代码如下:
public Panel(){
Runnable onLoadCallback = new Runnable() {
public void run() {
Query query = Query.create(dataUrl);
query.setTimeout(60);
query.send(new Callback() {
public void onResponse(QueryResponse response) {
if (response.isError()){
Window.alert(response.getMessage());
}
}
}
}
VisualizationUtils.loadVisualizationApi(onLoadCallback, PieChart.PACKAGE);
}
这可能是什么原因?我想不出为什么会发生这种情况?为什么这种情况只发生在A而不是B?
编辑:更多研究。
该查询始终有效(即 B 是 GWT 可视化站点中给出的示例 URL:请参阅注释 [1])。因此,我尝试在我的应用程序引擎中重现它 - 以下方式
s = "google.visualization.Query.setResponse({version:'0.6',status:'ok',sig:'106459472',table:{cols:[{id:'A',label:'Source',type:'string',pattern:''},{id:'B',label:'Percent',type:'number',pattern:'#0.01%'}],rows:[{c:[{v:'Oil'},{v:0.37,f:'37.00%'}]},{c:[{v:'Coal'},{v:0.25,f:'25.00%'}]},{c:[{v:'Natural Gas'},{v:0.23,f:'23.00%'}]},{c:[{v:'Nuclear'},{v:0.06,f:'6.00%'}]},{c:[{v:'Biomass'},{v:0.04,f:'4.00%'}]},{c:[{v:'Hydro'},{v:0.03,f:'3.00%'}]},{c:[{v:'Solar Heat'},{v:0.005,f:'0.50%'}]},{c:[{v:'Wind'},{v:0.003,f:'0.30%'}]},{c:[{v:'Geothermal'},{v:0.002,f:'0.20%'}]},{c:[{v:'Biofuels'},{v:0.002,f:'0.20%'}]},{c:[{v:'Solar photovoltaic'},{v:4.0E-4,f:'0.04%'}]}]}});";
response = HttpResponse(s, content_type="text/plain; charset=utf-8")
response['Expires'] = time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.gmtime())
return response
其中 s 是我们运行 B 查询时的数据。我也尝试添加 Expires 等,因为这似乎是唯一有区别的标头,但现在查询总是失败。
有关更多信息 - 我现在正在发送我的服务器响应与工作服务器响应之间的差异。他们看起来很相似。
HTTP/1.0 200 OK
Content-Type: text/plain
Date: Wed, 16 Jun 2010 11:07:12 GMT
Server: Google Frontend
Cache-Control: private, x-gzip-ok=""
google.visualization.Query.setResponse({version:'0.6',status:'ok',sig:'106459472',table:{cols:[{id:'A',label:'Source',type:'string',pattern:''},{id:'B',label:'Percent',type:'number',pattern:'#0.01%'}],rows:[{c:[{v:'Oil'},{v:0.37,f:'37.00%'}]},{c:[{v:'Coal'},{v:0.25,f:'25.00%'}]},{c:[{v:'Natural Gas'},{v:0.23,f:'23.00%'}]},{c:[{v:'Nuclear'},{v:0.06,f:'6.00%'}]},{c:[{v:'Biomass'},{v:0.04,f:'4.00%'}]},{c:[{v:'Hydro'},{v:0.03,f:'3.00%'}]},{c:[{v:'Solar Heat'},{v:0.005,f:'0.50%'}]},{c:[{v:'Wind'},{v:0.003,f:'0.30%'}]},{c:[{v:'Geothermal'},{v:0.002,f:'0.20%'}]},{c:[{v:'Biofuels'},{v:0.002,f:'0.20%'}]},{c:[{v:'Solar photovoltaic'},{v:4.0E-4,f:'0.04%'}]}]}});Connection closed by foreign host.
Mac$ telnet spreadsheets.google.com 80
Trying 209.85.231.100...
Connected to spreadsheets.l.google.com.
Escape character is '^]'.
GET http://spreadsheets.google.com/tq?key=pWiorx-0l9mwIuwX5CbEALA&range=A1:B12&gid=0&headers=-1
HTTP/1.0 200 OK
Content-Type: text/plain; charset=UTF-8
Date: Wed, 16 Jun 2010 11:07:58 GMT
Expires: Wed, 16 Jun 2010 11:07:58 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Server: GSE
google.visualization.Query.setResponse({version:'0.6',status:'ok',sig:'106459472',table:{cols:[{id:'A',label:'Source',type:'string',pattern:''},{id:'B',label:'Percent',type:'number',pattern:'#0.01%'}],rows:[{c:[{v:'Oil'},{v:0.37,f:'37.00%'}]},{c:[{v:'Coal'},{v:0.25,f:'25.00%'}]},{c:[{v:'Natural Gas'},{v:0.23,f:'23.00%'}]},{c:[{v:'Nuclear'},{v:0.06,f:'6.00%'}]},{c:[{v:'Biomass'},{v:0.04,f:'4.00%'}]},{c:[{v:'Hydro'},{v:0.03,f:'3.00%'}]},{c:[{v:'Solar Heat'},{v:0.005,f:'0.50%'}]},{c:[{v:'Wind'},{v:0.003,f:'0.30%'}]},{c:[{v:'Geothermal'},{v:0.002,f:'0.20%'}]},{c:[{v:'Biofuels'},{v:0.002,f:'0.20%'}]},{c:[{v:'Solar photovoltaic'},{v:4.0E-4,f:'0.04%'}]}]}});Connection closed by foreign host.
另外,请注意,App 引擎不允许 Expires 标头通过 - 这可能是原因吗?但如果这是原因,那么如果先发送B,然后发送A,则不应失败。
评论 [1] : http://spreadsheets.google.com/tq?key=pWiorx-0l9mwIuwX5CbEALA&range=A1:B12&gid=0&headers=-1
HI,
I have a visualization function in GWT which calls for two instances of the same panels - two queries. Now, suppose one url is A and the other url is B. Here, I am facing an issue in that if A is called first, then both A and B works. If B is called first, then only B works, A - times out. If I call both times A, only the first time A works, second time it times out. If I call B twice, it works both times without a hitch.
Even though the error comes at timed out, it actually is not timing out - in FF status bar, it shows till - transferring data from A, and then it gets stuck. This doesnt even show up in the first time query.
The only difference between A and B is that B returns very fast, while A returns comparitively slow.
The sample code is given below:
public Panel(){
Runnable onLoadCallback = new Runnable() {
public void run() {
Query query = Query.create(dataUrl);
query.setTimeout(60);
query.send(new Callback() {
public void onResponse(QueryResponse response) {
if (response.isError()){
Window.alert(response.getMessage());
}
}
}
}
VisualizationUtils.loadVisualizationApi(onLoadCallback, PieChart.PACKAGE);
}
What could be the reason for this? I cannot think of any reason why this should happen? Why is this happening only for A and not for B?
EDIT: More research.
The query which works all the time (i.e. B is the example URL given in GWT visualization site: see comment [1]). So, I tried in my app engine to reproduce it - the following way
s = "google.visualization.Query.setResponse({version:'0.6',status:'ok',sig:'106459472',table:{cols:[{id:'A',label:'Source',type:'string',pattern:''},{id:'B',label:'Percent',type:'number',pattern:'#0.01%'}],rows:[{c:[{v:'Oil'},{v:0.37,f:'37.00%'}]},{c:[{v:'Coal'},{v:0.25,f:'25.00%'}]},{c:[{v:'Natural Gas'},{v:0.23,f:'23.00%'}]},{c:[{v:'Nuclear'},{v:0.06,f:'6.00%'}]},{c:[{v:'Biomass'},{v:0.04,f:'4.00%'}]},{c:[{v:'Hydro'},{v:0.03,f:'3.00%'}]},{c:[{v:'Solar Heat'},{v:0.005,f:'0.50%'}]},{c:[{v:'Wind'},{v:0.003,f:'0.30%'}]},{c:[{v:'Geothermal'},{v:0.002,f:'0.20%'}]},{c:[{v:'Biofuels'},{v:0.002,f:'0.20%'}]},{c:[{v:'Solar photovoltaic'},{v:4.0E-4,f:'0.04%'}]}]}});";
response = HttpResponse(s, content_type="text/plain; charset=utf-8")
response['Expires'] = time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.gmtime())
return response
Where s is the data when we run the query for B. I tried to add Expires etc too, since that seems to be the only header which has the difference, but now, the query fails all the time.
For more info - I am now sending the difference between my server response vs the working server response. They seems to be pretty similar.
HTTP/1.0 200 OK
Content-Type: text/plain
Date: Wed, 16 Jun 2010 11:07:12 GMT
Server: Google Frontend
Cache-Control: private, x-gzip-ok=""
google.visualization.Query.setResponse({version:'0.6',status:'ok',sig:'106459472',table:{cols:[{id:'A',label:'Source',type:'string',pattern:''},{id:'B',label:'Percent',type:'number',pattern:'#0.01%'}],rows:[{c:[{v:'Oil'},{v:0.37,f:'37.00%'}]},{c:[{v:'Coal'},{v:0.25,f:'25.00%'}]},{c:[{v:'Natural Gas'},{v:0.23,f:'23.00%'}]},{c:[{v:'Nuclear'},{v:0.06,f:'6.00%'}]},{c:[{v:'Biomass'},{v:0.04,f:'4.00%'}]},{c:[{v:'Hydro'},{v:0.03,f:'3.00%'}]},{c:[{v:'Solar Heat'},{v:0.005,f:'0.50%'}]},{c:[{v:'Wind'},{v:0.003,f:'0.30%'}]},{c:[{v:'Geothermal'},{v:0.002,f:'0.20%'}]},{c:[{v:'Biofuels'},{v:0.002,f:'0.20%'}]},{c:[{v:'Solar photovoltaic'},{v:4.0E-4,f:'0.04%'}]}]}});Connection closed by foreign host.
Mac$ telnet spreadsheets.google.com 80
Trying 209.85.231.100...
Connected to spreadsheets.l.google.com.
Escape character is '^]'.
GET http://spreadsheets.google.com/tq?key=pWiorx-0l9mwIuwX5CbEALA&range=A1:B12&gid=0&headers=-1
HTTP/1.0 200 OK
Content-Type: text/plain; charset=UTF-8
Date: Wed, 16 Jun 2010 11:07:58 GMT
Expires: Wed, 16 Jun 2010 11:07:58 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Server: GSE
google.visualization.Query.setResponse({version:'0.6',status:'ok',sig:'106459472',table:{cols:[{id:'A',label:'Source',type:'string',pattern:''},{id:'B',label:'Percent',type:'number',pattern:'#0.01%'}],rows:[{c:[{v:'Oil'},{v:0.37,f:'37.00%'}]},{c:[{v:'Coal'},{v:0.25,f:'25.00%'}]},{c:[{v:'Natural Gas'},{v:0.23,f:'23.00%'}]},{c:[{v:'Nuclear'},{v:0.06,f:'6.00%'}]},{c:[{v:'Biomass'},{v:0.04,f:'4.00%'}]},{c:[{v:'Hydro'},{v:0.03,f:'3.00%'}]},{c:[{v:'Solar Heat'},{v:0.005,f:'0.50%'}]},{c:[{v:'Wind'},{v:0.003,f:'0.30%'}]},{c:[{v:'Geothermal'},{v:0.002,f:'0.20%'}]},{c:[{v:'Biofuels'},{v:0.002,f:'0.20%'}]},{c:[{v:'Solar photovoltaic'},{v:4.0E-4,f:'0.04%'}]}]}});Connection closed by foreign host.
Also, please note that App engine did not allow the Expires header to go through - can that be the reason? But if that is the reason, then it should not fail if B is sent first and then A.
Comment [1] : http://spreadsheets.google.com/tq?key=pWiorx-0l9mwIuwX5CbEALA&range=A1:B12&gid=0&headers=-1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题已经解决了。此错误的原因是 google QueryResponse 函数期望同一会话中的每个查询的响应 reqId 递增 - 我没有在任何地方看到记录。一旦 reqId 增加,它就开始正常工作。
This issue is solved. The reason for this error was that google QueryResponse function expects the response reqId to be incremented for each query in the same session - which I did not see documented anywhere. Once the reqId was incremented, it started working perfectly.