Restlet for Android:内部连接器错误 (1002) - 调用线程超时错误

发布于 2024-10-10 02:34:08 字数 2050 浏览 0 评论 0原文

我正在编写一个简单的 Android 应用程序,它与谷歌应用程序引擎上托管的宁静网络服务进行通信。 Web服务是使用Restlet框架开发的。以下是我的环境的详细信息:

  • 服务器端:Restlet v2.0.3 for GAE
  • Android 端:Restlet v2.0.3 for
  • Android Android:v2.2 API Level 8

我在 AndroidManifest.xml 中放置了以下权限:

<uses-permission android:name="android.permission.INTERNET" /> 

首先,当我正在本地开发服务器上开发 Web 服务,我能够从 Android 应用程序的 Restlet 客户端访问此 Web 服务,没有任何问题。

几天前,我将我的服务上传到 GAE 的 appspot,并使用这个新 URL 重新编译了我的 Android 应用程序。然而,这次我的应用程序似乎根本没有连接到这个网络服务。它尝试连接并阻塞大约一分钟左右,并在 logcat 中抛出此错误:

12-27 15:14:52.856: ERROR/MyActivity(362): Internal Connector Error (1002) - The calling thread timed out while waiting for a response to unblock it.
12-27 15:14:52.856: ERROR/MyActivity(362):     at org.restlet.resource.ClientResource$1.invoke(ClientResource.java:1648)
12-27 15:14:52.856: ERROR/MyActivity(362):     at $Proxy7.getAvailableItems(Native Method)
12-27 15:14:52.856: ERROR/MyActivity(362):     at com.example.activities.MyActivity$1.run(MyActivity.java:94)

我正在 GAE 上调用以下 Web 服务方法:

@Get
GetItemsResponse getAvailableItems(ItemCategory itemCategory);

此外,我在 Android 端执行此操作以绑定到 Web 服务:

    ClientResource clientResource = new ClientResource(myServiceUri);
    return clientResource.wrap(ItemsResource.class);

注意基于 appspot 的 Web 服务运行良好。我可以从外部浏览器访问该服务。它还正确地提供了一个 .jsp 文件,该文件是我的应用程序战争的一部分,并且我能够使用它。

另一方面,当 Android 应用程序尝试连接到此服务时,我什至在 appspot 仪表板中看不到任何传入请求日志。似乎 Android 请求由于某种原因甚至没有到达 GAE。

以下是我在 Android 端进行 Web 服务调用的方法...

  1. 对 Web 服务的调用发生在具有默认优先级的线程上。
  2. 该线程已生成 &在我的主要活动的 onStart 方法中开始。
  3. 同时,我在 UI 线程上呈现一个进度对话框。
  4. 一旦线程收到来自 Web 服务的任何响应,它就会使用特定值更新 SharedPreferences。如果调用返回任何错误,它会记录该错误,然后使用默认值更新 SharedPreferences。
  5. 这会导致调用我的 SharedPreferences 侦听器。然后,它取消进度对话框并呈现主 UI。

自从我将此服务移至 appspot 后,该线程总是返回,但我上面提到的例外。

我在这里做错了什么吗?为什么从 appspot 访问该服务时调用失败?如果您需要更多信息,请告诉我。

-卡扬·阿克拉

I am writing a simple android application that talks to a restful web-service hosted on google app engine. The web service is developed using the Restlet framework. Here are the details of my environment:

  • Server Side: Restlet v2.0.3 for GAE
  • Android Side: Restlet v2.0.3 for
  • Android Android: v2.2 API Level 8

I am placed the following permission in my AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET" /> 

At first, when I was developing the web service on my local development server, I was able to access this web service from within the Restlet client of my android app without any issues.

A few days back, I uploaded my service to the GAE's appspot and recompiled my android app with this new url. However, this time my app does not seem to connect to this web service at all. It attempts to connect and blocks for about a minute or so and throws up this error in the logcat:

12-27 15:14:52.856: ERROR/MyActivity(362): Internal Connector Error (1002) - The calling thread timed out while waiting for a response to unblock it.
12-27 15:14:52.856: ERROR/MyActivity(362):     at org.restlet.resource.ClientResource$1.invoke(ClientResource.java:1648)
12-27 15:14:52.856: ERROR/MyActivity(362):     at $Proxy7.getAvailableItems(Native Method)
12-27 15:14:52.856: ERROR/MyActivity(362):     at com.example.activities.MyActivity$1.run(MyActivity.java:94)

I am calling the following web service method on GAE:

@Get
GetItemsResponse getAvailableItems(ItemCategory itemCategory);

Moreover, I am doing this on the android side to bind to the web service:

    ClientResource clientResource = new ClientResource(myServiceUri);
    return clientResource.wrap(ItemsResource.class);

Note that the appspot-based web service is working fine. I am able to access the service from the browser outside. It also properly serves a .jsp file that is part of my application war and I'm able to use it.

On the other hand, during the time when the android app tries to connect to this service, I do not even see any incoming request log in my appspot dashboard. Seems like the android request isn't even reaching GAE for some reason.

Here's how I make the web service call on the android side...

  1. The call to the web service occurs on a Thread with default priority.
  2. This thread is spawned & started inside the onStart method of my main activity.
  3. Meanwhile, I render a progress dialog on the UI thread.
  4. Once the thread receives any response from the web service, it updates the SharedPreferences with a certain value. If the call returns any error, it logs this error and then updates SharedPreferences with a default value.
  5. This causes my SharedPreferences listener to be invoked. It then cancels the progress dialog and renders the main UI.

Ever since I moved this service to appspot, the thread always returns with the exception I mentioned above.

Am I doing something wrong here ? Why does the call to this service fail when I access it from appspot ? Please let me know if you need more information.

-Kalyan Akella

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

滥情稳全场 2024-10-17 02:34:08

我在使用restlet 2.0.4和android 1.5时遇到了类似的问题。
一切在本地运行良好,但在 GAE 中部署后我遇到了相同的超时异常。

我将服务上的注释 @Get 更改为 @Put 并且它起作用了。
这向我解释了为什么该服务可以通过浏览器运行。
我不知道为什么在这种情况下 @Get 不适用于 GAE 中部署的应用程序...

I had a similar problem using restlet 2.0.4 and android 1.5.
All worked well locally but I got the same timed out exception once deployed in GAE.

I changed the annotation @Get on the service to @Put and it worked.
That explained for me why the service worked from the browser.
I don't know why in this case @Get does not work with deployed app in GAE...

戏蝶舞 2024-10-17 02:34:08

我遇到了同样的问题(也在 GAE->Android 上)

尝试使用 org.restlet.ext.net 作为您的 http 客户端。
在restlet.org上,你被告知要像这样更改客户端:

    Engine.getInstance().getRegisteredClients().add(new HttpClientHelper(null));

但是我发现它不起作用,除非你这样做:

Engine.getInstance().getRegisteredClients().clear();
Engine.getInstance().getRegisteredClients().add(new HttpClientHelper(null));

确保在你的构建路径上有org.restlet.ext.net.jar,并确保你的HttpClientHelper注册实际上是org.restlet.ext.net.HttpClientHelper。

这解决了我使用最新的 Restlet 快照时的问题,不确定它是否适用于以前的版本。

这也解决了我在restlet中遇到的一些其他问题:

  • 使用HTTPS时出现1001错误
  • 发布数据时随机通信错误

I had the same issue (also on GAE->Android)

Try using org.restlet.ext.net as your http client.
On restlet.org you are told to change clients like this:

    Engine.getInstance().getRegisteredClients().add(new HttpClientHelper(null));

However i have found that it does not work unless you do:

Engine.getInstance().getRegisteredClients().clear();
Engine.getInstance().getRegisteredClients().add(new HttpClientHelper(null));

Make sure to have org.restlet.ext.net.jar on your buildpath, and make sure that the HttpClientHelper you register is actually org.restlet.ext.net.HttpClientHelper.

This solved the issue for me when using the latest snapshot of restlet, not sure if it works on previous releases.

This also sorted out some other issues i had with restlet:

  • 1001 error when using HTTPS
  • Communication Error randomly when posting data
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文